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.96) (envelope-from ) id 1vOcXC-00FmM8-1K for pgsql-novice@arkaria.postgresql.org; Thu, 27 Nov 2025 13:59:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vOcXA-006eJh-32 for pgsql-novice@arkaria.postgresql.org; Thu, 27 Nov 2025 13:59:45 +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.96) (envelope-from ) id 1vOcXA-006eJZ-27 for pgsql-novice@lists.postgresql.org; Thu, 27 Nov 2025 13:59:44 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vOcX8-001kvi-1j for pgsql-novice@lists.postgresql.org; Thu, 27 Nov 2025 13:59:44 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-42b32900c8bso616625f8f.0 for ; Thu, 27 Nov 2025 05:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1764251981; x=1764856781; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Lu4wIUSkVz/FOyhZH6NO4gveY6sRTkx0G0jgoOq5uRM=; b=Bd15rZrFyRHmTS5lvVRnOcPrcp++qkp2xN4Vz7IChGvu74TALA4cSBzTsZIqh6T440 kxNrsL3Csa4HUepkw7BzBXpCaRqLbHAT5yWfULyDNzm76GQo8QKZWtq4IQJNbGkXr32P 1v28U86inNzH9vAYKptPbyhsybOk4M1GZatGkc2lYLV+eoUVMnU2vyvPvjng2eAXy/n1 jnuiuCcRYYcxnyjZ9SqdNpEXJV/25gH5DMcrN2Prb9jJhnmNvzQMXtsjOh88chJ+j2ne Hy/nwR/7tsmoXDNDyYLvzgRh08pnzgS6wGlGM8bg5zGodATgF3O+mg5t4NE8qairI8Fh KKgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764251981; x=1764856781; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Lu4wIUSkVz/FOyhZH6NO4gveY6sRTkx0G0jgoOq5uRM=; b=aBYmrI2QN9TvbROPfFMVWwi9N5vNgxtpeY3ceM54fG363xaoSrptFcAUsf6uMbWOHY vSk8rGRsPn/0b5FS/q6/gqEE+OdKFFhbwQwcSpZPDRnvVMcDElKiyHcnXPWbLMCnTZiF hQhZwIQuIlIx2wHUvKK1ujC8LH4MMmq6+y1CMIhIGZS7S7Q8F27LKo6ipvoeqjXdjiDs 3C70GdlU264Fvs1dQVxbv9zPBTVCCvoF0WGwPuHjfblA/qBeJ4DBxC8XtfSf1OqmthWK +ci2JYUzn/9p+jKdDECFhTNMouMXA9y4kgALUVudqe5V2nvXCZLPz49w9ngMGG79PPZA iPxg== X-Forwarded-Encrypted: i=1; AJvYcCWyojPRmhFuNplf2DRcaYmofDMU6+AXFI2WwG0ByETb8gFlVBwUe5h3qIq1wRHVl58nz6S8UqAVEuFoWRo=@lists.postgresql.org X-Gm-Message-State: AOJu0YwBD3W+VofgkJGYFGj1FKSSQx569tT1ukIxFo/4zzcaHFba/Plw ZePNFFRE6cgwfFJMuZ2oevk0rj6KdOsf4/onlw6IvyUkElSMZ/tqkpBwb61j9NnfpkmvbB88Ej2 Gq3B/ X-Gm-Gg: ASbGncuHv82ag1DGVk6bvO2HsoBGkK2hSN9UfjPC3g1UGjeaYpZLoeQL4159kD3zQJZ ZYGCteQNqS4LsACiA5Dk3N7PoH6qsnEFGD98vENlVH3P68uSUW6FFpqrej9VsRin5K7i52gXAPJ G5DS68jrj1M/pA7yOetZzDT+sNaVTkj+QWBZ8kXslS0F8zNUysjeqWZrjg5nzqzQj5Tb6xYCN0X 0ApSwB44fs/POgJ3UHTI5tZqBpj0EE28Nuls2d4BpFPpxWzXnKsvhJEaZJlvt/iTsz5ivbaEKBH 28GC77v8V6iOjuNjaMsksHUXIJnwsNIQUIO+oE1wKxTFud92mF1bcQb4LDdOr379nGqP3j/u841 26sKZHE4UOgy+qEVLMqrDSc/AuKEUKVsbRg3OoN7nE8N032Mu+1DzYbI9sTqEMcwdC/osgMiOCC z+fyHXi5WVq0Nb4khFqH7xpNCkwcjaFtAhIz+UOSM= X-Google-Smtp-Source: AGHT+IEde6ma4MoVKtb7ubE3YjoBLfKqCr5I0tGXC30bbp/FjRB84kr5jXAXJVlZC1NdV7J3qAsFPg== X-Received: by 2002:a05:6000:2f81:b0:429:bc68:6c95 with SMTP id ffacd0b85a97d-42cc1d520camr28047514f8f.47.1764251980782; Thu, 27 Nov 2025 05:59:40 -0800 (PST) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:70:209:bf85:c4e1:b839:780d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1cac995esm3495428f8f.43.2025.11.27.05.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 05:59:40 -0800 (PST) Message-ID: <1f12660d233efc644edb6a23c7bd4bcc84b503af.camel@cybertec.at> Subject: Re: how long should Archive logs be retained From: Laurenz Albe To: "Subramanian,Ramachandran" , "pgsql-novice@lists.postgresql.org" Date: Thu, 27 Nov 2025 14:59:39 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2025-11-27 at 10:34 +0000, Subramanian,Ramachandran wrote: > How long should archived logs be retained? > =C2=A0 > I make pg_basebackups once =C2=A0a day =C2=A0with wal-method =E2=80=9Astr= eam=E2=80=98 =C2=A0and postgresql.conf has wal_level =3D replica and =C2=A0= archive_mode=3Don > =C2=A0 > Case 1:=C2=A0 Recovery to the point in time when the basebackup ended--= =C2=A0 Am I correct in > assuming that I do not need anything else other than the base ba= ckup if I want > to just recover to the point in time when the basebackup ended? > =C2=A0Please correct me if I am wrong. Correct. > Case 2: Recovery to the latest point =E2=80=93 For example if a server cr= ashes, I can simply > restart the server and postgres and it will rollforward all the a= ctive logs since > the last flush oft he data buffers to disk happened . Is my under= standing correct ? > =C2=A0 While I understand that all the log buffers are written as s= oon as a commit is > issued, how does Postgres keep track of when the data buffers wer= e flushed to disk? > In other words, how does Postgres know from which log sequence nu= mber it must begin > rolling forward?=C2=A0 Can we as users also see it? The redo LSN of the latest checkpoint is stored in the control file, so tha= t PostgreSQL can start recovering from there. You can use the pg_controldata command or the pg_control_checkpoint() table= function to get that information. PostgreSQL doesn't need the archive for crash recovery, it uses the WAL in = pg_wal. > Case 3: =C2=A0No archive logging and transaction that does not commit:=C2= =A0 Let us say that we have > not enabled archive logging and we have a long running update th= at fills up all > the active logs (WALs) and it has wrapped around. What happens n= ow?=C2=A0 Will the > system Hang?=C2=A0 Will Postgres cancel this thread and rollback= ? =C2=A0Should we manually > cancel the thread?=C2=A0 How can we find out which thread is wri= ting without commits? Transactions are independent of checkpoints. The WAL from the uncommitted = transaction will just be archived and removed from pg_wal after a checkpoint. PostgreSQL ne= ver needs to undo the modifications from an uncommitted transaction. > Case 4: Recovery to the latest point with Archive logging enabled:=C2=A0 = If=C2=A0 I have archive > logging enabled and I have transactions that wrap around the logs= without commit > and the server crashes, =C2=A0is it correct to assume that =C2=A0= I need=20 > =C2=A0=C2=A0=C2=A0a. my base backup ( with all the =E2=80=9Athen copied W= ALs=E2=80=98 ) > =C2=A0=C2=A0=C2=A0b. =C2=A0the current WALs in the active WAL directory > =C2=A0=C2=A0=C2=A0c. All the archived WALs from the time the base backup = began to the time the crash happened > =C2=A0 > to bring the system to a consistent state? No, the WAL in pg_wal is enough. You don't need an archive for that. The uncommitted data just get recovered while remaining invisible, and the = next VACUUM run will remove them. > My question in short is, Is it enough if I hold on to my archive logs sin= ce the last backup > for any recovery scenareo? You need to retain WAL from the *start* of the earliest backup you need to = recover on. I'd recommend that you look into a ready-made backup solution like pgBackRe= st. Yours, Laurenz Albe