Number of buffer hits in this sequence
</para></entry>
</row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>stats_reset</structfield> <type>timestamp with time zone</type>
+ </para>
+ <para>
+ Time at which these statistics were last reset
+ </para></entry>
+ </row>
</tbody>
</tgroup>
</table>
<para>
Resets statistics for a single table or index in the current database
or shared across all databases in the cluster to zero.
+ It also resets statistics for a single sequence or materialized view
+ in the current database.
</para>
<para>
This function is restricted to superusers by default, but other users
C.relname AS relname,
pg_stat_get_blocks_fetched(C.oid) -
pg_stat_get_blocks_hit(C.oid) AS blks_read,
- pg_stat_get_blocks_hit(C.oid) AS blks_hit
+ pg_stat_get_blocks_hit(C.oid) AS blks_hit,
+ pg_stat_get_stat_reset_time(C.oid) AS stats_reset
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE C.relkind = 'S';
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202603131
+#define CATALOG_VERSION_NO 202603161
#endif
n.nspname AS schemaname,
c.relname,
(pg_stat_get_blocks_fetched(c.oid) - pg_stat_get_blocks_hit(c.oid)) AS blks_read,
- pg_stat_get_blocks_hit(c.oid) AS blks_hit
+ pg_stat_get_blocks_hit(c.oid) AS blks_hit,
+ pg_stat_get_stat_reset_time(c.oid) AS stats_reset
FROM (pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = 'S'::"char");
schemaname,
relname,
blks_read,
- blks_hit
+ blks_hit,
+ stats_reset
FROM pg_statio_all_sequences
WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
pg_statio_sys_tables| SELECT relid,
schemaname,
relname,
blks_read,
- blks_hit
+ blks_hit,
+ stats_reset
FROM pg_statio_all_sequences
WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text));
pg_statio_user_tables| SELECT relid,
t
(1 row)
+-- Test that reset works for pg_statio_all_sequences
+-- Use the sequence to accumulate its stats, and reset them once first
+-- so that we have a baseline for comparison, similar to the previous test.
+-- stats_reset to compare to.
+CREATE SEQUENCE test_seq1;
+SELECT nextval('test_seq1');
+ nextval
+---------
+ 1
+(1 row)
+
+SELECT pg_stat_reset_single_table_counters('test_seq1'::regclass);
+ pg_stat_reset_single_table_counters
+-------------------------------------
+
+(1 row)
+
+SELECT stats_reset AS seq_reset_ts
+ FROM pg_statio_all_sequences WHERE relname ='test_seq1' \gset
+SELECT pg_stat_reset_single_table_counters('test_seq1'::regclass);
+ pg_stat_reset_single_table_counters
+-------------------------------------
+
+(1 row)
+
+SELECT stats_reset > :'seq_reset_ts'::timestamptz, blks_read + blks_hit
+ FROM pg_statio_all_sequences WHERE relname ='test_seq1';
+ ?column? | ?column?
+----------+----------
+ t | 0
+(1 row)
+
+DROP SEQUENCE test_seq1;
----
-- pg_stat_get_snapshot_timestamp behavior
----
SELECT stats_reset > :'db_reset_ts'::timestamptz FROM pg_stat_database WHERE datname = (SELECT current_database());
SELECT stats_reset > :'dbc_reset_ts'::timestamptz FROM pg_stat_database_conflicts WHERE datname = (SELECT current_database());
+-- Test that reset works for pg_statio_all_sequences
+
+-- Use the sequence to accumulate its stats, and reset them once first
+-- so that we have a baseline for comparison, similar to the previous test.
+-- stats_reset to compare to.
+CREATE SEQUENCE test_seq1;
+SELECT nextval('test_seq1');
+SELECT pg_stat_reset_single_table_counters('test_seq1'::regclass);
+SELECT stats_reset AS seq_reset_ts
+ FROM pg_statio_all_sequences WHERE relname ='test_seq1' \gset
+SELECT pg_stat_reset_single_table_counters('test_seq1'::regclass);
+SELECT stats_reset > :'seq_reset_ts'::timestamptz, blks_read + blks_hit
+ FROM pg_statio_all_sequences WHERE relname ='test_seq1';
+DROP SEQUENCE test_seq1;
+
----
-- pg_stat_get_snapshot_timestamp behavior