Objects
Query the following views to get access and I/O statistics for database objects in PolarDB for PostgreSQL (Compatible with Oracle). Use this data to identify performance bottlenecks and diagnose issues with tables, indexes, sequences, and functions.
Statistics in these views are not updated in real time. Each server process flushes accumulated statistics to shared memory just before going idle, so the data reflects recent—not current—activity. Queries and transactions still in progress are not included in the displayed totals.
Tables
pg_stat_all_tables
Use pg_stat_all_tables to understand how each table is being accessed—whether rows are retrieved by sequential scans or index scans, and how often rows are inserted, updated, or deleted. This helps identify tables that lack appropriate indexes or need more frequent vacuuming.
| Parameter | Type | Description |
|---|---|---|
relid | oid | The OID of the table. |
schemaname | name | The name of the schema to which the table belongs. |
relname | name | The name of the table. |
seq_scan | bigint | The number of sequential scans initiated on the table. |
seq_tup_read | bigint | The number of live rows fetched by sequential scans. |
idx_scan | bigint | The number of index scans initiated on the table. |
idx_tup_fetch | bigint | The number of live rows fetched by index scans. |
n_tup_ins | bigint | The number of inserted rows. |
n_tup_upd | bigint | The number of updated rows. This includes the rows that are updated by the Heap Only Tuple (HOT) feature. |
n_tup_del | bigint | The number of rows deleted from the table. |
n_tup_hot_upd | bigint | The number of rows updated by the HOT feature. The rows are updated without the need to separately update indexes. |
n_live_tup | bigint | The estimated number of live rows. |
n_dead_tup | bigint | The estimated number of dead rows. |
n_mod_since_analyze | bigint | The estimated number of rows that are modified after the table was last analyzed. |
last_vacuum | timestamp with time zone | The latest time when the table was manually vacuumed. The time consumed by the VACUUM FULL statement is not counted. |
last_autovacuum | timestamp with time zone | The latest time when the table was automatically vacuumed by the autovacuum daemon. |
last_analyze | timestamp with time zone | The latest time when the table was manually analyzed. |
last_autoanalyze | timestamp with time zone | The latest time when the table was automatically analyzed by the autovacuum daemon. |
vacuum_count | bigint | The number of manual VACUUM operations on the table. This value does not include the number of times VACUUM FULL is executed. |
autovacuum_count | bigint | The number of automatic VACUUM operations on the table by the autovacuum daemon. |
analyze_count | bigint | The number of manual ANALYZE operations on the table. |
autoanalyze_count | bigint | The number of automatic ANALYZE operations on the table by the autovacuum daemon. |
n_tup_updcounts all updated rows, including HOT updates.n_tup_hot_updcounts only HOT updates—rows updated in place without modifying index entries. A highn_tup_hot_updrelative ton_tup_updindicates that HOT updates are working efficiently.
pg_statio_all_tables
Use pg_statio_all_tables to determine the effectiveness of the buffer cache for each table. A low cache hit ratio indicates that the database is reading frequently from disk, which can degrade performance.
| Parameter | Type | Description |
|---|---|---|
relid | oid | The OID of the table. |
schemaname | name | The name of the schema to which the table belongs. |
relname | name | The name of the metatable. |
heap_blks_read | bigint | The number of disk blocks read from the table. |
heap_blks_hit | bigint | The number of buffer cache hits in the table. |
idx_blks_read | bigint | The number of disk blocks that are read from all the indexes in the table. |
idx_blks_hit | bigint | The number of buffer cache hits for all the indexes in the table. |
toast_blks_read | bigint | The number of disk blocks that are read from the TOAST table associated with the table. |
toast_blks_hit | bigint | The number of buffer cache hits in the TOAST table associated with the table. |
tidx_blks_read | bigint | The number of disk blocks that are read from the indexes for the TOAST table associated with the table. |
tidx_blks_hit | bigint | The number of buffer cache hits for the indexes for the TOAST table associated with the table. |
Indexes
pg_stat_all_indexes
Use pg_stat_all_indexes to determine which indexes are being used and how effective they are. Indexes with a low idx_scan count relative to the number of rows in the table may not be worth the overhead.
Indexes can be accessed by simple index scans, bitmap scans, or the query optimizer. In a bitmap scan, output from multiple indexes can be combined using AND or OR rules. Because individual rows in a bitmap scan cannot be associated with specific indexes, a bitmap scan increases idx_tup_read for the participating indexes and increases pg_stat_all_tables.idx_tup_fetch for the table—but does not affect idx_tup_fetch for the indexes themselves. If constant values fall outside the range of optimizer statistics, the optimizer may still access indexes to verify the values.
| Parameter | Type | Description |
|---|---|---|
relid | oid | The OID of the table for the index. |
indexrelid | oid | The OID of the index. |
schemaname | name | The name of the schema to which the index belongs. |
relname | name | The name of the table for the index. |
indexrelname | name | The name of the index. |
idx_scan | bigint | The number of scans initiated on the index. |
idx_tup_read | bigint | The number of index items returned by scans on the index. |
idx_tup_fetch | bigint | The number of live table rows that simple index scans fetch by using this index. |
idx_tup_readandidx_tup_fetchcan differ even without bitmap scans.idx_tup_readcounts index entries retrieved from the index, whileidx_tup_fetchcounts live rows fetched from the table.idx_tup_fetchis lower when dead rows or not-yet-committed rows are encountered during the scan, or when index-only scans avoid fetching heap rows entirely.
pg_statio_all_indexes
Use pg_statio_all_indexes to calculate the cache hit ratio for each index. This helps identify indexes that are read from disk frequently, which can slow down query execution.
| Parameter | Type | Description |
|---|---|---|
relid | oid | The OID of the table for the index. |
indexrelid | oid | The OID of the index. |
schemaname | name | The name of the schema in which the index resides. |
relname | name | The name of the table for the index. |
indexrelname | name | The name of the index. |
idx_blks_read | bigint | The number of disk blocks read from the index. |
idx_blks_hit | bigint | The number of buffer cache hits for the index. |
Sequences
pg_statio_all_sequences
pg_statio_all_sequences shows I/O statistics for each sequence in the current database. Use it to identify sequences with high disk read counts, which can indicate buffer cache pressure on sequence blocks.
| Parameter | Type | Description |
|---|---|---|
relid | oid | The OID of the sequence. |
schemaname | name | The name of the schema to which the sequence belongs. |
relname | name | The name of the sequence. |
blks_read | bigint | The number of disk blocks read from the sequence. |
blks_hit | bigint | The number of buffer cache hits in the sequence. |
Functions
pg_stat_user_functions
pg_stat_user_functions shows execution statistics for tracked functions. Use it to identify functions with high call counts or excessive total execution time.
| Parameter | Type | Description |
|---|---|---|
funcid | oid | The OID of the function. |
schemaname | name | The name of the schema to which the function belongs. |
funcname | name | The name of the function. |
calls | bigint | The number of calls for the function. |
total_time | double precision | The total time consumed to invoke the function and all functions it calls. Unit: milliseconds. |
self_time | double precision | The total time consumed to invoke the function, excluding time spent in functions it calls. Unit: milliseconds. |