Re: recovery_target immediate timestamp - Mailing list pgsql-hackers

From Euler Taveira
Subject Re: recovery_target immediate timestamp
Date
Msg-id CAH503wAje9b+k-p82ZaE5E4cXSq5YQi_6OQjS6N8RE0bxaD9OQ@mail.gmail.com
Whole thread Raw
In response to Re: recovery_target immediate timestamp  (Fujii Masao <masao.fujii@oss.nttdata.com>)
Responses Re: recovery_target immediate timestamp
List pgsql-hackers
On Wed, 11 Nov 2020 at 22:40, Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

On 2020/11/12 6:00, Euler Taveira wrote:
 
> The first patch adds a new message that prints the latest completed checkpoint
> when the consistent state is reached.

I'm not sure how useful this information is in practice.

Fujii, thanks for reviewing it. It provides the same information as the "last
completed transaction was" message.
 
> It also exposes the checkpoint timestamp
> in debug messages.

                        ereport(DEBUG1,
                                        (errmsg("checkpoint record is at %X/%X",
                                                        (uint32) (checkPointLoc >> 32), (uint32) checkPointLoc)));
+                       ereport(DEBUG1,
+                                       (errmsg("checkpoint time is %s", str_time(checkPoint.time))));

The above first debug message displays the LSN of the checkpoint record.
OTOH, the second message displays the time when the checkpoint started
(not the time when checkpoint record was written at the end of checkpoint).
So isn't it confusing to display those inconsistent information together?

Indeed the checkpoint timestamp is from before it determines the REDO LSN. Are
you saying the this checkpoint timestamp is inconsistent because it is not near
the point it saves the RedoRecPtr? If so, let's move checkPoint.time a few
lines below.

    /*    
     * Here we update the shared RedoRecPtr for future XLogInsert calls; this
     * must be done while holding all the insertion locks.
     *
     * Note: if we fail to complete the checkpoint, RedoRecPtr will be left
     * pointing past where it really needs to point.  This is okay; the only
     * consequence is that XLogInsert might back up whole buffers that it
     * didn't really need to.  We can't postpone advancing RedoRecPtr because
     * XLogInserts that happen while we are dumping buffers must assume that
     * their buffer changes are not included in the checkpoint.
     */
    RedoRecPtr = XLogCtl->Insert.RedoRecPtr = checkPoint.redo;
    checkPoint.time = (pg_time_t) time(NULL);

I realized that I was using the wrong variable in one of the debug messages.
 
> The second patch provides the checkpoint timestamp in the pg_waldump output and
> also when you enable wal_debug parameter. The pg_waldump output looks like

+1

+#ifdef FRONTEND
+               strftime(checkpointstr, sizeof(checkpointstr), "%c", localtime(&time_tmp));
+#else
+               pg_strftime(checkpointstr, sizeof(checkpointstr), "%c", pg_localtime(&time_tmp, log_timezone));
+#endif

You can simplify the code by using timestamptz_to_str() here instead, like xact_desc_commit() does.

I have the same idea until I realized that checkPoint.time is pg_time_t and not
TimestampTz. [digging the code a bit...] I figure out there is a function that
converts from pg_time_t to TimestampTz: time_t_to_timestamptz(). I removed that
ugly code but have to duplicate this function into compat.c. I don't have a
strong preference but I'm attaching a new patch.

At the end, I asked myself if it is worth changing this type from pg_time_t to
TimestampTz.


--
Euler Taveira                 http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachment

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Deleting older versions in unique indexes to avoid page splits
Next
From: Thomas Munro
Date:
Subject: Re: Optimising latch signals