postgres.git / summary / log / commit / refs
commit ff6f6e0470ecb362a389bb20aac46a843e496c2f
Author: Michael Paquier <michael@paquier.xyz>
Date: Tue Jun 30 03:47:57 2026 +0000
Change stat_lock.wait_time to double precision
Other statistics views (pg_stat_io, pg_stat_database, etc.) use float8
for all measured-time columns, the new pg_stat_lock standing out as an
outlier by using bigint.
This commit aligns pg_stat_lock with the other stats views for
consistency. Like pg_stat_io, the time is stored in microseconds, and
is displayed in milliseconds with a conversion done when the view is
queried.
While on it, replace a use of "long" by PgStat_Counter, the former could
overflow for large wait times where sizeof(long) is 4 bytes (aka WIN32).
Bump catalog version.
Author: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAHza6qerEiQehrbW5xaXyxvR0qJe3KBX1R4kocDz1+7Ygu8x-g@mail.gmail.com
Backpatch-through: 19
doc/src/sgml/monitoring.sgml | 2 +-
src/backend/storage/lmgr/proc.c | 9 +++++----
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 | 5 +++--
7 files changed, 14 insertions(+), 12 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..7d01c981a1f 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -1608,12 +1608,13 @@ ProcSleep(LOCALLOCK *locallock)
TimestampDifference(get_timeout_start_time(DEADLOCK_TIMEOUT),
GetCurrentTimestamp(),
&secs, &usecs);
- msecs = secs * 1000 + usecs / 1000;
- usecs = usecs % 1000;
-
/* 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,
+ (PgStat_Counter) secs * 1000000 + usecs);
+
+ msecs = secs * 1000 + usecs / 1000;
+ usecs = usecs % 1000;
if (log_lock_waits)
{
diff --git a/src/backend/utils/activity/pgstat_lock.c b/src/backend/utils/activity/pgstat_lock.c
index aec64f8fb4b..8910a15634d 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, PgStat_Counter usecs)
{
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 += usecs;
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..0c59df17901 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(pg_stat_us_to_ms(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 635c0d9cb13..875a147f753 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -57,6 +57,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202606281
+#define CATALOG_VERSION_NO 202606301
#endif
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 1a985becde3..efe13b7866a 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..72496695999 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 */
+ PgStat_Counter wait_time; /* time in microseconds */
PgStat_Counter fastpath_exceeded;
} PgStat_LockEntry;
@@ -638,7 +638,8 @@ 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,
+ PgStat_Counter usecs);
extern PgStat_Lock *pgstat_fetch_stat_lock(void);
/*
[parent: 7e5a19a16c55]