My database is associated with different usernames on the server and on my local machine. Whenever I try to restore it on my local machine from the backup downloaded from the server using the command
psql -d dbname -f backupfile.sql
I get the error output saying that
ERROR: role "myusername" does not exist
Despite the error message, the actual restore goes through. But it is annoying to see multiple error messages saying the same thing (once for each table). Is there a way I can suppress this error message. I searched quite a bit but could not find anything. There is no-owner
option for pgrestore
, but I could not find anything for psql.
Thank you for your help.
Best Answer
That is easy. Use the
--no-owner
and--no-privileges
options ofpg_dump
.You might be more happy if you used the custom format of
pg_dump
(-F c
). Then you'd restore withpg_restore
and could specify the options at restore time.