Search code examples
postgresqldokku

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?


Solution

  • 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.