Re: Archive logging not cleaning up pg_wal directory - Mailing list pgsql-general

From Justin Swanhart
Subject Re: Archive logging not cleaning up pg_wal directory
Date
Msg-id CAJM9iN1gwycOH6PBGhN6j5BnrdDMsMq6_rN4nb0dXGL_8m0zWA@mail.gmail.com
Whole thread Raw
In response to Re: Archive logging not cleaning up pg_wal directory  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-general
Thank you very much.  I had a stale replication slot.  I removed it and the logs were cleaned up immediately.

--Justin

On Thu, Apr 10, 2025 at 8:48 AM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
On Thu, 2025-04-10 at 08:28 -0400, Justin Swanhart wrote:
> I have the following in my postgresql.conf for archive logging:
> archive_command='test ! -f /var/lib/postgresql/prod_archive_logs/%f && cp %p /var/lib/postgresql/prod_archive_logs/%f'
>
> This command is properly copying the log files to my archive directory but they remain in the `pg_wal`
> directory after they are copied, consuming hundreds of gigs of space.  Am I supposed to create a cron
> job to clean out the `pg_wal` directory periodically (keep only 1 day of logs I guess?)
>
> I tried to use mv:
> archive_command='test ! -f /var/lib/postgresql/prod_archive_logs/%f && mv %p /var/lib/postgresql/prod_archive_logs/%f'
>
> When I did this the archives were moved away to the archive directory but when I tried to set up
> replication the server could not find the archived log to replicate from so I changed it to "cp" and now have this problem.
>
> What am I missing?

Something else is blocking WAL removal:
https://www.cybertec-postgresql.com/en/why-does-my-pg_wal-keep-growing/

Since you mention replication, my money is on a stale replication slot.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Archive logging not cleaning up pg_wal directory
Next
From: "David G. Johnston"
Date:
Subject: Re: Interesting case of IMMUTABLE significantly hurting performance