<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>index usage &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/index-usage/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 16 Jan 2018 10:51:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: Script to find Unused Indexes of Database</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-script-to-find-unused-indexes-of-database/</link>
					<comments>https://www.dbrnd.com/2018/01/sql-server-script-to-find-unused-indexes-of-database/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 30 Jan 2018 16:16:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[duplicate index]]></category>
		<category><![CDATA[index fragmentation]]></category>
		<category><![CDATA[Index Performance]]></category>
		<category><![CDATA[index usage]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[missing index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[unused indexes]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4081</guid>

					<description><![CDATA[As I am preparing important scripts for SQL Server DBA, so here I am also sharing one more vital script for finding the unused indexes of SQL Server Database. The management and maintenance of database index is a day to day exercise for a Database Administrator. The wrong or unused index can create performance issues [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-script-to-find-unused-indexes-of-database%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20Unused%20Indexes%20of%20Database" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-script-to-find-unused-indexes-of-database/" data-a2a-title="SQL Server: Script to find Unused Indexes of Database"></a></p><p>As I am preparing important scripts for SQL Server DBA, so here I am also sharing one more vital script for finding the unused indexes of SQL Server Database.</p>
<blockquote><p>The management and maintenance of database index is a day to day exercise for a Database Administrator. The wrong or unused index can create performance issues for a frequently used table.
</p></blockquote>
<blockquote><p>At every insert and update, the data of an index are also changing, and it requires some IO operations. Better to find the unused index and delete it.<br />
I also added &#8220;DropStatement&#8221; column in script for dropping unused Indexes.</p></blockquote>
<pre class="crayon-plain-tag">SELECT 
	OBJECT_NAME(i.OBJECT_ID) AS ObjectName
	,i.name AS UnusedIndexName	
	,8 * SUM(au.used_pages) AS IndexSizeInKB
	,CASE
		WHEN i.type = 0 THEN 'Heap'  
		WHEN i.type= 1 THEN 'Clustered' 
		WHEN i.type=2 THEN 'Non-Clustered'   
		WHEN i.type=3 THEN 'XML'   
		WHEN i.type=4 THEN 'Spatial'  
		WHEN i.type=5 THEN 'Clustered columnstore index'   
		WHEN i.type=6 THEN 'Nonclustered columnstore index'  
		WHEN i.type=7 THEN 'Nonclustered hash index.'
	END index_type
	,'DROP INDEX ' + i.name + ' ON ' + OBJECT_NAME(i.OBJECT_ID) AS DropStatement
FROM sys.indexes AS i 
LEFT JOIN sys.dm_db_index_usage_stats AS dius 
	ON dius.OBJECT_ID = i.OBJECT_ID 
		AND i.index_id = dius.index_id 
		AND dius.database_id = DB_ID() 
INNER JOIN sys.partitions AS p 
	ON p.OBJECT_ID = i.OBJECT_ID 
		AND p.index_id = i.index_id 
INNER JOIN sys.allocation_units AS au 
	ON au.container_id = p.partition_id 
WHERE OBJECTPROPERTY(i.OBJECT_ID, 'IsIndexable') = 1 
	AND OBJECTPROPERTY(i.OBJECT_ID, 'IsIndexed') = 1 
	AND dius.index_id IS NULL
	OR (dius.user_updates &gt; 0 
		AND dius.user_seeks = 0 
		AND dius.user_scans = 0 
		AND dius.user_lookups = 0)
GROUP BY OBJECT_NAME(i.OBJECT_ID), i.name, i.type 
ORDER BY OBJECT_NAME(i.OBJECT_ID)</pre> </p>
<p><strong>Other SQL Server Index related DBA Scripts:</strong></p>
<blockquote class="wp-embedded-content" data-secret="S1i20bnCFt"><p><a href="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/">SQL Server: Script to find Redundant and Duplicate Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/embed/#?secret=S1i20bnCFt" data-secret="S1i20bnCFt" width="600" height="338" title="&#8220;SQL Server: Script to find Redundant and Duplicate Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="ODjqcfmtkP"><p><a href="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/">SQL Server: Script to find Index Average Fragmentation in Percentage</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/embed/#?secret=ODjqcfmtkP" data-secret="ODjqcfmtkP" width="600" height="338" title="&#8220;SQL Server: Script to find Index Average Fragmentation in Percentage&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="9sUF7xBYiV"><p><a href="https://www.dbrnd.com/2015/11/sql-server-script-to-find-missing-indexes/">SQL Server: Script to find Missing Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/sql-server-script-to-find-missing-indexes/embed/#?secret=9sUF7xBYiV" data-secret="9sUF7xBYiV" width="600" height="338" title="&#8220;SQL Server: Script to find Missing Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="LqPIXi45yO"><p><a href="https://www.dbrnd.com/2015/10/sql-server-script-to-find-index-operational-stats/">SQL Server: Script to find Index Operational Stats</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/sql-server-script-to-find-index-operational-stats/embed/#?secret=LqPIXi45yO" data-secret="LqPIXi45yO" width="600" height="338" title="&#8220;SQL Server: Script to find Index Operational Stats&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/01/sql-server-script-to-find-unused-indexes-of-database/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Greenplum: Script to find the size and usage statistics of Indexes</title>
		<link>https://www.dbrnd.com/2017/06/greenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes/</link>
					<comments>https://www.dbrnd.com/2017/06/greenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 08 Jun 2017 16:16:56 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Greenplum DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[index usage]]></category>
		<category><![CDATA[pg_stat_all_indexes]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<category><![CDATA[Statistics]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5373</guid>

					<description><![CDATA[In this post, I am sharing a script to find the size and usage statistics of Greenplum Indexes. Having the complete knowledge of our database indexes is imperative. We should check the size and usage of indexes. Recently, I started my work with Greenplum which based on PostgreSQL 8.2, so I am sharing a script [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fgreenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes%2F&#038;title=Greenplum%3A%20Script%20to%20find%20the%20size%20and%20usage%20statistics%20of%20Indexes" data-a2a-url="https://www.dbrnd.com/2017/06/greenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes/" data-a2a-title="Greenplum: Script to find the size and usage statistics of Indexes"></a></p><p>In this post, I am sharing a script to find the size and usage statistics of Greenplum Indexes. Having the complete knowledge of our database indexes is imperative. We should check the size and usage of indexes.</p>
<p>Recently, I started my work with Greenplum which based on PostgreSQL 8.2, so I am sharing a script to check index usage in Greenplum.</p>
<pre class="crayon-plain-tag">SELECT
    t.schemaname AS schema_name
    ,t.tablename AS table_name
    ,indexname AS index_name
    ,c.reltuples AS num_rows
    ,pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size
    ,pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size
    ,CASE WHEN indisunique THEN 'Y'
       ELSE 'N'
    END AS UNIQUE
    ,idx_scan AS number_of_scans
    ,idx_tup_read AS tuples_read
    ,idx_tup_fetch AS tuples_fetched
FROM pg_tables t
LEFT OUTER JOIN pg_class c ON t.tablename=c.relname
LEFT OUTER JOIN
( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x
   JOIN pg_class c ON c.oid = x.indrelid
   JOIN pg_class ipg ON ipg.oid = x.indexrelid
   JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid )
AS t1
ON t.tablename = t1.ctablename;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/06/greenplum-script-to-find-the-size-and-usage-statistics-of-indexes-pg_stat_all_indexes/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find Index Size and Index Usage Statistics</title>
		<link>https://www.dbrnd.com/2017/01/postgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes/</link>
					<comments>https://www.dbrnd.com/2017/01/postgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 17 Jan 2017 20:39:12 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BRIN Index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index duplicate]]></category>
		<category><![CDATA[Index statestics]]></category>
		<category><![CDATA[index usage]]></category>
		<category><![CDATA[missing index]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3840</guid>

					<description><![CDATA[In this post, I am sharing one script to find Index Usage Statistics of PostgreSQL Database. This is a very useful script for DBA to find out the usage of indexes and size of indexes which help them for performance tuning activity. For DBA, working with Indexes is always important tasks so I have already [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fpostgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20Index%20Size%20and%20Index%20Usage%20Statistics" data-a2a-url="https://www.dbrnd.com/2017/01/postgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes/" data-a2a-title="PostgreSQL: Script to find Index Size and Index Usage Statistics"></a></p><p>In this post, I am sharing one script to find Index Usage Statistics of PostgreSQL Database.<br />
This is a very useful script for DBA to find out the usage of indexes and size of indexes which help them for performance tuning activity.</p>
<p>For DBA, working with Indexes is always important tasks so I have already shared a couple of articles on PostgreSQL Indexes. </p>
<blockquote><p><a href="https://www.dbrnd.com/2015/09/postgresql-script-to-find-the-unused-and-duplicate-index/" target="_blank">Duplicate Indexes:</a><br />
<a href="https://www.dbrnd.com/2015/10/postgresql-script-to-find-a-missing-indexes-of-the-schema/" target="_blank">Missing Indexes:</a><br />
<a href="https://www.dbrnd.com/2016/10/postgresql-how-we-can-create-index-on-expression-brin-btree-partial-index/" target="_blank">Expression Index:</a><br />
<a href="https://www.dbrnd.com/2016/08/postgresql-9-5-introduced-brin-block-range-index-with-detail-performance-test-report-on-6gb-table/" target="_blank">BRIN Index:</a></p></blockquote>
<p>In below script, You can also find occupied size of Indexes, Total tuple read and scan by Indexes. </p>
<pre class="crayon-plain-tag">SELECT
    pt.tablename AS TableName
    ,t.indexname AS IndexName
    ,pc.reltuples AS TotalRows
    ,pg_size_pretty(pg_relation_size(quote_ident(pt.tablename)::text)) AS TableSize
    ,pg_size_pretty(pg_relation_size(quote_ident(t.indexrelname)::text)) AS IndexSize
    ,t.idx_scan AS TotalNumberOfScan
    ,t.idx_tup_read AS TotalTupleRead
    ,t.idx_tup_fetch AS TotalTupleFetched
FROM pg_tables AS pt
LEFT OUTER JOIN pg_class AS pc 
	ON pt.tablename=pc.relname
LEFT OUTER JOIN
( 
	SELECT 
		pc.relname AS TableName
		,pc2.relname AS IndexName
		,psai.idx_scan
		,psai.idx_tup_read
		,psai.idx_tup_fetch
		,psai.indexrelname 
	FROM pg_index AS pi
	JOIN pg_class AS pc 
		ON pc.oid = pi.indrelid
	JOIN pg_class AS pc2 
		ON pc2.oid = pi.indexrelid
	JOIN pg_stat_all_indexes AS psai 
		ON pi.indexrelid = psai.indexrelid 
)AS T
    ON pt.tablename = T.TableName
WHERE pt.schemaname='public'
ORDER BY 1;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/01/postgresql-script-to-find-index-size-index-usage-statistics-of-a-database-pg_stat_all_indexes/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: SELECT with Index Hint option to Optimize the Query</title>
		<link>https://www.dbrnd.com/2016/10/mysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 19 Oct 2016 16:16:06 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[FORCE INDEX]]></category>
		<category><![CDATA[IGNORE INDEX]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Index Hint]]></category>
		<category><![CDATA[index usage]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[Query Optimizer]]></category>
		<category><![CDATA[USE INDEX]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3795</guid>

					<description><![CDATA[The Table Indexes are always the main focus to improve the performance of any SQL Query. In MySQL, We can provide INDEX Hint to Query Optimizer for choosing our analyzed Index. In most of the cases, Query Planner and Query Optimizer are accurate to choose perfect Index. But sometimes, still It is required to give [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&amp;linkname=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index%2F&#038;title=MySQL%3A%20SELECT%20with%20Index%20Hint%20option%20to%20Optimize%20the%20Query" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-select-with-index-hint-option-to-optimize-the-query-use-index-force-index-ignore-index/" data-a2a-title="MySQL: SELECT with Index Hint option to Optimize the Query"></a></p><p>The Table Indexes are always the main focus to improve the performance of any SQL Query.<br />
In MySQL, We can provide INDEX Hint to Query Optimizer for choosing our analyzed Index.</p>
<blockquote><p>In most of the cases, Query Planner and Query Optimizer are accurate to choose perfect Index.<br />
But sometimes, still It is required to give Index Hint for reducing the overall Query Planning Time.</p></blockquote>
<p>If we know that this Index is good for this query, we should Provide the Hint to Query Optimizer. </p>
<p>Here, You can also access one related article.</p>
<blockquote class="wp-embedded-content" data-secret="5V4cj4uvhh"><p><a href="https://www.dbrnd.com/2015/10/mysql-script-to-find-index-usage-statistics-of-a-database/">MySQL: Script to find Index Usage Statistics of a Database</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/mysql-script-to-find-index-usage-statistics-of-a-database/embed/#?secret=5V4cj4uvhh" data-secret="5V4cj4uvhh" width="600" height="338" title="&#8220;MySQL: Script to find Index Usage Statistics of a Database&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>MySQL supports command like USE INDEX, IGNORE INDEX, FORCE INDEX, which we can use for Index Hint.</strong> </p>
<blockquote><p>The USE INDEX hint tells MySQL to use only one of the named indexes to find rows in the table.<br />
The IGNORE INDEX tells MySQL to not use some particular index or indexes.<br />
The FORCE INDEX hint acts like USE INDEX , with the addition that a table scan is assumed to be very expensive.
</p></blockquote>
<p>Prepared small demonstration on this.</p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_EmployeeDetails
(
    EmpID INTEGER PRIMARY KEY 
    ,EmpName VARCHAR(50)
    ,EmpSalary BIGINT
    ,DepartmentName VARCHAR(50)
);</pre> </p>
<p><strong>Insert few sample Records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_EmployeeDetails
VALUES 
(1,'Anvesh',80000,'Sales')
,(2,'Neevan',90000,'Sales')
,(3,'Jenny',50000,'Production')
,(4,'Roy',60000,'Production')
,(5,'Martin',30000,'Research')
,(6,'Mahi',85000,'Research')
,(7,'Kruti',45000,'Research')
,(8,'Manish',75000,'Research');</pre> </p>
<p><strong>Create few sample Indexes:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_EmployeeDetails_EmpName ON tbl_EmployeeDetails (EmpName);
CREATE INDEX idx_tbl_EmployeeDetails_DepartmentName ON tbl_EmployeeDetails (DepartmentName);
CREATE INDEX idx_tbl_EmployeeDetails_EmpName_EmpSalary ON tbl_EmployeeDetails (EmpName,EmpSalary);</pre> </p>
<p><strong>Using USE INDEX:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_EmployeeDetails
USE INDEX (idx_tbl_EmployeeDetails_EmpName)
WHERE EmpName = 'Roy';

SELECT *FROM tbl_EmployeeDetails
USE INDEX (idx_tbl_EmployeeDetails_EmpName_EmpSalary)
WHERE EmpName = 'Roy' AND EmpSalary &gt; 50000;</pre> </p>
<p><strong>Using IGNORE INDEX:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_EmployeeDetails
IGNORE INDEX (idx_tbl_EmployeeDetails_EmpName)
WHERE EmpName = 'Roy' AND EmpSalary &gt; 50000;</pre> </p>
<p><strong>Using FORCE INDEX:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_EmployeeDetails
FORCE INDEX (idx_tbl_EmployeeDetails_EmpName)
WHERE EmpName = 'Roy' AND EmpSalary &gt; 50000;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL: Script to find Index Usage Statistics of a Database</title>
		<link>https://www.dbrnd.com/2015/10/mysql-script-to-find-index-usage-statistics-of-a-database/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 27 Oct 2015 18:50:55 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index usage]]></category>
		<category><![CDATA[INFORMATION_SCHEMA.STATISTICS]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=979</guid>

					<description><![CDATA[In this post, I am sharing a script to find the Index Usage Statistics of MySQL. This is a handy script for DBAs for finding the usage of indexes, and they can also take a decision to remove the unused indexes from the database server. Below are two different scripts: First, using SHOW INDEX: [crayon-6aab4a4dec48c738298811/] [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F10%2Fmysql-script-to-find-index-usage-statistics-of-a-database%2F&#038;title=MySQL%3A%20Script%20to%20find%20Index%20Usage%20Statistics%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2015/10/mysql-script-to-find-index-usage-statistics-of-a-database/" data-a2a-title="MySQL: Script to find Index Usage Statistics of a Database"></a></p><p>In this post, I am sharing a script to find the Index Usage Statistics of MySQL.<br />
This is a handy script for DBAs for finding the usage of indexes, and they can also take a decision to remove the unused indexes from the database server.</p>
<p>Below are two different scripts:</p>
<p><strong>First, using SHOW INDEX:</strong></p>
<pre class="crayon-plain-tag">SHOW INDEX FROM TableName FROM DatabaseName</pre> </p>
<p><strong>Second, using INFORMATION_SCHEMA.STATISTICS table:</strong></p>
<pre class="crayon-plain-tag">SELECT 
    TABLE_NAME
    ,INDEX_NAME
    ,SEQ_IN_INDEX
    ,COLUMN_NAME
    ,CARDINALITY
    ,INDEX_TYPE    
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE table_schema = 'DatabaseName'</pre> </p>
<p>You can take a decision basis on the SEQ_IN_INDEX column data. </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
