Re: pg_rewind WAL segments deletion pitfall

From: Alexander Kukushkin <cyberdemn(at)gmail(dot)com>
To: Sutou Kouhei <kou(at)clear-code(dot)com>
Cc: smithpb2250(at)gmail(dot)com, torikoshia(at)oss(dot)nttdata(dot)com, horikyota(dot)ntt(at)gmail(dot)com, michael(at)paquier(dot)xyz, pgsql-hackers(at)postgresql(dot)org, bungina(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_rewind WAL segments deletion pitfall
Date: 2024-07-12 09:00:24
Message-ID: CAFh8B==NeH=4c-3Fz3uvra-WyTQYY7QkH95m-vZNPOw2YK_KjQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi Sutou,

Thank you for picking it up!

On Fri, 12 Jul 2024 at 09:24, Sutou Kouhei <kou(at)clear-code(dot)com> wrote:

Here are my review comments:
>
> @@ -217,6 +221,26 @@ findLastCheckpoint(const char *datadir, XLogRecPtr
> forkptr, int tliIndex,
> + char xlogfname[MAXFNAMELEN];
> +
> + tli = xlogreader->seg.ws_tli;
> + segno = xlogreader->seg.ws_segno;
> +
> + snprintf(xlogfname, MAXPGPATH, XLOGDIR "/");
> + XLogFileName(xlogfname + strlen(xlogfname),
> + xlogreader->seg.ws_tli,
> + xlogreader->seg.ws_segno,
> WalSegSz);
> +
> + /*
> + * Make sure pg_rewind doesn't remove this file,
> because it is
> + * required for postgres to start after rewind.
> + */
> + insert_keepwalhash_entry(xlogfname);
>
> MAXFNAMELEN is 64 and MAXPGPATH is 1024. strlen(XLOGDIR "/")
> is 7 because XLOGDIR is "pg_wal". So xlogfname has enough
> size but snprintf(xlogfname, MAXPGPATH) is wrong usage.
> (And XLogFileName() uses snprintf(xlogfname, MAXFNAMELEN)
> internally.)
>

Nice catch!

I don't think we need another buffer here, just need to use MAXFNAMELEN,
because strlen("pg_wal/$wal_filename") + 1 = 32 perfectly fits into 64
bytes.

The new version is attached.

Regards,
--
Alexander Kukushkin

Attachment Content-Type Size
v10-0001-pg_rewind-wal-deletion-pitfall.patch text/x-patch 8.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-07-12 09:31:48 BUG #18534: ERROR: portal "C_n" does not exist type of error getting thrown.
Previous Message PG Bug reporting form 2024-07-12 07:58:27 BUG #18533: pg_basebackup uses out-of-bounds memory and a segment error occurs during backup

Browse pgsql-hackers by date

  From Date Subject
Next Message Rafia Sabih 2024-07-12 09:22:37 Re: Things I don't like about \du's "Attributes" column
Previous Message Bertrand Drouvot 2024-07-12 07:54:51 Re: Restart pg_usleep when interrupted