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 2018 April PostgreSQL: VACUUM VERBOSE to find data pages and dead row versions

PostgreSQL: VACUUM VERBOSE to find data pages and dead row versions

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

If you don’t know about that data pages, you must visit below article.
What is MVCC ?

Because of MVCC architecture, PostgreSQL generates dead rows at every UPDATE and DELETE.

You must remove the fragmentation by executing VACUUM ANALYZE command which removes the dead rows and update the related database statistics.

You can also use VACUUM VERBOSE to troubleshoot total number of data pages, total number of removable dead row version while executing a VACUUM ANALYZE.
(Check your query message window, where you can find detailed information generated by VACUUM VERBOSE.)

This is really very helpful information for PostgreSQL DBA to make sure about the fragmentation.

I have prepared a detailed demonstration of this.

Create a table with sample data:

1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE tbl_ItemTransactions
(
TranID SERIAL
,TransactionDate TIMESTAMPTZ
,TransactionName TEXT
) DISTRIBUTED BY (TranID);
 
INSERT INTO tbl_ItemTransactions
(TransactionDate, TransactionName)
SELECT x, 'ggkproduct'
FROM generate_series('2015-01-01 00:00:00'::timestamptz, '2016-08-01 00:00:00'::timestamptz,'5 seconds'::interval) a(x);

Check the size of table:

1
2
3
SELECT pg_size_pretty(pg_total_relation_size('tbl_ItemTransactions')) AS TableSize;
 
The size is: "496 MB"

Execute VACUUM VERBOSE to get data pages and dead row versions related information:

1
2
3
VACUUM VERBOSE ANALYZE tbl_ItemTransactions;
 
"tbl_itemtransactions": found 0 removable, 2496960 nonremovable row versions in 3970 pages (seg0 sdw1:40000 pid=17647)

Execute one DELETE to generate few dead tuples:

1
2
DELETE FROM tbl_ItemTransactions
WHERE TransactionDate BETWEEN '2016-04-01' AND '2016-08-01';

Now, examine the result of VACUUM VERBOSE where you can find 527040 removable rows:
You can find total 3970 pages and 527040 removable rows.

1
2
3
4
VACUUM VERBOSE ANALYZE tbl_ItemTransactions;
 
INFO: "tbl_itemtransactions": found 527040 removable, 1969920 nonremovable row versions in 3970 pages (seg1 sdw1:40001 pid=17649)
839 pages contain useful free space.

Now, execute one more time and you can find 3132 pages and 0 removable rows:

1
2
3
4
VACUUM VERBOSE ANALYZE tbl_ItemTransactions;
 
"tbl_itemtransactions": found 0 removable, 1969920 nonremovable row versions in 3132 pages (seg0 sdw1:40000 pid=17647)
1 pages contain useful free space.

Check the size of table:

1
2
3
SELECT pg_size_pretty(pg_total_relation_size('tbl_ItemTransactions')) AS TableSize;
 
The size is: "392 MB"

Apr 13, 2018Anvesh Patel
PostgreSQL: Use pgbench for testing the Load Performance of ServerPostgreSQL: Use RAISE Statements to debug your Query and Function performance

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

April 13, 2018 PostgreSQLAnvesh Patel, data pages, database, database research and development, dbrnd, dead rows, Multiversion Concurrency Control, MVCC, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks, VACUUM ANALYZE, VACUUM VERBOSE, VACUUM VERBOSE ANALYZE
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....