Disk space diagnostics

Updated at:

User data and write-ahead logging (WAL) data occupy most of the disk space in PolarDB for PostgreSQL (Compatible with Oracle).

Query the disk space occupied by user data

Query the disk space occupied by the user data in databases and tables:

  • Databases

    Run the \l command on your PostgreSQL client to view the disk space occupied by the data in each database. To perform this operation, the system must traverse the directory tree. This causes high CPU overhead and I/O overhead.

  • Tables

    You can use your client to connect to a database in which the data occupies a large amount of disk space. Then, you can run the \d command to view the disk space occupied by the data from each table in the database.

Query the disk space occupied by WAL logs

Execute the following SQL statement to view the disk space occupied by WAL logs.

SELECT pg_size_pretty(SUM(size)) FROM pg_ls_waldir();

PolarDB for PostgreSQL (Compatible with Oracle) reclaims the disk space occupied WAL logs by default. WAL logs can prevent in-memory data loss if the system crashes before the in-memory data is written to disks. After the in-memory data written to disks, the disk space occupied WAL logs is reclaimed.

If WAL logs occupy a large amount of disk space, check whether WAL logs are generated in unexpected scenarios such as inactive replication slots.

Note

If replication slots in the false state exist, execute the SELECT * FROM pg_replication_slots; statement to check further.