postgresqldokku

Importing existing database into new Dokku application


I have an existing application that I am trying to port over to Dokku, and part of that is getting the existing data store copied over. I am using the Dokku Postgres plugin, but am having trouble getting the database ported over.

In my existing app I am creating a dump of the database:

// Create dump file
pg_dump app_database > db.dump

// Copy over to server hosting Dokku app
scp db.dump sshdetails

// SSH into new server, then attempt to import dump file
dokku postgres:import db < db.dump

When I run the last command, I get the message: pg_restore: error: input file appears to be a text format dump. Please use psql.

I have tried formatting the dump in a few different formats but no luck. Any advice would be greatly appreciated. Thanks


Solution

  • From the source of dokku postgres:export command in dokku-postgres plugin :

    docker exec "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_dump -Fc --no-acl --no-owner -h localhost -U postgres -w "$DATABASE_NAME"
    

    The dokku postgres:export command have -Fc argument for pg_dump which export dump as archive suitable for input into pg_restore (more information into pg_dump man page) and pg_restore command seems to only accept custom format from pg_dump (cf. pg_restore man), so you should use the same -Fc argument in pg_dump command.