Generate pg_stat_get*() functions for databases using macros

The same code pattern is repeated 21 times for int64 counters (0 for
missing entry) and 5 times for doubles (0 for missing entry) on database
entries.  This code is switched to use macros for the basic code
instead, shaving a few hundred lines of originally-duplicated code
patterns.  The function names remain the same, but some fields of
PgStat_StatDBEntry have to be renamed to cope with the new style.

This is in the same spirit as 83a1a1b.

Author: Michael Paquier
Reviewed-by: Nathan Bossart, Bertrand Drouvot
Discussion: https://postgr.es/m/Y46stlxQ2LQE20Na@paquier.xyz
This commit is contained in:
Michael Paquier 2022-12-07 09:11:48 +09:00
parent 79f7c482f6
commit 8018ffbf58
4 changed files with 169 additions and 447 deletions

View File

@ -98,19 +98,19 @@ pgstat_report_recovery_conflict(int reason)
*/
break;
case PROCSIG_RECOVERY_CONFLICT_TABLESPACE:
dbentry->n_conflict_tablespace++;
dbentry->conflict_tablespace++;
break;
case PROCSIG_RECOVERY_CONFLICT_LOCK:
dbentry->n_conflict_lock++;
dbentry->conflict_lock++;
break;
case PROCSIG_RECOVERY_CONFLICT_SNAPSHOT:
dbentry->n_conflict_snapshot++;
dbentry->conflict_snapshot++;
break;
case PROCSIG_RECOVERY_CONFLICT_BUFFERPIN:
dbentry->n_conflict_bufferpin++;
dbentry->conflict_bufferpin++;
break;
case PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK:
dbentry->n_conflict_startup_deadlock++;
dbentry->conflict_startup_deadlock++;
break;
}
}
@ -127,7 +127,7 @@ pgstat_report_deadlock(void)
return;
dbent = pgstat_prep_database_pending(MyDatabaseId);
dbent->n_deadlocks++;
dbent->deadlocks++;
}
/*
@ -150,7 +150,7 @@ pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
pgstat_get_entry_ref_locked(PGSTAT_KIND_DATABASE, dboid, InvalidOid, false);
sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
sharedent->stats.n_checksum_failures += failurecount;
sharedent->stats.checksum_failures += failurecount;
sharedent->stats.last_checksum_failure = GetCurrentTimestamp();
pgstat_unlock_entry(entry_ref);
@ -177,8 +177,8 @@ pgstat_report_tempfile(size_t filesize)
return;
dbent = pgstat_prep_database_pending(MyDatabaseId);
dbent->n_temp_bytes += filesize;
dbent->n_temp_files++;
dbent->temp_bytes += filesize;
dbent->temp_files++;
}
/*
@ -195,7 +195,7 @@ pgstat_report_connect(Oid dboid)
pgLastSessionReportTime = MyStartTimestamp;
dbentry = pgstat_prep_database_pending(MyDatabaseId);
dbentry->n_sessions++;
dbentry->sessions++;
}
/*
@ -218,13 +218,13 @@ pgstat_report_disconnect(Oid dboid)
/* we don't collect these */
break;
case DISCONNECT_CLIENT_EOF:
dbentry->n_sessions_abandoned++;
dbentry->sessions_abandoned++;
break;
case DISCONNECT_FATAL:
dbentry->n_sessions_fatal++;
dbentry->sessions_fatal++;
break;
case DISCONNECT_KILLED:
dbentry->n_sessions_killed++;
dbentry->sessions_killed++;
break;
}
}
@ -274,10 +274,10 @@ pgstat_update_dbstats(TimestampTz ts)
* Accumulate xact commit/rollback and I/O timings to stats entry of the
* current database.
*/
dbentry->n_xact_commit += pgStatXactCommit;
dbentry->n_xact_rollback += pgStatXactRollback;
dbentry->n_block_read_time += pgStatBlockReadTime;
dbentry->n_block_write_time += pgStatBlockWriteTime;
dbentry->xact_commit += pgStatXactCommit;
dbentry->xact_rollback += pgStatXactRollback;
dbentry->blk_read_time += pgStatBlockReadTime;
dbentry->blk_write_time += pgStatBlockWriteTime;
if (pgstat_should_report_connstat())
{
@ -290,9 +290,9 @@ pgstat_update_dbstats(TimestampTz ts)
*/
TimestampDifference(pgLastSessionReportTime, ts, &secs, &usecs);
pgLastSessionReportTime = ts;
dbentry->total_session_time += (PgStat_Counter) secs * 1000000 + usecs;
dbentry->total_active_time += pgStatActiveTime;
dbentry->total_idle_in_xact_time += pgStatTransactionIdleTime;
dbentry->session_time += (PgStat_Counter) secs * 1000000 + usecs;
dbentry->active_time += pgStatActiveTime;
dbentry->idle_in_transaction_time += pgStatTransactionIdleTime;
}
pgStatXactCommit = 0;
@ -370,44 +370,44 @@ pgstat_database_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
#define PGSTAT_ACCUM_DBCOUNT(item) \
(sharedent)->stats.item += (pendingent)->item
PGSTAT_ACCUM_DBCOUNT(n_xact_commit);
PGSTAT_ACCUM_DBCOUNT(n_xact_rollback);
PGSTAT_ACCUM_DBCOUNT(n_blocks_fetched);
PGSTAT_ACCUM_DBCOUNT(n_blocks_hit);
PGSTAT_ACCUM_DBCOUNT(xact_commit);
PGSTAT_ACCUM_DBCOUNT(xact_rollback);
PGSTAT_ACCUM_DBCOUNT(blocks_fetched);
PGSTAT_ACCUM_DBCOUNT(blocks_hit);
PGSTAT_ACCUM_DBCOUNT(n_tuples_returned);
PGSTAT_ACCUM_DBCOUNT(n_tuples_fetched);
PGSTAT_ACCUM_DBCOUNT(n_tuples_inserted);
PGSTAT_ACCUM_DBCOUNT(n_tuples_updated);
PGSTAT_ACCUM_DBCOUNT(n_tuples_deleted);
PGSTAT_ACCUM_DBCOUNT(tuples_returned);
PGSTAT_ACCUM_DBCOUNT(tuples_fetched);
PGSTAT_ACCUM_DBCOUNT(tuples_inserted);
PGSTAT_ACCUM_DBCOUNT(tuples_updated);
PGSTAT_ACCUM_DBCOUNT(tuples_deleted);
/* last_autovac_time is reported immediately */
Assert(pendingent->last_autovac_time == 0);
PGSTAT_ACCUM_DBCOUNT(n_conflict_tablespace);
PGSTAT_ACCUM_DBCOUNT(n_conflict_lock);
PGSTAT_ACCUM_DBCOUNT(n_conflict_snapshot);
PGSTAT_ACCUM_DBCOUNT(n_conflict_bufferpin);
PGSTAT_ACCUM_DBCOUNT(n_conflict_startup_deadlock);
PGSTAT_ACCUM_DBCOUNT(conflict_tablespace);
PGSTAT_ACCUM_DBCOUNT(conflict_lock);
PGSTAT_ACCUM_DBCOUNT(conflict_snapshot);
PGSTAT_ACCUM_DBCOUNT(conflict_bufferpin);
PGSTAT_ACCUM_DBCOUNT(conflict_startup_deadlock);
PGSTAT_ACCUM_DBCOUNT(n_temp_bytes);
PGSTAT_ACCUM_DBCOUNT(n_temp_files);
PGSTAT_ACCUM_DBCOUNT(n_deadlocks);
PGSTAT_ACCUM_DBCOUNT(temp_bytes);
PGSTAT_ACCUM_DBCOUNT(temp_files);
PGSTAT_ACCUM_DBCOUNT(deadlocks);
/* checksum failures are reported immediately */
Assert(pendingent->n_checksum_failures == 0);
Assert(pendingent->checksum_failures == 0);
Assert(pendingent->last_checksum_failure == 0);
PGSTAT_ACCUM_DBCOUNT(n_block_read_time);
PGSTAT_ACCUM_DBCOUNT(n_block_write_time);
PGSTAT_ACCUM_DBCOUNT(blk_read_time);
PGSTAT_ACCUM_DBCOUNT(blk_write_time);
PGSTAT_ACCUM_DBCOUNT(n_sessions);
PGSTAT_ACCUM_DBCOUNT(total_session_time);
PGSTAT_ACCUM_DBCOUNT(total_active_time);
PGSTAT_ACCUM_DBCOUNT(total_idle_in_xact_time);
PGSTAT_ACCUM_DBCOUNT(n_sessions_abandoned);
PGSTAT_ACCUM_DBCOUNT(n_sessions_fatal);
PGSTAT_ACCUM_DBCOUNT(n_sessions_killed);
PGSTAT_ACCUM_DBCOUNT(sessions);
PGSTAT_ACCUM_DBCOUNT(session_time);
PGSTAT_ACCUM_DBCOUNT(active_time);
PGSTAT_ACCUM_DBCOUNT(idle_in_transaction_time);
PGSTAT_ACCUM_DBCOUNT(sessions_abandoned);
PGSTAT_ACCUM_DBCOUNT(sessions_fatal);
PGSTAT_ACCUM_DBCOUNT(sessions_killed);
#undef PGSTAT_ACCUM_DBCOUNT
pgstat_unlock_entry(entry_ref);

View File

@ -819,13 +819,13 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
/* The entry was successfully flushed, add the same to database stats */
dbentry = pgstat_prep_database_pending(dboid);
dbentry->n_tuples_returned += lstats->t_counts.t_tuples_returned;
dbentry->n_tuples_fetched += lstats->t_counts.t_tuples_fetched;
dbentry->n_tuples_inserted += lstats->t_counts.t_tuples_inserted;
dbentry->n_tuples_updated += lstats->t_counts.t_tuples_updated;
dbentry->n_tuples_deleted += lstats->t_counts.t_tuples_deleted;
dbentry->n_blocks_fetched += lstats->t_counts.t_blocks_fetched;
dbentry->n_blocks_hit += lstats->t_counts.t_blocks_hit;
dbentry->tuples_returned += lstats->t_counts.t_tuples_returned;
dbentry->tuples_fetched += lstats->t_counts.t_tuples_fetched;
dbentry->tuples_inserted += lstats->t_counts.t_tuples_inserted;
dbentry->tuples_updated += lstats->t_counts.t_tuples_updated;
dbentry->tuples_deleted += lstats->t_counts.t_tuples_deleted;
dbentry->blocks_fetched += lstats->t_counts.t_blocks_fetched;
dbentry->blocks_hit += lstats->t_counts.t_blocks_hit;
return true;
}

View File

@ -938,148 +938,85 @@ pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
}
Datum
pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
#define PG_STAT_GET_DBENTRY_INT64(stat) \
Datum \
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid dbid = PG_GETARG_OID(0); \
int64 result; \
PgStat_StatDBEntry *dbentry; \
\
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
result = 0; \
else \
result = (int64) (dbentry->stat); \
\
PG_RETURN_INT64(result); \
} \
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_xact_commit);
/* pg_stat_get_db_blocks_fetched */
PG_STAT_GET_DBENTRY_INT64(blocks_fetched);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_blocks_hit */
PG_STAT_GET_DBENTRY_INT64(blocks_hit);
/* pg_stat_get_db_conflict_bufferpin */
PG_STAT_GET_DBENTRY_INT64(conflict_bufferpin);
Datum
pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_conflict_lock */
PG_STAT_GET_DBENTRY_INT64(conflict_lock);
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_xact_rollback);
/* pg_stat_get_db_conflict_snapshot */
PG_STAT_GET_DBENTRY_INT64(conflict_snapshot);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_conflict_startup_deadlock */
PG_STAT_GET_DBENTRY_INT64(conflict_startup_deadlock);
/* pg_stat_get_db_conflict_tablespace */
PG_STAT_GET_DBENTRY_INT64(conflict_tablespace);
Datum
pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_deadlocks */
PG_STAT_GET_DBENTRY_INT64(deadlocks);
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_blocks_fetched);
/* pg_stat_get_db_sessions */
PG_STAT_GET_DBENTRY_INT64(sessions);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_sessions_abandoned */
PG_STAT_GET_DBENTRY_INT64(sessions_abandoned);
/* pg_stat_get_db_sessions_fatal */
PG_STAT_GET_DBENTRY_INT64(sessions_fatal);
Datum
pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_sessions_killed */
PG_STAT_GET_DBENTRY_INT64(sessions_killed);
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_blocks_hit);
/* pg_stat_get_db_temp_bytes */
PG_STAT_GET_DBENTRY_INT64(temp_bytes);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_temp_files */
PG_STAT_GET_DBENTRY_INT64(temp_files);
/* pg_stat_get_db_tuples_deleted */
PG_STAT_GET_DBENTRY_INT64(tuples_deleted);
Datum
pg_stat_get_db_tuples_returned(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_tuples_fetched */
PG_STAT_GET_DBENTRY_INT64(tuples_fetched);
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_tuples_returned);
/* pg_stat_get_db_tuples_inserted */
PG_STAT_GET_DBENTRY_INT64(tuples_inserted);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_tuples_returned */
PG_STAT_GET_DBENTRY_INT64(tuples_returned);
/* pg_stat_get_db_tuples_updated */
PG_STAT_GET_DBENTRY_INT64(tuples_updated);
Datum
pg_stat_get_db_tuples_fetched(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_xact_commit */
PG_STAT_GET_DBENTRY_INT64(xact_commit);
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_tuples_fetched);
/* pg_stat_get_db_xact_rollback */
PG_STAT_GET_DBENTRY_INT64(xact_rollback);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_tuples_inserted(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_tuples_inserted);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_tuples_updated(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_tuples_updated);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_tuples_deleted);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
@ -1099,111 +1036,6 @@ pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(result);
}
Datum
pg_stat_get_db_temp_files(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = dbentry->n_temp_files;
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_temp_bytes(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = dbentry->n_temp_bytes;
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_tablespace(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_tablespace);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_lock(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_lock);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_snapshot(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_snapshot);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_bufferpin(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_bufferpin);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_startup_deadlock(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_startup_deadlock);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
@ -1215,26 +1047,11 @@ pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_conflict_tablespace +
dbentry->n_conflict_lock +
dbentry->n_conflict_snapshot +
dbentry->n_conflict_bufferpin +
dbentry->n_conflict_startup_deadlock);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_deadlocks(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_deadlocks);
result = (int64) (dbentry->conflict_tablespace +
dbentry->conflict_lock +
dbentry->conflict_snapshot +
dbentry->conflict_bufferpin +
dbentry->conflict_startup_deadlock);
PG_RETURN_INT64(result);
}
@ -1252,7 +1069,7 @@ pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = (int64) (dbentry->n_checksum_failures);
result = (int64) (dbentry->checksum_failures);
PG_RETURN_INT64(result);
}
@ -1278,131 +1095,36 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(result);
}
Datum
pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
double result;
PgStat_StatDBEntry *dbentry;
#define PG_STAT_GET_DBENTRY_FLOAT8(stat) \
Datum \
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid dbid = PG_GETARG_OID(0); \
double result; \
PgStat_StatDBEntry *dbentry; \
\
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
result = 0; \
else \
result = ((double) dbentry->stat) / 1000.0; \
\
PG_RETURN_FLOAT8(result); \
} \
/* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = ((double) dbentry->n_block_read_time) / 1000.0;
/* pg_stat_get_db_active_time */
PG_STAT_GET_DBENTRY_FLOAT8(active_time);
PG_RETURN_FLOAT8(result);
}
/* pg_stat_get_db_blk_read_time */
PG_STAT_GET_DBENTRY_FLOAT8(blk_read_time);
Datum
pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
double result;
PgStat_StatDBEntry *dbentry;
/* pg_stat_get_db_blk_write_time */
PG_STAT_GET_DBENTRY_FLOAT8(blk_write_time);
/* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
result = ((double) dbentry->n_block_write_time) / 1000.0;
/* pg_stat_get_db_idle_in_transaction_time */
PG_STAT_GET_DBENTRY_FLOAT8(idle_in_transaction_time);
PG_RETURN_FLOAT8(result);
}
Datum
pg_stat_get_db_session_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
double result = 0.0;
PgStat_StatDBEntry *dbentry;
/* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = ((double) dbentry->total_session_time) / 1000.0;
PG_RETURN_FLOAT8(result);
}
Datum
pg_stat_get_db_active_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
double result = 0.0;
PgStat_StatDBEntry *dbentry;
/* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = ((double) dbentry->total_active_time) / 1000.0;
PG_RETURN_FLOAT8(result);
}
Datum
pg_stat_get_db_idle_in_transaction_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
double result = 0.0;
PgStat_StatDBEntry *dbentry;
/* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = ((double) dbentry->total_idle_in_xact_time) / 1000.0;
PG_RETURN_FLOAT8(result);
}
Datum
pg_stat_get_db_sessions(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result = 0;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = (int64) (dbentry->n_sessions);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_sessions_abandoned(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result = 0;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = (int64) (dbentry->n_sessions_abandoned);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_sessions_fatal(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result = 0;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = (int64) (dbentry->n_sessions_fatal);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_db_sessions_killed(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
int64 result = 0;
PgStat_StatDBEntry *dbentry;
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
result = (int64) (dbentry->n_sessions_killed);
PG_RETURN_INT64(result);
}
/* pg_stat_get_db_session_time */
PG_STAT_GET_DBENTRY_FLOAT8(session_time);
Datum
pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)

View File

@ -278,35 +278,35 @@ typedef struct PgStat_CheckpointerStats
typedef struct PgStat_StatDBEntry
{
PgStat_Counter n_xact_commit;
PgStat_Counter n_xact_rollback;
PgStat_Counter n_blocks_fetched;
PgStat_Counter n_blocks_hit;
PgStat_Counter n_tuples_returned;
PgStat_Counter n_tuples_fetched;
PgStat_Counter n_tuples_inserted;
PgStat_Counter n_tuples_updated;
PgStat_Counter n_tuples_deleted;
PgStat_Counter xact_commit;
PgStat_Counter xact_rollback;
PgStat_Counter blocks_fetched;
PgStat_Counter blocks_hit;
PgStat_Counter tuples_returned;
PgStat_Counter tuples_fetched;
PgStat_Counter tuples_inserted;
PgStat_Counter tuples_updated;
PgStat_Counter tuples_deleted;
TimestampTz last_autovac_time;
PgStat_Counter n_conflict_tablespace;
PgStat_Counter n_conflict_lock;
PgStat_Counter n_conflict_snapshot;
PgStat_Counter n_conflict_bufferpin;
PgStat_Counter n_conflict_startup_deadlock;
PgStat_Counter n_temp_files;
PgStat_Counter n_temp_bytes;
PgStat_Counter n_deadlocks;
PgStat_Counter n_checksum_failures;
PgStat_Counter conflict_tablespace;
PgStat_Counter conflict_lock;
PgStat_Counter conflict_snapshot;
PgStat_Counter conflict_bufferpin;
PgStat_Counter conflict_startup_deadlock;
PgStat_Counter temp_files;
PgStat_Counter temp_bytes;
PgStat_Counter deadlocks;
PgStat_Counter checksum_failures;
TimestampTz last_checksum_failure;
PgStat_Counter n_block_read_time; /* times in microseconds */
PgStat_Counter n_block_write_time;
PgStat_Counter n_sessions;
PgStat_Counter total_session_time;
PgStat_Counter total_active_time;
PgStat_Counter total_idle_in_xact_time;
PgStat_Counter n_sessions_abandoned;
PgStat_Counter n_sessions_fatal;
PgStat_Counter n_sessions_killed;
PgStat_Counter blk_read_time; /* times in microseconds */
PgStat_Counter blk_write_time;
PgStat_Counter sessions;
PgStat_Counter session_time;
PgStat_Counter active_time;
PgStat_Counter idle_in_transaction_time;
PgStat_Counter sessions_abandoned;
PgStat_Counter sessions_fatal;
PgStat_Counter sessions_killed;
TimestampTz stat_reset_timestamp;
} PgStat_StatDBEntry;