471,075 Members | 808 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

converting FK's to "DEFERRABLE"

In order to try to reduce lock contention on my FK's, I need to
convert them to DEFERRABLE. The straightforward way is to drop and
recreate the modified FK. However, on a table with 65M rows, this is
taking quite some time. I'm afraid how long it will take to update
both FK's on my 170M+ row table...

Anyhow, is there some trickier way to make an FK deferrable? Mucking
with the system tables, perhaps?

I see that pg_restore has a way to turn off triggers during the data
load. If I can guarantee no updates to the table in question, can I
use that same code to disable triggers, drop+add the FK, then
re-enable triggers? Or will that not avoid the check when I create
the new FK?

I'd like to avoid a few hours of downtime while updating these
triggers.

Thanks.

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D. Khera Communications, Inc.
Internet: kh***@kciLink.com Rockville, MD +1-301-869-4449 x806
AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
2 1894
Vivek Khera <kh***@kcilink.com> writes:
Anyhow, is there some trickier way to make an FK deferrable?


Hack its pg_constraint.condeferrable and pg_constraint.condeferred
fields (the latter is the INITIALLY DEFERRED flag). You will also
need to find the triggers that implement the constraint and update
their pg_trigger.tgdeferrable and pg_trigger.tginitdeferred copies
of these values. Then start fresh backend sessions and I think
you're there.

AFAIK the most reliable way to find the triggers is to follow the
linking entries in pg_depend.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2

On Sep 17, 2004, at 3:27 PM, Tom Lane wrote:
Vivek Khera <kh***@kcilink.com> writes:
Anyhow, is there some trickier way to make an FK deferrable?


Hack its pg_constraint.condeferrable and pg_constraint.condeferred
fields (the latter is the INITIALLY DEFERRED flag). You will also
need to find the triggers that implement the constraint and update
their pg_trigger.tgdeferrable and pg_trigger.tginitdeferred copies
of these values. Then start fresh backend sessions and I think
you're there.


Thanks a bunch. This worked flawlessly. Basically I did this:

begin;
select pg_constraint.oid from pg_constraint,pg_class where
pg_constraint.conrelid=pg_class.oid and relname='mytable' and
conname='$1';
X=oid number
update pg_constraint set condeferrable='t' where oid=X;
update pg_trigger set tgdeferrable='t' where oid in (select objid from
pg_depend where refobjid=X);
commit;

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D. MailerMailer, LLC Rockville, MD
http://www.MailerMailer.com/ +1-301-869-4449 x806
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by mustafa | last post: by
8 posts views Thread by prabha | last post: by
2 posts views Thread by Philippe Lang | last post: by
7 posts views Thread by Tor Aadnevik | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.