<?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_class &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/pg_class/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, 17 Jul 2018 07:05:56 +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 all Objects of a Particular User</title>
		<link>https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/</link>
					<comments>https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 03 Sep 2018 16:16:58 +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[Database Role]]></category>
		<category><![CDATA[database user]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_roles]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres]]></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=7708</guid>

					<description><![CDATA[In this post, I am sharing a script for getting the list of objects of a particular User (Owner of the Object) in PostgreSQL. Generally, PostgreSQL DBAs are using this kind of script for auditing purpose and object tracking purpose. Using the below script, you can get the list object for a particular user: I [&#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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" 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%2F09%2Fpostgresql-script-to-find-all-objects-of-a-particular-user%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20all%20Objects%20of%20a%20Particular%20User" data-a2a-url="https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/" data-a2a-title="PostgreSQL: Script to find all Objects of a Particular User"></a></p><p>In this post, I am sharing a script for getting the list of objects of a particular User (Owner of the Object) in PostgreSQL.<br />
Generally, PostgreSQL DBAs are using this kind of script for auditing purpose and object tracking purpose. </p>
<p>Using the below script, you can get the list object for a particular user:</p>
<p>I used a &#8216;postgres&#8217; default user in WHERE condition, which you can edit as per your user.</p>
<pre class="crayon-plain-tag">select 
    nsp.nspname as SchemaName
    ,cls.relname as ObjectName 
    ,rol.rolname as ObjectOwner
    ,case cls.relkind
        when 'r' then 'TABLE'
        when 'm' then 'MATERIALIZED_VIEW'
        when 'i' then 'INDEX'
        when 'S' then 'SEQUENCE'
        when 'v' then 'VIEW'
        when 'c' then 'TYPE'
        else cls.relkind::text
    end as ObjectType
from pg_class cls
join pg_roles rol 
	on rol.oid = cls.relowner
join pg_namespace nsp 
	on nsp.oid = cls.relnamespace
where nsp.nspname not in ('information_schema', 'pg_catalog')
    and nsp.nspname not like 'pg_toast%'
    and rol.rolname = 'postgres'  
order by nsp.nspname, cls.relname</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find the Used space by TOAST Table</title>
		<link>https://www.dbrnd.com/2017/12/postgresql-script-to-find-the-used-space-by-toast-table/</link>
					<comments>https://www.dbrnd.com/2017/12/postgresql-script-to-find-the-used-space-by-toast-table/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 29 Dec 2017 16:16:27 +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_class]]></category>
		<category><![CDATA[pg_index]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[toast table]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6852</guid>

					<description><![CDATA[If you don&#8217;t know about the TOAST Table, please visit the below article. PostgreSQL: What is TOAST (The Oversized-Attribute Storage Technique) In this post, I am sharing a script to check the used space by the TOAST tables in the PostgreSQL. We should avoid the auto-creation of TOAST table which is not suitable for database [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" 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-script-to-find-the-used-space-by-toast-table%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20the%20Used%20space%20by%20TOAST%20Table" data-a2a-url="https://www.dbrnd.com/2017/12/postgresql-script-to-find-the-used-space-by-toast-table/" data-a2a-title="PostgreSQL: Script to find the Used space by TOAST Table"></a></p><p>If you don&#8217;t know about the TOAST Table, please visit the below article. </p>
<blockquote class="wp-embedded-content" data-secret="N0UPzzgQem"><p><a href="https://www.dbrnd.com/2016/10/postgresql-what-is-toast-the-oversized-attribute-storage-technique-exceed-8-kb-data-page-size-extended-storage/">PostgreSQL: What is TOAST (The Oversized-Attribute Storage Technique)</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/10/postgresql-what-is-toast-the-oversized-attribute-storage-technique-exceed-8-kb-data-page-size-extended-storage/embed/#?secret=N0UPzzgQem" data-secret="N0UPzzgQem" width="600" height="338" title="&#8220;PostgreSQL: What is TOAST (The Oversized-Attribute Storage Technique)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In this post, I am sharing a script to check the used space by the TOAST tables in the PostgreSQL. </p>
<blockquote><p>We should avoid the auto-creation of TOAST table which is not suitable for database performance.<br />
Using below script, you can find the size and can take the appropriate decision on the biggest TOAST table of your database.</p></blockquote>
<p>Below script is returning two columns where relpages is a number of occupied pages by the TOAST table. (1 page = 8kb)</p>
<pre class="crayon-plain-tag">SELECT 
    relname
    ,relpages
FROM pg_class,
     (SELECT reltoastrelid
      FROM pg_class) AS ss
WHERE oid = ss.reltoastrelid OR
      oid = (SELECT indexrelid
             FROM pg_index
             WHERE indrelid = ss.reltoastrelid)
ORDER BY relname;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/12/postgresql-script-to-find-the-used-space-by-toast-table/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Move Table with Data from one Schema to another Schema</title>
		<link>https://www.dbrnd.com/2017/11/postgresql-move-table-with-data-from-one-schema-to-another-schema/</link>
					<comments>https://www.dbrnd.com/2017/11/postgresql-move-table-with-data-from-one-schema-to-another-schema/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 23 Nov 2017 16:16:54 +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_catalog]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_type]]></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>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[Table Copy]]></category>
		<category><![CDATA[Table Move]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6126</guid>

					<description><![CDATA[In this post, I am sharing a quick way to move your table with data from one schema to another schema of PostgreSQL. I already shared an article on, how to copy a table from one schema to another schema. PostgreSQL: Script to copy Table Data from one Schema to another Schema For moving 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%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&amp;linkname=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fpostgresql-move-table-with-data-from-one-schema-to-another-schema%2F&#038;title=PostgreSQL%3A%20Move%20Table%20with%20Data%20from%20one%20Schema%20to%20another%20Schema" data-a2a-url="https://www.dbrnd.com/2017/11/postgresql-move-table-with-data-from-one-schema-to-another-schema/" data-a2a-title="PostgreSQL: Move Table with Data from one Schema to another Schema"></a></p><p>In this post, I am sharing a quick way to move your table with data from one schema to another schema of PostgreSQL. </p>
<p>I already shared an article on, how to copy a table from one schema to another schema. </p>
<blockquote class="wp-embedded-content" data-secret="xeMf9dtttF"><p><a href="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/">PostgreSQL: Script to copy Table Data from one Schema to another Schema</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/embed/#?secret=xeMf9dtttF" data-secret="xeMf9dtttF" width="600" height="338" title="&#8220;PostgreSQL: Script to copy Table Data from one Schema to another Schema&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>For moving the table between the schemas is a very simple, you should just update the entry in pg_class and pg_type table.<br />
Something like update the table schema name from old to the new basis on given table name. </p>
<p><strong>Please check the below solution, try it your self:</strong></p>
<pre class="crayon-plain-tag">UPDATE pg_catalog.pg_class
SET relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
                    WHERE nspname = 'destination_schema')
WHERE relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
                      WHERE nspname = 'source_schema')
AND relname = 'table_name';</pre> </p>
<pre class="crayon-plain-tag">UPDATE pg_catalog.pg_type
SET typnamespace = (SELECT oid FROM pg_catalog.pg_namespace
                    WHERE nspname = 'destination_schema')
WHERE typnamespace = (SELECT oid FROM pg_catalog.pg_namespace
                      WHERE nspname = 'source_schema')
AND typname = 'table_name';</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/11/postgresql-move-table-with-data-from-one-schema-to-another-schema/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find Orphaned Sequence, not owned by any Column</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 03 Apr 2017 16:16:28 +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[orphan sequence]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_depend]]></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[Sequence object]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3818</guid>

					<description><![CDATA[In this post, I am sharing a script to find orphaned Sequence objects which not owned by any column of PostgreSQL Database. When we define a column using SERIAL or BIGSERIAL, PostgreSQL internally creates one sequence for it and associate with it. In RDBMS, A Sequence is an independent object, and you can use same [&#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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" 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-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20Orphaned%20Sequence%2C%20not%20owned%20by%20any%20Column" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-script-to-find-orphaned-sequence-not-owned-by-any-column-dba-can-remove-unwanted-sequence/" data-a2a-title="PostgreSQL: Script to find Orphaned Sequence, not owned by any Column"></a></p><p>In this post, I am sharing a script to find orphaned Sequence objects which not owned by any column of PostgreSQL Database. </p>
<blockquote><p>When we define a column using SERIAL or BIGSERIAL, PostgreSQL internally creates one sequence for it and associate with it.<br />
In RDBMS, A Sequence is an independent object, and you can use same sequence object for multiple tables as well. </p></blockquote>
<blockquote><p>In a development environment, we are executing DDL frequently commands like multiple CREATE or DROP statements, so there is possibility of Orphaned Sequence. </p></blockquote>
<p>A Database Administrator can use this script to remove unwanted Sequence and make sure that Postgres database is up to date.</p><pre class="crayon-plain-tag">SELECT 
	ns.nspname AS SchemaName
	,c.relname AS SequenceName
FROM pg_class AS c
JOIN pg_namespace AS ns 
	ON c.relnamespace=ns.oid
WHERE c.relkind = 'S'
  AND NOT EXISTS (SELECT * FROM pg_depend WHERE objid=c.oid AND deptype='a')
ORDER BY c.relname;</pre><p> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to find total Live Tuples and Dead Tuples (Row) of a Table</title>
		<link>https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/</link>
					<comments>https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 04 Oct 2016 16:16:17 +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[dead tuples]]></category>
		<category><![CDATA[live tuples]]></category>
		<category><![CDATA[Multi version concurrency control]]></category>
		<category><![CDATA[MVCC]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_stat_get_dead_tuples()]]></category>
		<category><![CDATA[pg_stat_get_live_tuples()]]></category>
		<category><![CDATA[pg_stat_user_tables]]></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[VACUUM]]></category>
		<category><![CDATA[VACUUM FULL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3701</guid>

					<description><![CDATA[This is one of the very important post for all PostgreSQL Database Professionals. In this post, I am sharing a small, but very powerful script to know about the Live Tuples (Rows) and Dead Tuples (Rows) of the PostgreSQL Object like: Tables and Indexes. If you don&#8217;t know about the MVCC (Multi Version Concurrency Control), [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fpostgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance%2F&#038;title=PostgreSQL%3A%20Script%20to%20find%20total%20Live%20Tuples%20and%20Dead%20Tuples%20%28Row%29%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/" data-a2a-title="PostgreSQL: Script to find total Live Tuples and Dead Tuples (Row) of a Table"></a></p><p>This is one of the very important post for all PostgreSQL Database Professionals. </p>
<blockquote><p>In this post, I am sharing a small, but very powerful script to know about the Live Tuples (Rows) and Dead Tuples (Rows) of the PostgreSQL Object like: Tables and Indexes. </p></blockquote>
<p>If you don&#8217;t know about the MVCC (Multi Version Concurrency Control), Please visit this article. </p>
<blockquote data-secret="xsJ3wB5C2a" 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 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=xsJ3wB5C2a" data-secret="xsJ3wB5C2a" 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>
<blockquote><p>PostgreSQL is based on MVCC Architecture. </p>
<p>In MVCC Architecture, When you update or delete any row, Internally It creates the new row and mark old row as unused. </p>
<p>This kind of data, we call as Dead Tuples or Dead Rows. (We can also say like, This is an internal fragmentation).
</p></blockquote>
<p>Periodically, We should find dead rows of the object and we should remove it using VACUUM techniques of PostgreSQL.<br />
By this way, we can increase the overall performance of PostgreSQL Database Server. </p>
<blockquote data-secret="LxJHZJGjlB" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/">PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/embed/#?secret=LxJHZJGjlB" data-secret="LxJHZJGjlB" width="600" height="338" title="&#8220;PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Find out Live Tuples or Dead Tuples using two different scripts. </strong></p>
<p><strong>Using system function and pg_class:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	relname AS ObjectName
	,pg_stat_get_live_tuples(c.oid) AS LiveTuples
	,pg_stat_get_dead_tuples(c.oid) AS DeadTuples
FROM pg_class c;</pre> </p>
<p><strong>Using pg_stat_user_tables:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	relname AS TableName
	,n_live_tup AS LiveTuples
	,n_dead_tup AS DeadTuples
FROM pg_stat_user_tables;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/10/postgresql-script-to-find-total-live-tuples-and-dead-tuples-row-of-a-table-execute-vacuum-remove-fragmentation-improve-performance/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</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: Important Statistics Table, Used by the Query Planner</title>
		<link>https://www.dbrnd.com/2016/09/postgresql-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 04 Sep 2016 12:55:17 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[ANALYZE]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_stats]]></category>
		<category><![CDATA[planner]]></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[query optimzer]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[VACUUM]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3585</guid>

					<description><![CDATA[In any RDBMS system, Different type of Statistics is very important for Query Optimizer and Planner to choose and generate the best Query Execution Plan. PostgreSQL Database Server also managing different types of Statistic which are used by the Query Optimizer to generate the best Query Execution Plan. Statistical data should be updated, Why? 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%2F2016%2F09%2Fpostgresql-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&amp;linkname=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" 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-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze%2F&#038;title=PostgreSQL%3A%20Important%20Statistics%20Table%2C%20Used%20by%20the%20Query%20Planner" data-a2a-url="https://www.dbrnd.com/2016/09/postgresql-important-statistics-table-used-by-the-query-planner-pg_class-pg_stats-vacuum-analyze/" data-a2a-title="PostgreSQL: Important Statistics Table, Used by the Query Planner"></a></p><p>In any RDBMS system, Different type of Statistics is very important for Query Optimizer and Planner to choose and generate the best Query Execution Plan. </p>
<blockquote><p>PostgreSQL Database Server also managing different types of Statistic which are used by the Query Optimizer to generate the best Query Execution Plan. </p></blockquote>
<p><strong>Statistical data should be updated, Why?</strong><br />
For Example, </p>
<blockquote><p>We have one table with 100000 rows, but table statistic data are not updated and showing only 1000 tuples information. </p></blockquote>
<blockquote><p>Query optimizer always looks into Statistic tables, It never looks into direct table files. </p></blockquote>
<blockquote><p>So in this situation, It generates the wrong Query Execution Plan because It has only 1000 rows information, but actually there are 100000 rows. </p></blockquote>
<p>PostgreSQL Database Server is mainly using two Statistical Table. </p>
<pre class="crayon-plain-tag">SELECT *FROM pg_class;
SELECT *FROM pg_stats;</pre> </p>
<blockquote><p>You can also query these tables and can find information about Tables, Indexes, Pages and others. </p></blockquote>
<blockquote><p>When you look into table pg_class, you can find &#8220;reltuples&#8221; column. You can compare this column value with your actual table record count. </p></blockquote>
<blockquote><p>If you find any mismatch, for that table statistic information is not updated. </p></blockquote>
<p><strong>Execute Analyze command:</strong></p>
<blockquote><p>When you find that Statistical information is not updated, you can execute the ANALYZE command on the Database or Table.<br />
After executing the ANALYZE command, It updates all require statistics.
</p></blockquote>
<blockquote class="wp-embedded-content" data-secret="es4VwJnXrq"><p><a href="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/">PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/postgresql-short-note-on-vacuum-vacuum-full-and-analyze/embed/#?secret=es4VwJnXrq" data-secret="es4VwJnXrq" width="600" height="338" title="&#8220;PostgreSQL: Short note on VACUUM, VACUUM FULL and ANALYZE&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Fast way to find the row count of a Table</title>
		<link>https://www.dbrnd.com/2015/10/postgresql-fast-way-to-find-the-row-count-of-a-table/</link>
					<comments>https://www.dbrnd.com/2015/10/postgresql-fast-way-to-find-the-row-count-of-a-table/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 08 Oct 2015 19:16:00 +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_class]]></category>
		<category><![CDATA[pg_stat_user_tables]]></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[row count]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=826</guid>

					<description><![CDATA[If a table has a 5000 or 500000 or 5000000000 records and the requirement is to find the total row count of the table, most of the Database Developer always executes COUNT(*) for getting the row count. I found that many of our team members also execute COUNT(*), but just imagine that table has 5000000000 [&#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%2F2015%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" 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%2F10%2Fpostgresql-fast-way-to-find-the-row-count-of-a-table%2F&#038;title=PostgreSQL%3A%20Fast%20way%20to%20find%20the%20row%20count%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2015/10/postgresql-fast-way-to-find-the-row-count-of-a-table/" data-a2a-title="PostgreSQL: Fast way to find the row count of a Table"></a></p><p>If a table has a 5000 or 500000 or 5000000000 records and the requirement is to find the total row count of the table, most of the Database Developer always executes COUNT(*) for getting the row count.</p>
<p>I found that many of our team members also execute COUNT(*), but just imagine that table has 5000000000 rows and COUNT(*) is taking a long time for getting the number of records. </p>
<p>The counting of the rows in such a big table always creates the performance issue and its also required I/O operation.</p>
<blockquote><p><strong>If you need exact row count for a given time, COUNT(*) is mandatory.<br />
But you can speed up this dramatically if the count does not have to be exact.<br />
You can use a metadata table or statistical table to find the row count, which is quite same as real row count.</strong></p></blockquote>
<p>Because the nature of MVCC, sometimes you can find the difference between actual record count and statistical table&#8217;s record count. </p>
<blockquote class="wp-embedded-content" data-secret="XCAWLM8eZm"><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=XCAWLM8eZm" data-secret="XCAWLM8eZm" 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>You can easily find roughly row count using statistical tables within 1 second. </p>
<blockquote><p>
I tested and compared the two results in my local machine with the row count of 5000000000.</p>
<p>My COUNT (*) returns a result after 8 to 10 minutes and also taken 10% to 25% CPU and Memory.<br />
After this, I found row count from the statistical table, and it didn&#8217;t take even one second.</p>
<p><strong>But I found the little difference between both the count. The count of a statistical table is higher than the actual count. (12585-row count is greater) because of MVCC.</strong></p>
<p><strong> You should configure auto-vacuum and analyze on the table.</strong></p>
<p><strong> I executed vacuum and analyze on the table, and now my count is same. </strong></p></blockquote>
<p>I would suggest, please use the statistical table for the row counts.<br />
I am providing two different scripts for finding the rough row count in the PostgreSQL.</p>
<pre class="crayon-plain-tag">SELECT reltuples::bigint AS EstimatedCount
FROM   pg_class
WHERE  oid = 'public.TableName'::regclass;</pre> </p>
<pre class="crayon-plain-tag">SELECT 
	schemaname
	,relname
	,n_live_tup AS EstimatedCount 
FROM pg_stat_user_tables 
ORDER BY n_live_tup DESC;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/10/postgresql-fast-way-to-find-the-row-count-of-a-table/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Script to Find Table and Column without comment or description</title>
		<link>https://www.dbrnd.com/2015/09/postgresql-script-to-find-table-and-column-without-comment-or-description/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 24 Sep 2015 16:38:42 +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_attribute]]></category>
		<category><![CDATA[pg_class]]></category>
		<category><![CDATA[pg_description]]></category>
		<category><![CDATA[pg_get_userbyid]]></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=715</guid>

					<description><![CDATA[In this post, I am sharing a script to find the table and column, which are not associated with any comment or description of PostgreSQL. Self-documentation is a most important thing for every developer and organization. In our company, We are very strictly following this rule as a database development standard in which we have [&#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%2F2015%2F09%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&amp;linkname=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" 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%2Fpostgresql-script-to-find-table-and-column-without-comment-or-description%2F&#038;title=PostgreSQL%3A%20Script%20to%20Find%20Table%20and%20Column%20without%20comment%20or%20description" data-a2a-url="https://www.dbrnd.com/2015/09/postgresql-script-to-find-table-and-column-without-comment-or-description/" data-a2a-title="PostgreSQL: Script to Find Table and Column without comment or description"></a></p><p>In this post, I am sharing a script to find the table and column, which are not associated with any comment or description of PostgreSQL.</p>
<p>Self-documentation is a most important thing for every developer and organization.<br />
In our company, We are very strictly following this rule as a database development standard in which we have to write a comment or description for every table and column.</p>
<blockquote><p>You can also manage this description using different UML tools.<br />
But better to other tools, we should write in the database so whenever you create a database diagram, comment or description added automatically.</p>
<p>The Humans are doing a mistake, so sometimes I have to find such a list objects which didn&#8217;t associate with any comment or description.</p></blockquote>
<p>I filtered below query by giving User_Name in WHERE clause, so if you want for all users, you should remove this filter. </p>
<p><strong>Find Table without comment.</strong></p>
<pre class="crayon-plain-tag">SELECT 
	pg_get_userbyid(pc.relowner)AS ObjectOwner
	,pc.relname AS TableName
	,pd.description AS Comment
FROM pg_class AS pc
LEFT OUTER JOIN pg_description AS pd 
	ON (pc.oid = pd.objoid)
WHERE pg_get_userbyid(pc.relowner) ='User_Name'
	AND pc.relkind = 'r'
	AND pd.description IS NULL;</pre> </p>
<p><strong>Find Column without comment. </strong></p>
<pre class="crayon-plain-tag">SELECT 
	pg_get_userbyid(pc.relowner) AS ObjectOwner
	,pc.relname AS TableName
	,pa.attname AS ColumnName
	,pd.description AS Comment
FROM pg_attribute AS pa
JOIN pg_class AS pc 
	ON (pa.attrelid = pc.oid)
LEFT OUTER JOIN pg_description AS pd 
	ON (pc.oid = pd.objoid AND pa.attnum = pd.objsubid)
WHERE pg_get_userbyid(pc.relowner) ='User_Name'
	AND pc.relkind = 'r'
	AND pd.description IS NULL
	AND pa.attnum &gt; 0
ORDER BY pa.attname;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
