PG-173: Added new WAL usage statistics.

pull/72/head
Ibrar Ahmed 2021-02-02 17:52:41 +00:00
parent d7228128ec
commit fb819a5b23
2 changed files with 40 additions and 13 deletions

View File

@ -283,6 +283,21 @@ SELECT resp_calls, query FROM pg_stat_monitor;
{1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} | select client_ip, query from pg_stat_monitor
{3," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 1"} | select * from pg_stat_monitor_reset()
{3," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 1"} | SELECT * FROM foo
SELECT * FROM histogram(4, '4B64EE85C83D9AAC') AS a(range TEXT, freq INT, bar TEXT);
range | freq | bar
-----------+------+--------------------------------
(0 - 1)} | 692 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(1 - 1)} | 0 |
(1 - 1)} | 0 |
(1 - 2)} | 572 | ■■■■■■■■■■■■■■■■■■■■■■■■■
(2 - 3)} | 74 | ■■■
(3 - 3)} | 0 |
(3 - 5)} | 9 |
(5 - 6)} | 1 |
(6 - 7)} | 1 |
(7 - 10)} | 1 |
(10 rows)
```
There are 10 timebase buckets of the time **`pg_stat_monitor.pgsm_respose_time_step`** in the field ``resp_calls``. The value in the field shows how many queries run in that period of time.

View File

@ -555,14 +555,16 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
exec_nested_level++;
#endif
bufusage_start = pgBufferUsage;
INSTR_TIME_SET_CURRENT(start);
PG_TRY();
{
if (prev_ProcessUtility)
prev_ProcessUtility(pstmt, queryString,
context, params, queryEnv,
bufusage_start = pgBufferUsage;
#if PG_VERSION_NUM >= 130000
walusage_start = pgWalUsage;
#endif
INSTR_TIME_SET_CURRENT(start);
PG_TRY();
{
if (prev_ProcessUtility)
prev_ProcessUtility(pstmt, queryString,
context, params, queryEnv,
dest
#if PG_VERSION_NUM >= 130000
,qc
@ -804,6 +806,7 @@ static void pgss_store(uint64 queryId,
/* Safety check... */
if (!IsSystemInitialized() || !pgss_qbuf[pgss->current_wbucket])
return;
/*
* Confine our attention to the relevant part of the string, if the query
@ -1001,9 +1004,18 @@ static void pgss_store(uint64 queryId,
if (sqlcode[0] != 0)
memset(&entry->counters.blocks, 0, sizeof(entry->counters.blocks));
#if PG_VERSION_NUM >= 130000
e->counters.walusage.wal_records += walusage->wal_records;
e->counters.walusage.wal_fpi += walusage->wal_fpi;
e->counters.walusage.wal_bytes += walusage->wal_bytes;
if (sqlcode[0] == 0)
{
e->counters.walusage.wal_records += walusage->wal_records;
e->counters.walusage.wal_fpi += walusage->wal_fpi;
e->counters.walusage.wal_bytes += walusage->wal_bytes;
}
else
{
e->counters.walusage.wal_records = 0;
e->counters.walusage.wal_fpi = 0;
e->counters.walusage.wal_bytes = 0;
}
#endif
SpinLockRelease(&e->mutex);
}
@ -2707,8 +2719,8 @@ get_histogram_bucket(double q_time)
for(index = 1; index <= b_count; index++)
{
double b_start = (index == 1)? 0 : exp(bucket_size * (index - 1));
double b_end = exp(bucket_size * index);
int64 b_start = (index == 1)? 0 : exp(bucket_size * (index - 1));
int64 b_end = exp(bucket_size * index);
if( (index == 1 && q_time < b_start)
|| (q_time >= b_start && q_time <= b_end)
|| (index == b_count && q_time > b_end) )