0

I am trying to containerize a python app and it has a postgres db which is in GCP cloud. But when I build the app its throwing an error telling the database does not exist i am unable to understand what is happening i can connect to the database by using Dbeaver tool but when I run the docker file the container is up but has some error logs. I have added the public ip of my laptop in gcp sql connections but unable to understand why it throws this error


I can see the logs that say

File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 187, 
in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  database "test-instance" does not exist

Docker file which i used

# Pull base image
FROM python:3.9

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY requirements.txt /code/
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

settings.py file how i reach out to the gcp db

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test-instance', 
        'USER': 'postgres', 
        'PASSWORD': 'abcder',
        'HOST': '35.224.136.9', 
        'PORT': '5432',
    }
}
3
  • I think you're confusing the Instance Name with DB name. Are you sure you're setting the right DB name and not the instance name? Commented Jun 15, 2022 at 19:19
  • Yes. I hope u are referring to value of name in database block which is present in settings.py? the value is db name which is test-instance this is what my postgres db is called in gcp Commented Jun 16, 2022 at 5:02
  • Issue was resolved it was cause the db i was confused with instance name and db name. Commented Jun 27, 2022 at 10:44

1 Answer 1

1

As mentioned in my comment, the OP was confusing the Instance Name with the DB name which are different things.

The Instance is the infrastructure (server) hosting the DB Engine and where the DBs are hosted.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.