To access the database from outside of the cloud, open the the cloud’s firewall using juju expose :

user@host:~$
juju expose postgresql

Once exposed, you can connect your database using the same credentials as above except the IP. This time, use the public IP assigned by the cloud provider to the PostgreSQL instance.

You can find it it with juju status:

user@host:~$
juju status postgresql
...
Unit           Workload  Agent  Machine  Public address  Ports     Message
postgresql/0*  active    idle   0        <public-ip>     5432/tcp  Primary
...
user@host:~$
psql postgresql://<username>:<password>@<public-ip>  :5432/test-db
psql (15.6 (Ubuntu 15.6-0ubuntu0.23.10.1), server 16.9 (Ubuntu 14.12-0ubuntu0.24.04.1))
Type "help" for help.

test-db=>

To close public access, run:

user@host:~$
juju unexpose postgresql