Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u2rKb-006wG0-04 for pgsql-general@arkaria.postgresql.org; Thu, 10 Apr 2025 12:48:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u2rKY-00BYTv-W8 for pgsql-general@arkaria.postgresql.org; Thu, 10 Apr 2025 12:48:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u2rKY-00BYTf-LS for pgsql-general@lists.postgresql.org; Thu, 10 Apr 2025 12:48:30 +0000 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u2rKX-0043tO-0a for pgsql-general@lists.postgresql.org; Thu, 10 Apr 2025 12:48:30 +0000 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-601f3674116so202673eaf.2 for ; Thu, 10 Apr 2025 05:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744289308; x=1744894108; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=Sy4uhy74tDz0J1IHiAqyPhRf5Qeq8A1yuTRCOJzFLLM=; b=l2Cs0TFQ5wtkf8iaCvVDzcpHoshGpeGTiw1GpwTZsPuFIrRcpggejePslqLpu1g2Ld JML+5NvIk3DcGJDcEWHGw8Y0sKrYGBj2v3qSIZc4Z+a/PYJB/YTtCxqNMHyNAqjg1YGg elnqtgG0ZTiCRElFbFzja1JQqMcbsK9O+Gmb+g/cGy+sG6Kh2hHmJJn4s3vX5aQ/H9fR ivjr82DMKaZzbXod5VA3ZpPGuwZXHXzyAA+yWudZ/NQwYDMo9RMhv5b9gER0GOfddjH9 V33kERTuaAgCjXtxouv8br5ZxE07RfKjzb+vvW3WMq+p8SpPcxbSZegsKsvxZsF8SMrm DNUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744289308; x=1744894108; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Sy4uhy74tDz0J1IHiAqyPhRf5Qeq8A1yuTRCOJzFLLM=; b=ooX/5ykYsN/DTCIZSUAQnkZ3Tu8TyndlX7R/69RD9uL2Gs+hbCS338XGoehGDH3V+i qWGjJCPX8+FcvIl7oN90NnBg/2boBe+1ILplGx+wVzWNPqvHbF2ulWrryWOqas1h/sgb QBaDaargltC4IhuFfIa8AII9a+3T1A9+wOvTWdTTEN/PC7uEdGaQYcX/fLcECQZOFxCw j4CoWaLyA/LMSOPpOZDbhLmsm54ltt2SvcpgXiXyA43lJ6hLFGHspFJAq+Ik/WcyV/p0 UkMWpuoTUc1Kj5jUuSp74cVUC/WG+BQLgNgaPl15OlnKtM9ZS4o4Z/7yoQvWiBaF2pKy 26fw== X-Gm-Message-State: AOJu0YzxS4gfc75IzRlffhRzX1k22DXZy+sAituVCVuGBk5gVMjUi6Nx ORm3qO/zsHiiNg/02McZPugC/76/lXbZ4+LJwefnmD9BrrUb8wIzpIjXnREY9KQDIn1gDyAhLMg AJtP+Qx4j+EDxPah369DKzur73v4pcA== X-Gm-Gg: ASbGnctVSwrDTA/Cl7trTuL93D7d8u5ujwPs5MvyKcBS/LFmzWg+j8V9rau3ApwQNnP Ze/n2AmgnpYiCTQ/gFBzYoH6N1W862MEqIViI4+vFKN1QjK1V+aex5EkEuZYedy1oNaV+bHiUcg LGPGXc94ECJvsijLKKaNzvc3fv5KuKtA5fmytUYnPm+WhjsZiiQt6BahU= X-Google-Smtp-Source: AGHT+IFz3Kp069/YhXaQWeDe4xaz8wFMpxA1yb0JVR2CqKs0ifvjRx5ADA/TZ65FuU4uTfMsdr9EYB/5Ms4214HdziY= X-Received: by 2002:a05:6820:623:b0:603:f973:1b3 with SMTP id 006d021491bc7-604657b2bfbmr1072641eaf.0.1744289308002; Thu, 10 Apr 2025 05:48:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 10 Apr 2025 08:48:16 -0400 X-Gm-Features: ATxdqUHtpZczNvj6NlDmmBhQrmUIiUb8zHgo9nMxxsP03YjhpqXss_JNWt_F53Y Message-ID: Subject: Re: Archive logging not cleaning up pg_wal directory To: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="00000000000096d33b06326c003d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000096d33b06326c003d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 10, 2025 at 8:29=E2=80=AFAM Justin Swanhart wrote: > Hi, > > I have the following in my postgresql.conf for archive logging: > archive_command=3D'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 bu= t > 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 o= ut > the `pg_wal` directory periodically (keep only 1 day of logs I guess?) > No. Definitely not. > > I tried to use mv: > archive_command=3D'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? --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --00000000000096d33b06326c003d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Apr 10, 2025 at 8:29=E2=80=AFAM J= ustin Swanhart <greenlion@gmail.c= om> wrote:
Hi,

I have the following in my po= stgresql.conf for archive logging:
archive_command=3D'test ! -f /var= /lib/postgresql/prod_archive_logs/%f && cp %p /var/lib/postgresql/p= rod_archive_logs/%f'

This command is properly = copying the log files to my archive directory but they remain in the `pg_wa= l` directory after they are copied, consuming hundreds of gigs of space.=C2= =A0 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.=C2=A0 Definitely not.
=C2=A0=

I tried to use mv:
a= rchive_command=3D'test ! -f /var/lib/postgresql/prod_archive_logs/%f &a= mp;& mv %p /var/lib/postgresql/prod_archive_logs/%f'

=
When I did this the archives were moved away to the archive dire= ctory but when I tried to set up replication the server could not find the= =C2=A0archived 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.=C2=A0 "Orphaned replication s= lot" is the typical reason.

Maybe you tried t= o set up replication at some point in the past, but then=C2=A0forgot to dro= p the slot?

-- <= /span>
Death= to <Redacted>, and butter sauce.
Don't boil me, I'm stil= l alive.
<Redacted> lobster!
--00000000000096d33b06326c003d--