Re: [GENERAL] please help me recover from duplicate key in unique index

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Charles Martin <martin_pgsql(at)yahoo(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] please help me recover from duplicate key in unique index
Date: 2000-01-04 23:47:39
Message-ID: 200001042347.SAA00530@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try:

SELECT oid, *
FROM table
GROUP BY oid
HAVING count(*) > 1

that should show your duplicates, and you can remove them using
table.oid = _bad_number_.

> Please help me recover our database from what I think
> is a duplicate key in unique index problem.
>
> We have a table of the following form:
>
> create table foo (id serial primary key, x
> integer)
>
> in our code we had, outside of any BEGIN/COMMIT block:
>
> insert into foo (x) values (...)
>
> Without the transaction block, I believe we have had
> duplicate keys inserted. I've fixed the bug in the
> code, but now I need to fix the database!
>
> When I try to vacuum, I get this:
>
> > vacuum;
> NOTICE: Rel sessions: TID 5/2: OID IS INVALID.
> TUPGONE 1.
> NOTICE: Rel sessions: TID 5/6: OID IS INVALID.
> TUPGONE 1.
> NOTICE: Rel sessions: TID 13/2: OID IS INVALID.
> TUPGONE 1.
> NOTICE: Rel sessions: TID 13/6: OID IS INVALID.
> TUPGONE 1.
> ERROR: Cannot insert a duplicate key into a unique
> index
>
> When I try to dump it out (to manually repair it), I
> get this:
>
> $ pg_dump gtmd000103 > gtmd.1
> pqWait() -- connection not open
> PQendcopy: resetting connection
> SQL query to dump the contents of Table 'content' did
> not execute correctly. After we read all the table
> contents from the backend, PQendcopy() failed.
> Explanation from backend: 'pqWait() -- connection not
> open
> '.
> The query was: 'COPY "content" TO stdout;
> '.
>
> Can anybody help me? I am desperate. Thanks.
>
> Charles
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://messenger.yahoo.com
>
> ************
>
>

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ed Loehr 2000-01-04 23:56:32 Re: [GENERAL] please help me recover from duplicate key in unique index
Previous Message Charles Martin 2000-01-04 23:30:33 please help: system info