I've tried to use postgresql 10 database with django 2,
when i ran
python manage.py makemigrations
python manage.py migrate
the output indicates the database is doing well.
but when i try to create a supseruser
python manage.py createsuperuser
the console actually hangs like below:
root#ca80209360d2:/app# python manage.py createsuperuser
Username (leave blank to use 'root'): tdy
Email address:
Password:
Password (again):
so after i entered the passwords, it doesn't print out super user created successfully as when I'm using sqlite..
I have to Ctrl+C:
^CTraceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/kombu/utils/functional.py", line 36, in __call__
return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/kombu/utils/functional.py", line 333, in retry_over_time
return fun(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 261, in connect
return self.connection
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 802, in connection
self._connection = self._establish_connection()
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 757, in _establish_connection
conn = self.transport.establish_connection()
File "/usr/local/lib/python3.5/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
conn.connect()
File "/usr/local/lib/python3.5/site-packages/amqp/connection.py", line 282, in connect
self.transport.connect()
File "/usr/local/lib/python3.5/site-packages/amqp/transport.py", line 109, in connect
self._connect(self.host, self.port, self.connect_timeout)
File "/usr/local/lib/python3.5/site-packages/amqp/transport.py", line 150, in _connect
self.sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 179, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/models.py", line 161, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/models.py", line 144, in _create_user
user.save(using=self._db)
File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 73, in save
super().save(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python3.5/site-packages/django/db/models/base.py", line 769, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/usr/local/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 178, in send
for receiver in self._live_receivers(sender)
File "/usr/local/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
for receiver in self._live_receivers(sender)
File "/app/api/models.py", line 17, in create_auth_token
task.delay(verification_link, instance.email)
File "/usr/local/lib/python3.5/site-packages/celery/app/task.py", line 413, in delay
return self.apply_async(args, kwargs)
File "/usr/local/lib/python3.5/site-packages/celery/app/task.py", line 536, in apply_async
**options
File "/usr/local/lib/python3.5/site-packages/celery/app/base.py", line 737, in send_task
amqp.send_task_message(P, name, message, **options)
File "/usr/local/lib/python3.5/site-packages/celery/app/amqp.py", line 554, in send_task_message
**properties
File "/usr/local/lib/python3.5/site-packages/kombu/messaging.py", line 181, in publish
exchange_name, declare,
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/kombu/messaging.py", line 187, in _publish
channel = self.channel
File "/usr/local/lib/python3.5/site-packages/kombu/messaging.py", line 209, in _get_channel
channel = self._channel = channel()
File "/usr/local/lib/python3.5/site-packages/kombu/utils/functional.py", line 38, in __call__
value = self.__value__ = self.__contract__()
File "/usr/local/lib/python3.5/site-packages/kombu/messaging.py", line 224, in <lambda>
channel = ChannelPromise(lambda: connection.default_channel)
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 819, in default_channel
self.ensure_connection()
File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 405, in ensure_connection
callback)
File "/usr/local/lib/python3.5/site-packages/kombu/utils/functional.py", line 345, in retry_over_time
sleep(1.0)
KeyboardInterrupt
Please help.
Thank You
Edit:
Below is the docker-compose.yml i used to setup the environment
version: "3.4"
services:
# PostgreSQL database
db:
# official postgres:9 with a sql file added to init django database
image: pg9init
hostname: db
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data/pgdata
- pgbackup:/pg_backups
redis:
image: redis:3
hostname: redis
rabbit:
image: rabbitmq:3
hostname: rabbit
environment:
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=mypass
ports:
- "5672:5672" # forward this port for debugging
- "15672:15672" # here can access rabbitmq management plugin
django:
# from python:3.5 with all django requirements installed
image: djangoenvimg
command: ./run_django.sh
environment:
- DJANGO_ENV=prod
- DOCKER_CONTAINER=1
volumes:
# mount current directory inside container, to avoid the need of re-building the image every time django updates.
- .:/app
ports:
- "8000:8000"
# instruct all 5 instances of djangoserver containers to share port 8000 via a load-balanced network
# called backend
depends_on:
- db
- rabbit
# Celery worker
worker:
image: djangoenvimg
command: ./run_celery.sh
environment:
- DJANGO_ENV=prod
- DOCKER_CONTAINER=1
volumes:
- .:/app
- /home/xx/Android/Sdk:/Sdk:ro
depends_on:
- rabbit
- redis
- db
# Creates the volume for postgresql database to preserve data during multiple container sessions
volumes:
pgdata:
pgbackup:
Related
I'm setting up an Amazon AWS test server with Django on which I use Postgres as a database. This was my way here:
$ sudo apt update
$ sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib
I downloaded my files from Github and created a virtual environment for it and inside I installed psycopg2.
$ pip install psycopg2
How I configured Postgres:
$ sudo -i -u postgres
$ psql
$ createuser --interactive (super user);
$ createdb Filme;
Some other information that may be useful about Postgres:
$ service postgresql status
> postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset:>
Active: active (exited) since Wed 2022-10-05 17:08:25 UTC; 20h ago
Main PID: 977 (code=exited, status=0/SUCCESS)
CPU: 1ms
Oct 05 17:08:25 ip-172-31-29-151 systemd[1]: Starting PostgreSQL RDBMS...
Oct 05 17:08:25 ip-172-31-29-151 systemd[1]: Finished PostgreSQL RDBMS.
$ pg_lsclusters
> Ver Cluster Port Status Owner Data directory Log file
14 main 5432 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
In my settings.py file of my project:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'Filme',
}
}
The error occurs when I try to run the migration to the new database:
$ (env) $ python3 manage.py migrate
> Traceback (most recent call last):
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "ubuntu" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ubuntu/Filmes/manage.py", line 22, in <module>
main()
File "/home/ubuntu/Filmes/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 114, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
return self._cursor()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
self.ensure_connection()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
with self.wrap_database_errors:
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/ubuntu/Filmes/env/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "ubuntu" does not exist
PS: I also followed the DigitalOcean tutorial, but I end up falling into an almost identical error. (https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04)
You've only configured the ENGINE and NAME settings. You have left all the other DB connection settings as default, such as the username, password, etc. So it is trying to connect to the database using the username of the current Linux user, which appears to be ubuntu. I'm guessing when you ran createuser you didn't specify a username of ubuntu and you didn't leave the password blank, so you need to set those settings in the Django database config.
Look at all those database connection settings in the Digital Ocean tutorial you linked, compared to the two settings you have configured in your settings file.
Note that since you are just running Django and Postgres on the same server, there is nothing AWS specific about your issue. It is the same as how you would configure Django/PostgreSQL on any other Linux server. If you are searching for "django connect to postgres on AWS" or something like that, (focusing on the AWS aspect of your problem, when in actuality there is no AWS aspect to your problem at all), that is probably preventing you from finding answers to your question.
I have a Django project that I'm trying to dockerize. I successfully added Django with gunicorn and nginx to Docker. However, when trying to add PostgreSQL, I encountered an issue. My Postgres container starts, but my gunicorn one doesn't start anymore, and I get this error in the logs, so it indeed seems like it comes from Postgres :
C:\Users\stephane.bernardelli>docker logs testapp-django_gunicorn-1
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 203, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 98, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 91, in handle
self.check(databases=[database])
File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 487, in check
all_issues = checks.run_checks(
File "/usr/local/lib/python3.10/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/usr/local/lib/python3.10/site-packages/django/core/checks/model_checks.py", line 36, in check_all_models
errors.extend(model.check(**kwargs))
File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1461, in check
*cls._check_indexes(databases),
File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1864, in _check_indexes
connection.features.supports_covering_indexes
File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/features.py", line 84, in is_postgresql_11
return self.connection.pg_version >= 110000
File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 354, in pg_version
with self.temporary_connection():
File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 639, in temporary_connection
with self.cursor() as cursor:
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 284, in cursor
return self._cursor()
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 260, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 243, in ensure_connection
with self.wrap_database_errors:
File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 203, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
I tried changing the host IP address of postgres in my settings, but it only changed the error, but didn't solve it.
Here is my docker-compose.yml:
version: '3.8'
services:
rabbitmq3:
image: rabbitmq:3-alpine
ports:
- 5672:5672
networks:
- main
postgres:
container_name: postgres
hostname: postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=Scripts Application
networks:
- main
ports:
- "5432:5432"
restart: on-failure
volumes:
- postgresql-data:/var/lib/postgresql/data
django_gunicorn:
volumes:
- static:/static
- media:/media
env_file:
- env
build:
context: .
ports:
- "8000:8000"
command: sh -c "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn main.wsgi:application --bind 0.0.0.0:8000"
depends_on:
- postgres
networks:
- main
nginx:
build: ./nginx
volumes:
- static:/static
- media:/media
ports:
- "80:80"
depends_on:
- django_gunicorn
networks:
- main
celery:
restart: always
build:
context: .
command: celery -A main worker -P eventlet -c 100 -l INFO
env_file:
- env
depends_on:
- rabbitmq3
- django_gunicorn
- postgres
networks:
- main
networks:
main:
volumes:
postgresql-data:
static:
media:
Dockerfile:
FROM python:3.10.5-alpine
ENV PYTHONUNBEFFERED = 1
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps
COPY ./src /app
WORKDIR /app
I have absolutely no idea where the problem could be coming from, so I'd be glad if someone could guide me on how to solve it, thank you in advance !
My RDS and web container are not connected.
But I did all the database-related settings in Django's settings, and I also set up AWS RDS properly.
What should I do more?
This is DATABASES of settings file of Django.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": env("SQL_DATABASE"),
"USER": env("SQL_USER"),
"PASSWORD": env("SQL_PASSWORD"),
"HOST": env("SQL_HOST"),
"PORT": env("SQL_PORT"),
}
}
I skipped the docker-compose.yml with nginx-proxy or TLS.
When I tested in local, I made and mounted DB containers on docker-compose, but in prod environments, I didn't make DB containers because I use AWS RDS.
Will this be a problem?
Please help me.
(ps.All of PROJECT_NAME replaced the actual project name.)
This is my docker-compose.yml
version: '3.8'
services:
web:
build:
context: .
dockerfile: prod.Dockerfile
image: project:web
command: gunicorn PROJECT_NAME.wsgi:application --bind 0.0.0.0:8000
env_file:
- envs/.env.prod
volumes:
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
expose:
- 8000
entrypoint:
- sh
- config/docker/entrypoint.prod.sh
volumes:
static_volume:
media_volume:
This is what I've got error from docker
Waiting for postgres...
PostgreSQL started
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: database "db-PROJECT_NAME-ec2" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: database "db-PROJECT_NAME-ec2" does not exist
[2021-09-18 15:09:21 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2021-09-18 15:09:21 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2021-09-18 15:09:21 +0000] [1] [INFO] Using worker: sync
[2021-09-18 15:09:21 +0000] [12] [INFO] Booting worker with pid: 12
Highly likely the reason is that the AWS RDS DB instance name differs from PostgreSQL DB name.
As per AWS RDS manual
For Databases, choose the name of the new DB instance.
On the RDS console, the details for the new DB instance appear. The DB instance has a status of creating until the DB instance is created and ready for use. When the state changes to available, you can connect to the DB instance. Depending on the DB instance class and storage allocated, it can take several minutes for the new instance to be available.
As per PostgreSQL: Documentation
dbname
Specifies the name of the database to be created. The name must be unique among all PostgreSQL databases in this cluster. The default is to create a database with the same name as the current system user.
Default dbname is postgres
So, you may want to try postgres instead db-PROJECT_NAME-ec2 as a DB name.
It worked after I followed the instructions at computingforgeeks.com/install-postgresql-on-debian-linux but I tried to run python manage.py dbbackup again today and it does not work.
I don't understand why it says No such file or directory: '/root/usr/bin/pg_dump' when the path matches the path from find . -name pg_dump
shell to postgres container
root#6d515751e154:/# pg_dump --version
pg_dump (PostgreSQL) 13.3 (Debian 13.3-1.pgdg100+1)
root#6d515751e154:/# find . -name pg_dump
./usr/lib/postgresql/13/bin/pg_dump
./usr/bin/pg_dump
base.py
DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE"),
"NAME": os.environ.get("SQL_DATABASE"),
"USER": os.environ.get("SQL_USER"),
"PASSWORD": os.environ.get("SQL_PASSWORD"),
"HOST": os.environ.get("SQL_HOST"),
"PORT": os.environ.get("SQL_PORT"),
}
}
DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS = {'location': os.path.join(BASE_DIR, '../backups')}
DBBACKUP_CONNECTORS = {
"default": {
"ENGINE": 'django.db.backends.postgresql_psycopg2',
"NAME": os.environ.get("SQL_DATABASE"),
"USER": os.environ.get("SQL_USER"),
"PASSWORD": os.environ.get("SQL_PASSWORD"),
"HOST": os.environ.get("SQL_HOST"),
"PORT": os.environ.get("SQL_PORT"),
# "DUMP_CMD": os.path.join( # Tried both of these
# os.environ['HOME'],
# "usr",
# "bin",
# "pg_dump"
# )
"DUMP_CMD": os.path.join( # Tried both of these
os.environ['HOME'],
"usr",
"lib",
"postgresql",
"13",
"bin",
"pg_dump"
)
}
}
docker-compose.yml
version: '3.8'
services:
wagtail:
build: .
container_name: wagtail
command: python /code/mysite/manage.py runserver 0.0.0.0:8000 --settings=mysite.settings.dev
restart: unless-stopped
volumes:
- .:/code
ports:
- 8000:8000
env_file:
- .env/.dev
depends_on:
- pgdb
networks:
- wagtailnet
pgdb:
image: postgres:13
container_name: pgdb
restart: unless-stopped
ports:
- 5432:5432
env_file:
- .env/.dev_db
volumes:
- pgdata:/var/lib/postgresql/data/
networks:
- wagtailnet
volumes:
pgdata:
networks:
wagtailnet:
Traceback 1:
Backing Up Database: postgres
CommandConnectorError: Error running: /root/usr/bin/pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
[Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 156, in run_command
raise exceptions.CommandConnectorError(
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 146, in run_command
process = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, env=full_env)
File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 156, in run_command
raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running: /root/usr/bin/pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
[Errno 2] No such file or directory: '/root/usr/bin/pg_dump'
Traceback 2:
Backing Up Database: postgres
CommandConnectorError: Error running: /root/usr/lib/postgresql/13/bin/pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
[Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 156, in run_command
raise exceptions.CommandConnectorError(
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 146, in run_command
process = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, env=full_env)
File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 156, in run_command
raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running: /root/usr/lib/postgresql/13/bin/pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
[Errno 2] No such file or directory: '/root/usr/lib/postgresql/13/bin/pg_dump'
Update above
I am running a django server(image python:3.8.2-slim-buster) and a postgresql(image postgres:13) database on separate docker containers. I am trying to use django-dbbackup to back up data and ran into this error.
# python manage.py dbbackup
System check identified some issues:
WARNINGS:
account.EmailAddress: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
account.EmailConfirmation: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialAccount: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialApp: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialToken: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Backing Up Database: postgres
CommandConnectorError: Error running: pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
pg_dump: server version: 13.3 (Debian 13.3-1.pgdg100+1); pg_dump version: 11.12 (Debian 11.12-0+deb10u1)
pg_dump: aborting because of server version mismatch
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 150, in run_command
raise exceptions.CommandConnectorError(
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/dbbackup/utils.py", line 118, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 61, in handle
self._save_new_backup(database)
File "/usr/local/lib/python3.8/site-packages/dbbackup/management/commands/dbbackup.py", line 74, in _save_new_backup
outputfile = self.connector.create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 78, in create_dump
dump = self._create_dump()
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 38, in _create_dump
stdout, stderr = self.run_command(cmd, env=self.dump_env)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/dbbackup/db/base.py", line 150, in run_command
raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running: pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres
pg_dump: server version: 13.3 (Debian 13.3-1.pgdg100+1); pg_dump version: 11.12 (Debian 11.12-0+deb10u1)
pg_dump: aborting because of server version mismatch
After searching for answers, I tried to update postgresql-client but it says I already have the newest version.
root#528fdf5ac614:/code/mysite# apt-get install postgresql-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
postgresql-client is already the newest version (11+200+deb10u4).
0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.
So I don't know how to proceed. Should I downgrade the database container using postgres:11.12 docker image? That means data will be lost?
Also, why does the error say dbbackup.db.exceptions.CommandConnectorError: Error running: pg_dump --host=pgdb --port=5432 --username=postgres --no-password --clean postgres ?
I have set the password in base.py like so:
base.py settings
DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE"),
"NAME": os.environ.get("SQL_DATABASE"),
"USER": os.environ.get("SQL_USER"),
"PASSWORD": os.environ.get("SQL_PASSWORD"),
"HOST": os.environ.get("SQL_HOST"),
"PORT": os.environ.get("SQL_PORT"),
}
}
DBBACKUP_CONNECTORS = {
"default": {
"USER": os.environ.get("SQL_USER"),
"PASSWORD": os.environ.get("SQL_PASSWORD"),
"HOST": os.environ.get("SQL_HOST"),
}
}
Your error is self-explanatory
pg_dump: server version: 13.3 (Debian 13.3-1.pgdg100+1); pg_dump version: 11.12 (Debian 11.12-0+deb10u1)
You should find psql as well as pg_dump for this installation under /postgres/bin/. This is the pg_dump you want to use. You can validate the version of pg_dump using
pg_dump --version
django-dbbackup allows you to specify the connector it uses to create the backup. In particular, it allows you to specify the dump command (DUMP_CMD). To specify the connector, add the following block to your settings.py:
import os # if not yet imported
DBBACKUP_CONNECTORS = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': 'xxx',
'PORT': 'xxx',
'DUMP_CMD': os.path.join(
os.environ["HOME"],
'xxx',
'bin',
'pg_dump'
)
}
}
Make desired changes as per your installation and user.
I have a Django-Celery-PostgreSQL project that should partially run in Docker. Having Redis and PostgreSQL servers running locally on the machine and using virtual environment for the project everything runs smoothly. But when I try to setup Docker instance Celery seems unable to connect to the Postgres database while Django can.
When running project in Docker I put only Django and Celery in it and set network_mode: "host". Redis and Postgres remains on the local machine. Django server itself works flawlessly reading and writing data into the Postgres database, but when I try to run Celery tasks - I get following exception (thrown by django_celery_results):
[2019-08-13 11:26:24,815: ERROR/MainProcess] Pool callback raised exception: OperationalError('could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?\n',)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/billiard/pool.py", line 1750, in safe_apply_callback
fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/worker/request.py", line 371, in on_failure
store_result=self.store_errors,
File "/usr/local/lib/python3.6/site-packages/celery/backends/base.py", line 160, in mark_as_failure
traceback=traceback, request=request)
File "/usr/local/lib/python3.6/site-packages/celery/backends/base.py", line 342, in store_result
request=request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django_celery_results/backends/database.py", line 38, in _store_result
using=using,
File "/usr/local/lib/python3.6/site-packages/django_celery_results/managers.py", line 50, in _inner
return fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django_celery_results/managers.py", line 129, in store_result
defaults=fields)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 538, in get_or_create
return self.get(**kwargs), False
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 402, in get
num = len(clone)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 256, in __len__
self._fetch_all()
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1098, in execute_sql
cursor = self.connection.cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Docker-compose:
version: '3'
services:
road_data_service:
build:
context: ./
dockerfile: ./_docker/backend/local_dev/Dockerfile
volumes:
- ./:/server
network_mode: "host"
ports:
- "8326:8000"
Dockerfile:
RUN apt-get update \
&& apt-get install -y binutils libproj-dev gdal-bin \
&& rm -rf /var/lib/apt/lists/*
WORKDIR ./
COPY ./ /server
COPY _docker/backend/local_dev/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
WORKDIR /server/
CMD python3 manage.py runserver 0.0.0.0:8000 && celery -A worker_name \
worker -l info
Turned out I messed up with the DJANGO_SETTINGS_MODULE in celery.py - Celery got common settings file and not the one intended for the local development.