From 259e533140d05c849ac25c1cac6c7f15f95e4326 Mon Sep 17 00:00:00 2001
From: TatsuyaKawata <kawatatatsuya0913@gmail.com>
Date: Mon, 15 Jun 2026 14:28:57 +0900
Subject: [PATCH v1] Change wait_time column of pg_stat_lock to double
 precision

Other statistics views (pg_stat_io, pg_stat_database, etc.) use
double precision for all measured-time columns. Align pg_stat_lock
with that convention by changing wait_time from bigint to double
precision, and preserve the sub-millisecond remainder in proc.c so
the additional precision is actually populated.
---
 doc/src/sgml/monitoring.sgml             | 2 +-
 src/backend/storage/lmgr/proc.c          | 3 ++-
 src/backend/utils/activity/pgstat_lock.c | 4 ++--
 src/backend/utils/adt/pgstatfuncs.c      | 2 +-
 src/include/catalog/catversion.h         | 2 +-
 src/include/catalog/pg_proc.dat          | 2 +-
 src/include/pgstat.h                     | 4 ++--
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 08d5b824552..6dcf05eb702 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -3359,7 +3359,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
      <row>
       <entry role="catalog_table_entry">
        <para role="column_definition">
-        <structfield>wait_time</structfield> <type>bigint</type>
+        <structfield>wait_time</structfield> <type>double precision</type>
        </para>
        <para>
         Total time spent waiting for locks of this type, in milliseconds.
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 6fa9de33e1c..fe5ff9afcb4 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -1613,7 +1613,8 @@ ProcSleep(LOCALLOCK *locallock)
 
 			/* Increment the lock statistics counters if done waiting. */
 			if (myWaitStatus == PROC_WAIT_STATUS_OK)
-				pgstat_count_lock_waits(locallock->tag.lock.locktag_type, msecs);
+				pgstat_count_lock_waits(locallock->tag.lock.locktag_type,
+										(double) msecs + (double) usecs / 1000.0);
 
 			if (log_lock_waits)
 			{
diff --git a/src/backend/utils/activity/pgstat_lock.c b/src/backend/utils/activity/pgstat_lock.c
index aec64f8fb4b..98fe5fd395f 100644
--- a/src/backend/utils/activity/pgstat_lock.c
+++ b/src/backend/utils/activity/pgstat_lock.c
@@ -140,11 +140,11 @@ pgstat_count_lock_fastpath_exceeded(uint8 locktag_type)
  * like lock acquisitions.
  */
 void
-pgstat_count_lock_waits(uint8 locktag_type, long msecs)
+pgstat_count_lock_waits(uint8 locktag_type, double msecs)
 {
 	Assert(locktag_type <= LOCKTAG_LAST_TYPE);
 	PendingLockStats.stats[locktag_type].waits++;
-	PendingLockStats.stats[locktag_type].wait_time += (PgStat_Counter) msecs;
+	PendingLockStats.stats[locktag_type].wait_time += msecs;
 	have_lockstats = true;
 	pgstat_report_fixed = true;
 }
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6f9c9c72de5..67c4cc2ab05 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -1761,7 +1761,7 @@ pg_stat_get_lock(PG_FUNCTION_ARGS)
 
 		values[i++] = CStringGetTextDatum(locktypename);
 		values[i++] = Int64GetDatum(lck_stats->waits);
-		values[i++] = Int64GetDatum(lck_stats->wait_time);
+		values[i++] = Float8GetDatum(lck_stats->wait_time);
 		values[i++] = Int64GetDatum(lck_stats->fastpath_exceeded);
 		values[i] = TimestampTzGetDatum(lock_stats->stat_reset_timestamp);
 
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index c4e94a3a09e..7f31a8a1548 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -57,6 +57,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	202606091
+#define CATALOG_VERSION_NO	202606151
 
 #endif
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index be157a5fbe9..22836099495 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -6064,7 +6064,7 @@
 { oid => '6509', descr => 'statistics: per lock type statistics',
   proname => 'pg_stat_get_lock', prorows => '10', proretset => 't',
   provolatile => 'v', proparallel => 'r', prorettype => 'record',
-  proargtypes => '', proallargtypes => '{text,int8,int8,int8,timestamptz}',
+  proargtypes => '', proallargtypes => '{text,int8,float8,int8,timestamptz}',
   proargmodes => '{o,o,o,o,o}',
   proargnames => '{locktype,waits,wait_time,fastpath_exceeded,stats_reset}',
   prosrc => 'pg_stat_get_lock' },
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index dfa2e837638..adcaf925507 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -349,7 +349,7 @@ typedef struct PgStat_IO
 typedef struct PgStat_LockEntry
 {
 	PgStat_Counter waits;
-	PgStat_Counter wait_time;	/* time in milliseconds */
+	double		wait_time;		/* time in milliseconds */
 	PgStat_Counter fastpath_exceeded;
 } PgStat_LockEntry;
 
@@ -638,7 +638,7 @@ extern bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
 
 extern void pgstat_lock_flush(bool nowait);
 extern void pgstat_count_lock_fastpath_exceeded(uint8 locktag_type);
-extern void pgstat_count_lock_waits(uint8 locktag_type, long msecs);
+extern void pgstat_count_lock_waits(uint8 locktag_type, double msecs);
 extern PgStat_Lock *pgstat_fetch_stat_lock(void);
 
 /*
-- 
2.34.1

