Commit 252b707b authored by Magnus Hagander's avatar Magnus Hagander

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: default avatarRobert Treat <rob@xzilla.net>
parent 90101564
...@@ -2600,13 +2600,15 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i ...@@ -2600,13 +2600,15 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
<entry><structfield>checksum_failures</structfield></entry> <entry><structfield>checksum_failures</structfield></entry>
<entry><type>bigint</type></entry> <entry><type>bigint</type></entry>
<entry>Number of data page checksum failures detected in this <entry>Number of data page checksum failures detected in this
database</entry> database (or on a shared object), or NULL if data checksums are not
enabled.</entry>
</row> </row>
<row> <row>
<entry><structfield>checksum_last_failure</structfield></entry> <entry><structfield>checksum_last_failure</structfield></entry>
<entry><type>timestamp with time zone</type></entry> <entry><type>timestamp with time zone</type></entry>
<entry>Time at which the last data page checksum failure was detected in <entry>Time at which the last data page checksum failure was detected in
this database, or on a shared object.</entry> this database (or on a shared object), or NULL if data checksums are not
enabled.</entry>
</row> </row>
<row> <row>
<entry><structfield>blk_read_time</structfield></entry> <entry><structfield>blk_read_time</structfield></entry>
......
...@@ -817,7 +817,7 @@ CREATE VIEW pg_stat_database AS ...@@ -817,7 +817,7 @@ CREATE VIEW pg_stat_database AS
D.oid AS datid, D.oid AS datid,
D.datname AS datname, D.datname AS datname,
CASE CASE
WHEN (D.oid = (0)::oid) THEN NULL::integer WHEN (D.oid = (0)::oid) THEN 0
ELSE pg_stat_get_db_numbackends(D.oid) ELSE pg_stat_get_db_numbackends(D.oid)
END AS numbackends, END AS numbackends,
pg_stat_get_db_xact_commit(D.oid) AS xact_commit, pg_stat_get_db_xact_commit(D.oid) AS xact_commit,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "postgres.h" #include "postgres.h"
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xlog.h"
#include "catalog/pg_authid.h" #include "catalog/pg_authid.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "common/ip.h" #include "common/ip.h"
...@@ -1526,6 +1527,9 @@ pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS) ...@@ -1526,6 +1527,9 @@ pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
int64 result; int64 result;
PgStat_StatDBEntry *dbentry; PgStat_StatDBEntry *dbentry;
if (!DataChecksumsEnabled())
PG_RETURN_NULL();
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0; result = 0;
else else
...@@ -1541,6 +1545,9 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS) ...@@ -1541,6 +1545,9 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
TimestampTz result; TimestampTz result;
PgStat_StatDBEntry *dbentry; PgStat_StatDBEntry *dbentry;
if (!DataChecksumsEnabled())
PG_RETURN_NULL();
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0; result = 0;
else else
......
...@@ -1806,7 +1806,7 @@ pg_stat_bgwriter| SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints ...@@ -1806,7 +1806,7 @@ pg_stat_bgwriter| SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints
pg_stat_database| SELECT d.oid AS datid, pg_stat_database| SELECT d.oid AS datid,
d.datname, d.datname,
CASE CASE
WHEN (d.oid = (0)::oid) THEN NULL::integer WHEN (d.oid = (0)::oid) THEN 0
ELSE pg_stat_get_db_numbackends(d.oid) ELSE pg_stat_get_db_numbackends(d.oid)
END AS numbackends, END AS numbackends,
pg_stat_get_db_xact_commit(d.oid) AS xact_commit, pg_stat_get_db_xact_commit(d.oid) AS xact_commit,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment