我需要用postgres username1从computer1转储postgres数据库,然后用postgres username2在computer2上还原它。我一直遇到一个错误,看起来备份文件想要使用username1:
当我在计算机2上运行此程序时:

psql dbname < backupname.pgsql

我得到这个错误:
ERROR:  role "username1" does not exist

我试过:
// Dumping from computer1:

pg_dump dbname > backupname.sql
pg_dump dbname > backupname.pgsql
pg_dump -U username1 dbname -N topology -T spacial_ref_sys > backupname.pgsql


// Restoring on computer2:

psql dbname < backupname.pgsql

需要修改的是转储还是还原才能通过此操作?

最佳答案

问题在于倾销。根据this post的见解,我可以使用以下方法解决此问题:

// On Computer1

pg_dump dbname -O -x > backupname.sql


// On Computer2

psql dbname < backupname.sql

pg_dump一起使用的选项标志是:
-O   <-- No owner
         Do not output commands to set ownership of objects to match the original database

-x   <-- No privileges
         Prevent dumping of access privileges (grant/revoke commands)

有关选项标志的更多信息,请参见PostgreSQL docs for pg_dump

09-07 14:58