G
G
GrackHack2019-03-16 18:16:51
PostgreSQL
GrackHack, 2019-03-16 18:16:51

How to safely apply Vacuum to a terabyte Postgress database?

DB on sale 1 terabyte. In it, 1 table weighs 900GB of it 300GB indexes, it has 500 million records of 1 kb maximum per record. How to safely make a VACUUM FULL and how much free disk space is required?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Melkij, 2019-03-16
@GrackHack

vacuum - run vacuum. There is nothing wrong with it, if you have not shot your legs off, then the base itself launches it according to the settings.
vacuum full - the story is very separate, because it's never a vacuum.
Places under vacuum full are needed for a copy of the table with indexes and for writing this copy to WAL. That is, theoretically, up to twice the volume.
Since the opportunity to leave for a few hours is not interesting for a working database, vacuum full is not done on large tables.
There is pg_repack that makes a copy of the table using a trigger and black magic (you still need free space), after that it rolls changes in the main table and replaces the main one with a fresh copy. Basically what vacuum full does, but without heavy table locking.
There ispgcompacttable going the other way. postgresql tries to place new rows at the beginning of the table, so bogus row updates at the end of the table are likely to be moved to the beginning, and empty pages at the end can be cut off by a normal vacuum. Plus to rebuild indexes (truth not all). Inplace update, copy space is not required. Of course, we also do not take a full table lock.

V
Vitaliy Orlov, 2019-03-16
@orlov0562

https://www.postgresql.org/docs/current/sql-vacuum.html
those. you need at least +1 TB
to make everything safe, especially on the prod, you need to mirror the database to another screw and then clean it up, then synchronize the accumulated changes with the main copy, and finally switch the prod to a new database

K
ky0, 2019-03-16
@ky0

To get started, find a system architect or DBA and give him an eye. He will understand why.

A
Alexey, 2019-04-01
@AlexeyVi

Author, start by studying the topic of AutoVacuum, it can be configured so that you no longer need to bother with manual vacuum. Yes, there are exceptions when only pg_repack helps, but this is more exotic.
Look for speeches by Ilya Kosmodemyansky on YouTube, he has a video where he covers this topic well

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question