From f151fd91d9f1a5e82b46a00bb7e3baae2b498161 Mon Sep 17 00:00:00 2001 From: "wu.chunyang" Date: Tue, 23 Jan 2024 21:49:35 +0800 Subject: [PATCH] Change postgresql socket path to a persistent path This patch changes the default socket patch on the host from "/var/run/postgresql" to "/var/lib/postgresql-socket". ensuring that the database container starts properly after a Nova instance is restarted. Story: 2010599 Task: 47471 Change-Id: I54a53cc802bbd20bb9e2c6508919e4c8dda38f2a --- ...postgresql-socket-path-2028103b91543e4c.yaml | 7 +++++++ trove/common/constants.py | 1 + trove/guestagent/datastore/postgres/manager.py | 5 +++-- trove/guestagent/datastore/postgres/service.py | 17 ++++++++++------- .../strategies/replication/postgresql.py | 4 ++-- 5 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/fix-postgresql-socket-path-2028103b91543e4c.yaml diff --git a/releasenotes/notes/fix-postgresql-socket-path-2028103b91543e4c.yaml b/releasenotes/notes/fix-postgresql-socket-path-2028103b91543e4c.yaml new file mode 100644 index 0000000000..b0504b0224 --- /dev/null +++ b/releasenotes/notes/fix-postgresql-socket-path-2028103b91543e4c.yaml @@ -0,0 +1,7 @@ +--- + +fixes: + - | + Fix a bug where the postgresql container is unable to recover + after a reboot of the Nova instance. + `Story 2010599 `__ \ No newline at end of file diff --git a/trove/common/constants.py b/trove/common/constants.py index afb05e0775..9133feea3b 100644 --- a/trove/common/constants.py +++ b/trove/common/constants.py @@ -19,3 +19,4 @@ DOCKER_NETWORK_NAME = "database-network" DOCKER_HOST_NIC_MODE = "docker-hostnic" DOCKER_BRIDGE_MODE = "bridge" MYSQL_HOST_SOCKET_PATH = "/var/lib/mysqld" +POSTGRESQL_HOST_SOCKET_PATH = "/var/lib/postgresql-socket" diff --git a/trove/guestagent/datastore/postgres/manager.py b/trove/guestagent/datastore/postgres/manager.py index fe1a959dd3..2967a56f48 100644 --- a/trove/guestagent/datastore/postgres/manager.py +++ b/trove/guestagent/datastore/postgres/manager.py @@ -18,6 +18,7 @@ from oslo_log import log as logging from oslo_service import periodic_task from trove.common import cfg +from trove.common import constants from trove.common import exception from trove.common.notification import EndNotification from trove.common import utils @@ -212,8 +213,8 @@ class PostgresManager(manager.Manager): '/var/lib/postgresql/data': { 'bind': '/var/lib/postgresql/data', 'mode': 'rw' }, - "/var/run/postgresql": {"bind": "/var/run/postgresql", - "mode": "ro"}, + constants.POSTGRESQL_HOST_SOCKET_PATH: + {"bind": "/var/run/postgresql", "mode": "ro"}, } extra_params = f"--pg-wal-archive-dir {service.WAL_ARCHIVE_DIR}" diff --git a/trove/guestagent/datastore/postgres/service.py b/trove/guestagent/datastore/postgres/service.py index d53332ba68..ebce60f45d 100644 --- a/trove/guestagent/datastore/postgres/service.py +++ b/trove/guestagent/datastore/postgres/service.py @@ -177,7 +177,8 @@ class PgSqlApp(service.BaseDbApp): user = "%s:%s" % (CONF.database_service_uid, CONF.database_service_uid) # Create folders for postgres on localhost - for folder in ['/etc/postgresql', '/var/run/postgresql']: + for folder in ['/etc/postgresql', + constants.POSTGRESQL_HOST_SOCKET_PATH]: operating_system.ensure_directory( folder, user=CONF.database_service_uid, group=CONF.database_service_uid, force=True, @@ -185,8 +186,8 @@ class PgSqlApp(service.BaseDbApp): volumes = { "/etc/postgresql": {"bind": "/etc/postgresql", "mode": "rw"}, - "/var/run/postgresql": {"bind": "/var/run/postgresql", - "mode": "rw"}, + constants.POSTGRESQL_HOST_SOCKET_PATH: + {"bind": "/var/run/postgresql", "mode": "rw"}, "/var/lib/postgresql": {"bind": "/var/lib/postgresql", "mode": "rw"}, "/var/lib/postgresql/data": {"bind": "/var/lib/postgresql/data", @@ -240,7 +241,8 @@ class PgSqlApp(service.BaseDbApp): LOG.info("Restarting database") # Ensure folders permission for database. - for folder in ['/etc/postgresql', '/var/run/postgresql']: + for folder in ['/etc/postgresql', + constants.POSTGRESQL_HOST_SOCKET_PATH]: operating_system.ensure_directory( folder, user=CONF.database_service_uid, group=CONF.database_service_uid, force=True, @@ -341,8 +343,8 @@ class PgSqlApp(service.BaseDbApp): image = f'{docker_image}:{CONF.datastore_version}' user = "%s:%s" % (CONF.database_service_uid, CONF.database_service_uid) volumes = { - "/var/run/postgresql": {"bind": "/var/run/postgresql", - "mode": "rw"}, + constants.POSTGRESQL_HOST_SOCKET_PATH: + {"bind": "/var/run/postgresql", "mode": "rw"}, "/var/lib/postgresql": {"bind": "/var/lib/postgresql", "mode": "rw"}, "/var/lib/postgresql/data": {"bind": "/var/lib/postgresql/data", @@ -746,7 +748,8 @@ class PgSqlAdmin(object): class PostgresConnection(object): - def __init__(self, user, password=None, host='/var/run/postgresql', + def __init__(self, user, password=None, + host=constants.POSTGRESQL_HOST_SOCKET_PATH, port=5432): """Utility class to communicate with PostgreSQL. diff --git a/trove/guestagent/strategies/replication/postgresql.py b/trove/guestagent/strategies/replication/postgresql.py index 048c0751a4..19c6d8ff50 100644 --- a/trove/guestagent/strategies/replication/postgresql.py +++ b/trove/guestagent/strategies/replication/postgresql.py @@ -126,8 +126,8 @@ class PostgresqlReplicationStreaming(base.Replication): '/var/lib/postgresql/data': { 'bind': '/var/lib/postgresql/data', 'mode': 'rw' }, - "/var/run/postgresql": {"bind": "/var/run/postgresql", - "mode": "ro"}, + constants.POSTGRESQL_HOST_SOCKET_PATH: + {"bind": "/var/run/postgresql", "mode": "ro"}, } extra_params = f"--pg-wal-archive-dir {pg_service.WAL_ARCHIVE_DIR}" service.create_backup(context, snapshot_info,