5

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?

dschwertfeger
  • 286
  • 1
  • 4
  • 21

2 Answers2

4

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.

dschwertfeger
  • 286
  • 1
  • 4
  • 21
  • Is it possible somehow to run "CREATE EXTENSION" using this console sesssion? I am getting "HINT: Must be superuser to create this extension". Thank you! – oivoodoo Oct 05 '14 at 22:35
1

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.

Rob
  • 25,984
  • 32
  • 109
  • 155
  • Yes, this works for a Rails app because it's built in and opens a Rails db console. I was looking for a more general way to open a `psql` console session, though. It's true that you can manually connect with `psql` using the connection parameters from `dokku postgresql:info ` but it's tedious to do. Thanks anyways! – dschwertfeger Aug 16 '14 at 10:40