<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dead tuples &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/dead-tuples/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 16 Jan 2018 11:34:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Greenplum: Script to find Table Fragmentation and total wasted space</title>
		<link>https://www.dbrnd.com/2018/02/greenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples/</link>
					<comments>https://www.dbrnd.com/2018/02/greenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 06 Feb 2018 16:16:38 +0000</pubDate>
				<category><![CDATA[Greenplum]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[bloat]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[dead tuples]]></category>
		<category><![CDATA[Greenplum Administrator]]></category>
		<category><![CDATA[Greenplum Error]]></category>
		<category><![CDATA[Greenplum Monitoring]]></category>
		<category><![CDATA[Greenplum Performance Tuning]]></category>
		<category><![CDATA[Greenplum Programming]]></category>
		<category><![CDATA[Greenplum Query]]></category>
		<category><![CDATA[Greenplum Tips and Tricks]]></category>
		<category><![CDATA[pg_size_pretty]]></category>
		<category><![CDATA[PostgreSQL 8.2]]></category>
		<category><![CDATA[table fragmentation]]></category>
		<category><![CDATA[wasted space]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4368</guid>

					<description><![CDATA[I recently started work with Greenplum Distributed RDBMS. Internally, it is using PostgreSQL 8.2 which is an ancient version of PostgreSQL. I shared a couple of articles on finding the fragmentation in PostgreSQL, but none of my scripts worked for Greenplum PostgreSQL 8.2. I have Posted one question on StackOverflow. Please check this link. Finally, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&amp;linkname=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F02%2Fgreenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples%2F&#038;title=Greenplum%3A%20Script%20to%20find%20Table%20Fragmentation%20and%20total%20wasted%20space" data-a2a-url="https://www.dbrnd.com/2018/02/greenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples/" data-a2a-title="Greenplum: Script to find Table Fragmentation and total wasted space"></a></p><p>I recently started work with Greenplum Distributed RDBMS. Internally, it is using PostgreSQL 8.2 which is an ancient version of PostgreSQL. </p>
<blockquote><p>I shared a couple of articles on finding the fragmentation in PostgreSQL, but none of my scripts worked for Greenplum PostgreSQL 8.2.</p></blockquote>
<p><a href="http://stackoverflow.com/questions/41564856/how-to-find-dead-tuples-fragmentation-in-postgresql-8-2-for-greenplum" target="_blank">I have Posted one question on StackOverflow. Please check this link.</a></p>
<blockquote><p>Finally, I found a script for finding the fragmentation of Greenplum tables which is very important for Greenplum DBA because Greenplum is a based on MVCC architecture which generates dead rows at every UPDATE / DELETE. </p></blockquote>
<blockquote class="wp-embedded-content" data-secret="HUgKW8A8OK"><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=HUgKW8A8OK" data-secret="HUgKW8A8OK" 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 use below script for finding the wasted space of the tables and can execute VACUUM ANALYZE on those tables. </p>
<pre class="crayon-plain-tag">select
	current_database() as dbname
	, relid
	, schemaname
	, tablename
	, round(bloat,1) as bloat_ratio
	, pg_size_pretty(expbytes) as expected_size
	, pg_size_pretty(relbytes) as relation_size
	, pg_size_pretty(wastedbytes) as wasted_space
	, round(1.0 * relbytes / nullif((sum(relbytes) over ())::bigint,0),4) as relative_size
	, round((bloat-1) * (1.0 * relbytes / nullif((sum(relbytes) over ())::bigint, 0)), 8) as concern
from
(
	SELECT
		relid
		, schemaname
		, tablename
		, CASE WHEN otta=0 THEN 
			0.0 
			ELSE 
			sml.relpages/otta::numeric 
			END AS bloat
		, reltuples::bigint
		, relpages::bigint
		, otta
		, (bs*otta)::bigint as expbytes
		, CASE WHEN relpages &lt; otta THEN 0 ELSE 
		(bs*(sml.relpages-otta))::bigint 
		END AS wastedbytes
		, CASE WHEN relpages &lt; otta THEN 0 ELSE relpages::bigint - otta END AS wastedpages
		, (bs*relpages)::bigint as relbytes
	FROM
	(
		SELECT
			schemaname
			, tablename
			, cc.oid as relid
			, cc.reltuples
			, cc.relpages
			, bs
			, CEIL((cc.reltuples*((datahdr+ma-(CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::float)) AS otta 
		FROM 
		(
			SELECT
				ma
				, bs
				, schemaname
				, tablename
				, (datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr
				, (maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2
			FROM
			(
				SELECT
					schemaname
					, tablename
					, hdr
					, ma
					, bs
					, SUM((1-s.null_frac)*avg_width) AS datawidth
					, MAX(s.null_frac) AS maxfracsum
					, hdr+(1+(count(case when s.null_frac&lt;&gt;0 then 1 end))/8) as nullhdr
				FROM 
				pg_stats s
				cross join 
				(
					SELECT
					current_setting('block_size')::numeric AS bs
					, CASE WHEN substring(version(),12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr
					, CASE WHEN version() ~ 'mingw32' THEN 8 ELSE 4 END AS ma
				) AS constants
				GROUP BY schemaname, tablename, hdr, ma, bs
			) AS foo
		) AS rs
		JOIN pg_class cc 
		ON
		cc.relname = rs.tablename 
		and cc.relkind = 'r'
		JOIN pg_namespace nn 
		ON
		cc.relnamespace = nn.oid 
		AND nn.nspname = rs.schemaname 
	) AS sml
) wrapper
where wastedbytes &gt; 2*1024*1024 and bloat &gt;= 1.4order by (bloat-1) * (1.0 * relbytes / nullif((sum(relbytes) over ())::bigint, 0)) desc;</pre> </p>
<p><strong><a href="http://www.dbaref.com/home/greenplum-dba-quick-reference/checkingbloatswithcustomizedscripts" target="_blank">Taken reference from this article </a></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/02/greenplum-script-to-find-table-fragmentation-and-total-wasted-space-dead-tuples/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</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 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>
	</channel>
</rss>
