-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collect more detailed postgres metrics for specified relations #1007
Comments
Nice description! Let's make sure to use EXPLAIN to see how complex these queries are. |
SELECT t.tablename, psai.indexrelname, pg_relation_size(quote_ident(indexrelname)::text) AS index_size
FROM pg_tables t
JOIN pg_class c ON t.tablename = c.relname
JOIN pg_index x ON c.oid = x.indrelid
JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid
WHERE t.tablename = 'my_table'; or more synthetically SELECT
nspname,
relname,
relkind as "type",
pg_table_size(C.oid) AS size,
pg_indexes_size(C.oid) AS idxsize,
pg_total_relation_size(C.oid) as "total"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND
nspname !~ '^pg_toast' AND
relkind IN ('r','i'); |
First example returns Second example uses a more liberal WHERE clause, getting all details beyond the specified relations. Leaning towards the simpler approach of collecting the desired index stats over global collection (for now) as this is an opt-in approach, reducing the probability of collecting unbounded lists. |
One query to get index, table and total size for a subset of the tables,
|
We already collect some metrics with tables and index data, such as rows and counts, but not disk space-related details for given relations.
(All metrics should be tagged with the relation that they came from, so an index stat should be tagged with the relation name. This may already be the case.)
Let's start with the easy ones.
table/relation/index size totals
Note:
pg_indexes_size()
was introduced in PG 9.0, so if we're still supporting 8.4 this particular one won't work.We could wrap each result in pg_size_pretty() if we wanted to handle units transformation, like so:
(This may prove harder to parse out the actual results as they change)
per-index size from a given relation
This is a more complex query right now, and could possibly be simplified, I hadn't looked too hard into where I could reduce the joins just yet.
Descriptions for each of the functions used are in Postgres Docs.
The text was updated successfully, but these errors were encountered: