Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi, On Sat, Jun 13, 2026 at 01:15:49PM +0900, Tatsuya Kawata wrote: > Hi, > > While developing the pg_stat_lock improvement proposed in (*1), I > noticed that the documentation of the fastpath_exceeded column in > pg_stat_lock could be more explicit about its scope. > > The current documentation describes it as: > > Number of times a lock of this type could not be acquired via fast > path because the fast path slot limit was exceeded. Increasing > max_locks_per_transaction can reduce this number. > > This omits the fact that fast-path locking only applies to relation > locks acquired in the weak modes (AccessShareLock, RowShareLock, > RowExclusiveLock), so the counter is always zero for any other > locktype. > > The attached patch adds a short clarification to the pg_stat_lock entry > in monitoring.sgml. I think that the current documentation is lacking explanation as to what the fast path means as a whole. So I think that what we could do instead, is to explain what fast path means (maybe around pg_lock?). Then, we could reference it in pg_stat_lock if we feel the need. Thoughts? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
On Mon, Jun 15, 2026 at 02:17:18PM +0000, Bertrand Drouvot wrote: > I think that the current documentation is lacking explanation as to what the fast > path means as a whole. So I think that what we could do instead, is to explain > what fast path means (maybe around pg_lock?). Then, we could reference it in > pg_stat_lock if we feel the need. A more centralized explanation that could then be used as a link from the page of the view sounds like a good plan here. -- Michael
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
Hi Bertrand-san, Michael-san,
Thanks for the feedback. Centralizing the explanation and linking
from views makes sense, so v2 takes that approach.
Specifically, v2:
* Adds a new "Fast-Path Locking" subsection under Explicit Locking
(13.3.1.1, inside Table-Level Locks).
* References the new section from:
- pg_stat_lock.fastpath_exceeded (monitoring.sgml)
- pg_locks.fastpath (system-views.sgml)
- max_locks_per_transaction (config.sgml)
Patch v2 attached.
Regards,
Tatsuya Kawata
Thanks for the feedback. Centralizing the explanation and linking
from views makes sense, so v2 takes that approach.
Specifically, v2:
* Adds a new "Fast-Path Locking" subsection under Explicit Locking
(13.3.1.1, inside Table-Level Locks).
* References the new section from:
- pg_stat_lock.fastpath_exceeded (monitoring.sgml)
- pg_locks.fastpath (system-views.sgml)
- max_locks_per_transaction (config.sgml)
Patch v2 attached.
Regards,
Tatsuya Kawata
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi Kawata-san,
On Sat, Jun 20, 2026 at 06:14:59PM +0900, Tatsuya Kawata wrote:
> Hi Bertrand-san, Michael-san,
>
> Thanks for the feedback. Centralizing the explanation and linking
> from views makes sense, so v2 takes that approach.
Thanks for the new version.
--- a/doc/src/sgml/mvcc.sgml
+++ b/doc/src/sgml/mvcc.sgml
@@ -1248,6 +1248,35 @@ ERROR: could not serialize access due to read/write dependencies among transact
+
+
+ Fast-Path Locking
The location looks ok to me.
+ for eligible locks, fast-path is used only when a per-backend slot is
+ available;
Should we add a description of the consequences of not being able to acquire the
lock in fast-path (when there are no available slots)? For example, we could
say that this is considerably more expensive and may be subject to contention.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
Hi Bertrand-san,
Thanks for the review.
> Should we add a description of the consequences of not being able to
> acquire the lock in fast-path (when there are no available slots)?
> For example, we could say that this is considerably more expensive
> and may be subject to contention.
Agreed. v3 adds the following paragraph at the end of the Fast-Path Locking subsection:
+ <para>
+ Acquiring a lock via the main lock table is considerably more
+ expensive than the fast path, and under heavy concurrent lock
+ activity can become a point of contention (observable as the
+ <literal>LockManager</literal> wait event).
+ </para>
Other parts of the patch are unchanged from v2.
v3 attached.
Regards,
Tatsuya Kawata
Thanks for the review.
> Should we add a description of the consequences of not being able to
> acquire the lock in fast-path (when there are no available slots)?
> For example, we could say that this is considerably more expensive
> and may be subject to contention.
Agreed. v3 adds the following paragraph at the end of the Fast-Path Locking subsection:
+ <para>
+ Acquiring a lock via the main lock table is considerably more
+ expensive than the fast path, and under heavy concurrent lock
+ activity can become a point of contention (observable as the
+ <literal>LockManager</literal> wait event).
+ </para>
Other parts of the patch are unchanged from v2.
v3 attached.
Regards,
Tatsuya Kawata
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi Kawata-san, On Mon, Jun 22, 2026 at 08:34:12PM +0900, Tatsuya Kawata wrote: > Hi Bertrand-san, > > Thanks for the review. > > > Should we add a description of the consequences of not being able to > > acquire the lock in fast-path (when there are no available slots)? > > For example, we could say that this is considerably more expensive > > and may be subject to contention. > > Agreed. v3 adds the following paragraph at the end of the Fast-Path Thanks! Looking closer, I'm not sure that in: - lock table + lock table. See for + details. the "for details" is needed. Looking at the pg_locks table, it looks like "(See xxxx)" would be more consistent. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
On Tue, Jun 23, 2026 at 04:07:39AM +0000, Bertrand Drouvot wrote: > Looking closer, I'm not sure that in: > > - lock table > + lock table. See for > + details. > > the "for details" is needed. Looking at the pg_locks table, it looks like > "(See xxxx)" would be more consistent. Hmm. system-views.sgml has a large paragraph about fast-path locks, and seems to be the only location in the official docs where the term is used. I am wondering if the paragraph in view-pg-locks could be improved and/or shortened with what you are proposing here, even if most of it points to the inconsistencies one could get when querying pg_locks due to the volatile nature of fast-path locks... At least a link on the pg_locks page pointing to this new section could be something to consider. -- Michael
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
Hi Bertrand-san, Michael-san,
Thanks for the additional review!
> Looking closer, I'm not sure that in:
>
> - lock table
> + lock table. See <xref linkend="locking-tables-fast-path"/> for
> + details.
>
> the "for details" is needed. Looking at the pg_locks table, it looks like
> "(See xxxx)" would be more consistent.
Fixed.
> I am wondering if the paragraph in view-pg-locks could be
> improved and/or shortened with what you are proposing here, even if
> most of it points to the inconsistencies one could get when querying
> pg_locks due to the volatile nature of fast-path locks... At least a
> link on the pg_locks page pointing to this new section could be
> something to consider.
Thanks for the detailed thought. I looked at that paragraph. I was
hoping to fold the two together, but the content did not seem to
overlap, so I limited the change to adding a link as you suggested.
v4 attached.
Regards,
Tatsuya Kawata
Thanks for the additional review!
> Looking closer, I'm not sure that in:
>
> - lock table
> + lock table. See <xref linkend="locking-tables-fast-path"/> for
> + details.
>
> the "for details" is needed. Looking at the pg_locks table, it looks like
> "(See xxxx)" would be more consistent.
Fixed.
> I am wondering if the paragraph in view-pg-locks could be
> improved and/or shortened with what you are proposing here, even if
> most of it points to the inconsistencies one could get when querying
> pg_locks due to the volatile nature of fast-path locks... At least a
> link on the pg_locks page pointing to this new section could be
> something to consider.
Thanks for the detailed thought. I looked at that paragraph. I was
hoping to fold the two together, but the content did not seem to
overlap, so I limited the change to adding a link as you suggested.
v4 attached.
Regards,
Tatsuya Kawata
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
On Sat, Jun 27, 2026 at 11:14:16PM +0900, Tatsuya Kawata wrote: > Thanks for the detailed thought. I looked at that paragraph. I was > hoping to fold the two together, but the content did not seem to > overlap, so I limited the change to adding a link as you suggested. I'm finding that rather acceptable. Bertrand-san, what do you think? -- Michael
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi, On Mon, Jun 29, 2026 at 09:31:36AM +0900, Michael Paquier wrote: > On Sat, Jun 27, 2026 at 11:14:16PM +0900, Tatsuya Kawata wrote: > > Thanks for the detailed thought. I looked at that paragraph. I was > > hoping to fold the two together, but the content did not seem to > > overlap, so I limited the change to adding a link as you suggested. > > I'm finding that rather acceptable. Bertrand-san, what do you think? Yeah. I just wonder if we should mention it does not apply to shared relation while at it. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
On Mon, Jun 29, 2026 at 04:52:32AM +0000, Bertrand Drouvot wrote: > Yeah. I just wonder if we should mention it does not apply to shared relation > while at it. [... checks code ...] EligibleForRelationFastPath() tells that, yes. An extra mention would be nice, good catch. Better than having to guess from the code. -- Michael
Re: [PATCH] doc: clarify pg_stat_lock.fastpath_exceeded scope
От:
Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Дата:
Hi Michael-san, Bertrand-san,
> Added a sentence about shared relations in the second paragraph, and
> applied the result on HEAD.
Thank you for the commit, and for all the reviews throughout the
thread. The final result is much better than what I started with.
Regards,
Tatsuya Kawata
> Added a sentence about shared relations in the second paragraph, and
> applied the result on HEAD.
Thank you for the commit, and for all the reviews throughout the
thread. The final result is much better than what I started with.
Regards,
Tatsuya Kawata
Re: Fix unsafe coding in ResourceOwnerReleaseAll()
On 12/08/2026 11:27, Rahila Syed wrote: >> More: unless I'm missing something, ResourceOwnerReleaseAllOfKind >> is called only from plancache.c's ReleaseAllPlanCacheRefsInOwner, >> which is called only in some very random-looking ways in plpgsql. >> I wonder whether there's not a bigger cleanup project indicated here. >> When I posted before, I thought that ResourceOwnerReleaseAllOfKind had >> a direct lineage to the old ResourceOwner code, but now I'm thinking >> maybe it shouldn't exist at all. Why should plpgsql be taking special >> care for particular kinds of resource entries, and why should it >> suppose that it owns all instances of that kind within that resowner? > > I agree that ResourceOwnerReleaseAllOfKind can be removed > > After digging into the resource owner code, it looks like a reason for > having the ResourceOwnerReleaseAllOfKind variant is to allow releasing > all of an owner's resources without going through the three-phase > release mechanism that ResourceOwnerRelease normally enforces > (BEFORE_LOCKS -> LOCKS -> AFTER_LOCKS). That phase ordering isn't > needed if a resource owner only ever holds one kind of resource and > has no children holding other kinds. > > The resource owners that ResourceOwnerReleaseAllOfKind is actually > called on (plpgsql's procedure-lifespan owner, the DO-block > simple-expression owner, and the shared simple-expression owner) are > all created specifically to retain resources across transaction > COMMIT/ROLLBACK boundaries. In practice they only ever hold plan-cache > refcounts, so a three-phase release is not required for them. These > owners are deleted immediately after the ResourceOwnerReleaseAllOfKind > call, which shows the intent at each call site is "release everything > this owner holds," rather than to "release only resources of this one > kind." > > I tested this by replacing all four call sites with three explicit > ResourceOwnerRelease() calls (one per phase) instead of the single > ResourceOwnerReleaseAllOfKind() call. This passes the plpgsql tests > and the regression suite without crashes or assertion failures. (patch > attached). > The drawback with this approach is that it takes three calls to > release the owners. > Since plan-cache refs are registered at RESOURCE_RELEASE_AFTER_LOCKS, > the BEFORE_LOCKS and LOCKS calls are no-ops for these owners, but are > still required to satisfy ResourceOwnerRelease's internal > phase-ordering assertions. > > One possible refactoring: pass a flag to ResourceOwnerRelease (or > ResourceOwnerReleaseAll) indicating it does not need to respect phase > ordering and can just release everything the owner holds in one pass. > That would let a caller drain a standalone, single-kind owner in one > call instead of three. +1 for having a function that just releases all resources in a resource owner in one call. I don't think it's performance critical so it could just call ResourceOwnerRelease() three times. ReleaseAuxProcessResources() could make use of it too. > If we had that, I don't think we would need > ResourceOwnerReleaseAllOfKind — unless a future use case requires > releasing resources of one particular kind from an owner that contains > different kinds of resources or has children holding different kinds > of resources belonging to different phases. +1 for removing it. I hope we don't need it in the future, it feels like a ugly wart in the first place. > Removing ResourceOwnerReleaseAllOfKind will also help get rid of one > of the flags "releasing" or "sorted" in ResourceOwnerData. You still need those flags when you release in phases. I don't see us getting rid of the three phases in the usual transaction-scoped resource owners any time soon, even if some resource owners don't need them. - Heikki