1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Change the timestamps recorded in transaction commit/abort xlog records

from time_t to TimestampTz representation.  This provides full gettimeofday()
resolution of the timestamps, which might be useful when attempting to
do point-in-time recovery --- previously it was not possible to specify
the stop point with sub-second resolution.  But mostly this is to get
rid of TimestampTz-to-time_t conversion overhead during commit.  Per my
proposal of a day or two back.
This commit is contained in:
Tom Lane
2007-04-30 21:01:53 +00:00
parent 641912b4d1
commit c432061963
7 changed files with 67 additions and 42 deletions

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.29 2007/04/03 16:34:35 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.30 2007/04/30 21:01:52 tgl Exp $
*
* NOTES
* Each global transaction is associated with a global transaction
@@ -1675,7 +1675,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
/* Emit the XLOG commit record */
xlrec.xid = xid;
xlrec.crec.xtime = time(NULL);
xlrec.crec.xact_time = GetCurrentTimestamp();
xlrec.crec.nrels = nrels;
xlrec.crec.nsubxacts = nchildren;
rdata[0].data = (char *) (&xlrec);
@@ -1753,7 +1753,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
/* Emit the XLOG abort record */
xlrec.xid = xid;
xlrec.arec.xtime = time(NULL);
xlrec.arec.xact_time = GetCurrentTimestamp();
xlrec.arec.nrels = nrels;
xlrec.arec.nsubxacts = nchildren;
rdata[0].data = (char *) (&xlrec);

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.241 2007/04/30 03:23:48 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.242 2007/04/30 21:01:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -773,7 +773,7 @@ RecordTransactionCommit(void)
MyProc->inCommit = true;
SetCurrentTransactionStopTimestamp();
xlrec.xtime = timestamptz_to_time_t(xactStopTimestamp);
xlrec.xact_time = xactStopTimestamp;
xlrec.nrels = nrels;
xlrec.nsubxacts = nchildren;
rdata[0].data = (char *) (&xlrec);
@@ -1069,7 +1069,7 @@ RecordTransactionAbort(void)
XLogRecPtr recptr;
SetCurrentTransactionStopTimestamp();
xlrec.xtime = timestamptz_to_time_t(xactStopTimestamp);
xlrec.xact_time = xactStopTimestamp;
xlrec.nrels = nrels;
xlrec.nsubxacts = nchildren;
rdata[0].data = (char *) (&xlrec);
@@ -1247,7 +1247,7 @@ RecordSubTransactionAbort(void)
xl_xact_abort xlrec;
XLogRecPtr recptr;
xlrec.xtime = time(NULL);
xlrec.xact_time = GetCurrentTimestamp();
xlrec.nrels = nrels;
xlrec.nsubxacts = nchildren;
rdata[0].data = (char *) (&xlrec);
@@ -4282,12 +4282,9 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
static void
xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
{
struct tm *tm = localtime(&xlrec->xtime);
int i;
appendStringInfo(buf, "%04u-%02u-%02u %02u:%02u:%02u",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
if (xlrec->nrels > 0)
{
appendStringInfo(buf, "; rels:");
@@ -4313,12 +4310,9 @@ xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
static void
xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec)
{
struct tm *tm = localtime(&xlrec->xtime);
int i;
appendStringInfo(buf, "%04u-%02u-%02u %02u:%02u:%02u",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
if (xlrec->nrels > 0)
{
appendStringInfo(buf, "; rels:");

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.267 2007/04/03 16:34:35 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.268 2007/04/30 21:01:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,7 +47,6 @@
#include "storage/procarray.h"
#include "storage/spin.h"
#include "utils/builtins.h"
#include "utils/nabstime.h"
#include "utils/pg_locale.h"
@@ -114,11 +113,11 @@ static bool recoveryTarget = false;
static bool recoveryTargetExact = false;
static bool recoveryTargetInclusive = true;
static TransactionId recoveryTargetXid;
static time_t recoveryTargetTime;
static TimestampTz recoveryTargetTime;
/* if recoveryStopsHere returns true, it saves actual stop xid/time here */
static TransactionId recoveryStopXid;
static time_t recoveryStopTime;
static TimestampTz recoveryStopTime;
static bool recoveryStopAfter;
/*
@@ -3536,7 +3535,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
recoveryStopXid,
str_time(recoveryStopTime));
timestamptz_to_str(recoveryStopTime));
nbytes = strlen(buffer);
errno = 0;
@@ -4276,17 +4275,16 @@ readRecoveryCommandFile(void)
recoveryTargetExact = false;
/*
* Convert the time string given by the user to the time_t format.
* We use type abstime's input converter because we know abstime
* has the same representation as time_t.
* Convert the time string given by the user to TimestampTz form.
*/
recoveryTargetTime = (time_t)
DatumGetAbsoluteTime(DirectFunctionCall1(abstimein,
CStringGetDatum(tok2)));
recoveryTargetTime =
DatumGetTimestampTz(DirectFunctionCall3(timestamptz_in,
CStringGetDatum(tok2),
ObjectIdGetDatum(InvalidOid),
Int32GetDatum(-1)));
ereport(LOG,
(errmsg("recovery_target_time = %s",
DatumGetCString(DirectFunctionCall1(abstimeout,
AbsoluteTimeGetDatum((AbsoluteTime) recoveryTargetTime))))));
timestamptz_to_str(recoveryTargetTime))));
}
else if (strcmp(tok1, "recovery_target_inclusive") == 0)
{
@@ -4464,7 +4462,7 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis)
{
bool stopsHere;
uint8 record_info;
time_t recordXtime;
TimestampTz recordXtime;
/* Do we have a PITR target at all? */
if (!recoveryTarget)
@@ -4479,14 +4477,14 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis)
xl_xact_commit *recordXactCommitData;
recordXactCommitData = (xl_xact_commit *) XLogRecGetData(record);
recordXtime = recordXactCommitData->xtime;
recordXtime = recordXactCommitData->xact_time;
}
else if (record_info == XLOG_XACT_ABORT)
{
xl_xact_abort *recordXactAbortData;
recordXactAbortData = (xl_xact_abort *) XLogRecGetData(record);
recordXtime = recordXactAbortData->xtime;
recordXtime = recordXactAbortData->xact_time;
}
else
return false;
@@ -4532,22 +4530,26 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis)
if (recoveryStopAfter)
ereport(LOG,
(errmsg("recovery stopping after commit of transaction %u, time %s",
recoveryStopXid, str_time(recoveryStopTime))));
recoveryStopXid,
timestamptz_to_str(recoveryStopTime))));
else
ereport(LOG,
(errmsg("recovery stopping before commit of transaction %u, time %s",
recoveryStopXid, str_time(recoveryStopTime))));
recoveryStopXid,
timestamptz_to_str(recoveryStopTime))));
}
else
{
if (recoveryStopAfter)
ereport(LOG,
(errmsg("recovery stopping after abort of transaction %u, time %s",
recoveryStopXid, str_time(recoveryStopTime))));
recoveryStopXid,
timestamptz_to_str(recoveryStopTime))));
else
ereport(LOG,
(errmsg("recovery stopping before abort of transaction %u, time %s",
recoveryStopXid, str_time(recoveryStopTime))));
recoveryStopXid,
timestamptz_to_str(recoveryStopTime))));
}
}