Running vacuum to free space of deleted records on vPostgres databases of the VMware vCenter Server Appliance 5.x
search cancel

Running vacuum to free space of deleted records on vPostgres databases of the VMware vCenter Server Appliance 5.x

book

Article ID: 336372

calendar_today

Updated On:

Products

VMware VMware vCenter Server

Issue/Introduction

Whenever the VMware Postgres database is manipulated, the records that are modified are changed but the old copy is kept for reference. During a delete operation, the records are only marked as deleted. Although the database in the VMware vCenter Server Appliance runs a maintenance job automatically to reclaim the space and remove these unused inaccessible records, sometimes it is necessary to run the maintenance job manually.

The maintenance process is called Vacuum. As mentioned earlier, the database is configured for Auto-Vacuum. However, if the changes to the database are high in number and quick, it may be necessary to run the process manually to reclaim space. This article explains how to manually run the Vacuum command from the command-line.

Environment

VMware vFabric Postgres Standard Edition 9.1.x
VMware vFabric Postgres Standard Edition 9
VMware vFabric Postgres Standard Edition 9.2.x
VMware vCenter Server Appliance 5.5.x
VMware vCenter Server Appliance 5.0.x
VMware vCenter Server Appliance 5.1.x

Resolution

To run the VMware Postgres Vacuum task manually:
  1. Log in to the VMware vCenter Server Appliance as root using SSH or the console.
  2. Run this command to stop the vCenter Server service:

    service vmware-vpxd stop
     
  3. Run this command to obtain the embedded vCenter Server database password:

    cat /etc/vmware-vpx/embedded_db.cfg | grep PASSWORD
     
  4. Run this command to check the available database storage space:

    df -h

    Note: The embedded database is stored at /storage/db
     
  5. Reclaim space by running this vacuum command:

    sudo -u postgres /opt/vmware/vpostgres/current/bin/vacuumdb -a -e -v -f -U postgres > /tmp/vacuumdb.log

    Note: By default, there are 5 databases: postgres, template0, template1, VCDB and ssodb. You are prompted for a password for each database in the cluster. Provide the password obtained in Step 3.
     
  6. Check the database storage space and verify space usage decrease by running this command:

    df -h
 
If the vacuum operation is unable to complete due to lack of space errors:
  1. Add temporary storage. For more information, see Adding additional temporary storage space to vCenter Server Appliance for VMware Postgres maintenance (2056449).
  2. Stop the VMware Postgres service by running this command:

    service vmware-vpostgres stop
     
  3. Copy the database files to new disk mount by running this command:

    cp -ar /storage/db/vpostgres /storage/db1/vpostgres
     
  4. Run this command to start the database from the new location:

    sudo -u postgres /opt/vmware/vpostgres/current/bin/pg_ctl -D /storage/db1/vpostgres start
     
  5. Run this command to verify that the service has started and is running from the correct location:

    sudo -u postgres /opt/vmware/vpostgres/current/bin/pg_ctl -D /storage/db1/vpostgres status
     
  6. Reclaim space by running this vacuum command:

    sudo -u postgres /opt/vmware/vpostgres/current/bin/vacuumdb -a -e -v -f -U postgres > /tmp/vacuumdb.log
     
  7. Check the database storage space and verify decrease in space usage by running this command:

    df -h

    Note: The new location of the database is /storage/db1.
     
  8. Run this command to stop the database from the new location:

    sudo -u postgres /opt/vmware/vpostgres/1.0/bin/pg_ctl -D /storage/db1/vpostgres stop
     
  9. Note: Snapshot of the vCenter server and a Full backup of the Current state needed before we proceed further. 
Run this command to remove the original database directory:

Important: It is strongly recommended that you have a backup of this directory and its contents before removing this directory, as rm -rf is a file/data deletion command.

rm -rf /storage/db/vpostgres
  1. Copy the new directory to the original location by running this command:

    cp -ar /storage/db1/vpostgres /storage/db/vpostgres
     
  2. Run this command to start the VMware Postgres service:

    service vmware-vpostgres start

    Note: To remove the temporary disk mount, shutdown the vCenter Server Appliance. Remove the temporary disk as necessary using edit settings in the vSphere Web Client and restart the vCenter Server Appliance.
     
  3. Run this command to verify the space usage decrease:

    df -h

    Note: The database is located at /storage/db.
     
  4. Start the vCenter Server service by running this command:

    service vmware-vpxd start


Additional Information

Adding additional temporary storage space to vCenter Server Appliance for VMware Postgres maintenance
回收 VMware vCenter Server Appliance 5.x 中的 VMware Postgres (vPostgres) 数据库空间

Impact/Risks:
If you delete a file, there is no way to recover it. Therefore, use caution when deleting files. If you are unsure about deleting a specific file, contact VMware Support for assistance.
If a system file is removed inadvertently, it may cause a permanent damage and can have issues with the functionality of the product itself.