diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index e548cf6b8d..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 = 23 +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) diff --git a/tests/unit/test_postgresql.py b/tests/unit/test_postgresql.py index a0ea56f646..6ea3907d4d 100644 --- a/tests/unit/test_postgresql.py +++ b/tests/unit/test_postgresql.py @@ -200,7 +200,8 @@ def test_generate_database_privileges_statements(self): ";' AS statement\nFROM pg_catalog.pg_views WHERE NOT schemaname IN ('pg_catalog', 'information_schema')) AS statements ORDER BY index) LOOP\n EXECUTE format(r.statement);\n END LOOP;\nEND; $$;" ), ] - ) + ), + "UPDATE pg_catalog.pg_largeobject_metadata\nSET lomowner = (SELECT oid FROM pg_roles WHERE rolname = 'test_user')\nWHERE lomowner = (SELECT oid FROM pg_roles WHERE rolname = 'operator');", ], ) # Test with multiple established relations.