aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2024-06-27 19:21:05 -0700
committerNoah Misch <noah@leadboat.com>2024-06-27 19:21:05 -0700
commit5b823b179e5e8ab32f140658698ca08f8c83f06e (patch)
tree3b2fc59de9850faf8af1dcf9bd67ab4df3961d04 /src
parent0cecc908e9749101b5e93ba58d76a62c9f226f9e (diff)
downloadpostgresql-5b823b179e5e8ab32f140658698ca08f8c83f06e.tar.gz
postgresql-5b823b179e5e8ab32f140658698ca08f8c83f06e.zip
AccessExclusiveLock new relations just after assigning the OID.
This has no user-visible, important consequences, since other sessions' catalog scans can't find the relation until we commit. However, this unblocks introducing a rule about locks required to heap_update() a pg_class row. CREATE TABLE has been acquiring this lock eventually, but it can heap_update() pg_class.relchecks earlier. create_toast_table() has been acquiring only ShareLock. Back-patch to v12 (all supported versions), the plan for the commit relying on the new rule. Reviewed (in an earlier version) by Robert Haas. Discussion: https://postgr.es/m/20240611024525.9f.nmisch@google.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/heap.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index a122bbffce7..ae2efdc760d 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1250,6 +1250,13 @@ heap_create_with_catalog(const char *relname,
}
/*
+ * Other sessions' catalog scans can't find this until we commit. Hence,
+ * it doesn't hurt to hold AccessExclusiveLock. Do it here so callers
+ * can't accidentally vary in their lock mode or acquisition timing.
+ */
+ LockRelationOid(relid, AccessExclusiveLock);
+
+ /*
* Determine the relation's initial permissions.
*/
if (use_user_acl)