Re: Archive logging not cleaning up pg_wal directory

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Archive logging not cleaning up pg_wal directory
Date: 2025-04-10 12:48:16
Message-ID: CANzqJaD0UAqHPtptbOg8KHN+Zc2VZzJpQeV0QZPqcXv_wsnJ1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Apr 10, 2025 at 8:29 AM Justin Swanhart <greenlion(at)gmail(dot)com> wrote:

> Hi,
>
> 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?)
>

No. Definitely not.

>
> 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?
>

PG retains WAL files when it thinks it needs them. "Orphaned replication
slot" is the typical reason.

Maybe you tried to set up replication at some point in the past, but
then forgot to drop the slot?

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Justin Swanhart 2025-04-10 13:12:52 Re: Archive logging not cleaning up pg_wal directory
Previous Message Laurenz Albe 2025-04-10 12:48:00 Re: Archive logging not cleaning up pg_wal directory