diff --git a/lib/charms/postgresql_k8s/v1/postgresql.py b/lib/charms/postgresql_k8s/v1/postgresql.py index 9bf411e80b..230fad343f 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,11 @@ 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) + cursor.execute("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';") if cursor.fetchone() is None: cursor.execute(f"CREATE TABLESPACE temp LOCATION '{temp_location}';")