From: | Lucas Possamai <drum(dot)lucas(at)gmail(dot)com> |
---|---|
To: | Melvin Davidson <melvin6925(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Unused indexes - PostgreSQL 9.2 |
Date: | 2016-05-23 23:23:15 |
Message-ID: | CAE_gQfUYk4GxFyLxA_nB-jdJVVPceqiKKMfvQyp4EMA_sCRfvw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello Melvin, how are you doing?
>>
> And what happens if you run this query?
>
> SELECT idstat.schemaname AS schema,
> idstat.relname AS table_name,
> indexrelname AS index_name,
> idstat.idx_scan AS times_used,
> pg_size_pretty(pg_relation_size(quote_ident(idstat.schemaname) ||
> '.' || quote_ident(idstat.relname))) AS table_size,
> pg_size_pretty(pg_relation_size(quote_ident(idstat.schemaname) ||
> '.' || quote_ident(indexrelname))) AS index_size,
> n_tup_upd + n_tup_ins + n_tup_del as num_writes,
> indexdef AS definition
> FROM pg_stat_user_indexes AS idstat
> JOIN pg_indexes ON indexrelname = indexname
> JOIN pg_stat_user_tables AS tabstat ON idstat.relname = tabstat.relname
> WHERE indexrelname = ' {YOUR QUERY NAME } ';
>
I've added some new indexes this week into my prod environment, and I used
your query to see if they're being used or not.
Query:
> SELECT idstat.schemaname AS schema,
> idstat.relname AS table_name,
> indexrelname AS index_name,
> idstat.idx_scan AS times_used,
> pg_size_pretty(pg_relation_size(quote_ident(idstat.schemaname) ||
> '.' || quote_ident(idstat.relname))) AS table_size,
> pg_size_pretty(pg_relation_size(quote_ident(idstat.schemaname) ||
> '.' || quote_ident(indexrelname))) AS index_size,
> n_tup_upd + n_tup_ins + n_tup_del as num_writes,
> indexdef AS definition
> FROM pg_stat_user_indexes AS idstat
> JOIN pg_indexes ON indexrelname = indexname
> JOIN pg_stat_user_tables AS tabstat ON idstat.relname = tabstat.relname
> WHERE indexrelname = 'ix_ja_jobs_clientid_title_time_job';
Returns:
> schema table_name index_name times_used table_size
> index_size num_writes definition
>
>
> ------ ---------- ---------------------------------- ---------- ----------
> ---------- ----------
> -------------------------------------------------------------------------------------------------------------------------------------------------------
> public ja_jobs ix_ja_jobs_clientid_title_time_job 41536 3526 MB
> 484 MB 38266927 CREATE INDEX "ix_ja_jobs_clientid_title_time_job" ON
> "ja_jobs" USING "btree" ("clientid", "lower"(("title")::"text")
> "varchar_pattern_ops", "time_job")
That index has been added just 3 hours ago, and you can see that the
times_used goes over 41000.... How is that possible??
Don't think the query is right.
Can you please check ?
Thank you.
From | Date | Subject | |
---|---|---|---|
Next Message | dandl | 2016-05-24 00:18:05 | Re: Fatal error "stack empty" on ROLLBACK |
Previous Message | Lucas Possamai | 2016-05-23 21:44:06 | Re: Increased I/O / Writes |