4

Unable to restore Postgres db dump

I have used following commnands

 sudo psql my_database_name < feb9.sql
    SET
    SET
    SET
    SET
    SET
    CREATE EXTENSION
    COMMENT
    SET
    SET
    SET
    ERROR:  relation "admin_tools_dashboard_preferences" already exists
    ALTER TABLE
    ERROR:  relation "admin_tools_dashboard_preferences_id_seq" already exists
    ALTER TABLE
    ALTER SEQUENCE
    ERROR:  relation "admin_tools_menu_bookmark" already exists
    ALTER TABLE
    ERROR:  relation "admin_tools_menu_bookmark_id_seq" already exists
    ALTER TABLE
    ALTER SEQUENCE
    ERROR:  relation "auth_group" already exists
    ALTER TABLE
    ERROR:  relation "auth_group_id_seq" already exists



ERROR:  duplicate key value violates unique constraint "product_rateclass_code_uniq"
DETAIL:  Key (code)=(0) already exists.
CONTEXT:  COPY product_rateclass, line 1: "40787    0   Tariff Rates"
 setval 
--------
  40791
(1 row)
ERROR:  relation "admin_tools_menu_bookmark_user_id" already exists
ERROR:  relation "auth_group_name_like" already exists
ERROR:  relation "auth_group_permissions_group_id" already exists
ERROR:  relation "auth_group_permissions_permission_id" already exists
ERROR:  relation "auth_permission_content_type_id" already exists
ERROR:  relation "auth_user_groups_group_id" already exists
ERROR:  relation "auth_user_groups_user_id" already exists
ERROR:  relation "auth_user_user_permissions_permission_id" already exists
ERROR:  relation "auth_user_user_permissions_user_id" already exists
ERROR:  relation "auth_user_username_like" already exists
REVOKE
REVOKE
GRANT
GRANT

I have received the above error logs (I have such logs running into hundreds of lines, I have used several lines for reference).

Post execution of the command, the database is still containing old records, instead of new records.

3
  • 1
    You are restoring the dump into a database that already contains all the tables. You need to drop them first Commented Feb 9, 2016 at 10:45
  • Please can you help me with the commands ? Is there any other way where I can restore the database without dropping current database like its done in mysql (Its for the first time I am dealing with postgresql) Commented Feb 9, 2016 at 10:47
  • 2
    If you run pg_dump with the --clean option the script will contain the necessary statements to drop everything before restoring it. Please see the manual for details Commented Feb 9, 2016 at 10:49

1 Answer 1

10

I dropped the existing database and created the new one.

$dropdb development_db_name
$ createdb developmnent_db_name

Then I restored the db using

 sudo psql my_database_name < feb9.sql
Sign up to request clarification or add additional context in comments.

1 Comment

I really really appreciate your answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.