Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnnJE-00FEKO-OE for pgsql-general@arkaria.postgresql.org; Fri, 22 Mar 2024 22:24:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rnnJC-007fEN-KR for pgsql-general@arkaria.postgresql.org; Fri, 22 Mar 2024 22:24:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnnJA-007fEE-QW for pgsql-general@lists.postgresql.org; Fri, 22 Mar 2024 22:24:18 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnnJ2-005ymV-29 for pgsql-general@lists.postgresql.org; Fri, 22 Mar 2024 22:24:16 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id D70C913800B8; Fri, 22 Mar 2024 18:24:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 22 Mar 2024 18:24:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1711146245; x=1711232645; bh=rrlU0qFoLi46LyeFRNOdOemFb6CG2bbHxOT8e7YSN/A=; b= dMHec5Q9NAI00V3YXBK6fG9qf0dpTdsXI3kcQIJHNxyYeD7XJRj5rOQB0vFtnLsb XViHwU1UT2TsjQmx/2oxTujsdO5DjZiXAgUl/2ulg9AheHPzSKcWmyEQf2yVTjfB 07rpSged4tByTStIBSlqjKtVwDkfJQoqF6YAYxhMBITA1WBi7OJZSUjMunZh9Uo9 wJ4jm2a2IbudraKpFZsZeK8vToyPdFFZDevQYXC8MvAcZ1URI8XhiToL1jU1Txni ZHifh5PSGXz1U+4izoKajujQ9+Z4S7CAN28RQSl8BmpyapJxYniDX9Wk5DhUwQgI XsAABSQtzhZfMfToB6mtFg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1711146245; x= 1711232645; bh=rrlU0qFoLi46LyeFRNOdOemFb6CG2bbHxOT8e7YSN/A=; b=S Ib4ogw+HV8jP6HGszw2FVRdtzqvvyZdFYFBa/dT0sJrL1jV2wjfPg79HH4tIRFvW SqES5Mfq6n0y/d+kcfluLSs5RH/jCJFoE7x1S8z+83kr4HXFHR0WJBh02cQmOobX pQtbpmfRlitX+7B/mF0tWernjZ1apVqfFirYayOTpBh8laWUJu0om3/BbukJ2Unb fnFixR/tzIXJA/etPlcLfEKKgqK7FMDGVJCLBKoCvsOwRIi4vT+lXHXtnfH84MDL 0kSP67Fa+bnk68ryTsDEbzeTnEMHqTXEpDRfhQHr3NRXDe+UOk+e+LQ1WVDgnHA4 E5mPtH0y3N9nkEpGt5dFQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtvddgleejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepfedvudevudegteegveejleeuueefhffggfeijeff vdeuiedugfelfeejveeggeeinecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 18:24:05 -0400 (EDT) Message-ID: <8a8aef5b-5239-4617-8b4c-ec54de02d4bb@aklaver.com> Date: Fri, 22 Mar 2024 15:24:04 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Timing out A Blocker Based on Time or Count of Waiters To: Fred Habash Cc: pgsql-general@lists.postgresql.org References: <4d234943-b4bf-4e59-aa89-e5d69e18a228@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/22/24 12:41, Fred Habash wrote: > Lock tree: All PID's waiting on a lock held by/blocked by single blocker > PID. Similar to what you see in the output of this script: > https://github.com/dataegret/pg-utils/blob/master/sql/locktree.sql > . > It uses the dot connotation to draw a tree. > > Waiters: The PID (first column) returned by this query, for example > > SELECT >     activity.pid, >     activity.usename, >     activity.query, >     blocking.pid AS blocking_id, >     blocking.query AS blocking_query > FROM pg_stat_activity AS activity > JOIN pg_stat_activity AS blocking ON blocking.pid = > ANY(pg_blocking_pids(activity.pid)); > > DDL example: An 'alter table ... alter column ...' would cause all DML > and SELECT statements to wait/block. > > Hope this answers your question. Thanks for your interest. Yes. To me the issue is, "Facing an issue where sometimes humans login to a database and run DDL statements causing a long locking tree of over 1000 waiters." where the problem is people running disruptive statements without regard to planning or what else is happening on the database. I am not sure that dropping a statement just based on a count is progress. If the DDL is important then it needs to be run at some point and you are conceivably back at the same blocking issue. This then leads to two possibilities either the DDL is not important and shouldn't be run or it is and some thought and timing needs to be applied before it is run. > > On Fri, Mar 22, 2024 at 12:32 PM Adrian Klaver > > wrote: > > On 3/22/24 09:25, Fred Habash wrote: > > Facing an issue where sometimes humans login to a database and > run DDL > > statements causing a long locking tree of over 1000 waiters. As a > > The above needs more explanation: > > 1) Define locking tree. > > 2) Define waiters. > > 3) Provide examples of the DDL. > > > > workaround, we asked developers to always start their DDL sessions > > with 'SET lock_timeout = 'Xs'. > > > > I reviewed the native lock timeout parameter in Postgres and > found 7. > > None seem to be related to blocker timeouts directly. > > > > idle_in_transaction_session_timeout > > idle_session_timeout > > lock_timeout: How long a session waits for a lock > > statement_timeout > > authentication_timeout > > deadlock_timeout > > log_lock_waits > > > > Instead, I put together a quick procedure that counts waiter > sessions > > for a given blocker and terminates it if waiter count exceeds a > threshold. > > > > Is there not a native way to ... > > 1. Automatically time out a blocker > > 2. A metric that shows how many waiters for a blocker? > > > > Thanks > > -- > > > > ---------------------------------------- > > Thank you > > > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > > > -- > > ---------------------------------------- > Thank you > > -- Adrian Klaver adrian.klaver@aklaver.com