If you are like me, you like to deploy on a dokku droplet using DigitalOcean! But how do you query your database, when it's on some VPS far away from you? Today I will show you how to connect to it, and edit the database after it's been deployed.
My use-case: Add some sample data which would take too long if done through the websites front-end forms!
Getting information about your database
First you need to get information about your database. This is based on Dokku, but there should be commands to achieve the same on the VPS-service you used.
In the terminal after ssh-ing into your server, run:
dokku postgres:expose database
to expose your database. Where database is your PSQL-service name you chose when setting up the Dokku container.
Output:
Service database exposed on port(s) [container->host]: 1234->????
I have hidden my port, but in my case I needed to use the last value, which is hidden for you.
Now you have all the required information. Hop into your Database Admin Program, for me it’s DataGrip!
Name is irrelevant
Host is my backend url
Port is the value I got from the command
My user is Postgres and my password is secret🤐
database is just the name of your database
URL is autogenerated.
Press connect, and then you can make operations in your dokku database 🙌
For example, I can select all of the posts in my database:
select * from post
Let me know if you have any problems! This was just supposed to be a short article since I couldn't find a good resources elsewhere😄
Top comments (0)