From 41fd24d2953a7d9d9a610331d48f28c7d684fdc7 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 19 Feb 2024 22:54:31 -0300 Subject: [PATCH] [DPE-3544] Fix large objects ownership (#349) * Fix large objects ownership Signed-off-by: Marcelo Henrique Neppel * Update library Signed-off-by: Marcelo Henrique Neppel --------- Signed-off-by: Marcelo Henrique Neppel --- lib/charms/postgresql_k8s/v0/postgresql.py | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 9b6c0c8f87..574e157780 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -35,7 +35,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 22 +LIBPATCH = 24 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" @@ -355,6 +355,13 @@ def _generate_database_privileges_statements( sql.Identifier(user), ) ) + statements.append( + """UPDATE pg_catalog.pg_largeobject_metadata +SET lomowner = (SELECT oid FROM pg_roles WHERE rolname = '{}') +WHERE lomowner = (SELECT oid FROM pg_roles WHERE rolname = '{}');""".format( + user, self.user + ) + ) else: for schema in schemas: schema = sql.Identifier(schema) @@ -572,15 +579,20 @@ def build_postgresql_parameters( if parameter in ["date_style", "time_zone"]: parameter = "".join(x.capitalize() for x in parameter.split("_")) parameters[parameter] = value - shared_buffers_max_value = int(int(available_memory * 0.4) / 10**6) + shared_buffers_max_value_in_mb = int(available_memory * 0.4 / 10**6) + shared_buffers_max_value = int(shared_buffers_max_value_in_mb * 10**3 / 8) if parameters.get("shared_buffers", 0) > shared_buffers_max_value: raise Exception( - f"Shared buffers config option should be at most 40% of the available memory, which is {shared_buffers_max_value}MB" + f"Shared buffers config option should be at most 40% of the available memory, which is {shared_buffers_max_value_in_mb}MB" ) if profile == "production": - # Use 25% of the available memory for shared_buffers. - # and the remaining as cache memory. - shared_buffers = int(available_memory * 0.25) + if "shared_buffers" in parameters: + # Convert to bytes to use in the calculation. + shared_buffers = parameters["shared_buffers"] * 8 * 10**3 + else: + # Use 25% of the available memory for shared_buffers. + # and the remaining as cache memory. + shared_buffers = int(available_memory * 0.25) effective_cache_size = int(available_memory - shared_buffers) parameters.setdefault("shared_buffers", f"{int(shared_buffers/10**6)}MB") parameters.update({"effective_cache_size": f"{int(effective_cache_size/10**6)}MB"})