Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console access to Dokku's PostgreSQL plugin?

Is there a way to get console access to Dokku's PostgreSQL plugin? On Heroku I'd do heroku pg:psql. Is this possible in a Dokku environment and if so how?

like image 561
dschwertfeger Avatar asked May 28 '14 10:05

dschwertfeger


2 Answers

There is in fact a way to do this directly with the dokku-pg-plugin.

The command postgresql:restore <db> < dump_file.sql connects to the specified database and restores it with the provided dump file. If you simply omit the dump file part (< dump_file.sql), a psql console session opens.

Since postgresql:restore <db> is semantically not the best way to open a console session, I have opened a pull request to add the command postgresql:console <db>.

So, until my PR is merged, the options for opening a psql console for a database are either:

  • doing it manually with psql -h 172.17.42.1 -p <port> -U root db with the <port> and password taken from the output of dokku postgresql:info <db>,
  • using the semantically incorrect command dokku postgresql:restore <db>, or
  • use my forked and patched version of the plugin which adds the command postgresql:console <db>.

Edit: The owner of the dokku-pg-plugin has merged my pull request. If you're using this plugin and are looking for a way to access your PostgreSQL console with it, you might want to update it to the latest version. Once you have done that, you can use the command postgresql:console <db> to open a psql session to the specified database.

like image 115
dschwertfeger Avatar answered Sep 30 '22 09:09

dschwertfeger


This worked for me for my Rails app that I'm running on Dokku:

dokku run <app-name> rails db

That brought up the console for the PostgreSQL container I created (via dokku postgresql:create <db>). I couldn't figure out another way to get at the PostgreSQL instance in that container, short of attempting to directly connect to the DB, with the connection info/credentials listed when you do this:

dokku postgresql:info <db>

I haven't tried that, though I suspect it would work.

like image 22
Rob Avatar answered Sep 30 '22 09:09

Rob