<?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_reset &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/pg_stat_reset/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, 21 Jan 2019 07:17:50 +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: Don&#8217;t take backup until your Database is changed</title>
		<link>https://www.dbrnd.com/2019/02/postgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple/</link>
					<comments>https://www.dbrnd.com/2019/02/postgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 25 Feb 2019 16:16:38 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[pg_stat_database]]></category>
		<category><![CDATA[pg_stat_reset]]></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[tup_inserted]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4442</guid>

					<description><![CDATA[In this post, I am sharing an important tip for PostgreSQL DBAs. I recently started work with a new PostgreSQL Client. They have total 326 databases in their PostgreSQL Server. They are taking full backup for all the database and this process is taking around total 7 hours. When I looked this, my first step [&#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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" 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%2F2019%2F02%2Fpostgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple%2F&#038;title=PostgreSQL%3A%20Don%E2%80%99t%20take%20backup%20until%20your%20Database%20is%20changed" data-a2a-url="https://www.dbrnd.com/2019/02/postgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple/" data-a2a-title="PostgreSQL: Don’t take backup until your Database is changed"></a></p><p>In this post, I am sharing an important tip for PostgreSQL DBAs. </p>
<p>I recently started work with a new PostgreSQL Client. They have total 326 databases in their PostgreSQL Server. They are taking full backup for all the database and this process is taking around total 7 hours. </p>
<p>When I looked this, my first step was to find database statistics. I have found 25% of databases are not being updated frequently. </p>
<blockquote><p>I added one additional check in a backup process like &#8220;skip the backup for those databases which have not been changed for any operations (DDL or DML operation)&#8221;.<br />
After this check, the backup process is taking around total 5 hours to complete the job.</p></blockquote>
<blockquote><p>Using pg_stat_database, you can check the stats of database and can compare the value for tuple columns with the old value. If you found any changes, your database has been changed.</p></blockquote>
<p>If any of your DBA reset the PostgreSQL database statistics using something like pg_stat_reset, you have to add some more extra logic to understand the difference between statistics. </p>
<p>Below is a sample demonstration:<br />
<strong>Create a backup table to store DatabaseStats:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE public.tbl_DatabaseStats AS
SELECT 
	datname
	,tup_inserted
	,tup_updated
	,tup_deleted	
FROM pg_stat_database;</pre> </p>
<p><strong>Perform few DDLs and DMLs actions:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE public.tbl_Students(rno int, name character varying);
INSERT INTO public.tbl_Students VALUES(1,'Anvesh');
CREATE TABLE public.tbl_Test88(id int);</pre> </p>
<p><strong>Compare the result of below two queries:</strong><br />
If you find differences on any of the columns of your Database, your database stats has been changed and you should take the backup of your database.</p>
<pre class="crayon-plain-tag">SELECT 
	datname
	,tup_inserted
	,tup_updated
	,tup_deleted	
FROM pg_stat_database;

SELECT *FROM public.tbl_DatabaseStats;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/02/postgresql-dont-take-backup-until-your-database-is-changed-check-pg_stat_database-tuple/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
