Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3E6BC18E5728 for ; Mon, 9 Jul 2012 23:46:48 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoQTN-0005NY-Lc for pgsql-performance@postgresql.org; Tue, 10 Jul 2012 02:46:47 +0000 Received: by pbbrp8 with SMTP id rp8so20207376pbb.19 for ; Mon, 09 Jul 2012 19:46:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:x-gm-message-state; bh=XTP3MdeHqCjj5JXKUHHCtvY+0IlcqAVi/9JOgCqV3gM=; b=SUMvb9kOz2aFFwFnMn9VH29TgklWNMniCkofa8k72il45PhEq2hly9jox8zFNz7Twj hIkqFCVUUNFKu7z/jv5WaNFvRIFDiRJK/3lT5x0/cGZP2XSG+O2agcTsncepKRqHWUZR L+INRzneC/B3GOmCbdAH0pT6ouRsEMzuVJUPt0AGv8wx1CjvL/CyBTxjGFJqtzjCVtNd Qw7FPRODECOXErvXJgNxjqlhzXzkZV3F6Y/foDps4zF3ettKkjL4uuBNK9nm4rYBSt0s L/gO8NWikB6OnpgSqvaqJ/bwwHHoID8+43eiMtJAATCPV71z6JEiRMi2b6fxV1aXACr4 VVfA== Received: by 10.68.195.167 with SMTP id if7mr65212735pbc.16.1341888391807; Mon, 09 Jul 2012 19:46:31 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id ob9sm28881861pbb.28.2012.07.09.19.46.28 (version=SSLv3 cipher=OTHER); Mon, 09 Jul 2012 19:46:30 -0700 (PDT) Message-ID: <4FFB9781.60601@ringerc.id.au> Date: Tue, 10 Jul 2012 10:46:25 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Yan Chunlu CC: Albe Laurenz , pgsql-performance@postgresql.org Subject: Re: how could select id=xx so slow? References: <4FFB848D.7080900@ringerc.id.au> In-Reply-To: Content-Type: multipart/alternative; boundary="------------080809080600070808040201" X-Gm-Message-State: ALoCoQlVuP9m5pwdGpem24kaNURm+9eJGFb2hDtVd6budT9aEkq6nGwRjmDH1VarfmOOgnRK60Ja X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/105 X-Sequence-Number: 47286 This is a multi-part message in MIME format. --------------080809080600070808040201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 07/10/2012 10:25 AM, Yan Chunlu wrote: > I didn't set log_min_duration_statement in the postgresql.conf, but > execute > /dbapi_con.cursor().execute("SET log_min_duration_statement to 30")/ > /for every connection./ OK, same effect: You're only logging slow statements. It's not at all surprising that BEGIN doesn't appear when a log_min_duration_statement is set. It's an incredibly fast operation. What's amazing is that it appears even once - that means your database must be in serious performance trouble, as BEGIN should take tenths of a millisecond on an unloaded system. For example my quick test here: LOG: statement: BEGIN; LOG: duration: 0.193 ms ... which is actually a lot slower than I expected, but hardly slow statement material. The frequent appearance of slow (multi-second) COMMIT statements in your slow statement logs suggests there's enough load on your database that there's real contention for disk, and/or that checkpoints are stalling transactions. First, you need to set log_min_messages = 'info' to allow Pg to complain about things like checkpoint frequency. Now temporarily set log_checkpoints = on to record when checkpoints happen and how long they take. Most likely you'll find you need to tune checkpoint behaviour. Some information, albeit old, on that is here: http://www.westnet.com/~gsmith/content/postgresql/chkp-bgw-83.htm Basically you might want to try increasing your checkpoint_completion_target and making the bgwriter more aggressive - assuming that your performance issues are in fact checkpoint related. It's also possible that they're just overall load, especially if you have lots and lots (hundreds) of connections to the database all trying to do work at once without any kind of admission control or pooling/queuing. In that case, introducing a connection pool like PgBouncer may help. -- Craig Ringer --------------080809080600070808040201 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 07/10/2012 10:25 AM, Yan Chunlu wrote:
I didn't set log_min_duration_statement in the postgresql.conf, but execute
dbapi_con.cursor().execute("SET log_min_duration_statement to 30")
for every connection.

OK, same effect: You're only logging slow statements.

It's not at all surprising that BEGIN doesn't appear when a log_min_duration_statement is set. It's an incredibly fast operation. What's amazing is that it appears even once - that means your database must be in serious performance trouble, as BEGIN should take tenths of a millisecond on an unloaded system. For example my quick test here:

LOG:  statement: BEGIN;
LOG:  duration: 0.193 ms

... which is actually a lot slower than I expected, but hardly slow statement material.

The frequent appearance of slow (multi-second) COMMIT statements in your slow statement logs suggests there's enough load on your database that there's real contention for disk, and/or that checkpoints are stalling transactions.


First, you need to set log_min_messages = 'info' to allow Pg to complain about things like checkpoint frequency.

Now temporarily set log_checkpoints = on to record when checkpoints happen and how long they take. Most likely you'll find you need to tune checkpoint behaviour. Some information, albeit old, on that is here:

  http://www.westnet.com/~gsmith/content/postgresql/chkp-bgw-83.htm

Basically you might want to try increasing your checkpoint_completion_target and making the bgwriter more aggressive - assuming that your performance issues are in fact checkpoint related.

It's also possible that they're just overall load, especially if you have lots and lots (hundreds) of connections to the database all trying to do work at once without any kind of admission control or pooling/queuing. In that case, introducing a connection pool like PgBouncer may help.

--
Craig Ringer
--------------080809080600070808040201--