0

I have two databases

db_dumped -- contains data in main_facebookparserresult table

lk_potok_4 -- contains empty table main_facebookparserresult

I want to copy data from db_dumped to lk_potok_4.

My actions: (no errors)

pg_dump -U postgres  -h localhost  -t main_facebookparserresult  db_dumped  | psql lk_potok_4 -U postgres  -h localhost

I see the following error

SET
...
 set_config 
------------
 
(1 row)

SET
SET
SET
SET
SET
SET
ERROR:  relation "main_facebookparserresult" already exists
ALTER TABLE
ERROR:  relation "main_facebookparserresult_id_seq" already exists
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
ERROR:  duplicate key value violates unique constraint "main_facebookparserresult_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY main_facebookparserresult, line 1
 setval 
--------
  34367
(1 row)

ERROR:  multiple primary keys for table "main_facebookparserresult" are not allowed
ERROR:  relation "main_facebookparserresult_account_type_id_825ffe90" already exists
ERROR:  relation "main_facebookparserresult_country_id_42b851f9" already exists
ERROR:  relation "main_facebookparserresult_current_city_id_4ea3868d" already exists
ERROR:  relation "main_facebookparserresult_edu_type_id_87f43c00" already exists
ERROR:  relation "main_facebookparserresult_employment_status_id_808992ba" already exists
ERROR:  relation "main_facebookparserresult_employment_type_id_911556be" already exists
ERROR:  relation "main_facebookparserresult_family_status_id_ee099277" already exists
ERROR:  relation "main_facebookparserresult_gender_id_2a17909b" already exists
ERROR:  relation "main_facebookparserresult_home_city_id_a8b99ee3" already exists
ERROR:  relation "main_facebookparserresult_relation_id_94f96514" already exists
ERROR:  relation "main_facebookparserresult_social_network_type_id_cd0395b0" already exists
ERROR:  relation "main_facebookparserresult_university_id_0890ffdd" already exists
ERROR:  constraint "main_facebookparserr_account_type_id_825ffe90_fk_main_acco" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_country_id_42b851f9_fk_main_coun" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_current_city_id_4ea3868d_fk_main_city" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_edu_type_id_87f43c00_fk_main_edut" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_employment_status_id_808992ba_fk_main_empl" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_employment_type_id_911556be_fk_main_empl" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_family_status_id_ee099277_fk_main_fami" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_relation_id_94f96514_fk_main_rela" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_social_network_type__cd0395b0_fk_main_soci" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserr_university_id_0890ffdd_fk_main_univ" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserresult_gender_id_2a17909b_fk_main_gender_id" for relation "main_facebookparserresult" already exists
ERROR:  constraint "main_facebookparserresult_home_city_id_a8b99ee3_fk_main_city_id" for relation "main_facebookparserresult" already exists

What I did wrong? How can i understand what is the error?

5
  • 1) db_dumped - is a database (not dump) Commented Mar 9, 2022 at 22:04
  • 2) I don't understand what should i fix in this part? | psql lk_potok_4 looks fine Commented Mar 9, 2022 at 22:05
  • 1
    My mistake I did not read the question correctly. Also I was looking at the wrong part of your commands. sudo -u postgres psql is going to drop you into the psql program. You cannot run the pg_dump ... from there. Just run the pg_dump .. in your user shell, you don't need to switch to the postgres user. Commented Mar 9, 2022 at 22:15
  • Thank you, but I have the next level error. Could you please take a look? Commented Mar 9, 2022 at 22:54
  • You need update your question with more detailed information about what you are trying to achieve? The errors you are seeing are because the table already exists in the receiving database. So one of the things you need to determine is whether you want to recreate the table from scratch or just move the data. Commented Mar 9, 2022 at 23:04

1 Answer 1

3

Your dump contains both the data and the schema for main_facebookparserresult. It's trying to create the table main_facebookparserresult, but it already exists.

You should either drop the table OR dump just the data with --data-only. Since the table is empty I would suggest dropping the table; this ensures the table is created correctly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you but, I ave another error. Please, take a look at UPDATE block
@Alex It is better if you ask a new question for each new problem. Editing the question makes the comments and answers make no sense. Asking a new question will get more visibility. Please link the new question @ me and I'll have a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.