<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pg_sequence on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/pg_sequence/</link><description>Recent content in Pg_sequence on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Sun, 17 Mar 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/pg_sequence/index.xml" rel="self" type="application/rss+xml"/><item><title>Identify Large PostgreSQL Indexes for Optimization</title><link>https://www.postgresscripts.com/post/identify-large-indexes-for-postgresql-database-optimization-with-sql/</link><pubDate>Sun, 17 Mar 2024 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/identify-large-indexes-for-postgresql-database-optimization-with-sql/</guid><description>
&lt;h2 id="unveiling-your-postgresql-indexes-a-deep-dive-with-code"&gt;Unveiling Your PostgreSQL Indexes: A Deep Dive with Code&lt;/h2&gt;
&lt;p&gt;In the realm of relational databases, efficient data retrieval is paramount. PostgreSQL achieves this partly through the magic of indexes. But have you ever wondered what lurks beneath the surface of these indexes? This post delves into a powerful Postgres Database code snippet that empowers you to unlock the secrets hidden within your indexes.&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 n.nspname AS schemaname,
&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; c.relname AS tablename,
&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; i.relname AS indexname,
&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; t.spcname AS tablespace,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 5&lt;/span&gt;&lt;span class="cl"&gt; pg_get_indexdef(i.oid) AS indexdef,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 6&lt;/span&gt;&lt;span class="cl"&gt; pg_size_pretty(pg_total_relation_size(i.oid)) AS index_size
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 7&lt;/span&gt;&lt;span class="cl"&gt;FROM pg_index x
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 8&lt;/span&gt;&lt;span class="cl"&gt; JOIN pg_class c ON c.oid = x.indrelid
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 9&lt;/span&gt;&lt;span class="cl"&gt; JOIN pg_class i ON i.oid = x.indexrelid
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;10&lt;/span&gt;&lt;span class="cl"&gt; LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;11&lt;/span&gt;&lt;span class="cl"&gt; LEFT JOIN pg_tablespace t ON t.oid = i.reltablespace
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;12&lt;/span&gt;&lt;span class="cl"&gt;WHERE (c.relkind = ANY (ARRAY[&amp;#39;r&amp;#39;::&amp;#34;char&amp;#34;, &amp;#39;m&amp;#39;::&amp;#34;char&amp;#34;, &amp;#39;p&amp;#39;::&amp;#34;char&amp;#34;]))
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;13&lt;/span&gt;&lt;span class="cl"&gt; AND (i.relkind = ANY (ARRAY[&amp;#39;i&amp;#39;::&amp;#34;char&amp;#34;, &amp;#39;I&amp;#39;::&amp;#34;char&amp;#34;]))
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;14&lt;/span&gt;&lt;span class="cl"&gt; order by index_size asc;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="unveiling-your-postgresql-indexes-a-deep-dive-with-code-1"&gt;Unveiling Your PostgreSQL Indexes: A Deep Dive with Code&lt;/h2&gt;
&lt;p&gt;In the realm of relational databases, efficient data retrieval is paramount. PostgreSQL achieves this partly through the magic of indexes. But have you ever wondered what lurks beneath the surface of these indexes? This post delves into a powerful Postgres Database code snippet that empowers you to unlock the secrets hidden within your indexes.&lt;/p&gt;</description></item></channel></rss>