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
Eliminating Growth Friction: How Enteros Aligns Database Performance, Cloud FinOps, and RevOps
- 28 January 2026
- Database Performance Management
Introduction For modern enterprises, growth is no longer limited by market demand alone—it is increasingly constrained by technology efficiency. As organizations scale digital platforms, launch new products, expand globally, and adopt AI-driven services, hidden friction inside their technology stack quietly erodes margins, slows execution, and undermines revenue outcomes. At the center of this friction sits … Continue reading “Eliminating Growth Friction: How Enteros Aligns Database Performance, Cloud FinOps, and RevOps”
AI SQL-Powered Database Management: Enteros’ Performance Intelligence Platform for Tech Enterprises
Introduction Technology enterprises today operate at unprecedented scale and speed. SaaS platforms, cloud-native applications, AI services, data marketplaces, and digital ecosystems now serve millions of users globally—often in real time. At the heart of this digital machinery lie databases. Databases power application responsiveness, AI pipelines, analytics engines, customer experiences, and revenue-generating workflows. Yet as technology … Continue reading “AI SQL-Powered Database Management: Enteros’ Performance Intelligence Platform for Tech Enterprises”
Keeping Operations Running at Scale: Enteros’ AIOps-Driven Database Performance Platform
- 27 January 2026
- Database Performance Management
Introduction In manufacturing plants and insurance enterprises alike, operational continuity is non-negotiable. A delayed production schedule, a failed claims transaction, or a slow underwriting system can ripple into lost revenue, regulatory exposure, and eroded customer trust. At the heart of these operations sit databases—quietly powering everything from shop-floor automation and supply chain planning to policy … Continue reading “Keeping Operations Running at Scale: Enteros’ AIOps-Driven Database Performance Platform”
Managing Real Estate Data at Scale: Enteros AI Platform for Database Performance and Cost Estimation
Introduction The real estate sector has undergone a dramatic digital transformation over the past decade. From commercial real estate (CRE) platforms and property management systems to residential marketplaces, smart buildings, and PropTech startups, modern real estate enterprises are now fundamentally data-driven organizations. Behind digital leasing platforms, pricing engines, tenant experience apps, IoT-enabled buildings, analytics dashboards, … Continue reading “Managing Real Estate Data at Scale: Enteros AI Platform for Database Performance and Cost Estimation”