<?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>fragmentation &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/fragmentation/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>Mon, 24 Jun 2019 19:36:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Script to find the total size of the Indexes</title>
		<link>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/</link>
					<comments>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 27 May 2019 16:16:18 +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[fragmentation]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[redundant 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>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4191</guid>

					<description><![CDATA[In this post, I am sharing one script to find the size of Indexes in SQL Server. The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation. I have already shared a couple of articles on SQL Server Indexes like: find [&#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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" data-a2a-url="https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/" data-a2a-title="SQL Server: Script to find the total size of the Indexes"></a></p><p>In this post, I am sharing one script to find the size of Indexes in SQL Server.</p>
<blockquote><p>The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation.</p></blockquote>
<p>I have already shared a couple of articles on SQL Server Indexes like: find duplicate indexes, unused indexes and fragmentation of indexes. </p>
<p>You can also access these articles after below T-SQL. </p>
<pre class="crayon-plain-tag">SELECT
	OBJECT_SCHEMA_NAME(i.OBJECT_ID) AS SchemaName
	,OBJECT_NAME(i.OBJECT_ID) AS TableName
	,i.name AS IndexName
	,8 * SUM(au.used_pages) AS IndexSizeInKB
FROM sys.indexes AS i
JOIN sys.partitions AS p 
	ON p.OBJECT_ID = i.OBJECT_ID 
		AND p.index_id = i.index_id
JOIN sys.allocation_units AS au 
	ON au.container_id = p.partition_id
GROUP BY 
	i.OBJECT_ID
	,i.index_id
	,i.name
ORDER BY OBJECT_NAME(i.OBJECT_ID),i.index_id</pre> </p>
<p><strong>Other related articles:</strong></p>
<blockquote class="wp-embedded-content" data-secret="iWrp53ltXi"><p><a href="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/">SQL Server: Find the total row count and size of the Tables</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/embed/#?secret=iWrp53ltXi" data-secret="iWrp53ltXi" width="600" height="338" title="&#8220;SQL Server: Find the total row count and size of the Tables&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="kFuNrnjgJI"><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=kFuNrnjgJI" data-secret="kFuNrnjgJI" 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="CLStlFpaQE"><p><a href="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/">SQL Server: Script to find usage of Database Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/embed/#?secret=CLStlFpaQE" data-secret="CLStlFpaQE" width="600" height="338" title="&#8220;SQL Server: Script to find usage of Database Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="CuRotuXr6g"><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 loading="lazy" 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=CuRotuXr6g" data-secret="CuRotuXr6g" 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>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server 2014: sys.column_store_row_groups to find information on Columnstore row groups</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 10 Jan 2018 16:16:25 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Columnstore Index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2014]]></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[sys.column_store_row_groups]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4216</guid>

					<description><![CDATA[SQL Server 2014 introduced sys.column_store_row_groups system view for finding the information on the Columnstore row groups. Using this system view, you can find information like total number of rows physically stored, and a column for the number of rows marked as deleted. If you find a high volume of deleted rows, you should decide to [&#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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&amp;linkname=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" 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-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation%2F&#038;title=SQL%20Server%202014%3A%20sys.column_store_row_groups%20to%20find%20information%20on%20Columnstore%20row%20groups" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-2014-sys-column_store_row_groups-to-find-information-on-columnstore-row-groups-fragmentation/" data-a2a-title="SQL Server 2014: sys.column_store_row_groups to find information on Columnstore row groups"></a></p><p>SQL Server 2014 introduced sys.column_store_row_groups system view for finding the information on the Columnstore row groups.</p>
<blockquote><p>Using this system view, you can find information like total number of rows physically stored, and a column for the number of rows marked as deleted.</p></blockquote>
<blockquote><p>If you find a high volume of deleted rows, you should decide to rebuild it. </p></blockquote>
<p><strong>T-SQL Script:</strong></p>
<pre class="crayon-plain-tag">SELECT
	OBJECT_NAME([csrg].[object_id]) AS TableName
	,[i].[name] AS IndexName
	,[csrg].[row_group_id]
	,[csrg].[delta_store_hobt_id]
	,[csrg].[state_description]
	,[csrg].[total_rows]
	,[csrg].[deleted_rows]
	,[csrg].[size_in_bytes]
FROM sys.column_store_row_groups AS csrg
LEFT OUTER JOIN sys.indexes AS i
	ON [csrg].[object_id] = [i].[object_id]
		AND [csrg].[index_id] = [i].[index_id]
ORDER BY [TableName],[IndexName]
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: How to Remove Forwarded Records of a Heap Table?</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-how-to-remove-forwarded-records-of-a-heap-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 04 Nov 2017 16:16:13 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Forwarded Record]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[heap table]]></category>
		<category><![CDATA[REBUILD]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6304</guid>

					<description><![CDATA[In the previous two posts, I shared basic about Forwarding Records of Heap Table and shared a script to find the count of Forwarded Records in SQL Server. In this post, I am sharing a practical demonstration on Forwarding Records like generate Forwarding Records and then Remove those Forwarding Records. Please check the below full [&#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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" 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%2F11%2Fsql-server-how-to-remove-forwarded-records-of-a-heap-table%2F&#038;title=SQL%20Server%3A%20How%20to%20Remove%20Forwarded%20Records%20of%20a%20Heap%20Table%3F" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-how-to-remove-forwarded-records-of-a-heap-table/" data-a2a-title="SQL Server: How to Remove Forwarded Records of a Heap Table?"></a></p><p>In the previous two posts, I shared basic about Forwarding Records of Heap Table and shared a script to find the count of Forwarded Records in SQL Server.</p>
<p>In this post, I am sharing a practical demonstration on Forwarding Records like generate Forwarding Records and then Remove those Forwarding Records.</p>
<p><strong>Please check the below full demonstration:</strong></p>
<p><strong>Create a sample HEAP table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_Heap
(
	Col1 INT IDENTITY(1,1)
	,Col2 VARCHAR(1000)	
)
GO</pre><p>
<strong>Insert sample records with VARCHAR(5) size:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_Heap (Col2) VALUES
('dbrnd')
GO 1000</pre><p>
<strong>Now, Update the data from VARCHAR(5) to VARCHAR(31):</strong></p><pre class="crayon-plain-tag">UPDATE tbl_Heap
SET Col2 = 'Database Research &amp; Development'
GO</pre><p>
<strong>Check the count of Forwarding Records:</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-6307" src="https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records.png" alt="" width="718" height="43" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records.png 718w, https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records-679x41.png 679w" sizes="auto, (max-width: 718px) 100vw, 718px" /></p>
<p><strong>For removing Forwarding Records, we should REBUILD the table:</strong></p><pre class="crayon-plain-tag">ALTER TABLE tbl_Heap REBUILD
GO</pre><p>
<strong>Now, Check the new count of Forwarding Records:</strong><br />
The count is 0 now.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-6308" src="https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records-Count.png" alt="" width="753" height="45" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records-Count.png 753w, https://www.dbrnd.com/wp-content/uploads/2017/09/SQL-Server-Forwarded-Records-Count-679x41.png 679w" sizes="auto, (max-width: 753px) 100vw, 753px" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the Forwarded Records count of a Table</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-script-to-find-the-forwarded-records-count-of-a-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 03 Nov 2017 16:16:00 +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[Forwarded Record]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[heap table]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6300</guid>

					<description><![CDATA[In the previous post, I shared basic about Forwarded Records in Heap table of SQL Server. In this post, I am sharing a script to check the count of Forwarded Records of a Table. In the below script, you can add a filter of your database and table for getting the number of Forwarding Records. [&#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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" 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%2F11%2Fsql-server-script-to-find-the-forwarded-records-count-of-a-table%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20Forwarded%20Records%20count%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-script-to-find-the-forwarded-records-count-of-a-table/" data-a2a-title="SQL Server: Script to find the Forwarded Records count of a Table"></a></p><p>In the previous post, I shared basic about Forwarded Records in Heap table of SQL Server.<br />
In this post, I am sharing a script to check the count of Forwarded Records of a Table. </p>
<p>In the below script, you can add a filter of your database and table for getting the number of Forwarding Records.</p>
<pre class="crayon-plain-tag">SELECT
	OBJECT_NAME(object_id) as TableName
	,index_type_desc
	,page_count
	,avg_page_space_used_in_percent
	,avg_record_size_in_bytes
	,forwarded_record_count
FROM sys.dm_db_index_physical_stats
(
	DB_ID('database_name')
	,OBJECT_ID('table_name')
	,NULL
	,NULL
	,'DETAILED'
)
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Must know &#8211; the Forwarded Records in HEAP Table</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-must-know-the-forwarded-records-in-heap-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 02 Nov 2017 16:16:31 +0000</pubDate>
				<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Forwarded Records]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[heap table]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6296</guid>

					<description><![CDATA[<div><img width="600" height="400" src="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation.jpg" class="attachment-post-image size-post-image wp-post-image" alt="postgresql fragmentation" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation.jpg 600w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-300x200.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-150x100.jpg 150w" sizes="auto, (max-width: 600px) 100vw, 600px" /></div>In this post, I am sharing an important note on Forwarded Records in the Heap table of SQL Server. Whenever DBA or Developer is facing performance issue, they are always talking about the table or index fragmentation, but no-one is discussing the Forwarded Records. What is heap Table Simple Example to understand Forwarded Records: You [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="600" height="400" src="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation.jpg" class="attachment-post-image size-post-image wp-post-image" alt="postgresql fragmentation" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation.jpg 600w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-300x200.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-150x100.jpg 150w" sizes="auto, (max-width: 600px) 100vw, 600px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&amp;linkname=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" 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%2F11%2Fsql-server-must-know-the-forwarded-records-in-heap-table%2F&#038;title=SQL%20Server%3A%20Must%20know%20%E2%80%93%20the%20Forwarded%20Records%20in%20HEAP%20Table" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-must-know-the-forwarded-records-in-heap-table/" data-a2a-title="SQL Server: Must know – the Forwarded Records in HEAP Table"></a></p><p>In this post, I am sharing an important note on Forwarded Records in the Heap table of SQL Server. Whenever DBA or Developer is facing performance issue, they are always talking about the table or index fragmentation, but no-one is discussing the Forwarded Records. </p>
<blockquote class="wp-embedded-content" data-secret="zyVYXmfaV7"><p><a href="https://www.dbrnd.com/2015/08/what-is-heap-table/">What is heap Table</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/08/what-is-heap-table/embed/#?secret=zyVYXmfaV7" data-secret="zyVYXmfaV7" width="600" height="338" title="&#8220;What is heap Table&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Simple Example to understand Forwarded Records:</strong></p>
<blockquote><p>You create a heap table, and one of the column types is VARCHAR(200).<br />
You inserted 100000 records and added a small size of the string in VARCHAR(200) like &#8220;dbrnd&#8221; value which is only VARCHAR(5).</p>
<p>Now next, you require updating the value from &#8220;dbrnd&#8221; to &#8220;Database Research &#038; Development&#8221; which is now VARCHAR(31).<br />
Previously, we stored our data based on VARCHAR(5), but while updating we need VARCHAR(31).</p>
<p>Before the update, all data correctly save in data page and for new update no more free space available on the data page. So SQL Server internally moves new data into the new page and assigned a new Relative Identifier (RID).</p>
<p>Now old page contains forwarding pointer to new RID and new records also back pointer to old records. </p></blockquote>
<p><em>&#8211; Called as Forwarded Records and which is also one type of internal fragmentation. </em></p>
<p><em>The biggest drawback of Forwarded Record is, it requires high I/O because SQL Server has to jump between the old data page and new data page for getting data. </em></p>
<p><strong>Few more following topics, which I will publish from tomorrow:</strong><br />
How to find the Forwarded Records?<br />
How to remove Forwarded Records?</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Why Shrink Database is bad, Check the practical demonstration</title>
		<link>https://www.dbrnd.com/2017/05/sql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 25 May 2017 16:16:03 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[Shrink Database]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5329</guid>

					<description><![CDATA[Few of SQL Server DBAs are frequently executing Shrink on database or data files. Why? because they are gaining more free space after shrink. You can find N number of theory on, why you should not shrink your database or data file in SQL Server? Instead of big theory, I am sharing full practical demonstration [&#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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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%2F05%2Fsql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&#038;title=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" data-a2a-url="https://www.dbrnd.com/2017/05/sql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation/" data-a2a-title="SQL Server: Why Shrink Database is bad, Check the practical demonstration"></a></p><p>Few of SQL Server DBAs are frequently executing Shrink on database or data files. Why? because they are gaining more free space after shrink. </p>
<p>You can find N number of theory on, why you should not shrink your database or data file in SQL Server?</p>
<blockquote><p>Instead of big theory, I am sharing full practical demonstration on this. You should not shrink your database or data files otherwise it generates massive fragmentation for your tables and indexes. Still, you can shrink your log file, but after full backup only. </p></blockquote>
<p><strong>Create a test database and use it:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE Test_Shrink
GO

Use Test_Shrink
GO</pre> </p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE Test_Shrink
GO

Use Test_Shrink
GO</pre> </p>
<p><strong>Create second sample table with clustered index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_test2
(
    id INT IDENTITY(1,1)
    ,tag CHAR (7000) DEFAULT 'dbrnd'
)
GO
CREATE CLUSTERED INDEX pk_test2 ON tbl_test2 (id);
GO</pre> </p>
<p><strong>Insert few sample records in both the tables:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_test1 DEFAULT VALUES;
GO 1500
 
INSERT INTO tbl_test2 DEFAULT VALUES;
GO 1500</pre> </p>
<p><strong>Check the average fragmentation of Index:</strong></p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
--0.33%</pre> </p>
<p><strong>Drop one sample table to test Shrink:</strong></p>
<pre class="crayon-plain-tag">DROP TABLE tbl_test1;
GO</pre> </p>
<p><strong>Shrink your database:</strong></p>
<pre class="crayon-plain-tag">DBCC SHRINKDATABASE (Test_Shrink);
GO</pre> </p>
<p><strong>Check the fragmentation of index:</strong><br />
You can find below result like 99.6% fragmentation for Index. Before shrink database, it was just 0.33%.</p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
--99.6%</pre> </p>
<p><strong>Now, REBUILD your index to remove the fragmentation:</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX pk_test2 ON tbl_test2 REBUILD
GO</pre> </p>
<p><strong>Check the fragmentation of index:</strong></p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
-- 0%</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Increase the speed of UPDATE query using HOT UPDATE (Heap only tuple)</title>
		<link>https://www.dbrnd.com/2016/12/postgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation/</link>
					<comments>https://www.dbrnd.com/2016/12/postgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 25 Dec 2016 13:28:47 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Fill Factor]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[HOT]]></category>
		<category><![CDATA[Hot only tuple]]></category>
		<category><![CDATA[MVCC]]></category>
		<category><![CDATA[performance]]></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>
		<category><![CDATA[UPDATE]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3708</guid>

					<description><![CDATA[What is HOT UPDATE (Heap Only Tuple) and How It helps to increase the performance of UPDATE Query? In this post, I am going to explain the answer of this question. This is one of the internal of PostgreSQL, but I am sure that most of you guys don&#8217;t know about PostgreSQL HOT. PostgreSQL requires [&#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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&amp;linkname=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" 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%2F12%2Fpostgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation%2F&#038;title=PostgreSQL%3A%20Increase%20the%20speed%20of%20UPDATE%20query%20using%20HOT%20UPDATE%20%28Heap%20only%20tuple%29" data-a2a-url="https://www.dbrnd.com/2016/12/postgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation/" data-a2a-title="PostgreSQL: Increase the speed of UPDATE query using HOT UPDATE (Heap only tuple)"></a></p><p><strong>What is HOT UPDATE (Heap Only Tuple) and How It helps to increase the performance of UPDATE Query?</strong><br />
In this post, I am going to explain the answer of this question. </p>
<blockquote><p>This is one of the internal of PostgreSQL, but I am sure that most of you guys don&#8217;t know about PostgreSQL HOT. </p></blockquote>
<p><strong>PostgreSQL requires HOT because of MVCC architecture.</strong><br />
Please read below articles, before start to knowing about the HOT. </p>
<blockquote><p><a href="https://www.dbrnd.com/2015/05/what-is-mvcc-multi-version-concurrency-control/" target="_blank"><strong>What is MVCC?</strong></a></p>
<p><a href="https://www.dbrnd.com/2016/03/postgresql-the-awesome-table-fillfactor-to-speedup-update-and-select-statement/" target="_blank"><strong>What is Fillfactor in PostgreSQL?</strong></a></p>
<p><a href="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/" target="_blank"><strong>What is Vacuum in PostgreSQL?</strong></a>
</p></blockquote>
<blockquote><p>In the MVCC architecture, When we update any record, internally MVCC architecture inserts a new record with new values and marks old record as deleted or discarded.<br />
When we vacuum, we can clean that deleted records and utilize that space.
</p></blockquote>
<p><strong>What is HOT (Hot Only Tuple)?</strong></p>
<blockquote><p>Now imagine that, we have total 500 data pages and we are updating record of page number 3, but unfortunately new record insert in page number 500. </p></blockquote>
<blockquote><p>It looks like very big internal fragmentation because of MVCC architecture.<br />
But actually this is not happening.</p></blockquote>
<blockquote><p>PostgreSQL has a concept of HOT, With a HOT dead tuple space can be automatically reclaimed at the time of INSERT or UPDATE if no changes are made to indexed columns. This allows for more consistent performance.</p></blockquote>
<blockquote><p>HOT means, creating a new update tuple if possible on the same page as the old tuple, and maintaining a chain of updated tuples linking a new version to the old tuple.</p></blockquote>
<blockquote><p>HOT updates can only reuse dead tuples from previous transactions directly, not from the same or concurrent ones.<br />
If you have big updates, changing large portions of the table at once, you might want to split them up in a couple of chunks.</p></blockquote>
<blockquote><p>HOT updates only work when the changed columns are not involved in indexes in any way because the indexes pointing the the old tuples need to point to the new version of it as of transaction id. </p></blockquote>
<blockquote><p>You might be blocking HOT updates with indexes on updated columns. If those are expendable, you might get better overall performance without them.</p></blockquote>
<p><strong>Let&#8217;s understand PostgreSQL HOT practically.</strong></p>
<p><strong>Create a table with Sample data: </strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Employees
(
	EmpID INT
	,EmpName CHARACTER VARYING 	
	,EmpDepartment CHARACTER VARYING
	,EmpSalary INT
);
 
INSERT INTO tbl_Employees
VALUES 
(1,'Anvesh','Database',90000)
,(2,'Jenny','JAVA',65000)
,(3,'Martin','PHP',85000)
,(4,'Roy','PHP',94000)
,(5,'Eric','PHP',70000)
,(6,'Rajesh','Animation',50000)
,(7,'Mahi','Database',40000)
,(8,'Sofia','JAVA',60000);</pre> </p>
<p><strong>Delete one record:</strong></p>
<pre class="crayon-plain-tag">DELETE FROM tbl_Employees WHERE EmpID = 7;</pre> </p>
<p><strong>Insert one New Record:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Employees
VALUES 
(7,'Junik','Database',10000);</pre> </p>
<p><strong>Please check If any HOT Update or not on table:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_stat_get_tuples_hot_updated('tbl_employees'::regclass::oid);
/*
Result:
pg_stat_get_tuples_hot_updated
------------------------------
0
*/</pre> </p>
<p><strong>Please update the statestic of that table:</strong></p>
<pre class="crayon-plain-tag">ANALYZE tbl_Employees;</pre> </p>
<p><strong>Now execute one more update command:</strong></p>
<pre class="crayon-plain-tag">UPDATE tbl_Employees SET EmpName = 'Robort' WHERE EmpID=7;</pre> </p>
<p><strong>Please check If any HOT Update or not on table:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_stat_get_tuples_hot_updated('tbl_employees'::regclass::oid);
/*
Result:
pg_stat_get_tuples_hot_updated
------------------------------
1
*/</pre> </p>
<p><strong>Again, do more update:</strong></p>
<pre class="crayon-plain-tag">UPDATE tbl_Employees SET EmpName = 'Manish' WHERE EmpID=8;
UPDATE tbl_Employees SET EmpName = 'Cerlin' WHERE EmpID=4;</pre> </p>
<p><strong>Please check If any change in number of HOT Update of a table:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_stat_get_tuples_hot_updated('tbl_employees'::regclass::oid);
/*
Result:
pg_stat_get_tuples_hot_updated
------------------------------
3
*/</pre> </p>
<p><strong>Now Apply, Index on EmpName Column:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_employees_empname 
ON tbl_employees USING BTREE (EmpName);</pre> </p>
<p><strong>After Index, execute few more update:</strong></p>
<pre class="crayon-plain-tag">UPDATE tbl_Employees SET EmpName = 'Kulin' WHERE EmpID=3;
UPDATE tbl_Employees SET EmpName = 'Priya' WHERE EmpID=5;</pre> </p>
<p><strong>After Index, Please check If any change in number of HOT Update of a table:</strong><br />
The result is same because If column has an Index, HOT Update does not work.</p>
<pre class="crayon-plain-tag">SELECT pg_stat_get_tuples_hot_updated('tbl_employees'::regclass::oid);
/*
Result:
pg_stat_get_tuples_hot_updated
------------------------------
3
*/</pre> </p>
<p><strong>You can also check number of HOT update of current transaction:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_stat_get_xact_tuples_hot_updated('tbl_employees'::regclass::oid);</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/12/postgresql-increase-the-speed-of-update-query-using-hot-update-heap-only-tuple-mvcc-fill-factor-vacuum-fragmentation/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to check Table Fragmentation using pgstattuple module</title>
		<link>https://www.dbrnd.com/2016/12/postgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze/</link>
					<comments>https://www.dbrnd.com/2016/12/postgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 22 Dec 2016 19:23:09 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL 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[dead tuple]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[free space]]></category>
		<category><![CDATA[live tuple]]></category>
		<category><![CDATA[pgstattuple]]></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=4158</guid>

					<description><![CDATA[This is very important task for PostgreSQL DBA to check the fragmentation level of Table. Please do not forget about that the PostgreSQL is based on MVCC architecture. Which is good in one way, but bad in another way. Using below article, You must read about MVCC and also access other related articles. What is [&#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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" 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%2F12%2Fpostgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze%2F&#038;title=PostgreSQL%3A%20How%20to%20check%20Table%20Fragmentation%20using%20pgstattuple%20module" data-a2a-url="https://www.dbrnd.com/2016/12/postgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze/" data-a2a-title="PostgreSQL: How to check Table Fragmentation using pgstattuple module"></a></p><p>This is very important task for PostgreSQL DBA to check the fragmentation level of Table.<img loading="lazy" decoding="async" class="alignright wp-image-4163 size-medium" title="postgresql fragmentation" src="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-300x200.jpg" alt="postgresql fragmentation" width="300" height="200" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-300x200.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation-150x100.jpg 150w, https://www.dbrnd.com/wp-content/uploads/2016/12/PostgreSQLFragmentation.jpg 600w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<blockquote><p>Please do not forget about that the PostgreSQL is based on MVCC architecture. Which is good in one way, but bad in another way.</p>
<p>Using below article, You must read about MVCC and also access other related articles.</p></blockquote>
<blockquote data-secret="rBWgG1BnSb" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/05/what-is-mvcc-multi-version-concurrency-control/">What is Multi Version Concurrency Control (MVCC)</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/05/what-is-mvcc-multi-version-concurrency-control/embed/#?secret=rBWgG1BnSb" data-secret="rBWgG1BnSb" width="600" height="338" title="&#8220;What is Multi Version Concurrency Control (MVCC)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote data-secret="C0qTcsvCip" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/">PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/embed/#?secret=C0qTcsvCip" data-secret="C0qTcsvCip" width="600" height="338" title="&#8220;PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote data-secret="52Q5WkuxDw" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/">PostgreSQL: Script to find total Live Tuples and Dead Tuples (Row) of a Table</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/embed/#?secret=52Q5WkuxDw" data-secret="52Q5WkuxDw" width="600" height="338" title="&#8220;PostgreSQL: Script to find total Live Tuples and Dead Tuples (Row) of a Table&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>PostgreSQL provides pgstattuple module to get all tuples information of a Table. You can find information like live_tuple, dead_tuple, free_space and other.</p></blockquote>
<blockquote><p>Using this information you can find fragmentation of table which you can remove using VACUUM / VACUUM FULL command.</p></blockquote>
<p>You must install the pgstattuple to find tuples related information. You can also use pgstatindex() to find information related to indexes.</p>
<p><strong>Load pgstattuple module:</strong><br />
<pre class="crayon-plain-tag">CREATE EXTENSION pgstattuple;</pre>
<strong>Create one sample table:</strong><br />
CREATE TABLE tbl_ItemTransactions<br />
<pre class="crayon-plain-tag">(
     TranID SERIAL
     ,TransactionDate TIMESTAMPTZ
     ,TransactionName TEXT
 );</pre>
<strong>Insert few millions of data:</strong><br />
<pre class="crayon-plain-tag">INSERT INTO tbl_ItemTransactions 
(TransactionDate, TransactionName)
SELECT x, 'dbrnd' 
FROM generate_series('2014-01-01 00:00:00'::timestamptz, '2016-08-01 00:00:00'::timestamptz,'2 seconds'::interval) a(x);</pre>
<strong>Check the tuple information using pgstattuple:</strong><br />
<pre class="crayon-plain-tag">SELECT *FROM pgstattuple('public.tbl_itemtransactions');</pre>
<strong>The Result:</strong><br />
<pre class="crayon-plain-tag">table_len          | 2125627392
tuple_count        | 40737601
tuple_len          | 1873929646
tuple_percent      | 88.16
dead_tuple_count   | 45
dead_tuple_len     | 7787
dead_tuple_percent | 0.88
free_space         | 9923
free_percent       | 1.96</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/12/postgresql-how-to-check-table-fragmentation-using-pgstattuple-module-remove-dead-tuple-vacuum-analyze/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: CLUSTER &#8211; Improve Index Performance (No default cluster index)</title>
		<link>https://www.dbrnd.com/2016/12/postgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 02 Dec 2016 04:22:42 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[CLUSTER]]></category>
		<category><![CDATA[Cluster Index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[explicit lock]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[Index Performance]]></category>
		<category><![CDATA[Order of data]]></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>
		<category><![CDATA[Primary key]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3964</guid>

					<description><![CDATA[I have received a few emails related to PostgreSQL default cluster index and I have received from the developers of Microsoft SQL Server. If you are Microsoft SQL Server developer, you know that Primary key of the Table is working as Cluster Index and resides in the same data page where data actually stored. In [&#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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&amp;linkname=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" 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%2F12%2Fpostgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data%2F&#038;title=PostgreSQL%3A%20CLUSTER%20%E2%80%93%20Improve%20Index%20Performance%20%28No%20default%20cluster%20index%29" data-a2a-url="https://www.dbrnd.com/2016/12/postgresql-cluster-improve-index-performance-no-default-cluster-index-explicit-lock-physical-order-data/" data-a2a-title="PostgreSQL: CLUSTER – Improve Index Performance (No default cluster index)"></a></p><p><em>I have received a few emails related to PostgreSQL default cluster index and I have received from the developers of Microsoft SQL Server.<br />
If you are Microsoft SQL Server developer, you know that Primary key of the Table is working as Cluster Index and resides in the same data page where data actually stored. </em></p>
<p><strong>In PostgreSQL, There is no concept like: Table Primary Key means default Cluster Index of that table. </strong><br />
<strong>In PostgreSQL, we have one CLUSTER command which is similar to Cluster Index.</strong> </p>
<blockquote><p>Once you create your table primary key or any other Index, you can execute the CLUSTER command by specifying that Index name to achieve the physical order of the Table Data. </p></blockquote>
<blockquote><p>CLUSTER instructs PostgreSQL to cluster the table specified by table_name based on the index specified by index_name. The index must already have been defined on table_name.</p></blockquote>
<blockquote><p>A clustering on an index forces the physical ordering of the data and you can have only one clustered index per table and should carefully pick which index you will use to cluster.</p></blockquote>
<blockquote><p>When a table is clustered, it is physically reordered based on the index information. Clustering is a one-time operation: when the table is subsequently updated, the changes are not clustered. That is, no attempt is made to store new or updated rows according to their index order. </p></blockquote>
<blockquote><p>If you wish, you can periodically recluster by issuing the CLUSTER command again and again. </p></blockquote>
<blockquote><p>A executing of CLUSTER command requires an ACCESS EXCLUSIVE lock on the table because It reorders your data. You can also get some free space by issuing CLUSTER because It rearranges the data in a particular order. </p></blockquote>
<blockquote><p>When you execute the CLUSTER command, It creates a temporary copy of the table therefore, you need free space on disk at least equal to the original table size. </p></blockquote>
<blockquote><p>When an index scan is used, a temporary copy of the table is created that contains the table data in the index order. Temporary copies of each index on the table are created as well. Therefore, you need free space on disk at least equal to the sum of the table size and the index sizes.</p></blockquote>
<blockquote><p>It is advisable to set maintenance_work_mem to a reasonably large value before clustering.</p></blockquote>
<blockquote><p>Once you are done with your CLUSTER, you should execute the ANALYZE command on that table because planner records statistics about the ordering of tables.
</p></blockquote>
<p><strong>Syntax of Cluster:</strong><br />
First time you must execute CLUSTER using the Index Name.</p>
<pre class="crayon-plain-tag">CLUSTER table_name USING index_name;</pre> </p>
<p><strong>Cluster the table:</strong><br />
Once you have executed CLUSTER with Index, next time you should execute only CLUSTER TABLE because It knows that which index already defined as CLUSTER.</p>
<pre class="crayon-plain-tag">CLUSTER table_name;</pre> </p>
<p><strong>Cluster all tables of database:</strong></p>
<pre class="crayon-plain-tag">CLUSTER;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: T-SQL Script to Rebuild all Indexes of a Database</title>
		<link>https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 29 Oct 2016 16:16:12 +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[fragmentation]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[Reorganize 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>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3633</guid>

					<description><![CDATA[In this post, I am sharing SQL Server Database Administrator script for rebuilding all Indexes of a Database. To Rebuild or Reorganize the Indexes is a very common task for DBA. If Index fragmentation is increasing, periodically it requires executing Rebuild Index for better performance. If we want to Rebuild all Indexes of a Database, [&#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%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&#038;title=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/" data-a2a-title="SQL Server: T-SQL Script to Rebuild all Indexes of a Database"></a></p><p>In this post, I am sharing SQL Server Database Administrator script for rebuilding all Indexes of a Database. </p>
<blockquote><p>To Rebuild or Reorganize the Indexes is a very common task for DBA.<br />
If Index fragmentation is increasing, periodically it requires executing Rebuild Index for better performance.</p></blockquote>
<blockquote><p>If we want to Rebuild all Indexes of a Database, we should build and generate the script because using default command we can only perform Rebuild operation on table level.</p></blockquote>
<blockquote data-secret="uWF28NbyO9" class="wp-embedded-content"><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 loading="lazy" 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=uWF28NbyO9" data-secret="uWF28NbyO9" 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>
<p>In below script, I commented Fill Factor related changes, and If anyone wants, they uncomment it.<br />
Please SELECT your database and execute the below script.</p>
<blockquote><p><strong>Note:</strong> Database <a href="https://msdn.microsoft.com/en-us/library/ms189858.aspx" target="_blank"><strong>REBUILD INDEX</strong></a> is a very costly operation and It requires an exclusive lock on table so please aware yourself before executing it.</p></blockquote>
<pre class="crayon-plain-tag">DECLARE @DatabaseName SYSNAME   = DB_NAME()
DECLARE @TableName VARCHAR(256) 
--DECLARE @FILLFACTOR INT = 85
DECLARE @SQL NVARCHAR(MAX) =

 'DECLARE curAllIndex CURSOR FOR SELECT TABLE_SCHEMA +
 ''.'' + TABLE_NAME AS TABLENAME  
 FROM ' + @DatabaseName + '.INFORMATION_SCHEMA.TABLES WHERE
 TABLE_TYPE = ''BASE TABLE'''  
 
BEGIN 
  EXEC sp_executeSQL @SQL  
  OPEN curAllIndex
  FETCH NEXT FROM curAllIndex INTO @TableName  
  WHILE (@@FETCH_STATUS = 0) 
  BEGIN  
       /* -- For using FillFactor setting. 
	   SET @DynamicSQL = 'ALTER INDEX ALL ON ' + @TableName +  
	   ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR,@FILLFACTOR) + ')' 
	   */
	   SET @SQL = 'ALTER INDEX ALL ON ' + @TableName +  
	   ' REBUILD ' 
       PRINT @SQL       
       EXEC sp_executeSQL @SQL 
       FETCH NEXT FROM curAllIndex INTO @TableName  
   END   
   CLOSE curAllIndex  
   DEALLOCATE curAllIndex 
END</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
