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" - postgresql

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.

Related

How to backup/recover database after a "missing chunk number 0" message?

PostgreSQL. When I try to backup the database via pgAdmin, I get error
pg_dump: error: Dumping the contents of table "filearchives" failed: PQgetResult() failed.
pg_dump: error: Error message from server: ������: missing chunk number 0 for toast value 1508672 in pg_toast_1245716
pg_dump: error: The command was: COPY public.filearchives (id, usedtime, docid, options, filesize, filename, stream) TO stdout;"
I followed these instructions: https://gist.github.com/supix/80f9a6111dc954cf38ee99b9dedf187a
There were similar errors for REINDEX and VACUUM on the main table (filearchives), but nothing for pg_toast and I was able to select all rows in the main table (filearchives), while there was supposed to be "Corrupted chunk read!".
When I do it via psql, there is no error message, but the backup is incomplete.
The database itself is working fine at the moment.
How to recover the database without removing records? Is there a way to create a backup?

Many syntax and permissions errors on postgres sql dump import

I am trying to import a .sql database dump into my postgres 9.6.1. I've tried in command line as well as the Postico GUI but get a ton of errors (like thousands of lines of errors) on import.
The SQL dump is from a coworker running postgres 9.4.5 and the SQL looks valid.
My Postgres Version:
PostgreSQL 9.6.1 on x86_64-apple-darwin, compiled by
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc.
build 5658) (LLVM build 2336.11.00), 64-bit
I've tried the following imports:
psql -U postgres dbname < ~/Desktop/dbname_local_db_20161122.sql
Then logging in and trying it:
psql -U postgres dbname
dbname=# \i ~/Desktop/dbname_local_db_20161122.sql
Errors: (there are way more than this)
Password for user postgres:
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
ERROR: schema "public" does not exist
ERROR: extension "citext" does not exist
ERROR: schema "public" does not exist
ERROR: extension "pg_trgm" does not exist
SET
ERROR: function "add_session_metric" already exists with same argument types
ERROR: role "myrole" does not exist
ERROR: function "session_metrics_partition_creation" already exists with same argument types
ERROR: role "myrole" does not exist
ERROR: function "session_metrics_partition_function" already exists with same argument types
ERROR: role "myrole" does not exist
SET
SET
ERROR: permission denied to create "pg_catalog.messages"
DETAIL: System catalog modifications are currently disallowed.
ERROR: relation "messages" does not exist
ERROR: permission denied to create "pg_catalog.Message_id_seq"
DETAIL: System catalog modifications are currently disallowed.
ERROR: relation "Message_id_seq" does not exist
ERROR: relation "Message_id_seq" does not exist
ERROR: permission denied to create "pg_catalog.sessions_users"
invalid command \N
invalid command \N
invalid command \N
invalid command \N
invalid command \N
invalid command \.
ERROR: syntax error at or near "2"
LINE 1: 2 hello 3 1 2015-11-12 09:25:14.646-07 2015-11-12 09:25:14.64...
ERROR: syntax error at or near "1"
LINE 1: 1
^
ERROR: relation "external_session_info_sessions" does not exist
invalid command \.
ERROR: syntax error at or near "2528"
LINE 1: 2528 1
^
invalid command \.
ERROR: relation "feedback_id_seq" does not exist
LINE 1: SELECT pg_catalog.setval('feedback_id_seq', 1, false);
Like I said, the SQL file looks valid. I've checked for compatibility issues from 9.4.5 to 9.6.1 but don't see any.
I do see PERMISSION DENIED but I am running the command as user postgres which has super user permissions:
First, the recommended way is to use pg_dump from the higher (target) database version to create the dump, because that version of pg_dump knows about incompatible changes that happened since and can create a dump that will restore correctly.
Some of the errors are normal if you restore a dump into a database that already has objects with the same names in it; often that is a sign that the dump should actually have been created with pg_dump -C to include a CREATE DATABASE statement.
However, your SQL script seems seriously messed up, and I doubt that it is an unmodified dump of a 9.4.5 database.
pg_dump will never dump any objects in pg_catalog. This schema can only contain system objects which are not included in a dump (they are created by CREATE DATABASE), and as you have seen, not even a superuser may create an object in that schema (unless allow_system_table_mods is on, which it really shouldn't be).

Rolled back on heroku, restored db, and now getting a ton of database errors

We deployed some code tonight but had to rollback. The rollback affected the database so we restored our database to one we captured right before the deploy. Now we're getting all types of database errors, such as:
ActiveRecord::UnknownPrimaryKey: Unknown primary key for table billing_accounts in model BillingAccount.
PG::SyntaxError: ERROR: zero-length delimited identifier at or near """" LINE 1: ... "billing_accounts" ORDER BY "billing_accounts"."" ASC LIM.
PG::InternalError: ERROR: cache lookup failed for type 19005
PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
I have no idea what to do about these errors, we're getting a ton of them. Help!!

Error while taking backup in Postgresql (Could not read Block X of relation base/Y/Z)

while taking a backup from my PostgrSQL Database
it showing that
pg_dump: Dumping the contents of table "gtab17" failed: PQgetResult() failed.
pg_dump: Error message from server: ERROR: invalid page header in block 9576 of relation base/17779/758869
pg_dump: The command was: COPY public.gtab17 (jrdetid, jrmid, acid, dr, cr, narr, ageamt) TO stdout;
i think my table gtab17 is corrupt
tried
Vaccum Full error on this table
INFO: vacuuming "public.gtab17" ; ERROR: row is too big: size 3256104, maximum size 8160
Analyze error
INFO: analyzing "public.gtab17" ;
ERROR: invalid page header in block 9576 of relation base/17779/758869
Database : PostgreSQL 9.2
OS : Windows XP SP3 ; FILESYSTEM : NTFS
i have googled but dint get any solution to solve this
It means, so your data file is corrupted - a solution is relative difficult - the best way is recovery from some older backup. You can try to fix it with replacing broken data page by zeroes - but you lost some data, and without some deeper knowledgeable you can destroy more than now it is.
REFER

error when trying to execute to sql

I'm using Mulestudio and am trying to insert into the Postgres database some data. I am modifying the log4j.properties file and below is how it looks like:
log4j.rootLogger = DEBUG, postgres
#
log4j.appender.postgres=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.postgres.layout=org.apache.log4j.PatternLayout
log4j.appender.postgres.driver=org.postgresql.Driver
log4j.appender.postgres.URL=jdbc:postgresql://127.0.0.1:5432/testing
log4j.appender.postgres.user=postgres
log4j.appender.postgres.password=pw
log4j.appender.postgres.sql=INSERT INTO LOGS VALUES ('%x', '%d{yyyy-MM-dd}','%C','%p','%m');
The error message that I get is
log4j:ERROR Failed to excute sql
org.postgresql.util.PSQLException: ERROR: syntax error at or near "edu"
'edu' is the first part of my project name (edu-stream-ucdnews). The instance of 'edu' only comes up in the title name and not in my data. I know that the error arises when I have the '%m' when I try to insert the data because when I change it to a hard-coded message like 'Hello', I don't get any error.
How do I solve this issue?
Are you sure your are connected to the database?
Try putting the fields name in your sql and lets check if we get a better error log:
log4j.appender.postgres.sql=INSERT INTO LOGS (field1, field2, ...) VALUES ('%x', '%d{yyyy-MM-dd}','%C','%p','%m');