<?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>dead lock &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/dead-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>Fri, 31 Mar 2017 20:23:50 +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>PostgreSQL 9.6: Introduced a pg_blocking_pids function to get blocking process id</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 07 Apr 2017 16:16:27 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></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[dead lock]]></category>
		<category><![CDATA[pg_blocking_pids]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL 9.6]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></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=5003</guid>

					<description><![CDATA[PostgreSQL 9.6 introduced a pg_blocking_pids() to get a blocking process id of your running transaction. When multiple sessions are trying to access a table, and that table is locked. At that time, we need to find that blocking process id which blocked that table so that we can take necessary steps. Using pg_blocking_pids(), we can [&#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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" 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%2F04%2Fpostgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id%2F&#038;title=PostgreSQL%209.6%3A%20Introduced%20a%20pg_blocking_pids%20function%20to%20get%20blocking%20process%20id" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-a-pg_blocking_pids-function-to-get-blocking-process-id/" data-a2a-title="PostgreSQL 9.6: Introduced a pg_blocking_pids function to get blocking process id"></a></p><p>PostgreSQL 9.6 introduced a pg_blocking_pids() to get a blocking process id of your running transaction. </p>
<p>When multiple sessions are trying to access a table, and that table is locked. At that time, we need to find that blocking process id which blocked that table so that we can take necessary steps.</p>
<p>Using pg_blocking_pids(), we can get that head process id which is blocking other connections.</p>
<p><strong>Below is a full demonstration of this:</strong></p>
<p><strong>First, save your current process id:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_backend_pid();
-- my process id is: 6720</pre> </p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_students(rno int, name character varying(10));</pre> </p>
<p><strong>Put your table in lock mode:</strong></p>
<pre class="crayon-plain-tag">BEGIN TRANSACTION;
LOCK tbl_students IN ACCESS EXCLUSIVE MODE;</pre> </p>
<p><strong>Open a new session, and save process id for that session also:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_backend_pid();
-- my process id is: 5936</pre> </p>
<p><strong>Now in that new session, try to insert below record:</strong><br />
Your result will be in waiting mode&#8230;</p>
<pre class="crayon-plain-tag">INSERT INTO tbl_students VALUES (1,'Anvesh');</pre> </p>
<p><strong>Open a third new session, and execute below command with process id of your second session:</strong></p>
<pre class="crayon-plain-tag">SELECT pg_blocking_pids(5936);</pre> </p>
<p><strong>The result is:</strong></p>
<pre class="crayon-plain-tag">pg_blocking_pids
--------------------
{6720}</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
