<?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_stat_activity &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/pg_stat_activity/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 11 Dec 2017 06:22:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>PostgreSQL: Important Statistics Views for Monitoring the Server</title>
		<link>https://www.dbrnd.com/2017/12/postgresql-important-statistics-views-for-monitoring-the-server/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 25 Dec 2017 16:16:24 +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[pg_stat_activity]]></category>
		<category><![CDATA[pg_stat_ssl]]></category>
		<category><![CDATA[pg_stat_user_functions]]></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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6861</guid>

					<description><![CDATA[In this post, I am sharing few important system or statistics views which we can use for monitoring the PostgreSQL Server. We should monitor the different statistics of the server which help us for improving the overall database performance. Below are few important views: Return the running queries/connections information: [crayon-6aaf69085cb23340260116/] Return the SSL information for [&#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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" 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%2F12%2Fpostgresql-important-statistics-views-for-monitoring-the-server%2F&#038;title=PostgreSQL%3A%20Important%20Statistics%20Views%20for%20Monitoring%20the%20Server" data-a2a-url="https://www.dbrnd.com/2017/12/postgresql-important-statistics-views-for-monitoring-the-server/" data-a2a-title="PostgreSQL: Important Statistics Views for Monitoring the Server"></a></p><p>In this post, I am sharing few important system or statistics views which we can use for monitoring the PostgreSQL Server. </p>
<p>We should monitor the different statistics of the server which help us for improving the overall database performance.</p>
<p>Below are few important views:</p>
<p><strong>Return the running queries/connections information:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_activity</pre> </p>
<p><strong>Return the SSL information for each connection:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_ssl</pre> </p>
<p><strong>Check the database statistics:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_database</pre> </p>
<p><strong>Check the table statistics:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_all_tables</pre> </p>
<p><strong>Check the system table statistics:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_sys_tables</pre> </p>
<p><strong>Check the index statistics:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_all_indexes</pre> </p>
<p><strong>Check the user functions statistics:</strong></p>
<pre class="crayon-plain-tag">select * from pg_stat_user_functions</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Set Application Name for each Session and Connection</title>
		<link>https://www.dbrnd.com/2017/12/postgresql-set-application-name-for-each-session-and-connection-pg_stat_activity/</link>
					<comments>https://www.dbrnd.com/2017/12/postgresql-set-application-name-for-each-session-and-connection-pg_stat_activity/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 15 Dec 2017 16:16:24 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[application_name]]></category>
		<category><![CDATA[code debug]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6812</guid>

					<description><![CDATA[In this post, I am sharing one of the best practice we can use in our day to day work with PostgreSQL. pg_stat_activity &#8211; we are using this view for finding the information of running queries. In the result of this view, we can see one column which is Application_Name. Which shows the application name [&#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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&amp;linkname=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" 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%2F12%2Fpostgresql-set-application-name-for-each-session-and-connection-pg_stat_activity%2F&#038;title=PostgreSQL%3A%20Set%20Application%20Name%20for%20each%20Session%20and%20Connection" data-a2a-url="https://www.dbrnd.com/2017/12/postgresql-set-application-name-for-each-session-and-connection-pg_stat_activity/" data-a2a-title="PostgreSQL: Set Application Name for each Session and Connection"></a></p><p>In this post, I am sharing one of the best practice we can use in our day to day work with PostgreSQL.</p>
<p>pg_stat_activity &#8211; we are using this view for finding the information of running queries. In the result of this view, we can see one column which is Application_Name. Which shows the application name of database connection.</p>
<p>More than 90% of PostgreSQL people are not using this column or feature.<br />
In our project, thousand of adhoc queries, DBA queries, user queries and application queries are running in PostgreSQL Server.</p>
<blockquote><p>I defined the Application name for each group and set the rule, like for all DBA and User has to set the application name before executing their query.</p>
<p>So, now I can easily monitor the purpose of the query by checking the Application_name column of pg_stat_activity.</p></blockquote>
<p><strong>Check the demo:</strong></p>
<p><strong>Set application name in one of my session:</strong></p><pre class="crayon-plain-tag">SET application_name = 'test_activity';</pre><p>
<strong>Check the result:</strong><br />
In the result, you can find the query of test_activity application.</p><pre class="crayon-plain-tag">select *from pg_Stat_activity;</pre><p>
<img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-6814" src="https://www.dbrnd.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-23-at-4.32.58-PM.png" alt="postgresql application name " width="1178" height="338" srcset="https://www.dbrnd.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-23-at-4.32.58-PM.png 1178w, https://www.dbrnd.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-23-at-4.32.58-PM-1030x296.png 1030w, https://www.dbrnd.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-23-at-4.32.58-PM-850x244.png 850w, https://www.dbrnd.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-23-at-4.32.58-PM-679x195.png 679w" sizes="(max-width: 1178px) 100vw, 1178px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/12/postgresql-set-application-name-for-each-session-and-connection-pg_stat_activity/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL 9.6: Introduced wait_event_type and wait_event new columns of pg_stat_activity</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 10 Apr 2017 16:16:45 +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[pg_stat_activity]]></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[wait_event]]></category>
		<category><![CDATA[wait_event_type]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5012</guid>

					<description><![CDATA[PostgreSQL 9.6 introduced new two columns of table pg_stat_activity. The columns are wait_event_type and wait_event. The column wait_event_type reports the type of event a backend is waiting for, and the wait_event which is the name of the event being waiting for. These both columns are very useful for finding a query event information. Please check [&#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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" 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-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity%2F&#038;title=PostgreSQL%209.6%3A%20Introduced%20wait_event_type%20and%20wait_event%20new%20columns%20of%20pg_stat_activity" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-wait_event_type-and-wait_event-new-columns-of-pg_stat_activity/" data-a2a-title="PostgreSQL 9.6: Introduced wait_event_type and wait_event new columns of pg_stat_activity"></a></p><p>PostgreSQL 9.6 introduced new two columns of table pg_stat_activity. The columns are wait_event_type and wait_event.</p>
<p>The column wait_event_type reports the type of event a backend is waiting for, and the wait_event which is the name of the event being waiting for. These both columns are very useful for finding a query event information.</p>
<p><strong>Please check small demonstration of this:</strong></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>
<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>
<strong>Open a new query session, and try to insert a below record:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_students VALUES (1,'Anvesh');</pre><p>
<strong>Open a new query session, and check the output of pg_stat_activity:</strong></p><pre class="crayon-plain-tag">SELECT query, wait_event_type, wait_event FROM pg_stat_activity</pre><p>
<img decoding="async" class="alignnone wp-image-5014 size-full" title="PostgreSQL Stat Activity" src="https://www.dbrnd.com/wp-content/uploads/2017/04/PostgreSQLStatActivity.png" alt="PostgreSQL Stat Activity" width="731" height="135" srcset="https://www.dbrnd.com/wp-content/uploads/2017/04/PostgreSQLStatActivity.png 731w, https://www.dbrnd.com/wp-content/uploads/2017/04/PostgreSQLStatActivity-300x55.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/04/PostgreSQLStatActivity-150x28.png 150w" sizes="(max-width: 731px) 100vw, 731px" /></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 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: Script to kill all idle sessions and connections of a Database</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database/</link>
					<comments>https://www.dbrnd.com/2016/08/postgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 04 Aug 2016 06:00:57 +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_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>
		<category><![CDATA[state_change]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1837</guid>

					<description><![CDATA[In this post, I am sharing one of the important script to kill all running idle connections and sessions of the PostgreSQL Database. I have prepared this script such a way that you can also filter idle connections base on a particular time interval. We are Database Administrator, and this is our responsibility to check [&#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-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database%2F&#038;title=PostgreSQL%3A%20Script%20to%20kill%20all%20idle%20sessions%20and%20connections%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database/" data-a2a-title="PostgreSQL: Script to kill all idle sessions and connections of a Database"></a></p><p>In this post, I am sharing one of the important script to kill all running idle connections and sessions of the PostgreSQL Database. </p>
<p>I have prepared this script such a way that you can also filter idle connections base on a particular time interval. </p>
<p>We are Database Administrator, and this is our responsibility to check idle connection periodically and if it requires to kill, we should do it. </p>
<p>To kill the connections is always not advisable, but in large systems where lots of transactions are going on in that situation we should kill idle connections base on a particular time interval. </p>
<pre class="crayon-plain-tag">SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'Database_Name'
	AND pid &lt;&gt; pg_backend_pid()
	AND state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled') 
	AND state_change &lt; current_timestamp - INTERVAL '15' MINUTE;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/08/postgresql-script-to-kill-all-idle-long-running-sessions-and-connections-of-a-database/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</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-6aaf69085e25c449497023/]]]></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>
		<item>
		<title>Script to find active sessions or connections in PostgreSQL</title>
		<link>https://www.dbrnd.com/2015/09/script-to-find-active-sessions-or-connections-in-postgresql/</link>
					<comments>https://www.dbrnd.com/2015/09/script-to-find-active-sessions-or-connections-in-postgresql/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 22 Sep 2015 16:54:35 +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_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=699</guid>

					<description><![CDATA[In this post, I am sharing a psql script to find a running or active sessions and connections of PostgreSQL. This script is handy for PostgreSQL DBA. I am using this same script for our productions PostgreSQL server. Below is a script: I filtered &#8220;idle connections&#8221; [crayon-6aaf69085e4a5924267315/]]]></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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&amp;linkname=Script%20to%20find%20active%20sessions%20or%20connections%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-active-sessions-or-connections-in-postgresql%2F&#038;title=Script%20to%20find%20active%20sessions%20or%20connections%20in%20PostgreSQL" data-a2a-url="https://www.dbrnd.com/2015/09/script-to-find-active-sessions-or-connections-in-postgresql/" data-a2a-title="Script to find active sessions or connections in PostgreSQL"></a></p><p>In this post, I am sharing a psql script to find a running or active sessions and connections of PostgreSQL.</p>
<p>This script is handy for PostgreSQL DBA.<br />
I am using this same script for our productions PostgreSQL server.</p>
<p><strong>Below is a script:</strong><br />
I filtered &#8220;idle connections&#8221;</p>
<pre class="crayon-plain-tag">SELECT 
	pid
	,datname
	,usename
	,application_name
	,client_hostname
	,client_port
	,backend_start
	,query_start
	,query	
FROM pg_stat_activity
WHERE state &lt;&gt; 'idle'
AND pid&lt;&gt;pg_backend_pid();</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/09/script-to-find-active-sessions-or-connections-in-postgresql/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
