Postgres - restore database with different owner
Posted on March 24, 2022 (Last modified on October 23, 2024) • 1 min read • 116 wordsSituation:
Go.
Step one, dump the database.
pg_dump -h database.host \
-U database_user \
-W \
-O -Ft \
database \
> database.dump.tar
Important here is -O
, which means --no-owner
, which means “do not include owner information.
Step two, restore the database. The database in which the dump file is restored has to exist. If you don’t know how to create it, see here.
pg_restore \
-h database.host \
-U different_database_user \
-W \
-d different_database \
--no-owner \
--role=different_database_user \
-Ft \
database.dump.tar
DISCLAIMER: I have no idea if there is a better way. That just worked.