Re: [PoC] pg_upgrade: allow to upgrade publisher node

Masahiko Sawada <sawada.mshk@gmail.com>

From: Masahiko Sawada <sawada.mshk@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Julien Rouhaud <rjuju123@gmail.com>, vignesh C <vignesh21@gmail.com>
Date: 2023-08-09T02:30:45Z
Lists: pgsql-hackers
On Mon, Aug 7, 2023 at 6:02 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Aug 7, 2023 at 2:02 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> >
> > On Mon, Aug 7, 2023 at 12:54 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > On Sun, Aug 6, 2023 at 6:02 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> > > >
> > > > IIUC the above query checks if the WAL record written at the slot's
> > > > confirmed_flush_lsn is a CHECKPOINT_SHUTDOWN, but there is no check if
> > > > this WAL record is the latest record.
> > > >
> > >
> > > Yeah, I also think there should be some way to ensure this. How about
> > > passing the number of records to read to this API? Actually, that will
> > > address my other concern as well where the current API can lead to
> > > reading an unbounded number of records if the confirmed_flush_lsn
> > > location is far behind the CHECKPOINT_SHUTDOWN. Do you have any better
> > > ideas to address it?
> >
> > It makes sense to me to limit the number of WAL records to read. But
> > as I mentioned below, if there is a chance of any WAL activity during
> > the upgrade, I'm not sure what limit to set.
> >
>
> In that case, we won't be able to pass the number of records. We need
> to check based on the type of records.
>
> >
> > > However, I am not
> > > sure if there can't be any additional WAL from checkpointer or
> > > bgwriter. Checkpointer has a code that ensures that if there is no
> > > important WAL activity then it would be skipped. Similarly, bgwriter
> > > also doesn't LOG xl_running_xacts unless there is an important
> > > activity.
> >
> > WAL records for hint bit updates could be generated even in upgrading mode?
> >
>
> Do you mean these records can be generated during reading catalog tables?

Yes.

>
> > > I feel if there is a chance of any WAL activity during the
> > > upgrade, we need to either change the check to ensure such WAL records
> > > are expected or document the same in some way.
> >
> > Yes, but how does it work with the above idea of limiting the number
> > of WAL records to read? If XLOG_FPI_FOR_HINT can still be generated in
> > the upgrade mode, we cannot predict how many such records are
> > generated after the latest CHECKPOINT_SHUTDOWN.
> >
>
> Right, as said earlier, in that case, we need to rely on the type of records.

Another idea would be that before starting the old cluster we check if
the slot's confirmed_flush_lsn in the slot state file matches the
latest checkpoint LSN got by pg_controlfile. We need another tool to
dump the slot state file, though.

>
> > I'm not really sure we should always perform the slot's
> > confirmed_flush_lsn check by default in the first place. With this
> > check, the upgrade won't be able to proceed if there is any logical
> > slot that is not used by logical replication (or something streaming
> > the changes using walsender), right? For example, if a user uses a
> > program that periodically consumes the changes from the logical slot,
> > the slot would not be able to pass the check even if the user executed
> > pg_logical_slot_get_changes() just before shutdown. The backend
> > process who consumes the changes is always terminated before the
> > shutdown checkpoint. On the other hand, I think there are cases where
> > the user can ensure that no meaningful WAL records are generated after
> > the last pg_logical_slot_get_changes(). I'm concerned that this check
> > might make upgrading such cases cumbersome unnecessarily.
> >
>
> You are right and I have mentioned the same case today in my response
> to Jonathan but do you have better ideas to deal with such slots than
> to give an ERROR?

It makes sense to me to give an ERROR for such slots but does it also
make sense to make the check optional?

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com



Commits

  1. Fix issues in binary_upgrade_logical_slot_has_caught_up().

  2. Fix a random failure in 003_logical_slots.pl.

  3. Fix a test in 003_logical_slots.

  4. Fix uninitialized slot array access during the upgrade.

  5. Fix the test 003_logical_slots.

  6. Commit b195e6d482 forgot to update meson.build.

  7. Use shorter file names in the upgrade logical slots test.

  8. Migrate logical slots to the new node during an upgrade.

  9. Flush logical slots to disk during a shutdown checkpoint if required.

  10. Prevent possibility of panics during shutdown checkpoint.