Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 8D49D1AC5EFD for ; Thu, 5 Jul 2012 03:34:12 -0300 (ADT) Received: from mail-gg0-f174.google.com ([209.85.161.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Smfdi-00051D-G4 for pgsql-admin@postgresql.org; Thu, 05 Jul 2012 06:34:12 +0000 Received: by gglu4 with SMTP id u4so7042718ggl.19 for ; Wed, 04 Jul 2012 23:33:56 -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:content-transfer-encoding :x-gm-message-state; bh=dSM0JSA7tuESJB5zF8FyWlEtySeDG2iaa8SwBFNNTDg=; b=jzn0S30Sv0xGmvz9yCEkMDzDIEqifnHjNXfeAg2LCyKD5aH79ki1QylxfhUv5fZvlC wYNIwlGKWcf4pHoVL5IE+6+dYEurjthHmWArFwvLUfHckRcJwsOUtOg3sGyvTB5+396n qYCsiJJzbg3/xXG+RoqqQA8kmSb/GQrTl2DP0W0bqSXbjBw4ddgnmX5IzppmPIac8c8s 7X5fIVEeQHMUggPYnCi8nKHTC6WWWRiahkHy5iycI4bHdpjn0ZEVeeDT7xQW3tGrk2so yzjTylljFc6MgLAT7/tuvr+3+6buXSfm+qE4MPUeiaf0mdw+TPcPUsBS5nhSQwIE+fJy m68A== Received: by 10.68.203.73 with SMTP id ko9mr25778099pbc.66.1341470035618; Wed, 04 Jul 2012 23:33:55 -0700 (PDT) Received: from ayaki.localdomain (124-169-169-118.dyn.iinet.net.au. [124.169.169.118]) by mx.google.com with ESMTPS id pe2sm19154382pbc.59.2012.07.04.23.33.53 (version=SSLv3 cipher=OTHER); Wed, 04 Jul 2012 23:33:54 -0700 (PDT) Message-ID: <4FF5354E.8090105@ringerc.id.au> Date: Thu, 05 Jul 2012 14:33:50 +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: Akash Kodibail CC: "pgsql-admin@postgresql.org" Subject: Re: Delay in completion of aggregation inserts when run in a single commit - PG 9.1.2 References: <67A07D932F8DCC41989A050EDE427A210CF9B5@JETWINSRVRPS02.onmobile.com> In-Reply-To: <67A07D932F8DCC41989A050EDE427A210CF9B5@JETWINSRVRPS02.onmobile.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Gm-Message-State: ALoCoQlgZLeAvKeEjmql7rVybr4JxLr2qXL3vDfov3+Q7LWJwUBjKAakPBkfezrT6QiRZ+ZzF1AK X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/19 X-Sequence-Number: 39736 On 07/05/2012 02:30 AM, Akash Kodibail wrote: > -Staging table population happens in expected time. Anywhere from > 10-15 minutes for each process. > > -Aggregation process almost never completes which is a set of 15 > insert queries. Entire process happens in a single commit (population > of staging tables and aggregation). > When you mean "never completes" - can you be more specific? Is the query not progressing - say, waiting on a lock? Is it doing work, but performing very poorly? Does it terminate with a failure? If so, error message? If the query just keeps running but you're not sure what it is or isn't doing, you should examine pg_stat_activity and pg_locks. From pg_stat_activity you can get the backend process ID; examine that backend using system tools (ps, top, etc) to see if it's using CPU and whether it's doing disk I/O. From pg_locks you can get an idea of whether a query is stuck waiting on a lock. > Could you be kind enough to explain how differently queries run when > in a “single commit” as opposed to running each of them individually? There shouldn't be tons of difference. The first queries continue to hold locks while the others run, but since you're in the same transaction it won't affect subsequent queries, only concurrent ones. If you have other concurrent work going on it's possible you're running into locking issues that you don't encounter when you release locks with individual commits. Also, some resources can only be released when a transaction commits. If you're doing something like using huge numbers of savepoints or PL/PgSQL BEGIN ... EXCEPT blocks it's possible you're running into resource issues. The SAVEPOINT code has improved massively since 8.3 when I had similar issues, but savepoints still aren't free. Start by looking at the locking situation, and by determining whether your query is making slow forward progress or is simply waiting. > > Postgresql.conf remains untouched, except for log writing which has > been made to “all”. > That's going to be VERY sub-optimal if you're bulk-loading data. You'll need to push checkpoint_segments right up. Check your logs; you're probably seeing warnings about checkpoints being too frequent. Hell, my checkpoint_segments is at 50 on my *laptop* - albeit a very fast SSD-equipped laptop that does lots of blk data uinit testing. You'll want to push effective_cache_size up to 4 or 5 GB given you have three instances. Hard to say re shared_buffers, I have little experience with running multiple instances on one machine. -- Craig Rin