How to restore postgres database into another database name

Simple, first create your database using template0 as your template database:

createdb -U test -T template0 zeus_production

Then, restore your dump on this database:

psql -U test zeus_production -f /path/to/zeus_development.dump.out

When restoring, always use template0 explicit, as it is always an empty and unmodifiable database. If you don’t use an explicit template, PostgreSQL will assume template1, and if it has some objects, like a table or function that your dumped database already has, you will get some errors while restoring.

Nonetheless, even if you were restoring on a database with the same name (zeus_development) you should create (or recreate) it the same way. Unless you used -C option while dumping (or -C of pg_restore if using a binary dump), which I don’t recommend, because will give you less flexibility (like restoring on a different database name).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)