From: | Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il> |
---|---|
To: | jim(at)reptiles(dot)org (Jim Mercer), pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: [GENERAL] slow inserts and updates on large tables |
Date: | 1999-02-17 09:18:50 |
Message-ID: | l03110700b2f036cdd928@[147.233.159.109] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
At 5:02 +0200 on 17/2/99, Jim Mercer wrote:
> if anyone has any pointers as to why this is so slow, lemme know.
Have you checked the usual stuff:
1) Each insert and update creates its own transaction. That is, an
insert is in fact:
BEGIN TRANSACTION;
INSERT...;
COMMIT;
So, to make things faster you should BEGIN TRANSACTION explicitly
before all the inserts and COMMIT after them. Or separate into
manageable bulks if you run into a memory problem.
2) Indexing tables mean faster SELECTs at the expense of slower INSERTs
and UPDATEs. There is no magic. The reasoning is that normally you
query the data a lot more than you change it.
Thus, it is preferable, before doing bulk inserts, to drop the
indices and recreate them afterwards. This is true when you are not
expectind the database to be queried at the same time the inserts are
made.
As for updates, it's trickier, because you actually use the index
for the WHERE part of the update. If speed is of an essence, I would
probably try the following:
SELECT * INTO TABLE temp_table FROM your_table WHERE update_condition;
DELETE FROM your_table WHERE update_condition;
DROP INDEX...;
INSERT INTO your_table SELECT ... FROM temp_table; -- update within select
CREATE INDEX...;
3) Back to the issue of INSERTS - copies are faster. If you can transform
the data into tab-delimited format as required by COPY, you save a lot
of time on parsing, planning etc.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
From | Date | Subject | |
---|---|---|---|
Next Message | Janis Pinkis | 1999-02-17 11:11:00 | AIX 4.3.2 and 6.4.2 |
Previous Message | Jim Mercer | 1999-02-17 05:10:18 | Re: [GENERAL] slow inserts and updates on large tables |