mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added the new columns last_seq_scan and last_idx_scan from the pg_stat_all_tables and pg_stat_all_indexes tables respectively to the Statistics tab. #6728
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
SELECT
|
||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||
pg_catalog.pg_relation_size({{ exid }}::OID) AS {{ conn|qtIdent(_('Index size')) }},
|
||||
last_idx_scan AS {{ conn|qtIdent(_('Last index scan')) }}
|
||||
{#=== Extended stats ===#}
|
||||
{% if is_pgstattuple %}
|
||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||
empty_pages AS {{ conn|qtIdent(_('Empty pages')) }},
|
||||
deleted_pages AS {{ conn|qtIdent(_('Deleted pages')) }},
|
||||
avg_leaf_density AS {{ conn|qtIdent(_('Average leaf density')) }},
|
||||
leaf_fragmentation AS {{ conn|qtIdent(_('Leaf fragmentation')) }}
|
||||
FROM
|
||||
pgstatindex('{{conn|qtIdent(schema)}}.{{conn|qtIdent(name)}}'), pg_catalog.pg_stat_all_indexes stat
|
||||
{% else %}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_indexes stat
|
||||
{% endif %}
|
||||
JOIN pg_catalog.pg_statio_all_indexes statio ON stat.indexrelid = statio.indexrelid
|
||||
JOIN pg_catalog.pg_class cl ON cl.oid=stat.indexrelid
|
||||
WHERE stat.indexrelid = {{ exid }}::OID
|
||||
@@ -0,0 +1,29 @@
|
||||
SELECT
|
||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||
pg_catalog.pg_relation_size({{ cid }}::OID) AS {{ conn|qtIdent(_('Index size')) }},
|
||||
last_idx_scan AS {{ conn|qtIdent(_('Last index scan')) }}
|
||||
{#=== Extended stats ===#}
|
||||
{% if is_pgstattuple %}
|
||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||
empty_pages AS {{ conn|qtIdent(_('Empty pages')) }},
|
||||
deleted_pages AS {{ conn|qtIdent(_('Deleted pages')) }},
|
||||
avg_leaf_density AS {{ conn|qtIdent(_('Average leaf density')) }},
|
||||
leaf_fragmentation AS {{ conn|qtIdent(_('Leaf fragmentation')) }}
|
||||
FROM
|
||||
pgstatindex('{{conn|qtIdent(schema)}}.{{conn|qtIdent(name)}}'), pg_catalog.pg_stat_all_indexes stat
|
||||
{% else %}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_indexes stat
|
||||
{% endif %}
|
||||
JOIN pg_catalog.pg_statio_all_indexes statio ON stat.indexrelid = statio.indexrelid
|
||||
JOIN pg_catalog.pg_class cl ON cl.oid=stat.indexrelid
|
||||
WHERE stat.indexrelid = {{ cid }}::OID
|
||||
@@ -0,0 +1,18 @@
|
||||
SELECT
|
||||
indexrelname AS {{ conn|qtIdent(_('Index name')) }},
|
||||
pg_catalog.pg_relation_size(indexrelid) AS {{ conn|qtIdent(_('Size')) }},
|
||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||
last_idx_scan AS {{ conn|qtIdent(_('Last index scan')) }}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_indexes stat
|
||||
JOIN pg_catalog.pg_class cls ON cls.oid=indexrelid
|
||||
LEFT JOIN pg_catalog.pg_depend dep ON (dep.classid = cls.tableoid AND dep.objid = cls.oid AND dep.refobjsubid = '0'
|
||||
AND dep.refclassid=(SELECT oid FROM pg_catalog.pg_class WHERE relname='pg_constraint'))
|
||||
LEFT OUTER JOIN pg_catalog.pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid)
|
||||
WHERE
|
||||
schemaname = '{{schema}}'
|
||||
AND stat.relname = '{{table}}'
|
||||
AND con.contype IS NULL
|
||||
ORDER BY indexrelname;
|
||||
@@ -0,0 +1,29 @@
|
||||
SELECT
|
||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||
idx_tup_read AS {{ conn|qtIdent(_('Index tuples read')) }},
|
||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||
pg_catalog.pg_relation_size({{ idx }}::OID) AS {{ conn|qtIdent(_('Index size')) }},
|
||||
last_idx_scan AS {{ conn|qtIdent(_('Last index scan')) }}
|
||||
{#=== Extended stats ===#}
|
||||
{% if is_pgstattuple %}
|
||||
,version AS {{ conn|qtIdent(_('Version')) }},
|
||||
tree_level AS {{ conn|qtIdent(_('Tree level')) }},
|
||||
index_size AS {{ conn|qtIdent(_('Index size')) }},
|
||||
root_block_no AS {{ conn|qtIdent(_('Root block no')) }},
|
||||
internal_pages AS {{ conn|qtIdent(_('Internal pages')) }},
|
||||
leaf_pages AS {{ conn|qtIdent(_('Leaf pages')) }},
|
||||
empty_pages AS {{ conn|qtIdent(_('Empty pages')) }},
|
||||
deleted_pages AS {{ conn|qtIdent(_('Deleted pages')) }},
|
||||
avg_leaf_density AS {{ conn|qtIdent(_('Average leaf density')) }},
|
||||
leaf_fragmentation AS {{ conn|qtIdent(_('Leaf fragmentation')) }}
|
||||
FROM
|
||||
pgstatindex('{{conn|qtIdent(schema)}}.{{conn|qtIdent(index)}}'), pg_catalog.pg_stat_all_indexes stat
|
||||
{% else %}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_indexes stat
|
||||
{% endif %}
|
||||
JOIN pg_catalog.pg_statio_all_indexes statio ON stat.indexrelid = statio.indexrelid
|
||||
JOIN pg_catalog.pg_class cl ON cl.oid=stat.indexrelid
|
||||
WHERE stat.indexrelid = {{ idx }}::OID
|
||||
@@ -0,0 +1,30 @@
|
||||
SELECT
|
||||
st.relname AS {{ conn|qtIdent(_('Table name')) }},
|
||||
pg_catalog.pg_relation_size(st.relid)
|
||||
+ CASE WHEN cl.reltoastrelid = 0 THEN 0 ELSE pg_catalog.pg_relation_size(cl.reltoastrelid)
|
||||
+ COALESCE((SELECT SUM(pg_catalog.pg_relation_size(indexrelid))
|
||||
FROM pg_catalog.pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0) END
|
||||
+ COALESCE((SELECT SUM(pg_catalog.pg_relation_size(indexrelid))
|
||||
FROM pg_catalog.pg_index WHERE indrelid=st.relid)::int8, 0) AS {{ conn|qtIdent(_('Total Size')) }},
|
||||
n_tup_ins AS {{ conn|qtIdent(_('Tuples inserted')) }},
|
||||
n_tup_upd AS {{ conn|qtIdent(_('Tuples updated')) }},
|
||||
n_tup_del AS {{ conn|qtIdent(_('Tuples deleted')) }},
|
||||
n_tup_hot_upd AS {{ conn|qtIdent(_('Tuples HOT updated')) }},
|
||||
n_live_tup AS {{ conn|qtIdent(_('Live tuples')) }},
|
||||
n_dead_tup AS {{ conn|qtIdent(_('Dead tuples')) }},
|
||||
last_vacuum AS {{ conn|qtIdent(_('Last vacuum')) }},
|
||||
last_autovacuum AS {{ conn|qtIdent(_('Last autovacuum')) }},
|
||||
last_analyze AS {{ conn|qtIdent(_('Last analyze')) }},
|
||||
last_autoanalyze AS {{ conn|qtIdent(_('Last autoanalyze')) }},
|
||||
last_seq_scan AS {{ conn|qtIdent(_('Last sequential scan')) }},
|
||||
vacuum_count AS {{ conn|qtIdent(_('Vacuum counter')) }},
|
||||
autovacuum_count AS {{ conn|qtIdent(_('Autovacuum counter')) }},
|
||||
analyze_count AS {{ conn|qtIdent(_('Analyze counter')) }},
|
||||
autoanalyze_count AS {{ conn|qtIdent(_('Autoanalyze counter')) }}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_tables st
|
||||
JOIN
|
||||
pg_catalog.pg_class cl on cl.oid=st.relid and cl.relkind IN ('r','s','t','p')
|
||||
WHERE
|
||||
schemaname = {{schema_name|qtLiteral(conn)}}
|
||||
ORDER BY st.relname;
|
||||
@@ -0,0 +1,54 @@
|
||||
SELECT
|
||||
seq_scan AS {{ conn|qtIdent(_('Sequential scans')) }},
|
||||
seq_tup_read AS {{ conn|qtIdent(_('Sequential tuples read')) }},
|
||||
idx_scan AS {{ conn|qtIdent(_('Index scans')) }},
|
||||
idx_tup_fetch AS {{ conn|qtIdent(_('Index tuples fetched')) }},
|
||||
n_tup_ins AS {{ conn|qtIdent(_('Tuples inserted')) }},
|
||||
n_tup_upd AS {{ conn|qtIdent(_('Tuples updated')) }},
|
||||
n_tup_del AS {{ conn|qtIdent(_('Tuples deleted')) }},
|
||||
n_tup_hot_upd AS {{ conn|qtIdent(_('Tuples HOT updated')) }},
|
||||
n_live_tup AS {{ conn|qtIdent(_('Live tuples')) }},
|
||||
n_dead_tup AS {{ conn|qtIdent(_('Dead tuples')) }},
|
||||
heap_blks_read AS {{ conn|qtIdent(_('Heap blocks read')) }},
|
||||
heap_blks_hit AS {{ conn|qtIdent(_('Heap blocks hit')) }},
|
||||
idx_blks_read AS {{ conn|qtIdent(_('Index blocks read')) }},
|
||||
idx_blks_hit AS {{ conn|qtIdent(_('Index blocks hit')) }},
|
||||
toast_blks_read AS {{ conn|qtIdent(_('Toast blocks read')) }},
|
||||
toast_blks_hit AS {{ conn|qtIdent(_('Toast blocks hit')) }},
|
||||
tidx_blks_read AS {{ conn|qtIdent(_('Toast index blocks read')) }},
|
||||
tidx_blks_hit AS {{ conn|qtIdent(_('Toast index blocks hit')) }},
|
||||
last_vacuum AS {{ conn|qtIdent(_('Last vacuum')) }},
|
||||
last_autovacuum AS {{ conn|qtIdent(_('Last autovacuum')) }},
|
||||
last_analyze AS {{ conn|qtIdent(_('Last analyze')) }},
|
||||
last_autoanalyze AS {{ conn|qtIdent(_('Last autoanalyze')) }},
|
||||
last_seq_scan AS {{ conn|qtIdent(_('Last sequential scan')) }},
|
||||
pg_catalog.pg_relation_size(stat.relid) AS {{ conn|qtIdent(_('Table size')) }},
|
||||
CASE WHEN cl.reltoastrelid = 0 THEN NULL ELSE pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(cl.reltoastrelid)
|
||||
+ COALESCE((SELECT SUM(pg_catalog.pg_relation_size(indexrelid))
|
||||
FROM pg_catalog.pg_index WHERE indrelid=cl.reltoastrelid)::int8, 0))
|
||||
END AS {{ conn|qtIdent(_('Toast table size')) }},
|
||||
COALESCE((SELECT SUM(pg_catalog.pg_relation_size(indexrelid))
|
||||
FROM pg_catalog.pg_index WHERE indrelid=stat.relid)::int8, 0)
|
||||
AS {{ conn|qtIdent(_('Indexes size')) }}
|
||||
{% if is_pgstattuple %}
|
||||
{#== EXTENDED STATS ==#}
|
||||
,tuple_count AS {{ conn|qtIdent(_('Tuple count')) }},
|
||||
tuple_len AS {{ conn|qtIdent(_('Tuple length')) }},
|
||||
tuple_percent AS {{ conn|qtIdent(_('Tuple percent')) }},
|
||||
dead_tuple_count AS {{ conn|qtIdent(_('Dead tuple count')) }},
|
||||
dead_tuple_len AS {{ conn|qtIdent(_('Dead tuple length')) }},
|
||||
dead_tuple_percent AS {{ conn|qtIdent(_('Dead tuple percent')) }},
|
||||
free_space AS {{ conn|qtIdent(_('Free space')) }},
|
||||
free_percent AS {{ conn|qtIdent(_('Free percent')) }}
|
||||
FROM
|
||||
pgstattuple('{{schema_name}}.{{table_name}}'), pg_catalog.pg_stat_all_tables stat
|
||||
{% else %}
|
||||
FROM
|
||||
pg_catalog.pg_stat_all_tables stat
|
||||
{% endif %}
|
||||
JOIN
|
||||
pg_catalog.pg_statio_all_tables statio ON stat.relid = statio.relid
|
||||
JOIN
|
||||
pg_catalog.pg_class cl ON cl.oid=stat.relid
|
||||
WHERE
|
||||
stat.relid = {{ tid }}::oid
|
||||
Reference in New Issue
Block a user