Database extensions not enabled on selected database
Bug #1977940 reported by
Arturo Enrique Seijas Fernández
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_
if self.model.
elif event.database != DATABASE_NAME:
return
Related branches
~gtrkiller/charm-k8s-postgresql:master
- Tom Haddon: Approve
- Canonical IS Reviewers: Pending requested
-
Diff: 18 lines (+6/-1)1 file modifiedsrc/clientrel.py (+6/-1)
To post a comment you must log in.
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` .