You can connect to your PostgreSQL database hosted on Dokku from your local machine in a couple of steps.
Expose the database
The first step involves exposing a port for the PostgreSQL database:
dokku postgres:expose <your-database-name>
Once you run the command, you'll see a similar output with a random-generated port:
-----> Service <your-database-name> exposed on port(s) [container->host]: 9999->1234
In case you forget or lose the exposed port, you can find it again with the following command:
dokku postgres:info <your-database-name>
The above command also displays other important information that you need later (username and password).
Note: make sure your VPS accepts connections on the exposed port. Additionally, add a Firewall rule that rejects all connections from all IPs except yours.
Now that your database is accessible from outside the VPS, you can use your favourite tool to connect to it.
Open the tool and fill in the fields as follows:
- General - Name -
your database name
- Connection - hostname/address -
your VPS IP
- Connection - Port -
your exposed port
- Connection - Username - `db username`
- Connection - Password -
db password
Reminder: You can retrieve all these details with the dokku postgres:info
command.

Lastly, save the details, and you're done. You can connect to your Dokku PostgreSQL database from your local machine and interact with it.
Also, check out: