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 1ullSF-005Ccw-Nd for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Aug 2025 09:38:03 +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 1ullSD-006cdU-Tg for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Aug 2025 09:38:02 +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 1ullSD-006cdM-Jn for pgsql-hackers@lists.postgresql.org; Tue, 12 Aug 2025 09:38:01 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ullSB-000B1K-0h for pgsql-hackers@lists.postgresql.org; Tue, 12 Aug 2025 09:38:01 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-458b49c98a7so33458955e9.1 for ; Tue, 12 Aug 2025 02:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754991478; x=1755596278; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=GATLwKiAJgeOA3wbXAcAczX4fscjayxjeXgY4kxZD6Y=; b=QfptUtYXxmtuGCI56dUFSfIcwqyoxYzXHrEu3TG3onRM8SjOxJvTUfluhl+erXd8PU 0X9aik4JrzPfA7iYDqguCfLgJChVkKVrbTQg8Gi9P2NVk44jrhq2ePawrbOc6tPIKnNm RMSJDD/WS6CVKzi6IgTDccx5sOfShlluI1OrCDreOgxyBVniGWrmpE3XyY4v7zqp8gIF FN0EKzZwAC4huTnlFGM7sx2Y7riuVgy/KCYEFKlDdTZikFB2ppzKubdI1Dnow4lQiImE ylUGDGMEH1OSVJJAKDvbpevq1AIidUE9mShu1nue2Ryybkd+He/NTxfIdVYZhoBWdvHl TqPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754991478; x=1755596278; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GATLwKiAJgeOA3wbXAcAczX4fscjayxjeXgY4kxZD6Y=; b=NARwQpCG1FIVt37GYbqtjMMx4zso5JMvCZhJwnBs1S+QCGye8uABlIkxXSm+01pbv2 1lU0ou9EHpMJDc8D1QgYqZb664bc3NjohLRJeg4rk5eazBWOTaFNaAubp7RL9AcYMwCS tIHq/JNF2tVdEQUqzjDv4TMcoKDs2TbRgDw8buGA7RS6EEglYtnM0vd7K++lfWh6Ef0t P6HIdc/sNAApF8m/bIx4sSZKguACccgJzi33yAqiA33dq8y0II8sXR0bEjAycPSjp0JV /4C0gJtm5KwYLP0Cql1IfLiHOYbpgTTg9mr0vG5gJffpP4UKU/RXY65hIc1RV4SoStx4 PeIg== X-Forwarded-Encrypted: i=1; AJvYcCX1bvGIVI/1oOqt/U8lfl/e4rXhQaMp1Uf7PZXJBpmbXww/rLLBhAVVI33UhMkW6ao8RheO8CQFa8mHB0Lj@lists.postgresql.org X-Gm-Message-State: AOJu0Yye1Xhw+QOjDJbAUqOp5yve4cYlMXN1fiasR0C4zWC7oiUBFJKb vMI+fy85BaKrvRCAyxPCY22R9V1MUuCeBvSALY+poSoWznamABUL6k6u X-Gm-Gg: ASbGncvdBWRAhBwA8jluq3StuehoA18GaRDhK1mSJLebG2t75BMBnunQmB+6tmur14c DXSDV8w2ZGyeU5DDNuaw5G2DzNmv8xC1iDmlJeLB6dZVPZSEoA+dpp9a2n1dapBp3KrfM3eu3BM U6gHfYDgMRDr2dXgZISNOuFbRfZnJx8gGQ0q/qrZZVPtJ30Xc4OaH8GxTx1MFj6fKCN92EfIDIl 3S58hhC6JOuqOsJW6Sj1ucWYvYLYiXez3Acq0tcY/ma4QpsgxQWfQQVjWWiZYBS64VA6bxNnkYX 1XQ1W49LX7/NhdTiP5J14S++T9yaaKhXi20rsIO1ml4RlDBG4NhDU2tfX3tamLhHku0Ovs4jG9K NB/TpvtjAk+D43OIE+XN49vsIxJ8Xq3AFBSG/TPQK4xtUiB1OkzHXQ5hp6GHpzHbk1I174W3dBg w7XnYEp7ScORckDYRZBPe88OvQQGV5CQDOtecjF7IEoqHqyPD7r+1vxQ== X-Google-Smtp-Source: AGHT+IFzXpZG3AfGKi6jktdftKfbN5r8yo9vT+beg0f350WsV4WPDLZuAT3ZbyglvevM3JR0b+B6pg== X-Received: by 2002:a05:600c:3b27:b0:456:285b:db24 with SMTP id 5b1f17b1804b1-45a10c00217mr22502735e9.28.1754991477532; Tue, 12 Aug 2025 02:37:57 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e5887b7fsm288348345e9.30.2025.08.12.02.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 02:37:57 -0700 (PDT) Date: Tue, 12 Aug 2025 09:37:55 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Jeff Davis , Greg Sabino Mullane , pgsql-hackers@lists.postgresql.org Subject: Re: Adding locks statistics Message-ID: References: <87c3170d0645cec732f0d7b2969c75db1b3c86c6.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Aug 12, 2025 at 08:44:58AM +0900, Michael Paquier wrote: > On Mon, Aug 11, 2025 at 02:53:58PM -0700, Jeff Davis wrote: > > On Mon, 2025-08-11 at 13:54 -0400, Greg Sabino Mullane wrote: > > > Great idea. +1. Here is a quick overall review to get things started. > > > > Can you describe your use case? I'd like to understand whether this is > > useful for users, hackers, or both. Thanks for looking at it! I provided a few examples in the initial email ([1]): " It can be used for example for: 1. checking if "waits" is close to "requests". Then it means you usually have to wait before acquiring the lock, which means you may have a concurrency issue. 2. lock_timeout and deadlock_timeout tuning (lock_timeout is visible only in the logs if log_min_error_statement is set appropriately). 3. checking the "requests"/"fastpath" ratio to see if "max_locks_per_transaction" needs tuning (see c4d5cb71d2). " Do these seem like useful use cases? > - Is there any decision-making where these numbers would help? These > decisions would shape in tweaking the configuration of the server or > the application to as we move from a "bad" number trend to a "good" > number trend. Right, I think that could help for lock_timeout and deadlock_timeout tuning. > - What would be good numbers? In this case, most likely a threshold > reached over a certain period of time. Also I think it's more a matter of ratio: waits/requests and requests/fastpath for example. > - Would these new stats overlap with similar statistics gathered in > the system, creating duplication and bloat in the pgstats for no real > gain? I don't think there is currently stats that overlap with those. > Looking at the patch, the data gathered is this, and I don't think > that we have metrics gathered in the system to get an idea of the > contention in this area, for timeouts and deadlocks: > + PgStat_Counter requests; > + PgStat_Counter waits; > + PgStat_Counter timeouts; > + PgStat_Counter deadlock_timeouts; > + PgStat_Counter deadlocks; > + PgStat_Counter fastpath; > > Isn't the "deadlock_timeout" one an overlap between timeout and > deadlock? I don't think so because: - deadlock_timeout and lock_timeout are 2 distincts GUCs - you could reach the deadlock_timeout without actually producing a deadlock > Regarding the fastpath locking, you'd want to optimize the fastpath to > be close to the number of requests. If you had these numbers, one > thing that I could see a DBA do is tune max_locks_per_transaction, > which is what influences the per-backend limit of fast-path locks, > with FastPathLockGroupsPerBackend. Exactly. > Using static counters for the pending data is going to be necessary > when these are called in critical sections, which is I guess why > you've done it this way, right? Yes and there is no need to over complicate this stuff as the max size is known: LOCKTAG_LAST_TYPE + 1. [1]: https://www.postgresql.org/message-id/aIyNxBWFCybgBZBS%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com