By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

Unable to restore postgres-dump-Version-8.2.4

P: 2
Hi All,

I have a python script which takes dump of postgres and restores the same.

When i take a dump there is no problem.
command to take dump:
Expand|Select|Wrap|Line Numbers
  1. pg_dump -b -c -C --format=c -d -h <<hostname>> -p 5432 -U postuser -f /tmp/april_23/abc.sql abc
Restore command:
Expand|Select|Wrap|Line Numbers
  1. pg_restore -c --format=c -h <<hostname>> -p 5432 -U postuser -d sfdb /tmp/april_23/abc.sql
While restoring the dump i got into following errors...

Traceback (most recent call last):
Expand|Select|Wrap|Line Numbers
  1.    File "./db.py", line 122, in restore_db
  2.     ret = app.util.executeCommand(self.cmd)
Expand|Select|Wrap|Line Numbers
  1.  
  2.  RuntimeError: pg_restore -c --format=c -h <<hostname>> -p 5432 -U postuser -d abc /tmp/april_23/abc.sql failed with exit code 256
  3. Std Err: pg_restore: [archiver (db)] Error while PROCESSING TOC:
  4. pg_restore: [archiver (db)] Error from TOC entry 5; 2615 2200 SCHEMA public postgres
  5. pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of schema public
  6.     Command was: DROP SCHEMA public;
  7. pg_restore: [archiver (db)] could not execute query: ERROR:  schema "public" already exists
  8.     Command was: CREATE SCHEMA public;
  9. pg_restore: [archiver (db)] Error from TOC entry 2229; 0 0 COMMENT SCHEMA public postgres
  10. pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of schema public
  11.     Command was: COMMENT ON SCHEMA public IS 'Standard public schema';
  12. pg_restore: WARNING:  no privileges could be revoked for "public"
  13. pg_restore: WARNING:  no privileges could be revoked for "public"
  14. pg_restore: WARNING:  no privileges were granted for "public"
  15. pg_restore: WARNING:  no privileges were granted for "public"
  16. WARNING: errors ignored on restore: 3
  17.  
  18. Stdoutput:
  19.  
  20. Unable to restore db
Any help would be of great.

Thanks
Prathap
Apr 23 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 700
I'm afraid you should give more information but this error is interesting
"ERROR: must be owner of schema public Command was: DROP SCHEMA public;".
Who did backup and who is trying to restore. What are database privileges. Why are you trying to delete public schema?
Apr 23 '08 #2

P: 2
I'm afraid you should give more information but this error is interesting

Who did backup and who is trying to restore. What are database privileges. Why are you trying to delete public schema?
backup and restore are done by "postgres" user. I have just incorporated the pgsq_restore snippet in my python script.

The python script is invoked as 'root' which does the dump and restore.
Code snippet:
Expand|Select|Wrap|Line Numbers
  1.  def dump_db(self):
  2.         if not os.path.exists(self.db_backup_file_path):
  3.             try:
  4.                 os.makedirs(self.db_backup_file_path)
  5.             except:
  6.                 self.printErrorAndExit("Unable to create path for DB backup: %s " %self.db_backup_file_path, 3)
  7.  
  8.         if self.db_name != '':
  9.             try:
  10.                 self.cmd = 'pg_dump -b -c -C --format=c -d -h '+ self.db_host
  11.                 self.cmd = self.cmd +' -p '+ self.db_port
  12.                 self.cmd = self.cmd +' -U '+ self.db_user
  13.                 self.cmd = self.cmd +' -f '+ self.db_backup_file
  14.                 self.cmd = self.cmd +' '+ self.db_name
  15.                 print self.cmd
  16.                 ret = app.util.executeCommand(self.cmd)
  17.             except:
  18.                 self.printErrorAndExit("Unable to take DB backup\n", 4)
  19.  
  20. ======================================================
  21.   # restores database
  22.     def restore_db(self):
  23.         if self.force:
  24.             option = 'YES'
  25.             print "Force option selected, so proceeding to replace the existing data by the dump you have selected."
  26.         else:
  27.             option  = app.util.readFromUser("Existing data will be replaced by the dump you have selected. Do you want to proceed? YES/NO", 'YES',  ['YES', 'NO'])
  28.             if option == 'YES':
  29.                 pass
  30.             else:
  31.                 self.printErrorAndExit("Exiting restore db on user request..")
  32.  
  33.         if not os.path.exists(self.db_backup_file):
  34.             self.printErrorAndExit("Unable to find DB backup file: %s " %self.db_backup_file_path, 5)
  35.  
  36.         if self.db_name != '':
  37.             try:
  38.                 self.cmd = 'pg_restore -c --format=c -h '+ self.db_host
  39.                 self.cmd = self.cmd +' -p '+ self.db_port
  40.                 self.cmd = self.cmd +' -U '+ self.db_user
  41.                 self.cmd = self.cmd +' -d '+ self.db_name
  42.                 self.cmd = self.cmd + ' ' + self.db_backup_file
  43.                 print self.cmd
  44.                 print "Restoring db, please wait...."
  45.                 ret = app.util.executeCommand(self.cmd)
  46.             except:
  47.                 print " ".join(app.util.getStackTraceAndException())
  48.                 self.printErrorAndExit("Unable to restore db\n", 6)
  49.         else:
  50.             self.printErrorAndExit("Unable to restore db, due to empty db name\n", 7)
Apr 23 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.