<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Index Maintenance on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/index-maintenance/</link><description>Recent content in Index Maintenance on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Wed, 10 Apr 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/index-maintenance/index.xml" rel="self" type="application/rss+xml"/><item><title>Find Unused PostgreSQL Indexes with pg_stat_all_indexes</title><link>https://www.postgresscripts.com/post/identifying-unused-indexes-in-postgresql-declutter-and-optimize/</link><pubDate>Wed, 10 Apr 2024 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/identifying-unused-indexes-in-postgresql-declutter-and-optimize/</guid><description>
&lt;h2 id="find-unused-postgresql-indexes-before-they-cost-you"&gt;Find Unused PostgreSQL Indexes Before They Cost You&lt;/h2&gt;
&lt;p&gt;Which indexes have gone unused since the statistics were last reset? &lt;code&gt;pg_stat_all_indexes&lt;/code&gt; counts every index scan per index, and an index whose &lt;code&gt;idx_scan&lt;/code&gt; is still zero after weeks of normal traffic is a candidate to drop. The query below lists those indexes, largest first, and leaves out the ones that enforce a unique or primary key constraint.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="7945792173"
data-ad-format="auto"
data-full-width-responsive="true"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Every index has a cost. It takes disk space, PostgreSQL has to maintain it as rows are inserted and updated, and its pages compete for shared buffers with the data your queries actually read. An index that no query uses pays all of those costs and returns nothing.&lt;/p&gt;</description></item></channel></rss>