Related to:
self._db_name = f"{self._topology.application}-grafana-k8s-{self._topology.model_uuid}"
In most cases, the application name is grafana, which then makes the DB name 56 characters long. The readonly replica, as implemented by PGB, appends the suffix _readonly, making the total # of chars in the replica name 65 characters, 2 more than the limit. However, on a fresh install, the PGB charm successfully starts the Pebble service. If the pod is rescheduled for any reason, or any factor triggers a pebble restart, the Pgbouncer Pebble service fails to start, with a log indicating that the _readonly DB's name is too long. However, because on the initial install the service was running, the primary DB is created in PG and any data created before the PGB service stopped is written to PG. This means, we need to migrate all data before changing the name. But how? Will this doc help?
Please see the following repro.
- Deploy and relate the necessary charms.
juju grafana-k8s grafana --channel dev/edge --trust
juju deploy traefik-k8s trfk --channel latest/edge --trust
juju deploy pgbouncer-k8s pgbouncer --channel 1/stable --trust
juju deploy postgresql-k8s pg --channel 14/stable --trust
juju relate grafana trfk:ingress
juju relate grafana pgbouncer:database
juju relate pgbouncer pg
- The resulting deployment will be:
Model Controller Cloud/Region Version SLA Timestamp
test ck8s ck8s 3.6.21 unsupported 12:08:04-04:00
App Version Status Scale Charm Channel Rev Address Exposed Message
grafana 12.4.2 active 1 grafana-k8s dev/edge 187 10.152.183.190 no
pg 14.20 active 1 postgresql-k8s 14/stable 774 10.152.183.46 no
pgbouncer 1.21.0 active 1 pgbouncer-k8s 1/stable 520 10.152.183.94 no
trfk 2.11.0 active 1 traefik-k8s latest/edge 295 10.152.183.49 no Serving at http://10.181.160.41
Unit Workload Agent Address Ports Message
grafana/0* active idle 10.1.0.55
pg/0* active idle 10.1.0.159 Primary
pgbouncer/0* active executing 10.1.0.42
trfk/0* active idle 10.1.0.140 Serving at http://10.181.160.41
Integration provider Requirer Interface Type Message
grafana:grafana grafana:grafana grafana_peers peer
grafana:replicas grafana:replicas grafana_replicas peer
pg:database pgbouncer:backend-database postgresql_client regular
pg:database-peers pg:database-peers postgresql_peers peer
pg:restart pg:restart rolling_op peer
pg:upgrade pg:upgrade upgrade peer
pgbouncer:database grafana:pgsql postgresql_client regular
pgbouncer:pgb-peers pgbouncer:pgb-peers pgb_peers peer
pgbouncer:upgrade pgbouncer:upgrade upgrade peer
trfk:peers trfk:peers traefik_peers peer
- The
pgbouncer.ini file will be like you see below. You can see that the _readonly is already over the 63 char limit.
[databases]
grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328 = host=pg-primary.test.svc.cluster.local dbname=grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328 port=5432 auth_user=pgbouncer_auth_relation_id_8
grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328_readonly = host=pg-primary.test.svc.cluster.local dbname=grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328 port=5432 auth_user=pgbouncer_auth_relation_id_8
- Despite the exceeding of the char limit in (3), the Pebble services are running:
juju ssh --container pgbouncer pgbouncer/0 pebble services
Service Startup Current Since
logrotate enabled backoff today at 16:08 UTC
metrics_server enabled active today at 16:07 UTC
pgbouncer_0 enabled active today at 16:06 UTC
pgbouncer_1 enabled active today at 16:06 UTC
pgbouncer_2 enabled active today at 16:06 UTC
pgbouncer_3 enabled active today at 16:06 UTC
- The DB is created in PG:
juju ssh --container postgresql pg/0 bash
psql --host=10.1.0.159 --username=operator --password --list
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------------------------------------------------+---------------+----------+---------+---------+---------------------------------
grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328 | relation_id_8 | UTF8 | C | C.UTF-8 | relation_id_8=CTc/relation_id_8+
- In the meantime, I can create dashboards in Grafana which are supposed to be stored in PG. For example, get the admin password:
juju run grafana/0 get-admin-password
Now login in with the PW and username admin. Create a dashboard. That dashboard is persisted because it's in the DB.
- If I trigger the PGB pod to be created, for example, by deleting the pod once:
sudo k8s kubectl delete pod pgbouncer-0 -n test
- I see logs in Pebble logs that the DB name is too long
2026-05-07T16:18:42.566Z [pgbouncer_0] 2026-05-07 16:18:42.566 UTC [44] FATAL cannot load config file
2026-05-07T16:18:44.002Z [pgbouncer_0] 2026-05-07 16:18:44.002 UTC [45] WARNING too long db name: grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328_readonly
2026-05-07T16:18:44.002Z [pgbouncer_0] 2026-05-07 16:18:44.002 UTC [45] ERROR cannot create database, no memory?
2026-05-07T16:18:44.002Z [pgbouncer_0] 2026-05-07 16:18:44.002 UTC [45] ERROR invalid value "host=pg-primary.test.svc.cluster.local dbname=grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328 port=5432 auth_user=pgbouncer_auth_relation_id_8" for parameter grafana-grafana-k8s-b2a13106-2262-49ac-8db1-74160e5a5328_readonly in configuration (/var/lib/pgbouncer/instance_0/pgbouncer.ini:6
- The Pebble services are inactive:
Service Startup Current Since
logrotate enabled inactive -
metrics_server enabled inactive -
pgbouncer_0 enabled backoff today at 16:19 UTC
pgbouncer_1 enabled inactive -
pgbouncer_2 enabled inactive -
pgbouncer_3 enabled inactive -
The question becomes, how can I move my data from the old DB to the new one after I update the Grafana charm by reducing the length of the DB name?
Related to:
The Grafana charm currently sets the following DB name:
In most cases, the application name is
grafana, which then makes the DB name 56 characters long. The readonly replica, as implemented by PGB, appends the suffix_readonly, making the total # of chars in the replica name 65 characters, 2 more than the limit. However, on a fresh install, the PGB charm successfully starts the Pebble service. If the pod is rescheduled for any reason, or any factor triggers apebble restart, the Pgbouncer Pebble service fails to start, with a log indicating that the_readonlyDB's name is too long. However, because on the initial install the service was running, the primary DB is created in PG and any data created before the PGB service stopped is written to PG. This means, we need to migrate all data before changing the name. But how? Will this doc help?Please see the following repro.
pgbouncer.inifile will be like you see below. You can see that the_readonlyis already over the 63 char limit.juju run grafana/0 get-admin-passwordNow login in with the PW and username
admin. Create a dashboard. That dashboard is persisted because it's in the DB.sudo k8s kubectl delete pod pgbouncer-0 -n testThe question becomes, how can I move my data from the old DB to the new one after I update the Grafana charm by reducing the length of the DB name?