Database extensions not enabled on selected database

Bug #1977940 reported by Arturo Enrique Seijas Fernández
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charm-k8s-postgresql
Fix Released
High
Unassigned

Bug Description

When creating a new database and enabling extensions, the extensions are not enabled in the new database but in 'postgres' database instead.

I would have expected these extensions to be enabled in the database specified in event.database.

I paste the snippet corresponding to the code that's causing this behaviour:

def _on_database_relation_joined(self, event: pgsql.DatabaseRelationJoinedEvent):
        if self.model.unit.is_leader():
            event.database = 'indico'
            event.extensions = ['pg_trgm:public', 'unaccent:public']
        elif event.database != DATABASE_NAME:
            event.defer()
            return

Related branches

Revision history for this message
Tom Haddon (mthaddon) wrote :

The problem seems to be in https://git.launchpad.net/charm-k8s-postgresql/tree/src/clientrel.py#n127 where our connection string is hard coded with `dbname="postgres"`. We then do `pg.ensure_extensions(con, req.extensions)`, so we're always applying this to the "postgres" database. If you compare this with the machine charm (https://git.launchpad.net/postgresql-charm/tree/reactive/postgresql/client.py#n294) the connection string is `con = postgresql.connect(database=master["database"])`.

In this charm, we can see higher up in the `on_db_relation_changed` we're logging `log.info(f"Client requested {req.database=} {req.roles=} {req.extensions=}"). We should create a new connection to the database named `req.database` for use with `pg.ensure_extensions`.

Changed in charm-k8s-postgresql:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Tom Haddon (mthaddon) wrote :

This has been fixed in revision 4.

Changed in charm-k8s-postgresql:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.