Routine Database Maintenance in PostgreSQL
Learn about the functionalities of a vacuum and how we can use it in our databases.
Routing database maintenance is an essential part of managing a PostgreSQL database.
Vacuuming
Vacuuming is one of the most common tasks we’ll need to perform as part of this maintenance process.
Database vacuuming is the process of removing old or stale records from a database. These records may have become corrupted or outdated, and vacuuming helps to reduce the database size by reclaiming the storage space that’s no longer used as a result of record deletions and updates. It helps us improve the performance of our database.
Performing a vacuum on a database
There are several steps involved in performing a vacuum on a PostgreSQL database. First, we must identify the tables or indexes that need to be vacuumed. We can do this by running a query or using a graphical tool, such as the PostgreSQL administration utility pgAdmin.
Once we’ve identified the objects that need to be vacuumed, we need to run a command to initiate the vacuuming process by running a vacuum query at the table level or database level.
The VACUUM
command
We can use the VACUUM
query in PostgreSQL to initiate the vacuuming process on our database. To run a VACUUM
query, we can use the following syntax:
Get hands-on with 1200+ tech skills courses.