且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PostgreSQL-备份数据库并在其他所有者上还原?

更新时间:2023-02-12 23:31:23

您应该使用-无所有者选项,这会停止 pg_restore 尝试将对象的所有权设置为原始所有者。相反,对象将由-role

You should use the --no-owner option, this stops pg_restore trying to set the ownership of the objects to the original owner. Instead the objects will be owned by the user specified by --role

createdb -p 5433 -T template0 db_name 
pg_restore -p 5433 --no-owner --role=owner2 -d db_name db_name.dump

pg_restore文档