> ## Content Index
> Fetch the complete content index at: https://catalins.tech/llms.txt
> Use this file to discover other available public pages before exploring further.

# Connect to Dokku PostgreSQL Database on Local Machine
- URL: https://catalins.tech/connect-to-dokku-postgresql-database-on-local-machine/
- Published: 2025-06-24T15:10:52.000Z
- Updated: 2025-06-24T15:24:17.000Z
- Author: Catalin Pit
- Tags: Dokku, PostgreSQL

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:

```ts
dokku postgres:expose <your-database-name>
```

Once you run the command, you'll see a similar output with a random-generated port:

```bash
-----> 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.

![](https://catalins.tech/content/images/2025/06/dokku-postgresql-database-connection-details-in-pg-admin.webp)

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:

- [Learn how to self-host your applications with Dokku, Hetzner and Cloudflare](https://catalins.tech/selfhost-with-dokku-hetzner-cloudflare/)