Skip to content

Commit 252b707

Browse files
committed
Return NULL for checksum failures if checksums are not enabled
Returning 0 could falsely indicate that there is no problem. NULL correctly indicates that there is no information about potential problems. Also return 0 as numbackends instead of NULL for shared objects (as no connection can be made to a shared object only). Author: Julien Rouhaud <rjuju123@gmail.com> Reviewed-by: Robert Treat <rob@xzilla.net>
1 parent 9010156 commit 252b707

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,13 +2600,15 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
26002600
<entry><structfield>checksum_failures</structfield></entry>
26012601
<entry><type>bigint</type></entry>
26022602
<entry>Number of data page checksum failures detected in this
2603-
database</entry>
2603+
database (or on a shared object), or NULL if data checksums are not
2604+
enabled.</entry>
26042605
</row>
26052606
<row>
26062607
<entry><structfield>checksum_last_failure</structfield></entry>
26072608
<entry><type>timestamp with time zone</type></entry>
26082609
<entry>Time at which the last data page checksum failure was detected in
2609-
this database, or on a shared object.</entry>
2610+
this database (or on a shared object), or NULL if data checksums are not
2611+
enabled.</entry>
26102612
</row>
26112613
<row>
26122614
<entry><structfield>blk_read_time</structfield></entry>

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ CREATE VIEW pg_stat_database AS
817817
D.oid AS datid,
818818
D.datname AS datname,
819819
CASE
820-
WHEN (D.oid = (0)::oid) THEN NULL::integer
820+
WHEN (D.oid = (0)::oid) THEN 0
821821
ELSE pg_stat_get_db_numbackends(D.oid)
822822
END AS numbackends,
823823
pg_stat_get_db_xact_commit(D.oid) AS xact_commit,

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "postgres.h"
1616

1717
#include "access/htup_details.h"
18+
#include "access/xlog.h"
1819
#include "catalog/pg_authid.h"
1920
#include "catalog/pg_type.h"
2021
#include "common/ip.h"
@@ -1526,6 +1527,9 @@ pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
15261527
int64 result;
15271528
PgStat_StatDBEntry *dbentry;
15281529

1530+
if (!DataChecksumsEnabled())
1531+
PG_RETURN_NULL();
1532+
15291533
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
15301534
result = 0;
15311535
else
@@ -1541,6 +1545,9 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
15411545
TimestampTz result;
15421546
PgStat_StatDBEntry *dbentry;
15431547

1548+
if (!DataChecksumsEnabled())
1549+
PG_RETURN_NULL();
1550+
15441551
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
15451552
result = 0;
15461553
else

src/test/regress/expected/rules.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ pg_stat_bgwriter| SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints
18061806
pg_stat_database| SELECT d.oid AS datid,
18071807
d.datname,
18081808
CASE
1809-
WHEN (d.oid = (0)::oid) THEN NULL::integer
1809+
WHEN (d.oid = (0)::oid) THEN 0
18101810
ELSE pg_stat_get_db_numbackends(d.oid)
18111811
END AS numbackends,
18121812
pg_stat_get_db_xact_commit(d.oid) AS xact_commit,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy