Skip to content

Commit 5147ab1

Browse files
committed
pg_stat_statements: Add local_blk_{read|write}_time
This commit adds to pg_stat_statements the two new fields for local buffers introduced by 295c36c, adding the time spent to read and write these blocks. These are similar to what is done for temp and shared blocks. This information available only if track_io_timing is enabled. Like for 5a3423a, no version bump is required in the module. Author: Nazir Bilal Yavuz Reviewed-by: Robert Haas, Melanie Plageman Discussion: https://postgr.es/m/CAN55FZ19Ss279mZuqGbuUNxka0iPbLgYuOQXqAKewrjNrp27VA@mail.gmail.com
1 parent 295c36c commit 5147ab1

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

contrib/pg_stat_statements/expected/oldextversions.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ AlTER EXTENSION pg_stat_statements UPDATE TO '1.11';
286286
temp_blks_written | bigint | | |
287287
shared_blk_read_time | double precision | | |
288288
shared_blk_write_time | double precision | | |
289+
local_blk_read_time | double precision | | |
290+
local_blk_write_time | double precision | | |
289291
temp_blk_read_time | double precision | | |
290292
temp_blk_write_time | double precision | | |
291293
wal_records | bigint | | |

contrib/pg_stat_statements/pg_stat_statements--1.10--1.11.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ CREATE FUNCTION pg_stat_statements(IN showtext boolean,
4343
OUT temp_blks_written int8,
4444
OUT shared_blk_read_time float8,
4545
OUT shared_blk_write_time float8,
46+
OUT local_blk_read_time float8,
47+
OUT local_blk_write_time float8,
4648
OUT temp_blk_read_time float8,
4749
OUT temp_blk_write_time float8,
4850
OUT wal_records int8,

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ typedef struct Counters
184184
* in msec */
185185
double shared_blk_write_time; /* time spent writing shared blocks,
186186
* in msec */
187+
double local_blk_read_time; /* time spent reading local blocks, in
188+
* msec */
189+
double local_blk_write_time; /* time spent writing local blocks, in
190+
* msec */
187191
double temp_blk_read_time; /* time spent reading temp blocks, in msec */
188192
double temp_blk_write_time; /* time spent writing temp blocks, in
189193
* msec */
@@ -1395,6 +1399,8 @@ pgss_store(const char *query, uint64 queryId,
13951399
e->counters.temp_blks_written += bufusage->temp_blks_written;
13961400
e->counters.shared_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_read_time);
13971401
e->counters.shared_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_write_time);
1402+
e->counters.local_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->local_blk_read_time);
1403+
e->counters.local_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->local_blk_write_time);
13981404
e->counters.temp_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_read_time);
13991405
e->counters.temp_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_write_time);
14001406
e->counters.usage += USAGE_EXEC(total_time);
@@ -1472,8 +1478,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
14721478
#define PG_STAT_STATEMENTS_COLS_V1_8 32
14731479
#define PG_STAT_STATEMENTS_COLS_V1_9 33
14741480
#define PG_STAT_STATEMENTS_COLS_V1_10 43
1475-
#define PG_STAT_STATEMENTS_COLS_V1_11 45
1476-
#define PG_STAT_STATEMENTS_COLS 45 /* maximum of above */
1481+
#define PG_STAT_STATEMENTS_COLS_V1_11 47
1482+
#define PG_STAT_STATEMENTS_COLS 47 /* maximum of above */
14771483

14781484
/*
14791485
* Retrieve statement statistics.
@@ -1828,6 +1834,11 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
18281834
values[i++] = Float8GetDatumFast(tmp.shared_blk_read_time);
18291835
values[i++] = Float8GetDatumFast(tmp.shared_blk_write_time);
18301836
}
1837+
if (api_version >= PGSS_V1_11)
1838+
{
1839+
values[i++] = Float8GetDatumFast(tmp.local_blk_read_time);
1840+
values[i++] = Float8GetDatumFast(tmp.local_blk_write_time);
1841+
}
18311842
if (api_version >= PGSS_V1_10)
18321843
{
18331844
values[i++] = Float8GetDatumFast(tmp.temp_blk_read_time);

doc/src/sgml/pgstatstatements.sgml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@
353353
</para></entry>
354354
</row>
355355

356+
<row>
357+
<entry role="catalog_table_entry"><para role="column_definition">
358+
<structfield>local_blk_read_time</structfield> <type>double precision</type>
359+
</para>
360+
<para>
361+
Total time the statement spent reading local blocks, in milliseconds
362+
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
363+
</para></entry>
364+
</row>
365+
366+
<row>
367+
<entry role="catalog_table_entry"><para role="column_definition">
368+
<structfield>local_blk_write_time</structfield> <type>double precision</type>
369+
</para>
370+
<para>
371+
Total time the statement spent writing local blocks, in milliseconds
372+
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
373+
</para></entry>
374+
</row>
375+
356376
<row>
357377
<entry role="catalog_table_entry"><para role="column_definition">
358378
<structfield>temp_blk_read_time</structfield> <type>double precision</type>

0 commit comments

Comments
 (0)