Preamble
PostgreSQL VACUUM statement is used to restore the storage by removing outdated data or tuples from a PostgreSQL database.
The syntax for the VACUUM statement in PostgreSQL
VACUUM [FULL] [FREEZE] [VERBOSE] [tab_name ];
OR
VACUUM [FULL] [FREEZE] [VERBOSE]
ANALYZE tab_name [ (col1_id, col2_id,... col_n_id) ];
Parameters and arguments of the statement
- FULL – Optional. If specified, the database shall write the entire table contents into a new file. This releases all unused space and requires an exclusive lock for each table that is cleared.
- FREEZE – Optional. If specified, the tuples are aggressively frozen when cleaning the table. This is the default behavior if FULL is specified, so it is redundant to specify both FULL and FREEZE.
- VERBOSE – Optional. If specified, an activity report will be printed detailing the VACUUM activity for each table.
- ANALYZE – Optional. If specified, the statistics used by the scheduler will be updated. These statistics are used to determine the most efficient plan to execute a particular query.
- tab_name – Optional. If specified, only the specified table will be cleared. If not specified, all tables in the database shall be cleared.
- col1_id, col2_id,… col_n_id – Optional. If specified, these shall be the columns to be analyzed.
Note:
- Each time you perform a table update, the original record shall be saved in the database. The vacuum will delete these old records (ie tuples) and reduce the size of the PostgreSQL database.
- You can only use vacuum tables in which you have VACUUM rights.
- You cannot run the VACUUM command in a transaction.
In PostgreSQL, the cleaning process is a common action to perform in order to remove old outdated tuples and minimize the database file size.
Example of using the VACUUM statement in PostgreSQL
Restore space for reuse in the same table.
This first example shows how to free up space so that unused space can be reused by the same table. This does not reduce the size of the PostgreSQL database file, since space is not freed up by the operating system, but only by the table from which space was allocated.
For example:
VACUUM;
This example will clear all tables in the database. This will free up space inside each table and leave the space available for reuse by the same table. It does not return space to the operating system, so the database file size will not be reduced.
Restore space and minimize the database file
If you want to clear all tables and minimize the database file by returning unused space to the operating system, you must run the following VACUUM operator:
VACUUM FULL;
In this example, all tables will be overwritten into a new file, which will require an exclusive lock on each table. The database file will be kept to a minimum as all unused space will be returned to the operating system.
Restore space for a table
Next, let’s see how to clear a particular table, not the entire database.
For example:
VACUUM products;
This example will clear only the products table. This will clear the space in the products table and leave the space available for use only for the products table. The database file size will not be reduced.
If you want to allocate unused space back to the operating system, you need to add the FULL option to the VACUUM statement as follows:
VACUUM FULL products;
This will not only free up unused space in the products table but also allow the operating system to free up space and reduce the size of the database.
VACUUM activity report
Finally, you can add the VERBOSE option to the VACUUM command to display the VACUUM process activity report.
For example:
VACUUM FULL VERBOSE products;
This will perform a complete cleaning of the products table. Let’s show you what you can see as output data for the VACUUM activity report:
trizor=# VACUUM FULL VERBOSE products;
INFO: vacuuming "public.products".
INFO: "products": found 4 removable, 5 nonremovable row versions in 1 page
DETAIL: 0 dead row versions cannot be removed yet.
CPU 0.00s/0.00u sec elapsed 0.04 sec.
VACUUM
This activity report will display the tables that have been cleared by VACUUM as well as detailed information and the time required to perform the cleaning operation.
What is a vacuum in PostgreSQL: Postgresql Vacuum
Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Driving Financial RevOps Efficiency with Enteros: AIOps-Powered Database Performance for Smarter Decision-Making
- 27 October 2025
- Database Performance Management
Introduction In today’s competitive financial ecosystem, where every second and every data point matters, achieving operational agility and revenue precision has become a top priority. Financial institutions — from banks and insurance companies to fintech innovators — are seeking more intelligent ways to manage their data-driven operations. The convergence of Revenue Operations (RevOps), database performance … Continue reading “Driving Financial RevOps Efficiency with Enteros: AIOps-Powered Database Performance for Smarter Decision-Making”
Revolutionizing Healthcare Efficiency with Enteros: SaaS Database Optimization, Generative AI, and Cloud FinOps Synergy
Introduction The healthcare sector has entered a new digital era driven by innovation, patient data analytics, and intelligent automation. From hospital management systems and patient monitoring to clinical research and predictive diagnostics, the industry’s growing dependence on cloud-based data systems has introduced both immense opportunities and operational challenges. As healthcare organizations scale their operations, managing … Continue reading “Revolutionizing Healthcare Efficiency with Enteros: SaaS Database Optimization, Generative AI, and Cloud FinOps Synergy”
⚡ The Hidden Blackout: How Data Lag Triggered a Grid Failure (and What It Taught Us About Energy Resilience)
📍 The Incident In late 2024, a regional utility company in Northern Europe experienced an unexpected power disruption.Not because of a storm.Not because of an overload.But because two monitoring systems were five seconds out of sync. Those five seconds cost the company 19 million euros in operational losses and emergency response. When analysts reconstructed the … Continue reading “⚡ The Hidden Blackout: How Data Lag Triggered a Grid Failure (and What It Taught Us About Energy Resilience)”
How Enteros is Revolutionizing Real Estate RevOps Through Generative AI and Smarter Database Performance
- 26 October 2025
- Database Performance Management
Introduction The real estate sector is no longer confined to property listings and offline transactions—it’s a complex, data-driven industry powered by technology, analytics, and automation. From property valuation and customer engagement to financial forecasting and deal execution, data plays a pivotal role in driving operational efficiency and revenue growth. However, managing this massive influx of … Continue reading “How Enteros is Revolutionizing Real Estate RevOps Through Generative AI and Smarter Database Performance”