-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathpostgres_index_cardinality_with_schema_name.sql
More file actions
49 lines (47 loc) · 1.09 KB
/
postgres_index_cardinality_with_schema_name.sql
File metadata and controls
49 lines (47 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--
-- Author: Hari Sekhon
-- Date: 2020-08-06 00:18:01 +0100 (Thu, 06 Aug 2020)
--
-- vim:ts=4:sts=4:sw=4:et:filetype=sql
--
-- https://github.com/HariSekhon/SQL-scripts
--
-- License: see accompanying Hari Sekhon LICENSE file
--
-- If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
--
-- https://www.linkedin.com/in/HariSekhon
--
-- PostgreSQL index cardinality with schema name
--
-- Tested on PostgreSQL 8.4, 9.x, 10.x 11.x, 12.x, 13.0
SELECT
schema_name,
relname,
reltuples AS "cardinality (reltuples)",
relpages
FROM (
SELECT
pg_catalog.pg_namespace.nspname AS schema_name,
relname,
reltuples,
relpages
FROM
pg_class
JOIN
pg_namespace ON relnamespace = pg_namespace.oid
WHERE
relkind = 'i'
) t
WHERE
schema_name NOT ILIKE 'pg_%'
AND
schema_name <> 'information_schema'
-- AND
-- relname LIKE 'someprefix%';
AND
relname NOT ILIKE 'pg_%'
ORDER BY
3 DESC,
schema_name,
relname;