Disk space diagnostics
In PolarDB for PostgreSQL, disk space is primarily consumed by two categories: user data (databases and tables) and write-ahead logging (WAL) data. Understanding which category is growing helps you identify the root cause faster.
Query user data disk usage
Connect to the database and run psql meta-commands to see how much space user data occupies.
By database
Run \l in your PostgreSQL client to list disk usage for each database. This command traverses the directory tree, so it incurs high CPU and I/O overhead on large clusters.
By table
Connect to the database with the highest disk usage, then run \d to see disk usage broken down by table.
Query WAL disk usage
Run the following SQL statement to get the total size of WAL data:
SELECT pg_size_pretty(SUM(size)) FROM pg_ls_waldir();PolarDB for PostgreSQL reclaims WAL disk space by default. WAL files are written to protect against in-memory data loss if the database crashes before flushing data to disk. Once the data is safely written to disk, the corresponding WAL files are reclaimed automatically.
If WAL is consuming a large amount of disk space, check whether WAL logs are generated in unexpected scenarios such as inactive replication slots:
SELECT * FROM pg_replication_slots;If replication slots in the false state exist, execute the statement above to check further.