<?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>lock &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/lock/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 16 Jan 2018 11:04:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Greenplum: Script to find blocked and deadlock by other blocking queries</title>
		<link>https://www.dbrnd.com/2018/02/greenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks/</link>
					<comments>https://www.dbrnd.com/2018/02/greenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 02 Feb 2018 16:16:41 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[long running queries]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4394</guid>

					<description><![CDATA[In this post, I am sharing a script to find a list of blocked and deadlock queries by other blocking queries of Greenplum Database Server. You can visit below article to know more about, what is a lock, deadlock, block and timeout? Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System? [&#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%2F02%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" 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%2Fgreenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks%2F&#038;title=Greenplum%3A%20Script%20to%20find%20blocked%20and%20deadlock%20by%20other%20blocking%20queries" data-a2a-url="https://www.dbrnd.com/2018/02/greenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks/" data-a2a-title="Greenplum: Script to find blocked and deadlock by other blocking queries"></a></p><p>In this post, I am sharing a script to find a list of blocked and deadlock queries by other blocking queries of Greenplum Database Server. </p>
<p>You can visit below article to know more about, what is a lock, deadlock, block and timeout?</p>
<blockquote class="wp-embedded-content" data-secret="CZy0OcEdgM"><p><a href="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/">Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/embed/#?secret=CZy0OcEdgM" data-secret="CZy0OcEdgM" width="600" height="338" title="&#8220;Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>If two queries are trying to get the same resource, both are depended on each other and generates block state first and then deadlock.</p>
<blockquote><p>In the below script, you can find a list of blocked queries and blocker queries with a value of time age.<br />
You can find a process_id of blocker query which we can kill for avoiding the deadlock situation.</p></blockquote>
<pre class="crayon-plain-tag">SELECT
	kl.pid as blocking_pid
	,ka.usename as blocking_user
	,ka.current_query as blocking_query
	,bl.pid as blocked_pid
	,a.usename as blocked_user
	,a.current_query as blocked_query
	,to_char(age(now(), a.query_start),'HH24h:MIm:SSs') as age
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a
	ON bl.pid = a.procpid
JOIN pg_catalog.pg_locks kl
	ON bl.locktype = kl.locktype
	and bl.database is not distinct from kl.database
	and bl.relation is not distinct from kl.relation
	and bl.page is not distinct from kl.page
	and bl.tuple is not distinct from kl.tuple
	and bl.transactionid is not distinct from kl.transactionid
	and bl.classid is not distinct from kl.classid
	and bl.objid is not distinct from kl.objid
	and bl.objsubid is not distinct from kl.objsubid
	and bl.pid &lt;&gt; kl.pid
JOIN pg_catalog.pg_stat_activity ka
	ON kl.pid = ka.procpid
WHERE kl.granted and not bl.granted
ORDER BY a.query_start;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/02/greenplum-script-to-find-blocked-and-deadlock-by-other-blocking-queries-pg_locks/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Greenplum: Find long running sessions with lock information</title>
		<link>https://www.dbrnd.com/2018/02/greenplum-find-long-running-sessions-with-lock-information-total-execution-time/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 01 Feb 2018 16:16:29 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[long running queries]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<category><![CDATA[sessions]]></category>
		<category><![CDATA[transactions]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4387</guid>

					<description><![CDATA[In this post, I am sharing a script to find long running queries or sessions with the lock information of Greenplum database server. In the below script, you can find the age column which gives you total execution time of running sessions. You can also find query lock related details. [crayon-6aa68846468be977379807/]]]></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%2F02%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&amp;linkname=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" 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%2Fgreenplum-find-long-running-sessions-with-lock-information-total-execution-time%2F&#038;title=Greenplum%3A%20Find%20long%20running%20sessions%20with%20lock%20information" data-a2a-url="https://www.dbrnd.com/2018/02/greenplum-find-long-running-sessions-with-lock-information-total-execution-time/" data-a2a-title="Greenplum: Find long running sessions with lock information"></a></p><p>In this post, I am sharing a script to find long running queries or sessions with the lock information of Greenplum database server. </p>
<p>In the below script, you can find the age column which gives you total execution time of running sessions. You can also find query lock related details.</p>
<pre class="crayon-plain-tag">select 
	age(now(),pg_stat_activity.query_start) as "age",
	pg_stat_activity.datname, pg_stat_activity.usename,
	pg_stat_activity.client_addr, pg_stat_activity.application_name,
	pg_locks.transactionid, pg_locks.transaction,
	pg_stat_activity.procpid, pg_stat_activity.query_start,
	pg_locks.mode, pg_stat_activity.current_query
from  pg_stat_activity, pg_locks
where pg_locks.pid = pg_stat_activity.procpid
and procpid &lt;&gt; pg_backend_pid()
and pg_locks.transactionid = pg_locks.transaction
order by 1 desc;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: When records lock, use %%lockres%% to find the page information of records</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 04 Mar 2017 16:16:35 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[%%lockres%%]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[data page]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[dm_tran_locks]]></category>
		<category><![CDATA[lock]]></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=4689</guid>

					<description><![CDATA[I shared a couple of articles on SQL Server database locking and how to detect a deadlock. Please access few of them. Different ways to detect a deadlock What happens after the Deadlock? I recently found an undocumented function %%lockres%% which we can use to locate the page information of records especially for those 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" 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%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&#038;title=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records/" data-a2a-title="SQL Server: When records lock, use %%lockres%% to find the page information of records"></a></p><p>I shared a couple of articles on SQL Server database locking and how to detect a deadlock. Please access few of them.</p>
<p><strong><a href="https://www.dbrnd.com/2016/04/sql-server-8-different-ways-to-detect-a-deadlock-in-a-database/" target="_blank">Different ways to detect a deadlock</a></strong><br />
<a href="https://www.dbrnd.com/2016/04/sql-server-what-happens-after-the-deadlock-arise/" target="_blank"><strong>What happens after the Deadlock?</strong></a></p>
<blockquote><p>I recently found an undocumented function <strong>%%lockres%%</strong> which we can use to locate the page information of records especially for those records which hold a Lock.</p></blockquote>
<blockquote><p>It returns a hash value same as like column &#8220;resource_description&#8221; of table sys.dm_tran_locks, but the good thing is you can use it in your SELECT statement and can correlate the column resource_description of table sys.dm_tran_locks.</p></blockquote>
<p>By this way, you can get the exact record, and it&#8217;s page info which currently held by a Lock.</p>
<p>Let me demonstrate this,<br />
<strong>Prerequisites:</strong><br />
Use below article and generate a sample deadlock situation in your database server.</p>
<blockquote class="wp-embedded-content" data-secret="FLnip7cgnO"><p><a href="https://www.dbrnd.com/2016/04/sql-server-t-sql-script-to-generate-a-deadlock-in-a-database/">SQL Server: T-SQL script to generate a DeadLock in a Database</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-t-sql-script-to-generate-a-deadlock-in-a-database/embed/#?secret=FLnip7cgnO" data-secret="FLnip7cgnO" width="600" height="338" title="&#8220;SQL Server: T-SQL script to generate a DeadLock in a Database&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Check the result of below query and note down the result of column &#8220;resource_description&#8221;:</strong></p><pre class="crayon-plain-tag">select *from sys.dm_tran_locks</pre><p>
<img fetchpriority="high" decoding="async" class="alignnone wp-image-4696 size-full" title="SQL Server Deadlock Result" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult.png" alt="SQL Server Deadlock Result" width="628" height="272" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult.png 628w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult-300x130.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult-150x65.png 150w" sizes="(max-width: 628px) 100vw, 628px" /></p>
<p><strong>Use %%lockres%% and SELECT both the tables:</strong><br />
You can easily correlate the result of sys.dm_tran_locks column resource_description and the result of %%lockres%%. You can find an exact record which held by a Lock.</p><pre class="crayon-plain-tag">SELECT %%lockres%% AS RecordPageInfo,* 
FROM tbl_SampleTable_A

SELECT %%lockres%% AS RecordPageInfo,* 
FROM tbl_SampleTable_B</pre><p>
<img loading="lazy" decoding="async" class="alignnone wp-image-4695 size-full" title="SQL Server Deadlock Record Page Info" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo.png" alt="SQL Server Deadlock Record Page Info" width="328" height="643" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo.png 328w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo-153x300.png 153w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo-150x294.png 150w" sizes="auto, (max-width: 328px) 100vw, 328px" /></p>
<p>After this exercise, Please COMMIT all your open transactions.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: How to generate a DeadLock in a Database (ERROR:  deadlock detected)</title>
		<link>https://www.dbrnd.com/2016/11/postgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 19 Nov 2016 12:13:52 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BEGIN]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[COMMIT]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[generate deadlock]]></category>
		<category><![CDATA[lock]]></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[transaction]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3873</guid>

					<description><![CDATA[The DeadLock in a database system is a very common thing and all Database Administrator responsible to detect and manage a DeadLock situation. In this post, I am sharing one small demonstration t to generate a DeadLock situation in a PostgreSQL. Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System? Most [&#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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&amp;linkname=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%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%2F11%2Fpostgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected%2F&#038;title=PostgreSQL%3A%20How%20to%20generate%20a%20DeadLock%20in%20a%20Database%20%28ERROR%3A%20%20deadlock%20detected%29" data-a2a-url="https://www.dbrnd.com/2016/11/postgresql-how-to-generate-a-deadlock-in-a-database-error-deadlock-detected/" data-a2a-title="PostgreSQL: How to generate a DeadLock in a Database (ERROR:  deadlock detected)"></a></p><p>The DeadLock in a database system is a very common thing and all Database Administrator responsible to detect and manage a DeadLock situation.</p>
<p>In this post, I am sharing one small demonstration t to generate a DeadLock situation in a PostgreSQL. </p>
<blockquote data-secret="ZVivaTqnPl" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/">Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/embed/#?secret=ZVivaTqnPl" data-secret="ZVivaTqnPl" width="600" height="338" title="&#8220;Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>Most of the time, We are facing DeadLock problem in our Production Database Server.<br />
But What happen, when Database Administrator wants to generate DeadLock situation and wants to create a script for detecting a DeadLock.</p></blockquote>
<p><strong>First create two sample tables:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE ABC (ID INT PRIMARY KEY);
CREATE TABLE XYZ (ID INT PRIMARY KEY);</pre> </p>
<p><strong>Open Session &#8211; 1 and execute below code:</strong></p>
<pre class="crayon-plain-tag">BEGIN;
INSERT INTO ABC VALUES (1);</pre> </p>
<p><strong>Open Session &#8211; 2 and execute below code:</strong></p>
<pre class="crayon-plain-tag">BEGIN;
INSERT INTO XYZ VALUES (1);
INSERT INTO ABC VALUES (1);</pre> </p>
<p><strong>Again open Session &#8211; 1 and execute below Insert Statement:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO XYZ VALUES (1);</pre> </p>
<p><strong>You will get a below deadlock message:</strong></p>
<pre class="crayon-plain-tag">ERROR:  deadlock detected
DETAIL:  Process 5944 waits for ShareLock on transaction 892; blocked by process 4884.
Process 4884 waits for ShareLock on transaction 891; blocked by process 5944.
HINT:  See server log for query details.
CONTEXT:  while inserting index tuple (0,2) in relation "xyz_pkey"</pre> </p>
<h2>Please visit other related articles:</h2>
<blockquote data-secret="75LewbEKVb" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/">PostgreSQL 9.5: Using FOR UPDATE SKIP LOCKED Option SELECT only Committed Records</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/embed/#?secret=75LewbEKVb" data-secret="75LewbEKVb" width="600" height="338" title="&#8220;PostgreSQL 9.5: Using FOR UPDATE SKIP LOCKED Option SELECT only Committed Records&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote data-secret="MqeJj9B5Nt" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/09/postgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block/">PostgreSQL: Script to find information about the Locks held by Open Transactions (pg_locks)</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/09/postgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block/embed/#?secret=MqeJj9B5Nt" data-secret="MqeJj9B5Nt" width="600" height="338" title="&#8220;PostgreSQL: Script to find information about the Locks held by Open Transactions (pg_locks)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote data-secret="jgqH9JxLjm" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/">Script to find sessions that are blocking other sessions in PostgreSQL</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/embed/#?secret=jgqH9JxLjm" data-secret="jgqH9JxLjm" width="600" height="338" title="&#8220;Script to find sessions that are blocking other sessions in PostgreSQL&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find information about the Locks held by Open Transactions (pg_locks)</title>
		<link>https://www.dbrnd.com/2016/09/postgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 06 Sep 2016 19:23:52 +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[DeadLock]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_locks]]></category>
		<category><![CDATA[pg_stat_activity]]></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=3582</guid>

					<description><![CDATA[In this post, I am sharing one script to find information about the Locks which are held by Open Transactions of PostgreSQL Database Server. Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System? PostgreSQL view pg_locks contains the main information about the all types of lock of Database Server. It contains [&#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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%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%2F09%2Fpostgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20information%20about%20the%20Locks%20held%20by%20Open%20Transactions%20%28pg_locks%29" data-a2a-url="https://www.dbrnd.com/2016/09/postgresql-script-to-find-information-about-the-locks-held-by-open-transactions-pg_locks-deadlock-lock-block/" data-a2a-title="PostgreSQL: Script to find information about the Locks held by Open Transactions (pg_locks)"></a></p><p>In this post, I am sharing one script to find information about the Locks which are held by Open Transactions of PostgreSQL Database Server.</p>
<blockquote data-secret="ECraasdyx3" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/">Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/embed/#?secret=ECraasdyx3" data-secret="ECraasdyx3" width="600" height="338" title="&#8220;Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>PostgreSQL view pg_locks contains the main information about the all types of lock of Database Server.<br />
It contains one row per active lockable object.</p></blockquote>
<p>This script is very helpful to all PostgreSQL Database Administrators.</p>
<p><strong>Below is a script:<br />
</strong><br />
<pre class="crayon-plain-tag">SELECT 
	pl.pid AS ProcessID
	,psa.datname AS DatabaseName
	,psa.usename AS UserName
	,psa.application_name AS ApplicationName
	,ps.relname AS ObjectName
	,psa.query_start AS QueryStartTime
	,psa.state AS QueryState
	,psa.query AS SQLQuery
	,pl.locktype
	,pl.tuple AS TupleNumber
	,pl.mode AS LockMode
	,pl.granted -- True if lock is held, false if lock is awaited
FROM pg_locks AS pl 
LEFT JOIN pg_stat_activity AS psa
	ON pl.pid = psa.pid
LEFT JOIN pg_class AS ps
	ON pl.relation = ps.oid</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL 9.5: Using FOR UPDATE SKIP LOCKED Option SELECT only Committed Records</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/</link>
					<comments>https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 14 Aug 2016 14:36:42 +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[FOR UPDATE SKIP LOCKED]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[MVCC]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[postgresql 9.5]]></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[SKIP LOCK]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3476</guid>

					<description><![CDATA[PostgreSQL 9.5 introduced one of the powerful feature called SKIP LOCKED which is used for SKIP uncommitted data. I am not going to make this more complex topic, explaining by one practical example. In our project we have implemented thread mechanism. Different threads are running and taking a fixed set of records from the 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&amp;linkname=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" 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%2F08%2Fpostgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread%2F&#038;title=PostgreSQL%209.5%3A%20Using%20FOR%20UPDATE%20SKIP%20LOCKED%20Option%20SELECT%20only%20Committed%20Records" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/" data-a2a-title="PostgreSQL 9.5: Using FOR UPDATE SKIP LOCKED Option SELECT only Committed Records"></a></p><p>PostgreSQL 9.5 introduced one of the powerful feature called SKIP LOCKED which is used for SKIP uncommitted data. </p>
<p>I am not going to make this more complex topic, explaining by one practical example. </p>
<blockquote><p>In our project we have implemented thread mechanism. Different threads are running and taking a fixed set of records from the Database.<br />
These threads basically implemented for performing Reverse Geo Coding on the stored Latitude and Longitude.<br />
I am giving 10000 records to each thread in each batch.<br />
Now the average execution time of each thread is 5 second to 7 second. </p></blockquote>
<blockquote><p>Now, one batch of 10000 records taken by thread_1 for 5 second to 7 second that same records should not taken by any other thread because that first 10000 records already under the process by thead_1.<br />
Thread_2 has taken next 10000 records which are not taken by thread_1.</p></blockquote>
<blockquote><p>Now with the PostgreSQL 9.5, we do not require any additional locking mechanism or isolation level to achieve this scenario.<br />
We can very easily achieve using FOR UPDATE SKIP LOCKED option. When we SELECT data using this option, it will skip all running transactions (uncommitted transaction) and return only required records to be processed. </p></blockquote>
<p><strong>Below is a full demonstration of this.</p>
<p>First create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Employee 
(
	EmpID INT
	,EmpName CHARACTER VARYING
);

INSERT INTO tbl_Employee 
VALUES (1,'Anvesh'),(2,'Roy')
,(3,'Benny'),(4,'Nivu');</pre> </p>
<p>Now we are going to test this option with the help of two different sessions.</p>
<p><strong>Open a new session and execute below queries in Session 1:</strong><br />
We have inserted four sample records and now will update one of record in OPEN TRANSACTION with out committing anything.</p>
<pre class="crayon-plain-tag">BEGIN TRANSACTION

UPDATE tbl_Employee SET EmpName = 'Martin' 
WHERE EmpID = 3;</pre> </p>
<p><strong>Open another session and execute below queries in Session 2:</strong><br />
<strong>First SELECT with out any option:</strong></p>
<blockquote><p>If you do not know, please read about the MVCC. </p>
<blockquote data-secret="feVCctJP4T" 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=feVCctJP4T" data-secret="feVCctJP4T" 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>
<p>PostgreSQL has a default MVCC architecture, in which you can select last committed row version.<br />
In the above query we have updated one record for EmpID=3, but when I execute simple SELECT statement then it returned the old value of EmpID=3.</p>
<p>This data is based on last committed row version. </p></blockquote>
<pre class="crayon-plain-tag">SELECT *FROM tbl_Employee;

/* Result:
EmpID    EmpName
--------------------
  1      Anvesh
  2      Roy
  4      Nivu
  3      Benny
*/</pre> </p>
<p><strong><br />
Now SELECT with NOWAIT option:</strong></p>
<blockquote><p>When you are trying to SELECT running transaction, It will raise the error like : can not obtain lock on row. You can not SELECT EmpID=3, but you can SELECT EmpID IN (1,2,4).</p></blockquote>
<p>Please find out below query and the result. </p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_Employee WHERE EmpID=3 FOR UPDATE NOWAIT;
SELECT *FROM tbl_Employee FOR UPDATE NOWAIT;

/* Result:
********** Error **********

ERROR: could not obtain lock on row in relation "tbl_employee"
SQL state: 55P03
*/</pre> </p>
<p><strong>Now finally, we test SKIP LOCKED option:</strong></p>
<blockquote><p>A SKIP LOCKED option simply sikped the records or rows which are the part of ROW Level Locking.<br />
You can find out in the below result, EmpID=3 is not in result because it is not committed yet and running in different session.</p></blockquote>
<pre class="crayon-plain-tag">/* Result:
SELECT *FROM tbl_Employee FOR UPDATE SKIP LOCKED;

EmpID    EmpName
--------------------
  1      Anvesh
  2      Roy
  4      Nivu
*/</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/08/postgresql-9-5-using-for-update-skip-locked-option-select-only-committed-records-mvcc-lock-with-nowait-thread/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-4)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 07 Jun 2016 05:25:29 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[DEADLOCK_PRIORITY]]></category>
		<category><![CDATA[explicit locking]]></category>
		<category><![CDATA[implicit locking]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[LOCK_TIMEOUT]]></category>
		<category><![CDATA[Multiversion Concurrency Control]]></category>
		<category><![CDATA[MVCC]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></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[transaction]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2925</guid>

					<description><![CDATA[Which two isolation levels support optimistic/row-versioned-based concurrency control? First is READ COMMITTED and Second is SNAPSHOT Isolation level. What is the size of a lock structure? The size of lock structure is 96 bytes. Which isolation level is using key-range lock? The SERIALIZABLE isolation level is using key-range lock. Can deadlocks occur on resources other [&#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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4%2F&#038;title=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-4%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-key-range-lock-deadlock_priority-lock_timeout-mvcc-day-4/" data-a2a-title="SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-4)"></a></p><p><strong>Which two isolation levels support optimistic/row-versioned-based concurrency control?</strong></p>
<blockquote><p>First is READ COMMITTED and Second is SNAPSHOT Isolation level.</p></blockquote>
<p><strong>What is the size of a lock structure?</strong></p>
<blockquote><p>The size of lock structure is 96 bytes.</p></blockquote>
<p><strong>Which isolation level is using key-range lock?</strong></p>
<blockquote><p>The SERIALIZABLE isolation level is using key-range lock.</p></blockquote>
<p><strong>Can deadlocks occur on resources other than a database object and if it YES, what are that other resources?</strong></p>
<blockquote><p>YES, deadlock can occur on other resources like: worker threads, Memory, Parallel query execution related resources, Multiple Active Result Sets resources.</p></blockquote>
<p><strong>When to use Lock Pages in Memory with SQL Server?</strong></p>
<blockquote><p>The Lock Pages in Memory user right is a good performance optimization practice when Tier 1 mission-critical SQL Server. When setting the SQL Server Lock Pages in Memory user right, the virtual machine’s memory reservation should also be set to match the amount of the provision memory.</p></blockquote>
<p><strong>What is the use of DEADLOCK_PRIORITY option?</strong></p>
<blockquote><p>SET DEADLOCK_PRIORITY is set at execute or run time and not at parse time.</p>
<p>If the sessions have different deadlock priorities, the session with the lowest deadlock priority is chosen as the deadlock victim.</p></blockquote>
<p><strong>What is the use of LOCK_TIMEOUT option?</strong></p>
<blockquote><p>It is the number of milliseconds that will pass before Microsoft SQL Server returns a locking error.</p>
<p>A value of -1 (default) indicates no time-out period and value of 0 means to not wait at all and return a message as soon as a lock is encountered.</p></blockquote>
<p><strong>How to check the value of LOCK_TIMEOUT?</strong></p><pre class="crayon-plain-tag">SELECT @@LOCK_TIMEOUT
GO</pre><p>
<strong>How you can set maximum number of available locks to minimize the memory usage?</strong></p>
<blockquote><p>You can use sp_configure to set a locks value.</p>
<p>Below is a T-SQL Script to set the lock value up to 20000.</p><pre class="crayon-plain-tag">Use AdventureWorks2012;
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'locks', 20000;
GO
RECONFIGURE;
GO</pre><p>
</p></blockquote>
<p><strong>Which steps should be taken to address common deadlock issues?</strong></p>
<ul>
<li>Understand which tables are involved in the deadlocks.</li>
<li>Understand which pieces of code correspond to the deadlock and which users execute those pieces of code.</li>
<li>Understand how the application is affected when a deadlock occurs.</li>
<li>Determine the length of the transaction.</li>
<li>Determine if the tables are highly fragmented and causing unnecessary page reads to complete the transaction.</li>
<li>Determine if the tables can be redesigned to prevent deadlocking.</li>
<li>Determine if additional or less indexes would improve the deadlocking.</li>
<li>Determine if the code accesses the tables in the same order and with a similar query plan.</li>
</ul>
<p><strong>Can we capture deadlock information in the XML File format?</strong></p>
<blockquote><p>SQL Server Profiler has the ability to capture the deadlock related information as XML files which can be analyzed to determine the overall locking and blocking issue.</p></blockquote>
<p><strong>What are the features of XML Deadlock File?</strong></p>
<ul>
<li>The XML Deadlocks feature gives you the ability to capture the deadlock related information and review the deadlocks independent of the Profiler interface.</li>
<li>Each of the deadlock files can be analyzed in order to determine trends with the deadlocks on your SQL Server.</li>
<li>Each deadlock situation can be stored in a separate file for per deadlock analysis.</li>
<li>The XML format gives you the ability to programmatically review the deadlocks.</li>
</ul>
<p><strong>What is the Multiversion Concurrency Control (MVCC)?</strong></p>
<blockquote class="wp-embedded-content" data-secret="PKYLojy76x"><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=PKYLojy76x" data-secret="PKYLojy76x" 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>
<p><strong>What is the Implicit Locking?</strong></p>
<blockquote><p>Implicit Lock means Lock is implied but is not acquired.</p>
<p>The Database will implicitly obtain the appropriate locks for your application at the point at which they are needed. An operation that reads an object will obtain a read lock; an operation that modifies an object will obtain a write lock.</p></blockquote>
<p><strong>What is the Explicit Locking?</strong></p>
<blockquote><p>Explicit Lock means Lock is explicitly requested for a record or table.</p>
<p>An application needing to reserve access to all required objects in advance can explicitly lock objects.</p>
<p>Explicit locking effectively freezes the objects, because no other session can modify them as long as they are locked.</p></blockquote>
<p><strong>I am confused between UPDLOCK and HOLDLOCK, would you please help me?</strong></p>
<blockquote><p>UPDLOCK does not block concurrent SELECT nor INSERT, but blocks any UPDATE or DELETE of the rows selected by T1.</p>
<p>HOLDLOCK means SERALIZABLE and therefore allows SELECTS, but blocks UPDATE and DELETES of the rows selected by T1, as well as any INSERT in the range selected by T1.</p></blockquote>
<p><strong>What is the meaning of wait and await in the Deadlock situation?</strong></p>
<blockquote><p>wait will synchronously block until the task completes. So the current thread is literally blocked waiting for the task to complete. As a general rule, you should use &#8220;async all the way down&#8221;; that is, don&#8217;t block on async code.</p>
<p>await will asynchronously wait until the task completes. This means the current method is &#8220;paused&#8221; (its state is captured) and the method returns an incomplete task to its caller. Later, when the await expression completes, the remainder of the method is scheduled as a continuation.</p></blockquote>
<p><strong>What is a Transaction in SQL Server ?</strong></p>
<blockquote><p>Transaction groups a set of T-Sql Statements into a single execution unit. Each transaction begins with a specific task and ends when all the tasks in the group successfully complete. If any of the tasks fails, the transaction fails. Therefore, atransaction has only two results: success or failure.</p></blockquote>
<p><strong>What are the types of Transactions?</strong></p>
<blockquote><p>Implicit – Specifies any Single Insert,Update or Delete statement as Transaction Unit.  No need to specify Explicitly.</p>
<p>Explicit – A group of T-Sql statements with the beginning and ending marked with Begin Transaction,Commit and RollBack. PFB an Example for Explicit transactions.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-3)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 06 Jun 2016 17:52:37 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[interivews]]></category>
		<category><![CDATA[Isolation]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[Lock escalation]]></category>
		<category><![CDATA[locking hints]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[spin lock]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[WITH (NOLOCK)]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2922</guid>

					<description><![CDATA[Database session A tries to update some data that is already locked by database session B. What happens to session A? The session A will actually be placed in what’s called a lock wait state, and session A will be stopped from making further progress with any SQL transaction that it’s performing. Another way of saying [&#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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3%2F&#038;title=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-3%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-locking-hints-escalation-spinlock-day-3/" data-a2a-title="SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-3)"></a></p><p><strong>Database session A tries to update some data that is already locked by database session B. </strong><strong>What happens to session A?</strong></p>
<blockquote><p>The session A will actually be placed in what’s called a lock wait state, and session A will be stopped from making further progress with any SQL transaction that it’s performing. Another way of saying this is that session A will be “stalled” until session B releases the lock on that data.</p></blockquote>
<p><strong>What is lock contention?</strong></p>
<blockquote><p>One problem that occurs with having locks is that locks can cause what’s known as contention.</p>
<p>In the best case, lock contention means that some user processes run slower because a session is waiting for a lock. In the worst case, having sessions compete for locks can make sessions stall for an indefinite period of time.</p></blockquote>
<p><strong>What is Locking Hints option?</strong></p>
<blockquote><p>Locking hints can be specified for individual table references in the SELECT, INSERT, UPDATE, and DELETE statements. The hints specify the type of locking or row versioning the instance of the SQL Server Database Engine uses for the table data.</p></blockquote>
<p><strong>Does Locking hints override the current transaction isolation level?</strong></p>
<blockquote><p>Yes, The Locking hints override the current transaction isolation level for the session.</p></blockquote>
<p><strong>What is WITH (NOLOCK)?</strong></p>
<blockquote><p>It is equivalent to READUNCOMMITTED isolation level and you can SELECT table dirty data which are not yet committed.</p></blockquote>
<p><strong>What is WITH (NOWAIT)?</strong></p>
<blockquote><p>It instructs the Database Engine to return a message as soon as a lock is encountered on the table. NOWAIT is equivalent to specifying SET LOCK_TIMEOUT 0 for a specific table.</p></blockquote>
<p><strong>What is WITH (ROWLOCK)?</strong></p>
<blockquote><p>It specifies that row locks are taken when page or table locks are ordinarily taken.</p></blockquote>
<p><strong>What is WITH (TABLOCK)?</strong></p>
<blockquote><p>Specifies that the acquired lock is applied at the table level. The type of lock that is acquired depends on the statement being executed.</p></blockquote>
<p><strong>What is WITH (UPDLOCK)?</strong></p>
<blockquote><p>It specifies that update locks are to be taken and held until the transaction completes. UPDLOCK takes update locks for read operations only at the row-level or page-level.</p></blockquote>
<p><strong>What is the use of sys.dm_tran_locks?</strong></p>
<blockquote><p>You can query the sys.dm_tran_locks dynamic management view to obtain information about the current state of locking in an instance of the Database Engine.</p></blockquote>
<p><strong>What is a Lock Escalation?</strong></p>
<blockquote><p>A query might have a resource locked for &#8220;shared&#8221; and escalate it to &#8220;exclusive&#8221; to perform an update. SQL Server does Lock Escalation in order to reduce memory overhead, by converting several fine-grained low level locks to coarse-grained high level locks. Page Locks are also escalated to Table Locks.</p></blockquote>
<p><strong>What is the Spinlock?</strong></p>
<blockquote><p>It controls access to a lock resource, such as a row or a table.</p>
<p>Without lock partitioning, one spinlock manages all lock requests for a single lock resource.</p>
<p>To reduce contention on a single lock resource, lock partitioning splits a single lock resource into multiple lock resources to distribute the load across multiple spinlocks.</p></blockquote>
<p><strong>How READ_COMMITTED internally implemented row level locks?</strong></p>
<blockquote><p>When SQL Server executes a statement at the read committed isolation level, it acquires short lived share locks on a row by row basis. The duration of these share locks is just long enough to read and process each row; the server generally releases each lock before proceeding to the next row.</p></blockquote>
<p><strong>Within the REPEATABLE_READ and SERIALIZABLE isolation levels, during a read operation and assuming row-level locking, how long are locks held or retained for?</strong></p>
<blockquote><p>Answer: Within either of these isolation levels, locks are held for the duration of the transaction, unlike within the READ_COMMITTED isolation level.</p></blockquote>
<p><strong>When Lock escalation is triggered?</strong></p>
<blockquote><p>When a single Transact-SQL statement acquires at least 5,000 locks on a single table or index.</p>
<p>When the number of locks in an instance of the Database Engine exceeds memory or configuration thresholds.</p>
<p>If locks cannot be escalated because of lock conflicts, the Database Engine periodically triggers lock escalation at every 1,250 new locks acquired.</p></blockquote>
<p><strong>Name as many of the lockable resources of the SQL Server.</strong></p>
<ul>
<li>RID (single row on a heap)</li>
<li>KEY (single row (or range) on an index)</li>
<li>PAGE</li>
<li>EXTENT</li>
<li>HOBT (heap or b-tree)</li>
<li>TABLE (entire table, all data and indexes)</li>
<li>FILE</li>
<li>APPLICATION</li>
<li>METADATA</li>
<li>ALLOCATION_UNIT</li>
<li>DATABASE</li>
</ul>
<p><strong>What is the least restrictive and the most restrictive type of lock?</strong></p>
<blockquote><p>The least restrictive type of lock is a shared lock. The most restrictive type of lock is a schema-modification.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-2)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 05 Jun 2016 17:55:04 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[exclusive lock]]></category>
		<category><![CDATA[intent lock]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[Isolation]]></category>
		<category><![CDATA[live lock]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[lock partitioning]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[schema lock]]></category>
		<category><![CDATA[shared lock]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></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[transaction]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[update lock]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2919</guid>

					<description><![CDATA[What is the Read Uncommitted Isolation Level of the SQL Server? SQL Server: What is Read Uncommitted Isolation Level? &#160; What is the READ COMMITTED Isolation Level of the SQL Server? SQL Server: READ COMMITTED Isolation Level with the READ_COMMITTED_SNAPSHOT option &#160; What is the READ COMMITTED Isolation Level with the READ_COMMITTED_SNAPSHOT option? When the [&#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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%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%2F06%2Fsql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2%2F&#038;title=SQL%20Server%3A%20Database%20Lock%2C%20Deadlock%2C%20Block%20and%20Isolation%20Interview%20Questions%20and%20%20%20Answers%20%28Day-2%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-lock-deadlock-block-and-isolation-interview-questions-and-answers-shared-update-exclusive-live-schema-intent-lock-day-2/" data-a2a-title="SQL Server: Database Lock, Deadlock, Block and Isolation Interview Questions and   Answers (Day-2)"></a></p><p><strong>What is the Read Uncommitted Isolation Level of the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="845OXYLMTN"><p><a href="https://www.dbrnd.com/2016/04/sql-server-what-is-read-uncommitted-isolation-level/">SQL Server: What is Read Uncommitted Isolation Level?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-what-is-read-uncommitted-isolation-level/embed/#?secret=845OXYLMTN" data-secret="845OXYLMTN" width="600" height="338" title="&#8220;SQL Server: What is Read Uncommitted Isolation Level?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>&nbsp;</p>
<p><strong>What is the READ COMMITTED Isolation Level of the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="Acks8yi2wc"><p><a href="https://www.dbrnd.com/2016/04/sql-server-read-committed-isolation-level-with-the-read_committed_snapshot-option/">SQL Server: READ COMMITTED Isolation Level with the READ_COMMITTED_SNAPSHOT option</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-read-committed-isolation-level-with-the-read_committed_snapshot-option/embed/#?secret=Acks8yi2wc" data-secret="Acks8yi2wc" width="600" height="338" title="&#8220;SQL Server: READ COMMITTED Isolation Level with the READ_COMMITTED_SNAPSHOT option&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>&nbsp;</p>
<p><strong>What is the READ COMMITTED Isolation Level with the READ_COMMITTED_SNAPSHOT option?</strong></p>
<blockquote><p>When the READ_COMMITTED_SNAPSHOT database option is ON, read committed isolation uses row versioning.</p>
<p>READ COMMITTED SNAPSHOT does optimistic reads and pessimistic writes. When data is updating, you can still read old version of data and there is no any share lock, but you cannot update that same data until the running update is not finished.</p></blockquote>
<p><strong>What is the REPEATABLE READ Isolation Level of the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="LqSBNPx9h7"><p><a href="https://www.dbrnd.com/2016/04/sql-server-what-is-repeatable-read-isolation-level/">SQL Server: What is REPEATABLE READ Isolation Level?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-what-is-repeatable-read-isolation-level/embed/#?secret=LqSBNPx9h7" data-secret="LqSBNPx9h7" width="600" height="338" title="&#8220;SQL Server: What is REPEATABLE READ Isolation Level?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>&nbsp;</p>
<p><strong>What is the SERIALIZABLE Isolation level of the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="bgNGRhASFf"><p><a href="https://www.dbrnd.com/2016/04/sql-sever-what-is-serializable-isolation-level/">SQL Sever: What is SERIALIZABLE Isolation level?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-sever-what-is-serializable-isolation-level/embed/#?secret=bgNGRhASFf" data-secret="bgNGRhASFf" width="600" height="338" title="&#8220;SQL Sever: What is SERIALIZABLE Isolation level?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the SNAPSHOT Isolation Level of the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="bvolybPzQT"><p><a href="https://www.dbrnd.com/2016/04/sql-server-what-is-snapshot-isolation-level/">SQL Server: What is SNAPSHOT Isolation Level?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-what-is-snapshot-isolation-level/embed/#?secret=bvolybPzQT" data-secret="bvolybPzQT" width="600" height="338" title="&#8220;SQL Server: What is SNAPSHOT Isolation Level?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>&nbsp;</p>
<p><strong>Can you enable SNAPSHOT Isolation Level for a particular SQL statement?</strong></p>
<blockquote><p>You cannot enable SNAPSHOT Isolation level at statement level.</p>
<p>You have to enable at the database level and after enabling all your database transactions will execute in MVCC fashion.</p></blockquote>
<p><strong>What is the difference between READ_COMMITTED_SNAPSHOT option and Snapshot Isolation Level?</strong></p>
<blockquote><p>Using READ_COMMITTED_SNAPSHOT option, you can SELECT old version of rows while it is updating, but you cannot execute new UPDATE on the same data until it finished a running UPDATE.</p>
<p>Using SNAPSHOT ISOLATION LEVEL, you can perform any kind of DML operation because it is managing different data version in the TempDB so the reader and writer never blocked by each other.</p></blockquote>
<p><strong>What is a Shared lock?</strong></p>
<blockquote><p>Shared (S): Used for read operations that do not change or update data, such as a SELECT statement.</p></blockquote>
<p><strong>What is an Update lock?</strong></p>
<blockquote><p>Update(U): Used on resources that can be updated. Prevents a common form of deadlock that occurs when multiple sessions are reading, locking, and potentially updating resources later.</p></blockquote>
<p><strong>What is an Exclusive lock?</strong></p>
<blockquote><p>Exclusive(X): Used for data-modification operations, such as INSERT, UPDATE, or DELETE. Ensures that multiple updates cannot be made to the same resource at the same time.</p></blockquote>
<p><strong>What is an Intent lock?</strong></p>
<blockquote><p>The Database Engine uses intent locks to protect placing a shared (S) lock or exclusive (X) lock on a resource lower in the lock hierarchy. Intent locks are named intent locks because they are acquired before a lock at the lower level, and therefore signal intent to place locks at a lower level.</p></blockquote>
<p><strong>What is a Schema lock?</strong></p>
<blockquote><p>The Database Engine uses schema modification (Sch-M) locks during a table data definition language (DDL) operation, such as adding a column or dropping a table. During the time that it is held, the Sch-M lock prevents concurrent access to the table.</p></blockquote>
<p><strong>What is a Bulk Update lock?</strong></p>
<blockquote><p>BulkUpdate (BU): Used when bulk copying data into a table and the TABLOCK hint is specified.</p></blockquote>
<p><strong>What is a Key range lock?</strong></p>
<blockquote><p>Key-range locks protect a range of rows implicitly included in a record set being read by a Transact-SQL statement while using the serializable transaction isolation level. Key-range locking prevents phantom reads.</p>
<p>A key range lock protects this requirement by preventing other transactions from inserting new rows whose keys would fall in the range of keys read by the serializable transaction.</p></blockquote>
<p><strong>Do you think lock is reducing the performance of the database system?</strong></p>
<blockquote><p>For large computer systems, locks on frequently referenced objects can become a performance bottleneck as acquiring and releasing locks place contention on internal locking resources.</p></blockquote>
<p><strong>What do you know about the lock partitioning?</strong></p>
<blockquote><p>Lock partitioning enhances locking performance by splitting a single lock resource into multiple lock resources. This feature is only available for systems with 16 or more CPUs, and is automatically enabled and cannot be disabled. Only object locks can be partitioned.</p></blockquote>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?</title>
		<link>https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/</link>
					<comments>https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 06 Apr 2016 20:26:13 +0000</pubDate>
				<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[Timeout]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2353</guid>

					<description><![CDATA[Timeout: When the client application is waiting for a require resource, Timeout occurs. There are multiple reasons for Timeout like transaction blocking, the distance network, high CPU utilization and multiple request user request at one time. The Database Timeout cannot affect to other running connection, and it treated independently, but for solving the Timeout issue [&#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%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&amp;linkname=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%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%2F2016%2F04%2Fdatabase-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system%2F&#038;title=Database%20Theory%3A%20What%20is%20Timeout%2C%20Lock%2C%20Block%2C%20and%20Deadlock%20in%20a%20Database%20System%3F" data-a2a-url="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/" data-a2a-title="Database Theory: What is Timeout, Lock, Block, and Deadlock in a Database System?"></a></p><p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/DeadlockBlockingLocking.jpg" rel="attachment wp-att-2360"><img loading="lazy" decoding="async" class="aligncenter wp-image-2360 " title="Deadlock Blocking Locking" src="https://www.dbrnd.com/wp-content/uploads/2016/04/DeadlockBlockingLocking-1024x811.jpg" alt="Deadlock Blocking Locking" width="430" height="320" /></a></p>
<p><strong>Timeout:</strong></p>
<blockquote><p>When the client application is waiting for a require resource, Timeout occurs.</p>
<p>There are multiple reasons for Timeout like transaction blocking, the distance network, high CPU utilization and multiple request user request at one time.</p>
<p>The Database Timeout cannot affect to other running connection, and it treated independently, but for solving the Timeout issue we need to check other causes like OS response, Network response, Database Timeout threshold value, number of Database Connections and other.</p></blockquote>
<p><strong>Lock: </strong></p>
<blockquote><p>When one process is accessing an object, it can request for a lock for that particular object so that other processes cannot perform read or update on that object.</p>
<p>There are different types of lock like Exclusive Lock, Non-exclusive Lock.</p>
<p>An Exclusive Lock prevents object or data from the reading and writing both the actions.<br />
A Non-Exclusive Lock allows read-only access for an object or data, but it prevents the write action for an object or data.</p></blockquote>
<p><strong>Block:</strong></p>
<blockquote><p>If two processes are accessing the same resource so at that time one process has to wait until the other process releases the occupied resource.</p>
<p>This is called blocking because one transaction is blocked by another transaction and all blocked processes kept in the waiting queue.</p>
<p>If the blocked transaction is waiting for a long time, it may generate a Database Timeout.<br />
If the long-running blocked transaction requires a lock, it may generate a Database Deadlock.</p></blockquote>
<p><strong>Deadlock:<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/Deadlock.jpg" rel="attachment wp-att-2363"><img loading="lazy" decoding="async" class="alignright wp-image-2363 " title="Database Deadlock" src="https://www.dbrnd.com/wp-content/uploads/2016/04/Deadlock-300x250.jpg" alt="Database Deadlock" width="317" height="266" /></a></strong></p>
<blockquote><p>One X process is waiting to complete the transaction of the Y process, and the same time, Y process is blocked because it is also waiting to complete the transaction of the X process.<br />
This is called as Deadlock situation.</p>
<p>In the Deadlock situation, both the processes trying to access a particular resource and also has a lock on that resource by each other, so both are waiting for each other to release a lock and complete the transaction.</p>
<p>Deadlock is a next stage of the blocking situation so if you want to avoid Deadlock situation, you should first find the blocked transaction and tried to remove internal dependency for those transactions.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
