pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedminor bug
10+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2023-01-19 44e9e34266 87591db191 0a269527f6 1b9a0b96a8 abe203304e 1034507245 Log the correct ending timestamp in recovery_target_xid mode.
* minor bug
@ 2023-01-16 18:59 Torsten Förtsch <tfoertsch123@gmail.com>
0 siblings, 1 reply; 10+ messages in thread
From: Torsten Förtsch @ 2023-01-16 18:59 UTC (permalink / raw)
To: pgsql-general
Hi,
not sure if this is known behavior.
Server version is 14.6 (Debian 14.6-1.pgdg110+1).
In a PITR setup I have these settings:
recovery_target_xid = '852381'
recovery_target_inclusive = 'false'
In the log file I see this message:
LOG: recovery stopping before commit of transaction 852381, time
2000-01-01 00:00:00+00
But:
postgres=# select * from pg_last_committed_xact();
xid | timestamp | roident
--------+-------------------------------+---------
852380 | 2023-01-16 18:00:35.054495+00 | 0
So, the timestamp displayed in the log message is certainly wrong.
Thanks,
Torsten
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-17 09:42 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Torsten Förtsch <tfoertsch123@gmail.com>
0 siblings, 2 replies; 10+ messages in thread
From: Laurenz Albe @ 2023-01-17 09:42 UTC (permalink / raw)
To: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org
On Mon, 2023-01-16 at 19:59 +0100, Torsten Förtsch wrote:
> not sure if this is known behavior.
>
> Server version is 14.6 (Debian 14.6-1.pgdg110+1).
>
> In a PITR setup I have these settings:
>
> recovery_target_xid = '852381'
> recovery_target_inclusive = 'false'
>
> In the log file I see this message:
>
> LOG: recovery stopping before commit of transaction 852381, time 2000-01-01 00:00:00+00
>
> But:
>
> postgres=# select * from pg_last_committed_xact();
> xid | timestamp | roident
> --------+-------------------------------+---------
> 852380 | 2023-01-16 18:00:35.054495+00 | 0
>
> So, the timestamp displayed in the log message is certainly wrong.
Redirected to -hackers.
If recovery stops at a WAL record that has no timestamp, you get this
bogus recovery stop time. I think we should show the recovery stop time
only if time was the target, as in the attached patch.
Yours,
Laurenz Albe
Attachments:
0001-Don-t-show-bogus-recovery-stop-time.patch (text/x-patch, 1.9K) download
From 622e52bbd652fc8872448e46c3ca0bc78dd847fe Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
Date: Tue, 17 Jan 2023 10:38:40 +0100
Subject: [PATCH] Don't show bogus recovery stop time
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If target for archive recovery was different from time, the
WAL record that ended recovery might not have a timestamp.
In that case, the log message at the end of recovery would
show a recovery time of midnight on 2000-01-01.
Reported-by: Torsten Förtsch
Author: Laurenz Albe
Discussion: https://postgr.es/m/CAKkG4_kUevPqbmyOfLajx7opAQk6Cvwkvx0HRcFjSPfRPTXanA@mail.gmail.com
---
src/backend/access/transam/xlogrecovery.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index bc3c3eb3e7..ce3718ca2d 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -2570,19 +2570,21 @@ recoveryStopsBefore(XLogReaderState *record)
recoveryStopLSN = InvalidXLogRecPtr;
recoveryStopName[0] = '\0';
- if (isCommit)
+ /* for targets other than time, we might have no stop time */
+ if (recoveryTarget == RECOVERY_TARGET_XID)
{
ereport(LOG,
- (errmsg("recovery stopping before commit of transaction %u, time %s",
+ (errmsg("recovery stopping before %s of transaction %u, time %s",
+ (isCommit ? "commit" : "abort"),
recoveryStopXid,
timestamptz_to_str(recoveryStopTime))));
}
else
{
ereport(LOG,
- (errmsg("recovery stopping before abort of transaction %u, time %s",
- recoveryStopXid,
- timestamptz_to_str(recoveryStopTime))));
+ (errmsg("recovery stopping before %s of transaction %u",
+ (isCommit ? "commit" : "abort"),
+ recoveryStopXid)));
}
}
--
2.39.0
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-17 10:12 Michael Paquier <michael@paquier.xyz>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
1 sibling, 0 replies; 10+ messages in thread
From: Michael Paquier @ 2023-01-17 10:12 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org
On Tue, Jan 17, 2023 at 10:42:03AM +0100, Laurenz Albe wrote:
> If recovery stops at a WAL record that has no timestamp, you get this
> bogus recovery stop time. I think we should show the recovery stop time
> only if time was the target, as in the attached patch.
Good catch! I'll try to take a look.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-17 15:32 Tom Lane <tgl@sss.pgh.pa.us>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
1 sibling, 1 reply; 10+ messages in thread
From: Tom Lane @ 2023-01-17 15:32 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Mon, 2023-01-16 at 19:59 +0100, Torsten Förtsch wrote:
>> So, the timestamp displayed in the log message is certainly wrong.
> If recovery stops at a WAL record that has no timestamp, you get this
> bogus recovery stop time. I think we should show the recovery stop time
> only if time was the target, as in the attached patch.
I don't think that is a tremendously useful definition: the user
already knows what recoveryStopTime is, or can find it out from
their settings easily enough.
I seem to recall that the original idea was to report the timestamp
of the commit/abort record we are stopping at. Maybe my memory is
faulty, but I think that'd be significantly more useful than the
current behavior, *especially* when the replay stopping point is
defined by something other than time.
(Also, the wording of the log message suggests that that's what
the reported time is supposed to be. I wonder if somebody messed
this up somewhere along the way.)
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-18 08:27 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 10+ messages in thread
From: Laurenz Albe @ 2023-01-18 08:27 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
On Tue, 2023-01-17 at 10:32 -0500, Tom Lane wrote:
> Laurenz Albe <laurenz.albe@cybertec.at> writes:
> > On Mon, 2023-01-16 at 19:59 +0100, Torsten Förtsch wrote:
> > > So, the timestamp displayed in the log message is certainly wrong.
>
> > If recovery stops at a WAL record that has no timestamp, you get this
> > bogus recovery stop time. I think we should show the recovery stop time
> > only if time was the target, as in the attached patch.
>
> I don't think that is a tremendously useful definition: the user
> already knows what recoveryStopTime is, or can find it out from
> their settings easily enough.
>
> I seem to recall that the original idea was to report the timestamp
> of the commit/abort record we are stopping at. Maybe my memory is
> faulty, but I think that'd be significantly more useful than the
> current behavior, *especially* when the replay stopping point is
> defined by something other than time.
>
> (Also, the wording of the log message suggests that that's what
> the reported time is supposed to be. I wonder if somebody messed
> this up somewhere along the way.)
recoveryStopTime is set to recordXtime (the time of the xlog record)
a few lines above that patch, so this is useful information if it is
present.
I realized that my original patch might be a problem for translation;
here is an updated version that does not take any shortcuts.
Yours,
Laurenz Albe
Attachments:
0001-Don-t-show-bogus-recovery-stop-time.V2.patch (text/x-patch, 2.3K) download
From b01428486f7795f757edd14f66362ee575d2f168 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
Date: Wed, 18 Jan 2023 09:23:50 +0100
Subject: [PATCH] Don't show bogus recovery stop time
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If target for archive recovery was different from time, the
WAL record that ended recovery might not have a timestamp.
In that case, the log message at the end of recovery would
show a recovery time of midnight on 2000-01-01.
Reported-by: Torsten Förtsch
Author: Laurenz Albe
Discussion: https://postgr.es/m/CAKkG4_kUevPqbmyOfLajx7opAQk6Cvwkvx0HRcFjSPfRPTXanA@mail.gmail.com
---
src/backend/access/transam/xlogrecovery.c | 35 +++++++++++++++++------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index bc3c3eb3e7..73929a535e 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -2570,19 +2570,38 @@ recoveryStopsBefore(XLogReaderState *record)
recoveryStopLSN = InvalidXLogRecPtr;
recoveryStopName[0] = '\0';
+ /* this could be simplified, but that might break translatability */
if (isCommit)
{
- ereport(LOG,
- (errmsg("recovery stopping before commit of transaction %u, time %s",
- recoveryStopXid,
- timestamptz_to_str(recoveryStopTime))));
+ if (recoveryStopTime != 0)
+ {
+ ereport(LOG,
+ (errmsg("recovery stopping before commit of transaction %u, time %s",
+ recoveryStopXid,
+ timestamptz_to_str(recoveryStopTime))));
+ }
+ else
+ {
+ ereport(LOG,
+ (errmsg("recovery stopping before commit of transaction %u",
+ recoveryStopXid)));
+ }
}
else
{
- ereport(LOG,
- (errmsg("recovery stopping before abort of transaction %u, time %s",
- recoveryStopXid,
- timestamptz_to_str(recoveryStopTime))));
+ if (recoveryStopTime != 0)
+ {
+ ereport(LOG,
+ (errmsg("recovery stopping before abort of transaction %u, time %s",
+ recoveryStopXid,
+ timestamptz_to_str(recoveryStopTime))));
+ }
+ else
+ {
+ ereport(LOG,
+ (errmsg("recovery stopping before abort of transaction %u",
+ recoveryStopXid)));
+ }
}
}
--
2.39.0
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-18 20:03 Tom Lane <tgl@sss.pgh.pa.us>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 2 replies; 10+ messages in thread
From: Tom Lane @ 2023-01-18 20:03 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Tue, 2023-01-17 at 10:32 -0500, Tom Lane wrote:
>> I seem to recall that the original idea was to report the timestamp
>> of the commit/abort record we are stopping at. Maybe my memory is
>> faulty, but I think that'd be significantly more useful than the
>> current behavior, *especially* when the replay stopping point is
>> defined by something other than time.
>> (Also, the wording of the log message suggests that that's what
>> the reported time is supposed to be. I wonder if somebody messed
>> this up somewhere along the way.)
> recoveryStopTime is set to recordXtime (the time of the xlog record)
> a few lines above that patch, so this is useful information if it is
> present.
Ah, but that only happens if recoveryTarget == RECOVERY_TARGET_TIME.
Digging in the git history, I see that this did use to work as
I remember: we always extracted the record time before printing it.
That was accidentally broken in refactoring in c945af80c. I think
the correct fix is more like the attached.
regards, tom lane
Attachments:
0001-Don-t-show-bogus-recovery-stop-time.V3.patch (text/x-diff, 851B) download
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 5e65785306..c14d1f3ef6 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -2548,8 +2548,13 @@ recoveryStopsBefore(XLogReaderState *record)
stopsHere = (recordXid == recoveryTargetXid);
}
- if (recoveryTarget == RECOVERY_TARGET_TIME &&
- getRecordTimestamp(record, &recordXtime))
+ /*
+ * Note: we must fetch recordXtime regardless of recoveryTarget setting.
+ * We don't expect getRecordTimestamp ever to fail, since we already know
+ * this is a commit or abort record; but test its result anyway.
+ */
+ if (getRecordTimestamp(record, &recordXtime) &&
+ recoveryTarget == RECOVERY_TARGET_TIME)
{
/*
* There can be many transactions that share the same commit time, so
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-19 12:57 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 10+ messages in thread
From: Laurenz Albe @ 2023-01-19 12:57 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
On Wed, 2023-01-18 at 15:03 -0500, Tom Lane wrote:
> Laurenz Albe <laurenz.albe@cybertec.at> writes:
> > On Tue, 2023-01-17 at 10:32 -0500, Tom Lane wrote:
> > > I seem to recall that the original idea was to report the timestamp
> > > of the commit/abort record we are stopping at. Maybe my memory is
> > > faulty, but I think that'd be significantly more useful than the
> > > current behavior, *especially* when the replay stopping point is
> > > defined by something other than time.
> > > (Also, the wording of the log message suggests that that's what
> > > the reported time is supposed to be. I wonder if somebody messed
> > > this up somewhere along the way.)
>
> > recoveryStopTime is set to recordXtime (the time of the xlog record)
> > a few lines above that patch, so this is useful information if it is
> > present.
>
> Ah, but that only happens if recoveryTarget == RECOVERY_TARGET_TIME.
> Digging in the git history, I see that this did use to work as
> I remember: we always extracted the record time before printing it.
> That was accidentally broken in refactoring in c945af80c. I think
> the correct fix is more like the attached.
Yes, you are right. Your patch looks fine to me.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-19 17:18 Torsten Förtsch <tfoertsch123@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 10+ messages in thread
From: Torsten Förtsch @ 2023-01-19 17:18 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
If we never expect getRecordTimestamp to fail, then why put it in the
if-condition?
getRecordTimestamp can fail if the record is not a restore point nor a
commit or abort record. A few lines before in the same function there is
this:
/* Otherwise we only consider stopping before COMMIT or ABORT records. */
if (XLogRecGetRmid(record) != RM_XACT_ID)
return false;
I guess that make sure getRecordTimestamp can never fail.
The way it is written in your patch invites it to be optimized out again.
The only thing that prevents it is the comment.
Why not
(void)getRecordTimestamp(record, &recordXtime);
if (recoveryTarget == RECOVERY_TARGET_TIME)
...
On Wed, Jan 18, 2023 at 9:03 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Laurenz Albe <laurenz.albe@cybertec.at> writes:
> > On Tue, 2023-01-17 at 10:32 -0500, Tom Lane wrote:
> >> I seem to recall that the original idea was to report the timestamp
> >> of the commit/abort record we are stopping at. Maybe my memory is
> >> faulty, but I think that'd be significantly more useful than the
> >> current behavior, *especially* when the replay stopping point is
> >> defined by something other than time.
> >> (Also, the wording of the log message suggests that that's what
> >> the reported time is supposed to be. I wonder if somebody messed
> >> this up somewhere along the way.)
>
> > recoveryStopTime is set to recordXtime (the time of the xlog record)
> > a few lines above that patch, so this is useful information if it is
> > present.
>
> Ah, but that only happens if recoveryTarget == RECOVERY_TARGET_TIME.
> Digging in the git history, I see that this did use to work as
> I remember: we always extracted the record time before printing it.
> That was accidentally broken in refactoring in c945af80c. I think
> the correct fix is more like the attached.
>
> regards, tom lane
>
>
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-19 17:25 Tom Lane <tgl@sss.pgh.pa.us>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 10+ messages in thread
From: Tom Lane @ 2023-01-19 17:25 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Torsten Förtsch <tfoertsch123@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Wed, 2023-01-18 at 15:03 -0500, Tom Lane wrote:
>> Ah, but that only happens if recoveryTarget == RECOVERY_TARGET_TIME.
>> Digging in the git history, I see that this did use to work as
>> I remember: we always extracted the record time before printing it.
>> That was accidentally broken in refactoring in c945af80c. I think
>> the correct fix is more like the attached.
> Yes, you are right. Your patch looks fine to me.
Pushed then. Thanks for the report!
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: minor bug
@ 2023-01-19 17:29 Tom Lane <tgl@sss.pgh.pa.us>
parent: Torsten Förtsch <tfoertsch123@gmail.com>
0 siblings, 0 replies; 10+ messages in thread
From: Tom Lane @ 2023-01-19 17:29 UTC (permalink / raw)
To: Torsten Förtsch <tfoertsch123@gmail.com>; +Cc: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>
=?UTF-8?Q?Torsten_F=C3=B6rtsch?= <tfoertsch123@gmail.com> writes:
> Why not
> (void)getRecordTimestamp(record, &recordXtime);
> if (recoveryTarget == RECOVERY_TARGET_TIME)
> ...
Could've done it like that, but I already pushed the other
version, and I don't think it's worth the trouble to change.
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2023-01-19 17:29 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 18:59 minor bug Torsten Förtsch <tfoertsch123@gmail.com>
2023-01-17 09:42 ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-01-17 10:12 ` Michael Paquier <michael@paquier.xyz>
2023-01-17 15:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-01-18 08:27 ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-01-18 20:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-01-19 12:57 ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-01-19 17:25 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-01-19 17:18 ` Torsten Förtsch <tfoertsch123@gmail.com>
2023-01-19 17:29 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox