Tuesday, August 23, 2011

Postgre SQL Database Restore Error

If you ran into this problem, you will probably know what I'm talking about. I will keep it short. Note that I am using postgresql 8.4 on Ubuntu 11.04.

I was trying to restore a database from a backup file using pgadmin3 and I kept getting:

pg_restore: archiver (db) connection to database ""some_database"" failed: FATAL: database ""some_database"" does not exist
pg_restore: *** aborted because of error

This is apparently because of a very simple error in the way pgadmin3 is handling restore database command.

It turns out that pgadmin3 is using the following command to restore a database from the backup file:

/usr/bin/pg_restore --port 5432 --username my_user_name --dbname \"some_database\" --verbose "/home/user/some_backup.backup"

However the quotation marks around some_database is confusing for postgresql. I don't understand why it is adding them by itself.

Instead the right command should have been:

/usr/bin/pg_restore --port 5432 --username my_user_name --dbname some_database --verbose "/home/user/some_backup.backup"

So I manually ran the command above in bash and it worked.

It's funny because pgadmin3 was supposed to make things simpler.