Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2019 February PostgreSQL: Don’t take backup until your Database is changed

PostgreSQL: Don’t take backup until your Database is changed

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

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 was to find database statistics. I have found 25% of databases are not being updated frequently.

I added one additional check in a backup process like “skip the backup for those databases which have not been changed for any operations (DDL or DML operation)”.
After this check, the backup process is taking around total 5 hours to complete the job.

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.

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.

Below is a sample demonstration:
Create a backup table to store DatabaseStats:

1
2
3
4
5
6
7
CREATE TABLE public.tbl_DatabaseStats AS
SELECT
datname
,tup_inserted
,tup_updated
,tup_deleted
FROM pg_stat_database;

Perform few DDLs and DMLs actions:

1
2
3
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);

Compare the result of below two queries:
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.

1
2
3
4
5
6
7
8
SELECT
datname
,tup_inserted
,tup_updated
,tup_deleted
FROM pg_stat_database;
 
SELECT *FROM public.tbl_DatabaseStats;

Feb 25, 2019Anvesh Patel
PostgreSQL: What is IMMUTABLE, STABLE, VOLATILE and COST of FunctionPostgreSQL: Bash Shell Script to execute psql command in UNIX / LINUX

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

February 25, 2019 PostgreSQLAnvesh Patel, backup, database, database research and development, dbrnd, pg_stat_database, pg_stat_reset, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Monitoring, PostgreSQL Performance Tuning, PostgreSQL Programming, PostgreSQL Tips and Tricks, tup_inserted
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....