public inbox for [email protected]  
help / color / mirror / Atom feed
From: Bertrand Drouvot <[email protected]>
Subject: [PATCH v11 1/3] Add storage/locktag.h
Date: Thu, 19 Mar 2026 09:50:06 +0000

Move LockTagType, LOCKTAG_LAST_TYPE, LockTagTypeNames and LOCKTAG out
of storage/lock.h into a new storage/locktag.h header. This will avoid
pulling in the heavyweight storage/lock.h header from pgstat.h in a following
commit.

Author: Bertrand Drouvot <[email protected]>
Discussion: https://postgr.es/m/abufUya2oK-_PJ3E%40paquier.xyz
---
 src/include/storage/lock.h    | 47 +-------------------------
 src/include/storage/locktag.h | 63 +++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 46 deletions(-)
 100.0% src/include/storage/

diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index 55ffaa5e4a5..e72d94bba49 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -21,6 +21,7 @@
 #include "access/transam.h"
 #include "lib/ilist.h"
 #include "storage/lockdefs.h"
+#include "storage/locktag.h"
 #include "storage/lwlock.h"
 #include "storage/procnumber.h"
 #include "storage/shmem.h"
@@ -127,52 +128,6 @@ typedef uint16 LOCKMETHODID;
 #define DEFAULT_LOCKMETHOD	1
 #define USER_LOCKMETHOD		2
 
-/*
- * LOCKTAG is the key information needed to look up a LOCK item in the
- * lock hashtable.  A LOCKTAG value uniquely identifies a lockable object.
- *
- * The LockTagType enum defines the different kinds of objects we can lock.
- * We can handle up to 256 different LockTagTypes.
- */
-typedef enum LockTagType
-{
-	LOCKTAG_RELATION,			/* whole relation */
-	LOCKTAG_RELATION_EXTEND,	/* the right to extend a relation */
-	LOCKTAG_DATABASE_FROZEN_IDS,	/* pg_database.datfrozenxid */
-	LOCKTAG_PAGE,				/* one page of a relation */
-	LOCKTAG_TUPLE,				/* one physical tuple */
-	LOCKTAG_TRANSACTION,		/* transaction (for waiting for xact done) */
-	LOCKTAG_VIRTUALTRANSACTION, /* virtual transaction (ditto) */
-	LOCKTAG_SPECULATIVE_TOKEN,	/* speculative insertion Xid and token */
-	LOCKTAG_OBJECT,				/* non-relation database object */
-	LOCKTAG_USERLOCK,			/* reserved for old contrib/userlock code */
-	LOCKTAG_ADVISORY,			/* advisory user locks */
-	LOCKTAG_APPLY_TRANSACTION,	/* transaction being applied on a logical
-								 * replication subscriber */
-} LockTagType;
-
-#define LOCKTAG_LAST_TYPE	LOCKTAG_APPLY_TRANSACTION
-
-extern PGDLLIMPORT const char *const LockTagTypeNames[];
-
-/*
- * The LOCKTAG struct is defined with malice aforethought to fit into 16
- * bytes with no padding.  Note that this would need adjustment if we were
- * to widen Oid, BlockNumber, or TransactionId to more than 32 bits.
- *
- * We include lockmethodid in the locktag so that a single hash table in
- * shared memory can store locks of different lockmethods.
- */
-typedef struct LOCKTAG
-{
-	uint32		locktag_field1; /* a 32-bit ID field */
-	uint32		locktag_field2; /* a 32-bit ID field */
-	uint32		locktag_field3; /* a 32-bit ID field */
-	uint16		locktag_field4; /* a 16-bit ID field */
-	uint8		locktag_type;	/* see enum LockTagType */
-	uint8		locktag_lockmethodid;	/* lockmethod indicator */
-} LOCKTAG;
-
 /*
  * These macros define how we map logical IDs of lockable objects into
  * the physical fields of LOCKTAG.  Use these to set up LOCKTAG values,
diff --git a/src/include/storage/locktag.h b/src/include/storage/locktag.h
new file mode 100644
index 00000000000..22ad9c22798
--- /dev/null
+++ b/src/include/storage/locktag.h
@@ -0,0 +1,63 @@
+/*-------------------------------------------------------------------------
+ *
+ * locktag.h
+ *	  POSTGRES LOCKTAG to look up a LOCK item in the lock hashtable.
+ *
+ *
+ * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/storage/locktag.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef LOCKTAG_H_
+#define LOCKTAG_H_
+
+/*
+ * LOCKTAG is the key information needed to look up a LOCK item in the
+ * lock hashtable.  A LOCKTAG value uniquely identifies a lockable object.
+ *
+ * The LockTagType enum defines the different kinds of objects we can lock.
+ * We can handle up to 256 different LockTagTypes.
+ */
+typedef enum LockTagType
+{
+	LOCKTAG_RELATION,			/* whole relation */
+	LOCKTAG_RELATION_EXTEND,	/* the right to extend a relation */
+	LOCKTAG_DATABASE_FROZEN_IDS,	/* pg_database.datfrozenxid */
+	LOCKTAG_PAGE,				/* one page of a relation */
+	LOCKTAG_TUPLE,				/* one physical tuple */
+	LOCKTAG_TRANSACTION,		/* transaction (for waiting for xact done) */
+	LOCKTAG_VIRTUALTRANSACTION, /* virtual transaction (ditto) */
+	LOCKTAG_SPECULATIVE_TOKEN,	/* speculative insertion Xid and token */
+	LOCKTAG_OBJECT,				/* non-relation database object */
+	LOCKTAG_USERLOCK,			/* reserved for old contrib/userlock code */
+	LOCKTAG_ADVISORY,			/* advisory user locks */
+	LOCKTAG_APPLY_TRANSACTION,	/* transaction being applied on a logical
+								 * replication subscriber */
+} LockTagType;
+
+#define LOCKTAG_LAST_TYPE	LOCKTAG_APPLY_TRANSACTION
+
+extern PGDLLIMPORT const char *const LockTagTypeNames[];
+
+/*
+ * The LOCKTAG struct is defined with malice aforethought to fit into 16
+ * bytes with no padding.  Note that this would need adjustment if we were
+ * to widen Oid, BlockNumber, or TransactionId to more than 32 bits.
+ *
+ * We include lockmethodid in the locktag so that a single hash table in
+ * shared memory can store locks of different lockmethods.
+ */
+typedef struct LOCKTAG
+{
+	uint32		locktag_field1; /* a 32-bit ID field */
+	uint32		locktag_field2; /* a 32-bit ID field */
+	uint32		locktag_field3; /* a 32-bit ID field */
+	uint16		locktag_field4; /* a 16-bit ID field */
+	uint8		locktag_type;	/* see enum LockTagType */
+	uint8		locktag_lockmethodid;	/* lockmethod indicator */
+} LOCKTAG;
+
+#endif							/* LOCKTAG_H_ */
-- 
2.34.1


--YVZ2rdHTqHRFZ4HX
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v11-0002-Add-lock-statistics.patch"



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [PATCH v11 1/3] Add storage/locktag.h
  In-Reply-To: <no-message-id-724101@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox