How do I make my Django app in Dokku use Postgres dump as database?

Posted May 6, 2014 8k views
Hi, I've recently uploaded my Django app to a Dokku droplet, and I want to know how I can make it to work with a dump of a database I have. I've tried restoring to Postgres my dump but it's not working, but, even if I where to restore data from dump, I still don't know how can I make my app to use that database. Could you tell me (baby steps) how can I make my Django app work with a Postgres database in Dokku droplet? Thanks a lot!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
11 answers
Are you using the PostgreSQL plugin for Dokku? See:

If so, you should be able to import a dump with:

dokku postgresql:restore app_name < app.sql

The key thing to remember is that Dokku runs the app from inside of a Docker container. So the database dump needs to be restored to the Postgres instance inside the container, not on the host system.
When I do it I find it answers with:

Unknown (or too old) PostgreSQL container

I'm not sure if I'm using the PostgreSQL plugin for Dokku, when I started the droplet, I selected the Dokku option (instead of Linux distribution, I selected it from application option), so I'm not sure where it comes from.

Yes, I'm using the PostgreSQL plugin for Dokku. Now I'm following tutorial

You'd need to install the plugin yourself. Check out that GitHub link for more information, but basically what you need to do is:

cd /var/lib/dokku/plugins/
git clone postgresql
dokku plugins-install

Then to set it up for the first time, you can run:

dokku postgresql:create appname
dokku postgresql:restore appname < dump_file.sql

If you'd rather just access the docker container the app is running directly, you can get a interactive shell with:

docker run -i -t dokku/appname /bin/bash
I have a myApp.dump, How could I make it so it becomes a .sql??

When I try I get:

invalid command \?4???b@?????:??I0j_8?s?A?x??r7??ء4?p?m!???c???.?(^???4?~_?hslSA?QA?[4?[ir??O
invalid command \?/??(?1?Y=??S?+?٠???3?.M?!??Ku??H_?H߻T??>9
invalid command \invalid command \|?A??c?e?
invalid command \????uj?f??K?-o??VqY??z;M???~?*7g,?G??????
ERROR: invalid byte sequence for encoding "UTF8": 0xea8e51

-----> myApp database restored
EDIT: When I try to restore
That seems like you are getting the import commands correct, but you are now hitting another error with charterer encoding. What's the encoding of your database dump? Run:

file youfile.sql

When I run the command I get

PostgreSQL custom database dump - v1.12-0
The dump was created from Heroku where original app exists (I want to migrate)
This answer over on StackExchange seems relevant:

Previous 1 2 Next