Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 9847C2E008D for ; Sun, 11 May 2008 09:06:14 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 32114-09 for ; Sun, 11 May 2008 09:06:04 -0300 (ADT) X-Greylist: delayed 00:35:15.619302 by SQLgrey-1.7.6 Received: from b.mail.sonic.net (b.mail.sonic.net [64.142.19.5]) by developer.postgresql.org (Postfix) with ESMTP id 6E0B12E0089 for ; Sun, 11 May 2008 09:06:05 -0300 (ADT) Received: from newshell.sonic.net (bolt.sonic.net [208.201.242.19]) by b.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id m4BBUlqS015004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 11 May 2008 04:30:47 -0700 Received: from bolt.sonic.net (IDENT:05Lr/US49KSIIXb416EUehyti4h5JIwy@localhost.localdomain [127.0.0.1]) by newshell.sonic.net (8.13.6/8.12.1) with ESMTP id m4BBUl0I004813; Sun, 11 May 2008 04:30:47 -0700 Received: (from daveg@localhost) by bolt.sonic.net (8.13.6/8.12.1/Submit) id m4BBUluZ004812; Sun, 11 May 2008 04:30:47 -0700 Date: Sun, 11 May 2008 04:30:47 -0700 From: daveg To: pgsql-patches@postgresql.org Cc: hari@efrontier.com Subject: pg_dump lock timeout Message-ID: <20080511113047.GV5673@sonic.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/194 X-Sequence-Number: 6220 Attached is a patch to add a commandline option to pg_dump to limit how long pg_dump will wait for locks during startup. The intent of this patch is to allow pg_dump to fail if a table lock cannot be taken in a reasonable time. This allows the caller of pg_dump to retry or otherwise correct the situation, without having locks held for long periods, and without pg_dump having a long window during which catalog changes can occur. It works by setting statement_timeout to the user specified delay during the startup phase where it is taking access share locks on all the tables. Once all the locks are taken, it sets statement_timeout back to the default. If a lock table statement times out, the dump fails with the statement timed out error. The orginal motivation was a client who runs heavy batch workloads and uses truncate table and other DML in long transactions. This has created some unhappy interaction scenarios with pg_dump: - pg_dump ends up waiting hours on a DML table lock that is part of a long transaction. Once the lock is released, pg_dump runs only to find some table later in the list has been dropped. So pg_dump fails. - pg_dump waits on a lock while holding access share locks on most of the tables. Other processes that want to do DML wait on pg_dump. After a while, large parts of the application are blocked while pg_dump waits on locks. Eventually the operations staff notice that pg_dump is blocking production and kill the dump. Please have a look and consider it for merging. Thanks -dg -- David Gould If simplicity worked, the world would be overrun with insects.