How to restore a postgres database with a different owner

To restore a database and have the tables owned by a different user use the pg_dump command like this:

as root user run:

su postgres
pg_dump -Fc database_name > database_name.dump
exit

Now you can restore using pg_restore.


createuser -P -s -e new_user
createdb -O new_user new_database

su postgres
pg_restore -v -d new_database -O -U new_user -h localhost database_name.dump
exit

After this don’t forget to modify the new_user and drop the superuser privilege.

This entry was posted in postgres. Bookmark the permalink.

Comments are closed.