Unable to restore psql database from pg_dump with a different username

后端 未结 3 1146
情话喂你
情话喂你 2021-01-18 08:00

I need to dump a postgres database from computer1 with postgres username1 and then restore it on computer2 with postgres username2. I keep running into the error that looks

3条回答
  •  时光取名叫无心
    2021-01-18 08:30

    The problem is with the dumping. With insight from this post I was able to resolve this using:

    // On Computer1
    
    pg_dump dbname -O -x > backupname.sql
    
    
    // On Computer2
    
    psql dbname < backupname.sql
    

    The option flags used with pg_dump are:

    -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)
    

    See the PostgreSQL docs for pg_dump for more info on the option flags.

提交回复
热议问题