PG-173: Added new WAL usage statistics.
parent
12ba1e39d1
commit
8410572ce3
|
@ -70,7 +70,10 @@ CREATE FUNCTION pg_stat_monitor(IN showtext boolean,
|
|||
OUT blk_write_time float8,
|
||||
OUT resp_calls text,
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
|
@ -145,7 +148,10 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
|||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
round(cpu_user_time::numeric, 4) as cpu_user_time,
|
||||
round(cpu_sys_time::numeric, 4) as cpu_sys_time
|
||||
round(cpu_sys_time::numeric, 4) as cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes
|
||||
FROM pg_stat_monitor(TRUE), pg_database WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
PG_MODULE_MAGIC;
|
||||
|
||||
#define BUILD_VERSION "0.7.0"
|
||||
#define PG_STAT_STATEMENTS_COLS 42 /* maximum of above */
|
||||
#define PG_STAT_STATEMENTS_COLS 45 /* maximum of above */
|
||||
#define PGSM_TEXT_FILE "/tmp/pg_stat_monitor_query"
|
||||
|
||||
#define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
|
||||
|
@ -1000,6 +1000,11 @@ static void pgss_store(uint64 queryId,
|
|||
e->counters.sysinfo.stime = stime;
|
||||
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;
|
||||
#endif
|
||||
SpinLockRelease(&e->mutex);
|
||||
}
|
||||
}
|
||||
|
@ -1251,6 +1256,28 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
|||
values[i++] = IntArrayGetTextDatum(tmp.resp_calls, MAX_RESPONSE_BUCKET);
|
||||
values[i++] = Float8GetDatumFast(tmp.sysinfo.utime);
|
||||
values[i++] = Float8GetDatumFast(tmp.sysinfo.stime);
|
||||
#if PG_VERSION_NUM >= 130000
|
||||
{
|
||||
char buf[256];
|
||||
Datum wal_bytes;
|
||||
|
||||
values[i++] = Int64GetDatumFast(tmp.walusage.wal_records);
|
||||
values[i++] = Int64GetDatumFast(tmp.walusage.wal_fpi);
|
||||
|
||||
snprintf(buf, sizeof buf, UINT64_FORMAT, tmp.walusage.wal_bytes);
|
||||
|
||||
/* Convert to numeric. */
|
||||
wal_bytes = DirectFunctionCall3(numeric_in,
|
||||
CStringGetDatum(buf),
|
||||
ObjectIdGetDatum(0),
|
||||
Int32GetDatum(-1));
|
||||
values[i++] = wal_bytes;
|
||||
}
|
||||
#else
|
||||
nulls[i++] = true;
|
||||
nulls[i++] = true;
|
||||
nulls[i++] = true;
|
||||
#endif
|
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||
}
|
||||
free(query_txt);
|
||||
|
@ -2587,7 +2614,7 @@ int
|
|||
read_query_buffer(int bucket_id, uint64 queryid, char *query_txt)
|
||||
{
|
||||
int fd = 0;
|
||||
int buf_len;
|
||||
int buf_len = 0;
|
||||
char file_name[1024];
|
||||
unsigned char *buf = NULL;
|
||||
int off = 0;
|
||||
|
@ -2711,7 +2738,7 @@ get_histogram_timings(PG_FUNCTION_ARGS)
|
|||
{
|
||||
int64 b_start = (index == 1)? 0 : exp(bucket_size * (index - 1));
|
||||
int64 b_end = exp(bucket_size * index);
|
||||
sprintf(range[index-1], "(%d - %d)}", b_start, b_end);
|
||||
sprintf(range[index-1], "(%ld - %ld)}", b_start, b_end);
|
||||
}
|
||||
return TextArrayGetTextDatum(range, b_count, 1024);
|
||||
}
|
||||
|
|
|
@ -209,6 +209,12 @@ typedef struct SysInfo
|
|||
float stime; /* system cpu time */
|
||||
} SysInfo;
|
||||
|
||||
typedef struct Wal_Usage
|
||||
{
|
||||
int64 wal_records; /* # of WAL records generated */
|
||||
int64 wal_fpi; /* # of WAL full page images generated */
|
||||
uint64 wal_bytes; /* total amount of WAL bytes generated */
|
||||
} Wal_Usage;
|
||||
/*
|
||||
* The actual stats counters kept within pgssEntry.
|
||||
*/
|
||||
|
@ -221,6 +227,7 @@ typedef struct Counters
|
|||
Blocks blocks;
|
||||
SysInfo sysinfo;
|
||||
ErrorInfo error;
|
||||
Wal_Usage walusage;
|
||||
int plans;
|
||||
int resp_calls[MAX_RESPONSE_BUCKET]; /* execution time's in msec */
|
||||
} Counters;
|
||||
|
|
Loading…
Reference in New Issue