From 944197896cb06469166bb4221ebe251ca99bb652 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Thu, 4 Sep 2025 09:48:11 -0300 Subject: [PATCH 1/2] Fix temp tablespace permissions Signed-off-by: Marcelo Henrique Neppel --- lib/charms/postgresql_k8s/v1/postgresql.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/charms/postgresql_k8s/v1/postgresql.py b/lib/charms/postgresql_k8s/v1/postgresql.py index 9bf411e80b..cdbbed5c0d 100644 --- a/lib/charms/postgresql_k8s/v1/postgresql.py +++ b/lib/charms/postgresql_k8s/v1/postgresql.py @@ -20,6 +20,8 @@ """ import logging +import os +import pwd from collections import OrderedDict from typing import Dict, List, Optional, Set, Tuple @@ -1058,6 +1060,10 @@ def set_up_database(self, temp_location: Optional[str] = None) -> None: cursor = connection.cursor() if temp_location is not None: + user = pwd.getpwnam("_daemon_") + os.chown(temp_location, uid=user.pw_uid, gid=user.pw_gid) + os.chmod(temp_location, 0o700) + cursor.execute("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';") if cursor.fetchone() is None: cursor.execute(f"CREATE TABLESPACE temp LOCATION '{temp_location}';") From 231869c9d0d59fb0db47e4dfb5a5ae0b51c4ad0d Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Thu, 4 Sep 2025 09:53:04 -0300 Subject: [PATCH 2/2] Add comment for fix Signed-off-by: Marcelo Henrique Neppel --- lib/charms/postgresql_k8s/v1/postgresql.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/charms/postgresql_k8s/v1/postgresql.py b/lib/charms/postgresql_k8s/v1/postgresql.py index cdbbed5c0d..230fad343f 100644 --- a/lib/charms/postgresql_k8s/v1/postgresql.py +++ b/lib/charms/postgresql_k8s/v1/postgresql.py @@ -1060,6 +1060,7 @@ def set_up_database(self, temp_location: Optional[str] = None) -> None: cursor = connection.cursor() if temp_location is not None: + # Fix permissions on the temporary tablespace location when a reboot happens and tmpfs is being used. user = pwd.getpwnam("_daemon_") os.chown(temp_location, uid=user.pw_uid, gid=user.pw_gid) os.chmod(temp_location, 0o700)