<?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>Rebuild Index &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/rebuild-index/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, 06 Feb 2018 21:09:19 +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: After Dropping a Column, Rebuild the table and get the Space</title>
		<link>https://www.dbrnd.com/2018/02/sql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 27 Feb 2018 16:16:29 +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[Rebuild Index]]></category>
		<category><![CDATA[REBUILD TABLE]]></category>
		<category><![CDATA[Refresh 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=7145</guid>

					<description><![CDATA[<div><img width="679" height="272" src="https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-679x272.png" class="attachment-post-image size-post-image wp-post-image" alt="Database Space Recovery" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-679x272.png 679w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-1030x412.png 1030w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-850x340.png 850w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery.png 1250w" sizes="(max-width: 679px) 100vw, 679px" /></div>In this post, I am sharing a demonstration on how to recover the occupied space by a SQL Server table, after dropping a big size of the column. Many times, we are getting a request like &#8220;No Space in Development Server&#8221;. Developers are testing their code and design so they are dropping and creating columns [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="272" src="https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-679x272.png" class="attachment-post-image size-post-image wp-post-image" alt="Database Space Recovery" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-679x272.png 679w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-1030x412.png 1030w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery-850x340.png 850w, https://www.dbrnd.com/wp-content/uploads/2018/02/Database-Space-Recovery.png 1250w" sizes="(max-width: 679px) 100vw, 679px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&amp;linkname=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" 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%2F02%2Fsql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space%2F&#038;title=SQL%20Server%3A%20After%20Dropping%20a%20Column%2C%20Rebuild%20the%20table%20and%20get%20the%20Space" data-a2a-url="https://www.dbrnd.com/2018/02/sql-server-after-dropping-a-column-rebuild-the-table-and-get-the-space/" data-a2a-title="SQL Server: After Dropping a Column, Rebuild the table and get the Space"></a></p><p>In this post, I am sharing a demonstration on how to recover the occupied space by a SQL Server table, after dropping a big size of the column.</p>
<blockquote><p>Many times, we are getting a request like &#8220;No Space in Development Server&#8221;. Developers are testing their code and design so they are dropping and creating columns in tables.<br />
But after this, we should refresh the table by rebuilding their indexes. </p></blockquote>
<p>Please check the below full demonstration on this, and try it yourself:</p>
<p><strong>Create a table with sample data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_TableSize (ID BIGINT, Name CHAR(2000), CONSTRAINT pk_Id PRIMARY KEY(ID))
GO

INSERT INTO tbl_TableSize VALUES
(1,'Anvesh'),(2,'Roy'),(3,'Jenny')
,(4,'Martin'),(5,'Neevan'),(6,'Nupur')
GO</pre><p> </p>
<p><strong>Check the average taken space of a table:</strong></p><pre class="crayon-plain-tag">SELECT 
	page_count
	,avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats(db_id('db_name'), object_id('tbl_TableSize'), NULL, NULL , 'Detailed')

--Result:
page_count           avg_page_space_used_in_percent
-------------------- ------------------------------
2                    74.7343711391154
1                    0.395354583642204</pre><p> </p>
<p><strong>Now, Drop a CHAR column:</strong></p><pre class="crayon-plain-tag">ALTER TABLE tbl_TableSize DROP COLUMN Name
GO</pre><p> </p>
<p><strong>Now check the size again:</strong><br />
No difference found!</p><pre class="crayon-plain-tag">SELECT 
	page_count
	,avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats(db_id('test'), object_id('tbl_TableSize'), NULL, NULL , 'Detailed')

--Result:
page_count           avg_page_space_used_in_percent
-------------------- ------------------------------
2                    74.7343711391154
1                    0.395354583642204</pre><p> </p>
<p><strong>Now, Rebuild the clustered index:</strong></p><pre class="crayon-plain-tag">ALTER INDEX pk_Id ON tbl_TableSize REBUILD
GO</pre><p> </p>
<p><strong>Check the size again:</strong><br />
Now, you can see the huge difference in the table size, and occupied space by dropped column has been recovered. </p>
<pre class="crayon-plain-tag">SELECT 
	page_count
	,avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats(db_id('test'), object_id('tbl_TableSize'), NULL, NULL , 'Detailed')

--Result:
page_count           avg_page_space_used_in_percent
-------------------- ------------------------------
1                    1.23548307388189</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 12 Nov 2017 16:16:59 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BLOCKER]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[MAX_DURATION]]></category>
		<category><![CDATA[REBUILD]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2014]]></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>
		<category><![CDATA[WAIT_AT_LOW_PRIORITY]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6113</guid>

					<description><![CDATA[SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX. In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction. But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options. For ABORT_AFTER_WAIT, took the reference from Microsoft: [&#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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&#038;title=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/" data-a2a-title="SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation"></a></p><p>SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX.</p>
<blockquote><p>In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction.<br />
But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options.</p></blockquote>
<p><a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-index-transact-sql" target="_blank" rel="noopener noreferrer">For ABORT_AFTER_WAIT, took the reference from Microsoft:</a></p><pre class="crayon-plain-tag">ABORT_AFTER_WAIT = [NONE | SELF | BLOCKERS]</pre><p>
<strong>NONE:</strong> Continue waiting for the lock with normal (regular) priority.</p>
<p><strong>SELF:</strong> Exit the online index rebuild DDL operation currently being executed without taking any action.</p>
<p><strong>BLOCKERS:</strong> Kill all user transactions that block the online index rebuild DDL operation so that the operation can continue. The BLOCKERS option requires the login to have ALTER ANY CONNECTION permission.</p>
<p><strong>Please check the below demonstration, where I am comparing old and new approach of REBUILD INDEX:</strong></p>
<p><strong>Create a sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_DumpData
(
	ID INT 
	,RandomID VARCHAR(MAX)
	,CONSTRAINT pk_tbl_DumpData_ID PRIMARY KEY(ID)
)
GO</pre><p>
<p><strong>Insert dummy data:</strong></p><pre class="crayon-plain-tag">;WITH CTE AS
(
	SELECT 1 ID
	UNION all
	SELECT ID + 1
	FROM CTE   
	WHERE ID + 1 &lt;= 100000
)
INSERT INTO tbl_DumpData(ID,RandomID)
SELECT 
	ID
	,NEWID() AS RandomID
FROM CTE 
OPTION (MAXRECURSION 0)
GO</pre><p>
<p><strong>Open new session/query window, execute below update:</strong></p><pre class="crayon-plain-tag">BEGIN TRANSACTION
UPDATE tbl_DumpData SET RandomID = 39840972340234 WHERE ID = 8</pre><p>
<p><strong>Jump to old session window, and execute below REBUILD:</strong><br />
<em>It is Running&#8230; Running&#8230; Running&#8230;, because table is locked by another transaction</em></p><pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
)
GO</pre><p>
<p><strong>Check the lock table:</strong><br />
You can find that your REBUILD query is in WAIT mode.</p><pre class="crayon-plain-tag">SELECT *FROM sys.dm_tran_locks</pre><p>
<img decoding="async" class="alignnone size-full wp-image-6115" src="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png" alt="SQL Index Lock" width="740" height="136" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png 740w, https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock-679x125.png 679w" sizes="(max-width: 740px) 100vw, 740px" /></p>
<p><strong>Now stop the execution of the previous REBUILD, and execute below REBUILD WITH WAIT_AT_LOW_PRIORITY:</strong><br />
Set MAX_DURATION for one minute and ABORT_AFTER_WAIT type is SELF.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = SELF
	)
   )
)
GO</pre>
<p><strong>Above REBUILD will wait for One minute and then it will throw an error message:</strong><br />
<pre class="crayon-plain-tag">Msg 1222, Level 16, State 56, Line 1
Lock request time out period exceeded.</pre>
<p><strong>Now, test with BLOCKER option:</strong><br />
It will wait for one minute, and then it will kill the open UPDATE transaction to finish the REBUILD operation.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = BLOCKERS 
	)
   )
)
GO</pre>
<p><strong>Now, go to another transaction where UPDATE transaction was there:</strong><br />
Try to execute any query, you will get below error message because this session is terminated by REBUILD + BLOCKERS.<br />
<pre class="crayon-plain-tag">SELECT *FROM tbl_DumpData</pre>
<p><strong>Error:</strong><br />
<pre class="crayon-plain-tag">Msg 0, Level 20, State 0, Line 0
The connection is broken and recovery is not possible.  The connection is marked by the server as unrecoverable.  No attempt was made to restore the connection.</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Enable CHECKSUM Page Verification to detect a prime spot of Data Corruption</title>
		<link>https://www.dbrnd.com/2017/02/sql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 07 Feb 2017 16:16:58 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[CHECKSUM]]></category>
		<category><![CDATA[data corruption]]></category>
		<category><![CDATA[data validation]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[file integrity]]></category>
		<category><![CDATA[Rebuild Index]]></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=4484</guid>

					<description><![CDATA[From the MSDN, &#8220;When CHECKSUM is enabled for the PAGE_VERIFY database option, the SQL Server Database Engine calculates a checksum over the contents of the whole page, and stores the value in the page header when a page is written to disk. When the page read from disk, the checksum is recomputed and compared 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%2F2017%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&amp;linkname=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" 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%2F02%2Fsql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption%2F&#038;title=SQL%20Server%3A%20Enable%20CHECKSUM%20Page%20Verification%20to%20detect%20a%20prime%20spot%20of%20Data%20Corruption" data-a2a-url="https://www.dbrnd.com/2017/02/sql-server-enable-checksum-page-verification-to-detect-a-prime-spot-of-corruption/" data-a2a-title="SQL Server: Enable CHECKSUM Page Verification to detect a prime spot of Data Corruption"></a></p><p><strong>From the MSDN,</strong></p>
<blockquote><p><strong>&#8220;</strong>When CHECKSUM is enabled for the PAGE_VERIFY database option, the SQL Server Database Engine calculates a checksum over the contents of the whole page, and stores the value in the page header when a page is written to disk.</p>
<p>When the page read from disk, the checksum is recomputed and compared to the checksum value that stored in the page header. This helps provide a high level of data file integrity.<strong>&#8220;</strong></p></blockquote>
<p>Guys, You have two options, wait for huge data corruption and detect it a very first level of data corruption.</p>
<blockquote><p>Once you enable CHECKSUM, every read off and write off a check for CHECKSUM and validates it. If it finds any mismatch or broken chain of CHECKSUM value, it indicates data corruption immediately.</p>
<p><img loading="lazy" decoding="async" class="alignright wp-image-4489 size-full" title="SQL Server Checksum" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerChecksum.jpg" alt="SQL Server Checksum" width="448" height="84" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerChecksum.jpg 448w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerChecksum-300x56.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerChecksum-150x28.jpg 150w" sizes="auto, (max-width: 448px) 100vw, 448px" /></p></blockquote>
<blockquote><p>CHECKSUM option doesn&#8217;t prevent the data corruption, it gives you more confidence against data corruption, and you can detect data corruption error faster and solve it in the better way.</p></blockquote>
<blockquote><p>It occupies little CPU I/O for maintaining a CHECKSUM values, but it is acceptable.</p></blockquote>
<p><strong>Find all databases which are not configured for CHECKSUM verification:</strong></p><pre class="crayon-plain-tag">USE master
GO

SELECT NAME
        ,page_verify_option_desc
FROM master .sys.databases
WHERE page_verify_option_desc != 'CHECKSUM'
GO</pre><p>
<strong>Enable CHECKSUM for your Database:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE Database_Name
SET PAGE_VERIFY CHECKSUM WITH NO_WAIT
GO</pre><p>
<strong>Important Note: </strong><br />
Once you enable and CHECKSUM for your database, It does not instantly add CHECKSUMs to your existing data pages in the database. You have to read each page using INSERT/UPDATE/DELETE or simply you can execute REBUILD option for your indexes.</p>
<p><strong>Other related articles:</strong></p>
<blockquote data-secret="kwte1ixkoM" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/11/sql-server-monitor-and-manage-database-corruption/">SQL Server: Monitor and Manage Database Corruption</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/sql-server-monitor-and-manage-database-corruption/embed/#?secret=kwte1ixkoM" data-secret="kwte1ixkoM" width="600" height="338" title="&#8220;SQL Server: Monitor and Manage Database Corruption&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Rebuild all Indexes using REINDEXDB utility and REINDEX command</title>
		<link>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/</link>
					<comments>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 05 Jan 2017 18:34:36 +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[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>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[reindex]]></category>
		<category><![CDATA[reindexdb]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3645</guid>

					<description><![CDATA[The Index Rebuilding is a very common and routine task for a Database Administrator. All types of RDBMS system have various types of Reindexing option. The Index Rebuilding is necessary periodically to remove fragmentation of Indexes. PostgreSQL provides two ways to perform Reindexing on Database. Using REINDEX command: You can execute REINDEX command on 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%2F2017%2F01%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&#038;title=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" data-a2a-url="https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/" data-a2a-title="PostgreSQL: Rebuild all Indexes using REINDEXDB utility and REINDEX command"></a></p><p>The Index Rebuilding is a very common and routine task for a Database Administrator. </p>
<blockquote><p>All types of RDBMS system have various types of Reindexing option.<br />
The Index Rebuilding is necessary periodically to remove fragmentation of Indexes. </p></blockquote>
<p>PostgreSQL provides two ways to perform Reindexing on Database.</p>
<p><strong>Using REINDEX command:</strong></p>
<blockquote><p>You can execute REINDEX command on Database, Table and Index.<br />
You can connect PostgreSQL using PGAdmin or PSQL tools to execute this command. </p></blockquote>
<p><strong>Reindex all indexes of Database:</strong></p>
<pre class="crayon-plain-tag">REINDEX DATABASE Database_Name;</pre> </p>
<p><strong>Reindex on particular Index:</strong></p>
<pre class="crayon-plain-tag">REINDEX INDEX Index_Name;</pre> </p>
<p><strong>Reindex on particular Table:</strong></p>
<pre class="crayon-plain-tag">REINDEX TABLE Table_Name;</pre> </p>
<p><strong>Using REINDEXDB.EXE utility:</strong></p>
<blockquote><p>A REINDEXDB is a one type of utility of PostgreSQL. It is an executable file which we can run without connect to database server.</p></blockquote>
<blockquote><p>A REINDEXDB requires command line arguments like database_username, database_name.<br />
We can execute REINDEXDB using command prompt of the Operating System. </p></blockquote>
<p>Below an example of Windows Command Prompt, the same way you can also execute in Linux.</p>
<p><strong>Reindex all Database of PostgreSQL Server:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -U user_name -a
Password:****</pre> </p>
<p><strong>Reindex on particular Database:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -d database -U user_name
Password:****</pre> </p>
<p><strong>Reindex on particular Table:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -d database_name -U user_name -t table_name
Password:****</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</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>
