Received: from mail.memeticsystems.com (flywheel.memeticsystems.com [64.85.80.85]) by postgresql.org (8.11.3/8.11.4) with SMTP id g0SKMul27308 for ; Mon, 28 Jan 2002 15:22:56 -0500 (EST) (envelope-from peter@memeticsystems.com) Received: (qmail 23672 invoked from network); 28 Jan 2002 20:22:56 -0000 Received: from unknown (HELO PETER) (63.249.24.21) by flywheel.memeticsystems.com with SMTP; 28 Jan 2002 20:22:56 -0000 From: "Peter T. Brown" To: "'Tom Lane'" Cc: Subject: Re: performance tuning on inserts Date: Mon, 28 Jan 2002 12:22:55 -0800 Message-ID: <002e01c1a839$92be6cc0$7d00000a@PETER> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <22285.1012248099@sss.pgh.pa.us> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Archive-Number: 200201/229 X-Sequence-Number: 3110 Regarding the SQL: The query I showed there is built dynamically from a library of queries chosen by the application user (using a web gui). For now, I don't have any way to intelligently condense the often complex series of operations into a single 'smart' query. That being said, I still don't understand why doing all those inserts should take so long since the entire table should be in memory... I am pretty sure I've allowed enough shared_buffers. Regarding timestamps in pg_xlog: as I understand things, if wal_buffers and checkpoint_segments are high enough the files in pg_xlog should never be used, right? Thanks Again, Peter T. Brown -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us] Sent: Monday, January 28, 2002 12:02 PM To: Peter T. Brown Cc: pgsql-admin@postgresql.org Subject: Re: [ADMIN] performance tuning on inserts "Peter T. Brown" writes: > All of my queries rely heavily on doing INSERT INTO. So is there some > special behavior with insert's, where they are flushed to disk one by one? > If I simply increase checkpoint_segments to 50 or so would this cause > inserts to occur only in memory and be flushed to disk at a later > time? Increasing checkpoint_segments is a good idea if you do lots of bulky inserts. Basically you don't want checkpoints happening every few seconds; at most one every couple minutes would be my recommendation. If checkpoint_segments is too small then you're forcing frequent checkpoints. Whether 6 is enough is hard to tell from the data you've given. You could look at the file timestamps in pg_xlog to try to estimate how often a new segment is started. Note that there's some interaction here: reducing the frequency of checkpoints will actually reduce the volume of WAL traffic. > Sample SQL: > INSERT INTO "VisitorPointer" ("CohortGroupID","VisitorID") SELECT > 51,"Tidbit"."VisitorID" FROM "Tidbit" WHERE "Tidbit"."CustomFieldID" = 27 > AND "Tidbit"."Value" LIKE 'asd1834%' > CREATE TEMP TABLE temp5946 AS SELECT DISTINCT ON ("VisitorID") * FROM > "VisitorPointer" WHERE "CohortGroupID" = 51; DELETE FROM "VisitorPointer" > WHERE "CohortGroupID" = 51; > INSERT INTO "VisitorPointer" SELECT * FROM temp5946; DROP TABLE temp5946; Seems like a little work on improving your SQL wouldn't hurt either. Couldn't the above mess be reduced to a single command? Viz INSERT INTO "VisitorPointer" ("CohortGroupID","VisitorID") SELECT DISTINCT 51,"Tidbit"."VisitorID" FROM "Tidbit" WHERE "Tidbit"."CustomFieldID" = 27 AND "Tidbit"."Value" LIKE 'asd1834%' All that inserting of rows you're only going to delete a moment later is costing you. regards, tom lane