<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pg_stat_user_indexes on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/pg_stat_user_indexes/</link><description>Recent content in Pg_stat_user_indexes on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Tue, 31 Mar 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/pg_stat_user_indexes/index.xml" rel="self" type="application/rss+xml"/><item><title>Find PostgreSQL Index Bloat and Wasted Space</title><link>https://www.postgresscripts.com/post/find-postgresql-index-bloat-and-wasted-space/</link><pubDate>Tue, 31 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/find-postgresql-index-bloat-and-wasted-space/</guid><description>
&lt;h2 id="how-to-find-index-bloat-and-wasted-space-in-postgresql"&gt;How to Find Index Bloat and Wasted Space in PostgreSQL&lt;/h2&gt;
&lt;p&gt;Just like tables, PostgreSQL indexes can become bloated over time. When rows are updated or deleted, the old index entries are not removed immediately. They stay in the index as dead entries, wasting space and slowing down index scans.&lt;/p&gt;
&lt;p&gt;B-tree indexes are the most common type in PostgreSQL and the most prone to bloat. This query estimates how much space is wasted in each B-tree index, so you can decide which ones need to be rebuilt.&lt;/p&gt;</description></item><item><title>PostgreSQL Statistics Settings Query Guide</title><link>https://www.postgresscripts.com/post/postgresql-statistics-settings-query-guide/</link><pubDate>Tue, 17 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/postgresql-statistics-settings-query-guide/</guid><description>
&lt;h2 id="postgresql-statistics-settings-query-guide"&gt;PostgreSQL Statistics Settings Query Guide&lt;/h2&gt;
&lt;p&gt;This PostgreSQL query retrieves all statistics collection configuration settings from the &lt;code&gt;pg_settings&lt;/code&gt; system view. These parameters control what runtime data PostgreSQL collects about query execution, table activity, and performance, feeding into the &lt;code&gt;pg_stat_*&lt;/code&gt; monitoring views.&lt;/p&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;PostgreSQL's statistics collector gathers data about database activity and makes it available through system views like &lt;code&gt;pg_stat_activity&lt;/code&gt;, &lt;code&gt;pg_stat_user_tables&lt;/code&gt;, and &lt;code&gt;pg_stat_statements&lt;/code&gt;. If the underlying collection settings are disabled, those views return incomplete or empty data.&lt;/p&gt;</description></item><item><title>List PostgreSQL Tables by Size with SQL</title><link>https://www.postgresscripts.com/post/list-postgresql-tables-by-size-with-sql/</link><pubDate>Sun, 15 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/list-postgresql-tables-by-size-with-sql/</guid><description>
&lt;h2 id="list-postgresql-tables-by-size-with-sql"&gt;List PostgreSQL Tables by Size with SQL&lt;/h2&gt;
&lt;p&gt;This PostgreSQL query lists all tables in the current database sorted by their total size, largest first. It uses &lt;code&gt;pg_total_relation_size()&lt;/code&gt; to include the table data, indexes, TOAST storage, and free space map in the size calculation.&lt;/p&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Disk space pressure is a common operational concern in any growing database. Knowing which tables consume the most space allows administrators to prioritise archiving, partitioning, or compression efforts. It also helps explain sudden disk growth when a particular table has expanded unexpectedly.&lt;/p&gt;</description></item><item><title>How to Monitor PostgreSQL Index Cache for High Speed Queries</title><link>https://www.postgresscripts.com/post/how-to-monitor-postgresql-index-cache-for-high-speed-queries/</link><pubDate>Mon, 18 Mar 2024 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/how-to-monitor-postgresql-index-cache-for-high-speed-queries/</guid><description>
&lt;h2 id="keeping-postgresql-queries-speeding-along-monitoring-index-cache-hit-rates"&gt;Keeping PostgreSQL Queries Speeding Along: Monitoring Index Cache Hit Rates&lt;/h2&gt;
&lt;p&gt;For a smooth-running PostgreSQL database, ensuring efficient access to frequently used data is crucial. Indexes act as shortcuts, speeding up queries. But how well are those indexes utilized? This post explores a SQL query that helps you monitor the PostgreSQL index cache hit rate, offering valuable insights into your database's performance.&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="sample-code"&gt;Sample Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;1&lt;/span&gt;&lt;span class="cl"&gt;SELECT sum(idx_blks_read) as idx_read,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;2&lt;/span&gt;&lt;span class="cl"&gt; sum(idx_blks_hit) as idx_hit,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;3&lt;/span&gt;&lt;span class="cl"&gt; (sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit) as ratio
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;4&lt;/span&gt;&lt;span class="cl"&gt;FROM pg_statio_user_indexes;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Understanding the Code:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Monitor PostgreSQL Index Usage for Speedy Queries</title><link>https://www.postgresscripts.com/post/monitor-postgresql-index-usage-for-speedy-queries/</link><pubDate>Sun, 17 Mar 2024 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/monitor-postgresql-index-usage-for-speedy-queries/</guid><description>
&lt;h2 id="monitoring-postgresql-index-usage-keeping-your-queries-speedy"&gt;Monitoring PostgreSQL Index Usage: Keeping Your Queries Speedy&lt;/h2&gt;
&lt;p&gt;In the fast-paced world of web applications, ensuring efficient database queries is paramount. PostgreSQL's powerful indexing capabilities play a crucial role in achieving optimal performance. This post delves into a SQL query that helps you monitor index usage rates and identify areas for potential optimization.&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;p&gt;The Table Index Usage Rates Should not be less than 0.99&lt;/p&gt;</description></item></channel></rss>