<?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>measure &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/measure/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>Wed, 11 Oct 2017 11:12:51 +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: How to measure the size of a Table Row and Data Page?</title>
		<link>https://www.dbrnd.com/2016/03/postgresql-how-to-measure-the-size-of-a-table-row-and-data-page/</link>
					<comments>https://www.dbrnd.com/2016/03/postgresql-how-to-measure-the-size-of-a-table-row-and-data-page/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 29 Mar 2016 04:35:18 +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[Fillfactor]]></category>
		<category><![CDATA[measure]]></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=2193</guid>

					<description><![CDATA[In this post, I am sharing a script to measure the size of a PostgreSQL Table Row. I taken reference from this dba.statckexchange. But again, I would like to share this information with some additional information. Fillfactor storage parameter of PostgreSQL Table. Before changing the default value of Fillfactor, we should measure the size of [&#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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&amp;linkname=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" 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%2F03%2Fpostgresql-how-to-measure-the-size-of-a-table-row-and-data-page%2F&#038;title=PostgreSQL%3A%20How%20to%20measure%20the%20size%20of%20a%20Table%20Row%20and%20Data%20Page%3F" data-a2a-url="https://www.dbrnd.com/2016/03/postgresql-how-to-measure-the-size-of-a-table-row-and-data-page/" data-a2a-title="PostgreSQL: How to measure the size of a Table Row and Data Page?"></a></p><p>In this post, I am sharing a script to measure the size of a PostgreSQL Table Row. </p>
<p>I taken reference from this <a href="http://dba.stackexchange.com/questions/23879/measure-the-size-of-a-postgresql-table-row/23933#23933" target="_blank">dba.statckexchange</a>. </p>
<p>But again, I would like to share this information with some additional information. </p>
<p><a href="https://www.dbrnd.com/2016/03/postgresql-the-awesome-table-fillfactor-to-speedup-update-and-select-statement/" target="_blank"><strong>Fillfactor storage parameter of PostgreSQL Table. </strong></a></p>
<blockquote><p>Before changing the default value of Fillfactor, we should measure the size of Table Row. </p>
<p>For knowing the row size is very important because if table row size is larger, we should not change the default value of Fillfactor.
</p></blockquote>
<blockquote><p>When we are doing performance optimization, this is very important to find the size of the Data page and Table row, otherwise unnecessary we are dealing with high fragmentation and executing VACUUM FULL or VACUUM again and again.
</p></blockquote>
<blockquote><p>If your total row size is under 8kb, you can take decision to alter table storage parameters. </p></blockquote>
<p><strong>Create sample table using JSON data type:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSON
	,Address JSON
);</pre> </p>
<p><strong>Insert few sample JSON formatted record:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'{"firstName": "Anvesh", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Hyderabad"
			,"USA": "Newyork"
		}
	}'
)
,(
	2
	,'Production'
	,'{"firstName": "Neevan", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Ahmedabad"
			,"USA": "Washington DC"
		}
	}'
)
,(
	3
	,'Animation'
	,'{"firstName": "Eric", "lastName": "Lorn"}'
	,'
	{"address" : 
		{ 
			"India": "Mumbai"
			,"USA": "Chicago"
		}
	}'
);</pre> </p>
<p><strong>Script to measure the size of Table row and Data page:</strong></p>
<pre class="crayon-plain-tag">WITH cteTableInfo AS 
(
	SELECT 
		COUNT(1) AS ct
		,SUM(length(t::text)) AS TextLength  
		,'public.tbl_testjson'::regclass AS TableName  
	FROM public.tbl_testjson AS t  
)
,cteRowSize AS 
(
   SELECT ARRAY [pg_relation_size(TableName)
               , pg_relation_size(TableName, 'vm')
               , pg_relation_size(TableName, 'fsm')
               , pg_table_size(TableName)
               , pg_indexes_size(TableName)
               , pg_total_relation_size(TableName)
               , TextLength
             ] AS val
        , ARRAY ['Total Relation Size'
               , 'Visibility Map'
               , 'Free Space Map'
               , 'Table Included Toast Size'
               , 'Indexes Size'
               , 'Total Toast and Indexes Size'
               , 'Live Row Byte Size'
             ] AS Name
   FROM cteTableInfo
)
SELECT 
	unnest(name) AS Description
	,unnest(val) AS Bytes
	,pg_size_pretty(unnest(val)) AS BytesPretty
	,unnest(val) / ct AS bytes_per_row
FROM cteTableInfo, cteRowSize

UNION ALL SELECT '------------------------------', NULL, NULL, NULL
UNION ALL SELECT 'TotalRows', ct, NULL, NULL FROM cteTableInfo
UNION ALL SELECT 'LiveTuples', pg_stat_get_live_tuples(TableName), NULL, NULL FROM cteTableInfo
UNION ALL SELECT 'DeadTuples', pg_stat_get_dead_tuples(TableName), NULL, NULL FROM cteTableInfo;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/03/postgresql-how-to-measure-the-size-of-a-table-row-and-data-page/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
