Import postgres database without roles

The default behavior of the import is that it replaces all roles it does not know with the role you are doing the import with. So depending on what you need the database for, you might just be fine with importing it and with ignoring the error messages.

Quoting from http://www.postgresql.org/docs/9.2/static/backup-dump.html#BACKUP-DUMP-RESTORE

Before restoring an SQL dump, all the users who own objects or were granted permissions on objects in the dumped database must already exist. If they do not, the restore will fail to recreate the objects with the original ownership and/or permissions. (Sometimes this is what you want, but usually it is not.)


The answer that you might be looking for is adding the --no-owner to the pg_restore command. Unlike the accepted answer at the moment, the command should create every object with the current user even if the role in the dump don't exist in the database.

So no element will get skipped by pg_restore but if some elements imported are owned by different users, all of the records will be now owned by only one user as far as I can tell.


With pg_restore you can use the --role=rolename option to force a role name to be used to perform the restore. But the dump must be non plain text format.
For example you can dump with:

pg_dump -F c -Z 9 -f my_file.backup my_database_name

and than you can restore it with:

pg_restore -d my_database_name --role=my_role_name my_file.backup

for more info: http://www.postgresql.org/docs/9.2/static/app-pgrestore.html