Use Caution

PostgreSQL Write-Ahead Logging Folder (pg_wal)

Quick Answer: pg_wal stores PostgreSQL Write-Ahead Logs for crash recovery and replication. Do NOT manually delete pg_wal files; use pg_archivecleanup.

Bottom Line: Exercise Caution. You should NOT manually delete files inside pg_wal (formerly pg_xlog) using rm commands. Deleting active WAL segment files manually will corrupt the PostgreSQL database cluster and prevent PostgreSQL from starting.


What is the PostgreSQL pg_wal Folder?

Located at /var/lib/postgresql/data/pg_wal on Linux (or C:\Program Files\PostgreSQL\XX\data\pg_wal), this folder is managed by the PostgreSQL Database Engine.

PostgreSQL uses WAL (Write-Ahead Logging) to ensure ACID compliance and crash safety. Changes to database tables are written to 16 MB WAL segment files before being committed to main database files.

If WAL archiving fails or a replication slot becomes inactive, WAL files pile up rapidly inside pg_wal, consuming 10 GB to 100 GB+.


Can You Delete pg_wal Files?

⚠️ Caution Required.

  • Manual rm corrupts database: Deleting active WAL files directly using OS commands will corrupt PostgreSQL transaction logs and crash the service.
  • Safe to clean via archiving / pg_archivecleanup: Adjusting max_wal_size or clearing inactive replication slots safely cleans pg_wal.

How to Safely Clean Up PostgreSQL pg_wal

  1. Log into PostgreSQL console:
    psql -U postgres
  2. Check for abandoned replication slots holding WAL files:
    SELECT slot_name, active FROM pg_replication_slots;
  3. Drop inactive slots:
    SELECT pg_drop_replication_slot('abandoned_slot_name');

Method 2: Adjust WAL Size in postgresql.conf

Reduce max_wal_size in /etc/postgresql/XX/main/postgresql.conf:

max_wal_size = 4GB
min_wal_size = 1GB

  • Learn about deleting [MySQL binlog-files)-files)-files)-files)-files)-files)-files) files].
  • How to clean up [Redis dump.rdb file].
  • Check if you can clean Linux /var/log.

Discussion

Loading authentication...

Related in developer

The AI Engineer's Model Disk Cleanup Guide: Hugging Face, Ollama & PyTorch

The ultimate 1,200-word field guide for AI developers and local LLM hobbyists to reclaim 200GB+ from Ollama, Hugging Face, PyTorch, and vLLM model weights.

Safe to Delete

Android Studio System Index Cache (AndroidStudio Cache)

Android Studio caches Gradle project indexes, VFS caches, and compiler artifacts. Invalidate and clear is safe.

Safe to Delete

Ansible Automation Temp & Fact Cache (~/.ansible/tmp)

Ansible stores temporary playbook execution modules and target host fact JSON caches in ~/.ansible/tmp. Clearing Ansible tmp is safe.

Safe to Delete
Back to all files