问题描述
我使用以下命令在不同服务器上的数据库上进行了备份,其角色与我所需的角色不同:
I did backup on database on different server and that has different role than I need, with this command:
pg_dump -Fc db_name -f db_name.dump
然后我将备份复制到另一台需要还原数据库的服务器上,但没有用于该数据库的此类所有者。假设数据库拥有所有者 owner1
,但是在其他服务器上我只有 owner2
,我需要还原该数据库并进行更改
Then I copied backup to another server where I need to restore the database, but there is no such owner that was used for that database. Let say database has owner owner1
, but on different server I only have owner2
and I need to restore that database and change owner.
还原时我在另一台服务器上所做的操作:
What I did on another server when restoring:
createdb -p 5433 -T template0 db_name
pg_restore -p 5433 --role=owner2 -d db_name db_name.dump
但是运行还原时出现以下错误:
But when restore is run I get these errors:
pg_restore: [archiver (db)] could not execute query: ERROR: role "owner1" does not exist
如何指定它,以便更改所有者?还是不可能?
How can I specify it so it would change owner? Or is it impossible?
推荐答案
您应该使用-无所有者
选项,这会停止 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
这篇关于PostgreSQL-备份数据库并在其他所有者上还原?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!