Deploy on Juju storage
Charmed PostgreSQL uses Juju storage abstraction to utilize data volume provided by different clouds keeping the same UI/UX for endusers.
- Charmed PostgreSQL 16 supports multiple storage:
archive
,data
,logs
andtemp
. - Charmed PostgreSQL 14 supports single storage:
pgdata
. - Legacy PostgreSQL charm in track “latest” doesn’t support Juju Storage abstraction.
Charmed PostgreSQL 16
Check the metadata.yaml for find Juju storage name and tech details:
Charmed PostgreSQL 16 storage list
TODO
Charmed PostgreSQL 16 supports multiple storage archive
, data
, logs
and temp
. See the deployment examples below.
Charmed PostgreSQL 14
Check the metadata.yaml for find Juju storage name and tech details:
Charmed PostgreSQL 14 storage list
storage:
pgdata:
type: filesystem
location: /var/snap/charmed-postgresql/common
Charmed PostgreSQL 14 supports single storage pgdata
attaching it on juju deploy
and mounted inside the Snap common folder /var/snap/charmed-postgresql/common
.
Example of 'Juju storage'
> juju deploy postgresql
> juju storage
Unit Storage ID Type Size Status Message
postgresql/0 pgdata/0 filesystem pending
> juju storage
Unit Storage ID Type Pool Size Status Message
postgresql/0 pgdata/0 filesystem rootfs 97 GiB attached
> juju show-storage pgdata/0
pgdata/0:
kind: filesystem
life: alive
status:
current: attached
since: 01 May 2025 18:47:04+02:00
persistent: false
attachments:
units:
postgresql/0:
machine: "0"
location: /var/snap/charmed-postgresql/common
life: alive
> juju ssh postgresql/0 mount | grep /var/snap/charmed-postgresql/common
/dev/sda1 on /var/snap/charmed-postgresql/common type ext4 (rw,relatime,discard,errors=remount-ro)
Juju Storage deploy examples
Define the storage size:
> juju deploy postgresql --storage pgdata=10G
> juju storage
Unit Storage ID Type Pool Size Status Message
postgresql/1 pgdata/1 filesystem lxd 10 GiB attached
Define the storage location:
Juju supports wide list of different storage pools:
> juju create-storage-pool mystoragepool lxd
> juju storage-pools | grep mystoragepool
mystoragepool lxd
> juju deploy postgresql --storage pgdata=5G,mystoragepool
> juju storage
Unit Storage ID Type Pool Size Status Message
postgresql/2 pgdata/2 filesystem mystoragepool 5 GiB attached
Re-deploy detached storage
To re-deploy the application with old Juju Storage, it is necessary to provide all charm/db credentials/passwords as Juju User secrets. TL;DR:
# Note old passwords
> juju show-secret --reveal database-peers.postgresql.app
# Add new Juju User secret with old password values
> juju add-secret mypgpass \
monitoring-password=oQDLAVMV1AHFZq1L \
operator-password=IXarOnndC9XKoytS \
patroni-password=vWzJZIktqi0qGMCx \
raft-password=2pALATzLJsrpAf5q \
replication-password=2bcnAQhXLrX3ekVP \
rewind-password=bBqQOXiC7whSqQbR
# Find old storage id:
> juju storage
# Re-deploy new app re-using old storage and old credentials
> juju deploy postgresql \
--channel 16/candidate \
--attach-storage pgdata/5 \
--config system-users=newsecret54321id
# Grant access to new secrets for re-deployed application
> juju grant-secret mypgpass postgresql
Complete old storage re-deployment example
Prepare the test data to restore later:
# Add a new model
> juju add-model teststorage
# Deploy the new postgresql to dump storage with credentials
> juju deploy postgresql --channel 16/edge --storage pgdata=5Gcompleted
Deployed "postgresql" from charm-hub charm "postgresql", revision 613 in channel 16/edge on [email protected]/stable
# Wait for deployment completed:
> juju status
...
Unit Workload Agent Machine Public address Ports Message
postgresql/0* active idle 0 10.189.210.99 5432/tcp Primary
# Reveal the Juju secrets for the simpliest DB access:
> juju show-secret --reveal database-peers.postgresql.app
d09v83poie738j7af4n0:
revision: 2
checksum: 9e28910800d4dd94cd655d5d5f49a9bb7e4b7fbf6dde232328e4f6734c7bdf84
owner: postgresql
label: database-peers.postgresql.app
created: 2025-05-01T22:22:07Z
updated: 2025-05-01T22:22:10Z
content:
monitoring-password: 6inFApK8IyJuJ6LG
operator-password: I8mkza6vIhD2w1Rh
patroni-password: JAYSlB3mQXi9g4fc
raft-password: eFWUOCYb1lIOpGuM
replication-password: SFBx8OL9XxXiWwcC
rewind-password: 92xT4yTniiG7OEch
# Create a test data
> PGPASSWORD=I8mkza6vIhD2w1Rh psql -h 10.189.210.99 -U operator -d postgres -c "create table a (id int);"
CREATE TABLE
> PGPASSWORD=I8mkza6vIhD2w1Rh psql -h 10.189.210.99 -U operator -d postgres -c "\d"
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | a | table | operator
(1 row)
# Check the storage status
> juju storage
Unit Storage ID Type Pool Size Status Message
postgresql/0 pgdata/0 filesystem lxd 5.0 GiB attached
# Remove the old application keeping the storage:
> juju remove-application postgresql --destroy-storage=false
WARNING This command will perform the following actions:
will remove application postgresql
- will remove unit postgresql/0
- will detach storage pgdata/0
Continue [y/N]? y
# Check the status (app and secrets are gone, but storage stays):
> juju status
Model Controller Cloud/Region Version SLA Timestamp
teststorage lxd localhost/localhost 3.6.5 unsupported 00:28:44+02:00
Model "admin/teststorage" is empty.
> juju secrets
ID Name Owner Rotation Revision Last updated
> juju storage
Unit Storage ID Type Pool Size Status Message
pgdata/0 filesystem lxd 5.0 GiB detached
Re-deploy the postgresql application reusing storage pgdata/0
:
# Create a new Juju User secret
> juju add-secret mypgpass \
monitoring-password=6inFApK8IyJuJ6LG \
operator-password=I8mkza6vIhD2w1Rh \
patroni-password=JAYSlB3mQXi9g4fc \
raft-password=eFWUOCYb1lIOpGuM \
replication-password=SFBx8OL9XxXiWwcC \
rewind-password=92xT4yTniiG7OEch
secret:d09vcn1oie738j7af4ng
# Re-deploy app with old storage and old passwords
> juju deploy postgresql \
--channel 16/edge \
--attach-storage pgdata/0 \
--config system-users=d09vcn1oie738j7af4ng
Deployed "postgresql" from charm-hub charm "postgresql", revision 613 in channel 16/edge on [email protected]/stable
# Grant new application access to manually created Juju User secret
> juju grant-secret mypgpass postgresql
# Wait for deployment
> juju status
...
Unit Workload Agent Machine Public address Ports Message
postgresql/1* active idle 1 10.189.210.179 5432/tcp Primary
# Check the old data access once deployment completed (use new App IP!):
> PGPASSWORD=I8mkza6vIhD2w1Rh psql -h 10.189.210.179 -U operator -d postgres -c "\d"
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | a | table | operator
(1 row)
# Old storage re-used:
> juju storage
Unit Storage ID Type Pool Size Status Message
postgresql/1 pgdata/0 filesystem lxd 5.0 GiB attached