How to do it...

Assuming pg1 is our current primary node and /dev/VG_POSTGRES/LV_DATA is the device we formatted with XFS, follow these steps there as the root user:

  1. Examine the current fragmentation status with this command:
        xfs_db -f -c frag /dev/VG_POSTGRES/LV_DATA
  1. Defragment the filesystem with xfs_fsr:
        xfs_fsr -t 600 /dev/VG_POSTGRES/LV_DATA
  1. View the real-time fragmentation status afterwards:
        xfs_db -f -c frag -r /dev/VG_POSTGRES/LV_DATA

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.