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
How Predictive Database Analytics Helps Optimize Cloud Resource Utilization
- 23 June 2026
- Database Performance Management
As enterprises continue migrating workloads to the cloud, optimizing resource utilization has become a critical business priority. Cloud infrastructure offers scalability, flexibility, and operational agility, but it also introduces new cost and performance challenges. Without proper visibility into workload behavior, organizations often struggle to balance application performance with infrastructure efficiency. At the center of this … Continue reading “How Predictive Database Analytics Helps Optimize Cloud Resource Utilization”
Why Proactive SQL Performance Monitoring Is Essential for Enterprise Growth
In today’s digital economy, enterprise growth depends heavily on application speed, scalability, and reliability. As businesses expand their digital services, customer interactions, transactions, analytics, and operational workloads grow exponentially. Behind nearly every business-critical application lies SQL-driven databases that process and manage massive amounts of structured data in real time. From financial transactions and e-commerce purchases … Continue reading “Why Proactive SQL Performance Monitoring Is Essential for Enterprise Growth”
How to Enable Data-Driven Media Growth with Enteros Cost Attribution and Software Management
- 22 June 2026
- Software Engineering
Introduction The media industry is experiencing one of the most significant transformations in its history. Streaming services, digital publishing platforms, online advertising ecosystems, video-on-demand applications, and content distribution networks have fundamentally changed how audiences consume content. Modern media organizations now operate highly complex digital ecosystems that support: Streaming platforms Digital publishing systems Video content delivery … Continue reading “How to Enable Data-Driven Media Growth with Enteros Cost Attribution and Software Management”
How to Enable Intelligent Wealth Management Operations with Enteros Database Software, AIOps Platform, and Gen AI
Introduction The wealth management industry is undergoing a major transformation. As investors demand personalized financial services, real-time portfolio visibility, and digital-first experiences, wealth management firms are increasingly relying on technology to drive operational efficiency, improve client engagement, and accelerate business growth. Modern wealth management organizations now support: Portfolio management platforms Wealth advisory applications Digital client … Continue reading “How to Enable Intelligent Wealth Management Operations with Enteros Database Software, AIOps Platform, and Gen AI”