Re: Performance hit of foreign key constraints?

From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-general(at)postgresql(dot)org
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance hit of foreign key constraints?
Date: 2003-07-23 09:54:01
Message-ID: 3F1EA891.16257.43E80B6@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

On 23 Jul 2003 at 16:05, Jean-Christian Imbeault wrote:

> I have a database which is constantly being written to. A web server's
> log file (and extras) is being written to it. There are no deletions or
> updates (at least I think so :).
>
> As the web traffic increases so will the write intensity.
>
> Right now the database tables have no foreign keys defined even though
> there are foreign keys. The code that inserts into the DB is simple
> enough (now) that we can make sure that nothing is inserted if the
> corresponding fk does not exist and that all fk checks pass.
>
> I want to add foreign key constraints to the table definitions but I am
> worried that it might be a big performance hit. Can anyone tell me how
> much of a performance hit adding one foreign key constraint to one field
> in a table will roughly be?
>
> Also, for a DB that is write-intensive and rarely read, what are some
> things I can do to increase performance? (Keeping in mind that there is
> more than on DB on the same pg server).

1. Insert them in batches. Proper size of transactions can speed the write
performance heavily.
2. What kind of foreign keys you have? It might be possible to reduce FK
overhead if you are checking against small number of records.
3. Tune your hardware for write performance like getting a good-for-write RAID.
I forgot which performs which for read and write.
4. Tune WAL and move it to separate drive. That should win you some
performance.

HTH

Bye
Shridhar

--
Beauty: What's in your eye when you have a bee in your hand.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2003-07-23 10:47:29 Re: 'last updated' or 'last added'
Previous Message Richard Huxton 2003-07-23 09:33:28 General thanks to a locale coder

Browse pgsql-performance by date

  From Date Subject
Next Message Rajesh Kumar Mallah 2003-07-23 10:21:48 factoring problem with view in 7.3.3
Previous Message Richard Huxton 2003-07-23 08:49:09 Re: slow table updates