Comments on: Understanding of Bloat and VACUUM in PostgreSQL https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/ Sat, 20 Jan 2024 00:53:37 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Vignesh https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10971470 Fri, 22 Nov 2019 08:11:23 +0000 https://www.percona.com/blog/?p=51502#comment-10971470 Great explanation. Can you please explain Transaction ID Wraparound in PSQL in a detail ?

]]>
By: Gascard https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969559 Tue, 14 Aug 2018 17:56:00 +0000 https://www.percona.com/blog/?p=51502#comment-10969559 Hello avinash,
Thank you for the explanation, I will follow you . Thierry

]]>
By: vikramreddyrec1234 https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969555 Tue, 14 Aug 2018 05:18:28 +0000 https://www.percona.com/blog/?p=51502#comment-10969555 Hello Avi,
its good explanation. as you mention “VACUUM does not usually reclaim the space to filesystem unless the dead tuples are beyond the high water mark.”

–> is there a query to check dead tuples are beyond the high water mark or not?

]]>
By: avivallarapu https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969552 Mon, 13 Aug 2018 15:18:03 +0000 https://www.percona.com/blog/?p=51502#comment-10969552 Thank You Raghavendra. You can rebuild a table online using pg_repack. We would be submitting a blog post on it soon and then add a comment with the link.

]]>
By: avivallarapu https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969551 Mon, 13 Aug 2018 15:08:22 +0000 https://www.percona.com/blog/?p=51502#comment-10969551 Yes, autovacuum/vacuum does take care of Indexes

We have a hidden column called ctid which is the physical location of the row version within its table. Both Table and its Indexes would have same matching ctid. It may be used as a row identifier that would change upon Update/Table rebuild.

percona=# CREATE TABLE percona (id int, name varchar(20));
CREATE TABLE
percona=# CREATE INDEX percona_id_index ON percona (id);
CREATE INDEX
percona=# INSERT INTO percona VALUES (1,’avinash’),(2,’vallarapu’),(3,’avi’),;
INSERT 0 3
percona=# SELECT id, name, ctid from percona;
id | name | ctid
—-+———–+——-
1 | avinash | (0,1)
2 | vallarapu | (0,2)
3 | avi | (0,3)
(3 rows)

percona=# DELETE from percona where id < 3;
DELETE 2

After deleting the records, let us see the items inside table/index pages

Table
=======
percona=# SELECT t_xmin, t_xmax, tuple_data_split('percona'::regclass, t_data, t_infomask, t_infomask2, t_bits) FROM heap_page_items(get_raw_page('percona', 0));
t_xmin | t_xmax | tuple_data_split
——–+——–+——————————————-
3825 | 3826 | {"\\x01000000","\\x116176696e617368"}
3825 | 3826 | {"\\x02000000","\\x1576616c6c6172617075"}
3825 | 0 | {"\\x03000000","\\x09617669"}
(3 rows)

Index
=======
percona=# SELECT * FROM bt_page_items('percona_id_index', 1);
itemoffset | ctid | itemlen | nulls | vars | data
————+——-+———+——-+——+————————-
1 | (0,1) | 16 | f | f | 01 00 00 00 00 00 00 00
2 | (0,2) | 16 | f | f | 02 00 00 00 00 00 00 00
3 | (0,3) | 16 | f | f | 03 00 00 00 00 00 00 00
(3 rows)

After running VACUUM, corresponding pointers with same ctid are also removed from Index through a RowExclusiveLock.

percona=# VACUUM ANALYZE percona;
VACUUM
percona=# SELECT t_xmin, t_xmax, tuple_data_split('percona'::regclass, t_data, t_infomask, t_infomask2, t_bits) FROM heap_page_items(get_raw_page('percona', 0));
t_xmin | t_xmax | tuple_data_split
——–+——–+——————————-
| |
| |
3825 | 0 | {"\\x03000000","\\x09617669"}
(3 rows)

percona=# SELECT * FROM bt_page_items('percona_id_index', 1);
itemoffset | ctid | itemlen | nulls | vars | data
————+——-+———+——-+——+————————-
1 | (0,3) | 16 | f | f | 03 00 00 00 00 00 00 00
(1 row)

]]>
By: Peter Zaitsev https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969545 Mon, 13 Aug 2018 00:08:50 +0000 https://www.percona.com/blog/?p=51502#comment-10969545 Hi Avi,

This is a good explanation which related to the data. What is about the bloat in the indexes, which I assume also can contain old pointers. How does this play in the picture ?

]]>
By: raghavendra https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969543 Sun, 12 Aug 2018 11:56:41 +0000 https://www.percona.com/blog/?p=51502#comment-10969543 Very nice explanation. Where can I find the ways to rebuild a table online without blocking .

]]>
By: Tiago Corcelli Oliveira https://www.percona.com/blog/basic-understanding-bloat-vacuum-postgresql-mvcc/#comment-10969539 Wed, 08 Aug 2018 14:01:29 +0000 https://www.percona.com/blog/?p=51502#comment-10969539 Very very good explain.

]]>