referential integrity violation - key referenced from xxx not found in yyy

Started by Luiz Henriqueover 19 years ago8 messagesbugs
Jump to latest
#1Luiz Henrique
luizhwk@gmail.com

Hi,

I'm running Postgresql 7.3 in Debian Woody OS.

After some time working properly, insert's statements related this error:

----
referential integrity violation - key referenced from xxx not found in yyy
----

This error would be normal, if the key really doesn't exist, but the key
exist.
The insert's work some times, and some times don't.

Is there any file corrupted?
Removing the fk constraint would resolve the problem?

Thanks!!

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Luiz Henrique (#1)
Re: referential integrity violation - key referenced from

On Wed, 2 Aug 2006, Luiz Henrique wrote:

Hi,

I'm running Postgresql 7.3 in Debian Woody OS.

After some time working properly, insert's statements related this error:

----
referential integrity violation - key referenced from xxx not found in yyy
----

This error would be normal, if the key really doesn't exist, but the key
exist.
The insert's work some times, and some times don't.

Is there any file corrupted?

It's hard to say. I'd have expected that a select * from parent where
key=value would fail for both the fk check and for a check to see if the
key exists assuming they used the same plan. Can you make a standalone
test case?

Removing the fk constraint would resolve the problem?

Well, it'd stop the message, but if there is corruption, it wouldn't fix
that.

#3Luiz Henrique
luizhwk@gmail.com
In reply to: Stephan Szabo (#2)
Re: referential integrity violation - key referenced from

Hi, could you tell me how postgresql look for a referenced key? It looks in
table index? Maybe only the index is corrupted?

Thanks!

Show quoted text

On 8/2/06, Stephan Szabo <sszabo@megazone.bigpanda.com> wrote:

On Wed, 2 Aug 2006, Luiz Henrique wrote:

Hi,

I'm running Postgresql 7.3 in Debian Woody OS.

After some time working properly, insert's statements related this

error:

----
referential integrity violation - key referenced from xxx not found in

yyy

----

This error would be normal, if the key really doesn't exist, but the key
exist.
The insert's work some times, and some times don't.

Is there any file corrupted?

It's hard to say. I'd have expected that a select * from parent where
key=value would fail for both the fk check and for a check to see if the
key exists assuming they used the same plan. Can you make a standalone
test case?

Removing the fk constraint would resolve the problem?

Well, it'd stop the message, but if there is corruption, it wouldn't fix
that.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

#4Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Luiz Henrique (#3)
Re: referential integrity violation - key referenced from

On Fri, 4 Aug 2006, Luiz Henrique wrote:

Hi, could you tell me how postgresql look for a referenced key? It looks in
table index? Maybe only the index is corrupted?

It basically runs a query like:
SELECT * FROM parenttable WHERE keycol1 = ? [AND keycol2 = ? ...] FOR
SHARE

It should act like a prepared statement would (which might be different
than it would with the ?s replaced by the actual values).

#5Luiz Henrique
luizhwk@gmail.com
In reply to: Stephan Szabo (#4)
Re: referential integrity violation - key referenced from

Hi,

my problem was problably corrupted index files. I recreated the index and
it's ok now. The hardware was being unpluged from power source without
shuthing down, I guess that's the cause.
I used the fallowing commands to recreate index:

/etc/init.d/postgresql stop
su postgres
/usr/lib/postgresql/bin/postgres -D /var/lib/postgres/data -O -P db
reindex database db;
/etc/init.d/postgresql start

Thanks!

Show quoted text

On 8/4/06, Stephan Szabo <sszabo@megazone.bigpanda.com> wrote:

On Fri, 4 Aug 2006, Luiz Henrique wrote:

Hi, could you tell me how postgresql look for a referenced key? It looks

in

table index? Maybe only the index is corrupted?

It basically runs a query like:
SELECT * FROM parenttable WHERE keycol1 = ? [AND keycol2 = ? ...] FOR
SHARE

It should act like a prepared statement would (which might be different
than it would with the ?s replaced by the actual values).

#6Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Luiz Henrique (#5)
Re: referential integrity violation - key referenced from

On Aug 15, 2006, at 8:50 AM, Luiz Henrique wrote:

my problem was problably corrupted index files. I recreated the
index and it's ok now. The hardware was being unpluged from power
source without shuthing down, I guess that's the cause.

What version are you using? In recent versions, indexes are supposed
to be safe from corruption, even through crashes.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

#7Luiz Henrique
luizhwk@gmail.com
In reply to: Jim Nasby (#6)
Re: referential integrity violation - key referenced from

It's Postgresql 7.2.1, installed with stable version of Debian Woody, at the
time.

Show quoted text

On 8/21/06, Jim Nasby <jnasby@pervasive.com> wrote:

On Aug 15, 2006, at 8:50 AM, Luiz Henrique wrote:

my problem was problably corrupted index files. I recreated the
index and it's ok now. The hardware was being unpluged from power
source without shuthing down, I guess that's the cause.

What version are you using? In recent versions, indexes are supposed
to be safe from corruption, even through crashes.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Luiz Henrique (#7)
Re: referential integrity violation - key referenced from

"Luiz Henrique" <luizhwk@gmail.com> writes:

On 8/21/06, Jim Nasby <jnasby@pervasive.com> wrote:

What version are you using? In recent versions, indexes are supposed
to be safe from corruption, even through crashes.

It's Postgresql 7.2.1, installed with stable version of Debian Woody, at the
time.

7.2.1 is ancient and has a very long list of known bugs. We officially
abandoned support for the 7.2.* branch more than a year ago, upon
finding some bugs that were simply not practical to fix in that branch.

If you must keep using 7.2.*, at least get yourself onto 7.2.8, the last
of that series. But you'd be doing yourself a real favor by expending
a little more effort and moving to a current release series ---
preferably 8.1.*.

regards, tom lane