<?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>pg_locks &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/pg_locks/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, 15 Sep 2017 10:27:55 +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: 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 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>Script to find sessions that are blocking other sessions in PostgreSQL</title>
		<link>https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/</link>
					<comments>https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 23 Sep 2015 17:17:31 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[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=711</guid>

					<description><![CDATA[In this post, I am sharing a script to find sessions that are blocking other sessions in PostgreSQL. Instead of finding blocked sessions or processes, sometimes it is better to find those sessions which are the root of blocking. PostgreSQL DBA can use this script to find the cause of blocked transactions. [crayon-6aa0a840ddfd6932239785/]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&amp;linkname=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fscript-to-find-sessions-that-are-blocking-other-sessions-in-postgresql%2F&#038;title=Script%20to%20find%20sessions%20that%20are%20blocking%20other%20sessions%20in%20PostgreSQL" data-a2a-url="https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/" data-a2a-title="Script to find sessions that are blocking other sessions in PostgreSQL"></a></p><p>In this post, I am sharing a script to find sessions that are blocking other sessions in PostgreSQL.</p>
<p>Instead of finding blocked sessions or processes, sometimes it is better to find those sessions which are the root of blocking.</p>
<p>PostgreSQL DBA can use this script to find the cause of blocked transactions. </p>
<pre class="crayon-plain-tag">SELECT 
	pl.pid as blocked_pid
	,psa.usename as blocked_user
	,pl2.pid as blocking_pid
	,psa2.usename as blocking_user
	,psa.query as blocked_statement
FROM pg_catalog.pg_locks pl
JOIN pg_catalog.pg_stat_activity psa
	ON pl.pid = psa.pid
JOIN pg_catalog.pg_locks pl2
JOIN pg_catalog.pg_stat_activity psa2
	ON pl2.pid = psa2.pid
	ON pl.transactionid = pl2.transactionid 
		AND pl.pid != pl2.pid
WHERE NOT pl.granted;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/09/script-to-find-sessions-that-are-blocking-other-sessions-in-postgresql/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
