postgresql-charms-single-kernel 0.0.1__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: 0.0.1
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
@@ -0,0 +1,11 @@
1
+ single_kernel_postgresql/__init__.py,sha256=F57JUcML43xgR0kpj9csryZkAoDSBPLLRjzSTHPaTd4,116
2
+ single_kernel_postgresql/abstract_charm.py,sha256=grlJCmpz8rq7_NKVkyuoK7_8I2r6DRkh5DhbtyPWna8,792
3
+ single_kernel_postgresql/config/__init__.py,sha256=k9Ud5ZZNd3l0nn8xi8AIlT45oZk8hJ542BjAFGDJzuc,140
4
+ single_kernel_postgresql/config/literals.py,sha256=4EpAnoxCEMfOCPpFD5dyAU_0h2OwAHgEX9OjTWNcaQg,527
5
+ single_kernel_postgresql/utils/__init__.py,sha256=VwAEW3wYjs99q38bid47aS6Os4s3catK4H5HfdPkp94,121
6
+ single_kernel_postgresql/utils/filesystem.py,sha256=CJ2iXqFPKM0NfqqZSTDlENOrM0RW7rmTmcuzwV0bR9A,552
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,,
@@ -5,6 +5,9 @@
5
5
  This module should contain the literals used in the charms (paths, enums, etc).
6
6
  """
7
7
 
8
+ # Permissions.
9
+ POSTGRESQL_STORAGE_PERMISSIONS = 0o700
10
+
8
11
  # Relations.
9
12
  PEER = "database-peers"
10
13
 
@@ -13,5 +16,6 @@ BACKUP_USER = "backup"
13
16
  MONITORING_USER = "monitoring"
14
17
  REPLICATION_USER = "replication"
15
18
  REWIND_USER = "rewind"
19
+ SNAP_USER = "_daemon_"
16
20
  USER = "operator"
17
21
  SYSTEM_USERS = [MONITORING_USER, REPLICATION_USER, REWIND_USER, USER]
@@ -0,0 +1,20 @@
1
+ # Copyright 2025 Canonical Ltd.
2
+ # See LICENSE file for licensing details.
3
+ """Filesystem utilities."""
4
+
5
+ import os
6
+ import pwd
7
+
8
+ from ..config.literals import SNAP_USER
9
+
10
+
11
+ def change_owner(path: str) -> None:
12
+ """Change the ownership of a file or a directory to the snap user.
13
+
14
+ Args:
15
+ path: path to a file or directory.
16
+ """
17
+ # Get the uid/gid for the snap user.
18
+ user_database = pwd.getpwnam(SNAP_USER)
19
+ # Set the correct ownership for the file or directory.
20
+ os.chown(path, uid=user_database.pw_uid, gid=user_database.pw_gid)
@@ -20,14 +20,18 @@ Any charm using this library should import the `psycopg2` or `psycopg2-binary` d
20
20
  """
21
21
 
22
22
  import logging
23
+ import os
24
+ import pwd
23
25
  from collections import OrderedDict
26
+ from datetime import datetime, timezone
24
27
  from typing import Dict, List, Optional, Set, Tuple
25
28
 
26
29
  import psycopg2
27
30
  from ops import ConfigData
28
31
  from psycopg2.sql import SQL, Identifier, Literal
29
32
 
30
- from ..config.literals import BACKUP_USER, SYSTEM_USERS
33
+ from ..config.literals import BACKUP_USER, POSTGRESQL_STORAGE_PERMISSIONS, SNAP_USER, SYSTEM_USERS
34
+ from .filesystem import change_owner
31
35
 
32
36
  # Groups to distinguish HBA access
33
37
  ACCESS_GROUP_IDENTITY = "identity_access"
@@ -1071,6 +1075,32 @@ class PostgreSQL:
1071
1075
  cursor = connection.cursor()
1072
1076
 
1073
1077
  if temp_location is not None:
1078
+ # Fix permissions on the temporary tablespace location when a reboot happens and tmpfs is being used.
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
+ )
1102
+
1103
+ # Ensure a fresh temp tablespace exists at the expected location.
1074
1104
  cursor.execute("SELECT TRUE FROM pg_tablespace WHERE spcname='temp';")
1075
1105
  if cursor.fetchone() is None:
1076
1106
  cursor.execute(f"CREATE TABLESPACE temp LOCATION '{temp_location}';")
@@ -1,10 +0,0 @@
1
- single_kernel_postgresql/__init__.py,sha256=F57JUcML43xgR0kpj9csryZkAoDSBPLLRjzSTHPaTd4,116
2
- single_kernel_postgresql/abstract_charm.py,sha256=grlJCmpz8rq7_NKVkyuoK7_8I2r6DRkh5DhbtyPWna8,792
3
- single_kernel_postgresql/config/__init__.py,sha256=k9Ud5ZZNd3l0nn8xi8AIlT45oZk8hJ542BjAFGDJzuc,140
4
- single_kernel_postgresql/config/literals.py,sha256=2McbLq3gCSFEXXgBYu52nYLb-RS088sNMYO4JZFWMSY,449
5
- single_kernel_postgresql/utils/__init__.py,sha256=VwAEW3wYjs99q38bid47aS6Os4s3catK4H5HfdPkp94,121
6
- single_kernel_postgresql/utils/postgresql.py,sha256=_N9y_fcr2l8tNscfgZ5dYnWFMp8NvV9bydFmEUmntsY,74191
7
- postgresql_charms_single_kernel-0.0.1.dist-info/METADATA,sha256=NMis-jmTpyfdIF2MJwaglMCVKJpXxamP47YKw4FLQeU,483
8
- postgresql_charms_single_kernel-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- postgresql_charms_single_kernel-0.0.1.dist-info/top_level.txt,sha256=fH85HKyfDV3--1JuYe-rWJmN5XTlXVXGOBO5iNA36Rk,25
10
- postgresql_charms_single_kernel-0.0.1.dist-info/RECORD,,