pgsql: Improve TRUNCATE by avoiding early lock queue

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve TRUNCATE by avoiding early lock queue
Date: 2018-08-10 16:28:34
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve TRUNCATE by avoiding early lock queue

A caller of TRUNCATE could previously queue for an access exclusive lock
on a relation it may not have permission to truncate, potentially
interfering with users authorized to work on it. This can be very
intrusive depending on the lock attempted to be taken. For example,
pg_authid could be blocked, preventing any authentication attempt to
happen on a PostgreSQL instance.

This commit fixes the case of TRUNCATE so as RangeVarGetRelidExtended is
used with a callback doing the necessary ACL checks at an earlier stage,
avoiding lock queuing issues, so as an immediate failure happens for
unprivileged users instead of waiting on a lock that would not be
taken.

This is rather similar to the type of work done in cbe24a6 for CLUSTER,
and the code of TRUNCATE is this time refactored so as there is no
user-facing changes. As the commit for CLUSTER, no back-patch is done.

Reported-by: Lloyd Albin, Jeremy Schneider
Author: Michael Paquier
Reviewed by: Nathan Bossart, Kyotaro Horiguchi
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f841ceb26d701e7f5f48190bf7290c400cba30a2

Modified Files
--------------
src/backend/commands/tablecmds.c | 84 ++++++++++++++-----
src/test/isolation/expected/truncate-conflict.out | 99 +++++++++++++++++++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/truncate-conflict.spec | 38 +++++++++
4 files changed, 204 insertions(+), 18 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-08-10 18:14:35 pgsql: Cosmetic cleanups in initdb.c.
Previous Message Alexander Korotkov 2018-08-10 14:36:26 pgsql: Fix typo in SP-GiST error message