psycopg2.OperationalError: server closed the connection unexpectedly
I tried setting up odoo and postgres containers in azure using docker-compose, when running them i have an issue with the server closing the connection,
That's what I get from the log in the the start of the postgres container :
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".Data page checksums are disabled.
fixing permissions on existing directory /tmp ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... okSuccess. You can now start the database server using:
pg_ctl -D /tmp -l logfile start
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
waiting for server to start....2022-10-17 14:27:53.717 UTC [758] LOG: starting PostgreSQL 13.8 (Debian 13.8-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-10-17 14:27:53.735 UTC [758] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-17 14:27:53.761 UTC [759] LOG: database system was shut down at 2022-10-17 14:27:46 UTC
2022-10-17 14:27:53.774 UTC [758] LOG: database system is ready to accept connections
done
server started/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down...2022-10-17 14:27:53.985 UTC [758] LOG: received fast shutdown request
.2022-10-17 14:27:53.999 UTC [758] LOG: aborting any active transactions
2022-10-17 14:27:54.006 UTC [758] LOG: background worker "logical replication launcher" (PID 765) exited with exit code 1
2022-10-17 14:27:54.007 UTC [760] LOG: shutting down
2022-10-17 14:27:54.090 UTC [758] LOG: database system is shut down
done
server stoppedPostgreSQL init process complete; ready for start up.
2022-10-17 14:27:54.241 UTC [696] LOG: starting PostgreSQL 13.8 (Debian 13.8-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-10-17 14:27:54.242 UTC [696] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-10-17 14:27:54.242 UTC [696] LOG: listening on IPv6 address "::", port 5432
2022-10-17 14:27:54.267 UTC [696] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-17 14:27:54.307 UTC [770] LOG: database system was shut down at 2022-10-17 14:27:54 UTC
2022-10-17 14:27:54.317 UTC [696] LOG: database system is ready to accept connections
Then that is the resulted logs from the odoo container :
2022-10-17 14:27:02,735 445 INFO ? odoo: Odoo version 15.0-20221012
2022-10-17 14:27:02,735 445 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf
2022-10-17 14:27:02,735 445 INFO ? odoo: addons paths: ['/usr/lib/python3/dist-packages/odoo/addons', '/var/lib/odoo/addons/15.0', '/mnt/extra-addons']
2022-10-17 14:27:02,735 445 INFO ? odoo: database: odoo@db:5432
2022-10-17 14:27:02,960 445 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf
2022-10-17 14:27:03,367 445 INFO ? odoo.service.server: HTTP service (werkzeug) running on localhost:8069
Exception in thread odoo.service.cron.cron0:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 445, in cron_thread
pg_conn.poll()
psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 473, in target
self.cron_thread(i)
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 457, in cron_thread
thread.start_time = None
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 162, in exit
self.close()
File "<decorator-gen-4>", line 2, in close
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 90, in check
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 379, in close
return self._close(False)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 405, in _close
self.rollback()
File "<decorator-gen-8>", line 2, in rollback
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 90, in check
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 484, in rollback
result = self._cnx.rollback()
psycopg2.InterfaceError: connection already closed
Exception in thread odoo.service.cron.cron1:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 445, in cron_thread
pg_conn.poll()
psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 473, in target
self.cron_thread(i)
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 457, in cron_thread
thread.start_time = None
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 162, in exit
self.close()
File "<decorator-gen-4>", line 2, in close
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 90, in check
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 379, in close
return self._close(False)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 405, in _close
self.rollback()
File "<decorator-gen-8>", line 2, in rollback
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 90, in check
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 484, in rollback
result = self._cnx.rollback()
psycopg2.InterfaceError: connection already closedWhen I check the postgres logs again cause the connection was open the 1st time, i get this from it (after restart) :
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".Data page checksums are disabled.
fixing permissions on existing directory /tmp ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
My docker-compose.yml :
version: '3.2'
services:
db:
image: registryodoo.azurecr.io/samples/postgres:13
volumes:
- db:/var/lib/postgresql/data/pgdata
deploy:
restart_policy:
condition: always
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: odoo
POSTGRES_DB: postgres
POSTGRES_USER: odoo
PGDATA: /tmp
healthcheck:
test: ["CMD-SHELL", "pg_isready -U odoo"]
interval: 5s
timeout: 5s
retries: 5
odoocontainer:
depends_on:
db:
condition: service_healthy
image: registryodoo.azurecr.io/samples/odoo:latest
volumes:
- data:/var/lib/odoo
- extra-addons:/mnt/extra-addons
ports:
- 8069:8069
deploy:
restart_policy:
condition: always
environment:
HOST: db
USER: odoo
PASSWORD: odoo
volumes:
data:
driver: azure_file
driver_opts:
share_name: datafileshare
storage_account_name: odooaccount1
db:
driver: azure_file
driver_opts:
share_name: dbfileshare
storage_account_name: odooaccount1
extra-addons:
driver: azure_file
driver_opts:
share_name: odoofileshare
storage_account_name: odooaccount1
Can't figure what's the origin issue and how to solve it