File tree Expand file tree Collapse file tree 1 file changed +5
-18
lines changed Expand file tree Collapse file tree 1 file changed +5
-18
lines changed Original file line number Diff line number Diff line change @@ -200,24 +200,11 @@ pg_stat_user_tables:
200
200
pg_indexes_size(pg_class.oid) AS index_size,
201
201
pg_total_relation_size(pg_class.reltoastrelid) AS toast_size
202
202
FROM
203
- pg_stat_user_tables u
204
- JOIN pg_class ON pg_class.oid = u.relid AND pg_class.relkind <> 'm' -- exclude matviews to prevent query being locked when refreshing MV
205
- UNION ALL
206
- SELECT
207
- c.oid,
208
- SUM(c.relpages::bigint*8192) AS table_size,
209
- coalesce(SUM(idx.index_bytes),0) as index_size,
210
- coalesce(SUM((c2.relpages+c3.relpages)::bigint*8192),0) AS toast_size
211
- FROM pg_stat_user_tables u
212
- JOIN pg_class c ON u.relid=c.oid AND c.relkind='m' -- matviews only
213
- LEFT JOIN pg_class c2 ON c2.oid = c.reltoastrelid
214
- LEFT JOIN pg_index it ON it.indrelid=c.reltoastrelid -- only one index per pg_toast table
215
- LEFT JOIN pg_class c3 ON c3.oid=it.indexrelid
216
- CROSS JOIN LATERAL (
217
- SELECT SUM(c4.relpages::bigint*8192) AS index_bytes
218
- FROM pg_index i JOIN pg_class c4 ON i.indrelid=c.oid AND c4.oid=i.indexrelid
219
- ) idx
220
- GROUP BY c.oid
203
+ pg_stat_user_tables ut
204
+ JOIN pg_class ON pg_class.oid = ut.relid
205
+ WHERE NOT EXISTS (
206
+ SELECT 1 FROM pg_locks WHERE pg_locks.relation = ut.relid AND pg_locks.mode = 'AccessExclusiveLock'
207
+ )
221
208
) t ON u.relid = t.oid
222
209
;
223
210
metrics :
You can’t perform that action at this time.
0 commit comments