Fork me on GitHub
#off-topic
<
2020-11-26
>
dazld18:11:34

Random question, did any of you ever come across something that can parse Postgres explain/analyse output, and give some kind of programmatic insights? Indexes used, or not, etc..?

valtteri19:11:00

Did you already try explain/analyze tooling in PGAdmin4? It provides a visual graph and nice stats about the query plan.

dazld00:11:24

Both great suggestions, thanks

dazld00:11:49

At back of my mind was something like a library that could warn if an index wasn’t being used, or partially used

dharrigan06:11:44

Oh, you can run a SQL query for that. I'm sure you could adapt this to run within your application, to give you some insight...

dharrigan06:11:10

SELECT s.schemaname,
       s.relname AS tablename,
       s.indexrelname AS indexname,
       pg_size_pretty(pg_relation_size(s.indexrelid)) AS index_size,
       idx_scan as index_scans
FROM pg_catalog.pg_stat_user_indexes s
   JOIN pg_catalog.pg_index i ON s.indexrelid = i.indexrelid
WHERE s.idx_scan = 0                     -- has never been scanned
  AND 0 <>ALL (i.indkey)                 -- no index column is an expression
  AND pg_relation_size(relid) > 5 * 8192 -- has some data in the table
  AND NOT i.indisunique                  -- is not a UNIQUE index
  AND NOT EXISTS                         -- does not enforce a constraint
         (SELECT 1 FROM pg_catalog.pg_constraint c
          WHERE c.conindid = s.indexrelid)
  AND s.schemaname = 'REPLACE_ME_WITH_YOUR_SCHEMA_NAME'
ORDER BY pg_relation_size(s.indexrelid) / nullif(idx_scan, 0) DESC NULLS FIRST,
         pg_relation_size(i.indexrelid) DESC;

👍 3
Jared Kristensen23:11:20

Hi everyone, I wanted to introduce myself. I'm ceo/co-founder of http://audiencerepublic.com. We are 100% clojure on the back end, and I'm looking forward to meeting more people in the clojure world 🙂

👍 9
👋 30
3
clojure-spin 3