postgresql-charms-single-kernel 16.0.0__py3-none-any.whl → 16.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: postgresql-charms-single-kernel
3
- Version: 16.0.0
3
+ Version: 16.0.1
4
4
  Summary: Shared and reusable code for PostgreSQL-related charms
5
5
  Author-email: Canonical Data Platform <data-platform@lists.launchpad.net>
6
6
  License-Expression: Apache-2.0
@@ -4,8 +4,8 @@ single_kernel_postgresql/config/__init__.py,sha256=k9Ud5ZZNd3l0nn8xi8AIlT45oZk8h
4
4
  single_kernel_postgresql/config/literals.py,sha256=4EpAnoxCEMfOCPpFD5dyAU_0h2OwAHgEX9OjTWNcaQg,527
5
5
  single_kernel_postgresql/utils/__init__.py,sha256=VwAEW3wYjs99q38bid47aS6Os4s3catK4H5HfdPkp94,121
6
6
  single_kernel_postgresql/utils/filesystem.py,sha256=CJ2iXqFPKM0NfqqZSTDlENOrM0RW7rmTmcuzwV0bR9A,552
7
- single_kernel_postgresql/utils/postgresql.py,sha256=DX97VTTU73lgxe-XD1vDt72Eflxr5_sfDwRdqJf32ZE,74505
8
- postgresql_charms_single_kernel-16.0.0.dist-info/METADATA,sha256=ITQ_tJx-VDpTAaNp3-GkLClq1zmK2NBUd-WIRD3MkPQ,484
9
- postgresql_charms_single_kernel-16.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- postgresql_charms_single_kernel-16.0.0.dist-info/top_level.txt,sha256=fH85HKyfDV3--1JuYe-rWJmN5XTlXVXGOBO5iNA36Rk,25
11
- postgresql_charms_single_kernel-16.0.0.dist-info/RECORD,,
7
+ single_kernel_postgresql/utils/postgresql.py,sha256=bM57IUWPX4x0u7yL68zYdlPcBs7SIDRKj28zzeMXXeI,75950
8
+ postgresql_charms_single_kernel-16.0.1.dist-info/METADATA,sha256=CcN0WZUEcOdlf2ho3l_K60JTq8qMhzanZ5NW73EcMc4,484
9
+ postgresql_charms_single_kernel-16.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ postgresql_charms_single_kernel-16.0.1.dist-info/top_level.txt,sha256=fH85HKyfDV3--1JuYe-rWJmN5XTlXVXGOBO5iNA36Rk,25
11
+ postgresql_charms_single_kernel-16.0.1.dist-info/RECORD,,
@@ -21,14 +21,16 @@ Any charm using this library should import the `psycopg2` or `psycopg2-binary` d
21
21
 
22
22
  import logging
23
23
  import os
24
+ import pwd
24
25
  from collections import OrderedDict
26
+ from datetime import datetime, timezone
25
27
  from typing import Dict, List, Optional, Set, Tuple
26
28
 
27
29
  import psycopg2
28
30
  from ops import ConfigData
29
31
  from psycopg2.sql import SQL, Identifier, Literal
30
32
 
31
- from ..config.literals import BACKUP_USER, POSTGRESQL_STORAGE_PERMISSIONS, SYSTEM_USERS
33
+ from ..config.literals import BACKUP_USER, POSTGRESQL_STORAGE_PERMISSIONS, SNAP_USER, SYSTEM_USERS
32
34
  from .filesystem import change_owner
33
35
 
34
36
  # Groups to distinguish HBA access
@@ -1074,9 +1076,31 @@ class PostgreSQL:
1074
1076
 
1075
1077
  if temp_location is not None:
1076
1078
  # Fix permissions on the temporary tablespace location when a reboot happens and tmpfs is being used.
1077
- change_owner(temp_location)
1078
- os.chmod(temp_location, POSTGRESQL_STORAGE_PERMISSIONS)
1079
+ temp_location_stats = os.stat(temp_location)
1080
+ if (
1081
+ pwd.getpwuid(temp_location_stats.st_uid).pw_name != SNAP_USER
1082
+ or temp_location_stats.st_mode != POSTGRESQL_STORAGE_PERMISSIONS
1083
+ ):
1084
+ change_owner(temp_location)
1085
+ os.chmod(temp_location, POSTGRESQL_STORAGE_PERMISSIONS)
1086
+ # Rename existing temp tablespace if it exists, instead of dropping it.
1087
+ cursor.execute("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';")
1088
+ if cursor.fetchone() is not None:
1089
+ new_name = f"temp_{datetime.now(timezone.utc).strftime('%Y%m%d%H%M%S')}"
1090
+ cursor.execute(f"ALTER TABLESPACE temp RENAME TO {new_name};")
1091
+
1092
+ # List temp tablespaces with suffix for operator follow-up cleanup and log them.
1093
+ cursor.execute(
1094
+ "SELECT spcname FROM pg_tablespace WHERE spcname LIKE 'temp_%';"
1095
+ )
1096
+ temp_tbls = sorted([row[0] for row in cursor.fetchall()])
1097
+ logger.info(
1098
+ "There are %d temp tablespaces that should be checked and removed: %s",
1099
+ len(temp_tbls),
1100
+ ", ".join(temp_tbls),
1101
+ )
1079
1102
 
1103
+ # Ensure a fresh temp tablespace exists at the expected location.
1080
1104
  cursor.execute("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';")
1081
1105
  if cursor.fetchone() is None:
1082
1106
  cursor.execute(f"CREATE TABLESPACE temp LOCATION '{temp_location}';")