when i restore my data i use pg_restore but it gives me error i tried all the solution - postgresql

pg_restore: error: COPY failed for table "ir_ui_view_group_rel": ERROR: duplicate key value violates unique constraint "ir_ui_view_group_rel_view_id_group_id_key"
DETAIL: Key (view_id, group_id)=(245, 5) already exists.
CONTEXT: COPY ir_ui_view_group_rel, line 1

Related

insert null value for auto incremented primary key

I'm using aws glue and i'm trying to insert (in pg databases) line with null value in primary key. I get this error :
An error occurred while calling o204.pyWriteDynamicFrame. ERROR: null value in column "abc" violates not-null constraint.
The issue is that primary key has a sequence
nextval('abc'::regclass).
Is it a parameter in glue to avoid this error ? Thanks
Conf :
AWS GLUE,
Python job,
Postgres databases

data corrupted in postgres - right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx"

I am new to Postgres and we are using it for tests reports, we had an issue with our environment that entered duplicate keys to one of the table and since then we are getting this message when trying to run migration scripts:
error: migration failed: right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx" in line 0: UPDATE log SET project_id = (SELECT project_id FROM item_project WHERE item_project.item_id=log.item_id LIMIT 1); (details: pq: right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx")
I tried to run pg_dump and got this error:
pg_dump: error: query was: SELECT pg_catalog.pg_get_viewdef('457544'::pg_catalog.oid) AS viewdef
pg_dumpall: error: pg_dump failed on database "reportportal", exiting
Can anyone help here?
Restore your backup, and research what parameters you changed and what you did to end up with data corruption in the first place.

Why is liquibase deleting databasechangelog rows and trying to create a renamed database table?

I am using postgres 10.5 and liquibase 3.6.2 on a Mac.
I nuke & re-create my database, run liquibase update, and it works.
But a second liquibase update fails with an exception that the pkey already exists.
After the first liquibase update, the databasechangelog table contains 97 entries. After the second, it contains 10, and the time and deployment ids for those are different than they were after the first update!
Table foo was created in an early change.
Later it was changed to be named bar, but the pkey is still foo.pkey.
Liquibase-update should not be trying to re-create foo, but it does, and fails because foo.pkey already exists.
A) In general, how can I get liquibase to output more info about what it's doing? I tried both of the commands:
liquibase --logLevel=debug --logFile=`pwd`/foo.log update
liquibase --logLevel debug --logFile `pwd`/foo.log update
Both seem to work the same, and foo.log isn't created and there's no more output in the terminal.
B) How can I stop liquibase from trying to re-make this and nuking my databasechangelog?
I tried to make a small example that fails, but this seems to work... Others here are using it with postgres 9.5.10 with no problem...
All I see in the terminal is:
Starting Liquibase at Wed, 14 Nov 2018 13:06:44 PST (version 3.6.2 built at 2018-07-03 11:28:09)
Unexpected error running Liquibase: ERROR: relation "cant_change_pkey" already exists [Failed SQL: CREATE TABLE nuss.cant_change (message_id UUID NOT NULL, origin VARCHAR(4), type VARCHAR(12) NOT NULL, CONSTRAINT CANT_CHANGE_PKEY PRIMARY KEY (message_id), UNIQUE (message_id))]
liquibase.exception.MigrationFailedException: Migration failed for change set db/changelog/changelog-new1.xml::first-one::rstrauss:
Reason: liquibase.exception.DatabaseException: ERROR: relation "cant_change_pkey" already exists [Failed SQL: CREATE TABLE nuss.cant_change (message_id UUID NOT NULL, origin VARCHAR(4), type VARCHAR(12) NOT NULL, CONSTRAINT CANT_CHANGE_PKEY PRIMARY KEY (message_id), UNIQUE (message_id))]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:637)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:78)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.commandline.Main.doMigration(Main.java:1205)
at liquibase.integration.commandline.Main.run(Main.java:191)
at liquibase.integration.commandline.Main.main(Main.java:129)
Caused by: liquibase.exception.DatabaseException: ERROR: relation "cant_change_pkey" already exists [Failed SQL: CREATE TABLE nuss.cant_change (message_id UUID NOT NULL, origin VARCHAR(4), type VARCHAR(12) NOT NULL, CONSTRAINT CANT_CHANGE_PKEY PRIMARY KEY (message_id), UNIQUE (message_id))]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600)
... 7 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: relation "cant_change_pkey" already exists
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:352)
... 12 common frames omitted
For more information, please use the --logLevel flag

Restore Postgres database dump

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.
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

pg_dump's custom format creates errors the plain format doesn't have

I've pored through the documentation of pg_dump and pg_restore and haven't found anything that would indicate that the custom format is more restrictive in some way. In fact, everything seems to indicate the opposite.
I'm running pg_dump like:
pg_dump --host=example.com --username=xxx --dbname=xxx \
--format=plain --table=ns_* --data-only > dump
And restoring that with:
cat dump | psql --host=example.com --username=xxx --dbname=xxx
And that that works fine. No errors and the data looks completely as expected. But if I change pg_dump to use the custom syntax like so:
pg_dump --host=example.com --username=xxx --dbname=xxx \
--format=custom --table=ns_* --data-only > dump
And then restore with:
pg_restore --host=example.com --username=xxx --dbname=xxx \
--data-only --single-transaction dump
I get the error:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2210; 0 1440417 TABLE DATA <table_name> <database_name>
pg_restore: [archiver (db)] COPY failed for table "<table_name>": ERROR: duplicate key value violates unique constraint "<table_name>_pkey"
DETAIL: Key (ex_id)=(7) already exists.
CONTEXT: COPY <table_name>, line 1
I don't see why this error occurs. First and foremost, it doesn't make any sense because there's obviously no duplicate key, otherwise the regular insertion would have failed (and manual inspection confirms this).
The database I'm inserting into is empty. It's been initialized with the schema (same schema that we're dumping from) and that's it.
Perhaps of note is that the primary keys have been modified in the past. They were all incremented by a set number, which required removing the primary key constraint temporarily. But this shouldn't invalidate the data (and the fact that the plain text format works shows the data is valid).