Skip to content

Commit 8f37eb5

Browse files
author
Artur Zakirov
committed
Calculate recovery_time using current_timestamp()
1 parent a3b3fa1 commit 8f37eb5

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

backup.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,11 @@ pg_stop_backup(pgBackup *backup)
779779
PGresult *res;
780780
uint32 xlogid;
781781
uint32 xrecoff;
782+
783+
/*
784+
* We will use this values if there are no transactions between start_lsn
785+
* and stop_lsn.
786+
*/
782787
time_t recovery_time;
783788
TransactionId recovery_xid;
784789

@@ -789,19 +794,17 @@ pg_stop_backup(pgBackup *backup)
789794

790795
if (from_replica)
791796
res = pgut_execute(backup_conn,
792-
"SELECT *, txid_snapshot_xmax(txid_current_snapshot()) FROM pg_stop_backup(false)",
797+
"SELECT *, txid_snapshot_xmax(txid_current_snapshot()),"
798+
" current_timestamp(0)::timestamp"
799+
" FROM pg_stop_backup(false)",
793800
0, NULL);
794801
else
795802
res = pgut_execute(backup_conn,
796-
"SELECT *, txid_snapshot_xmax(txid_current_snapshot()) FROM pg_stop_backup()",
803+
"SELECT *, txid_snapshot_xmax(txid_current_snapshot()),"
804+
" current_timestamp(0)::timestamp"
805+
" FROM pg_stop_backup()",
797806
0, NULL);
798807

799-
/*
800-
* We will use this value if there are no transactions between start_lsn
801-
* and stop_lsn.
802-
*/
803-
recovery_time = time(NULL);
804-
805808
/*
806809
* Extract timeline and LSN from results of pg_stop_backup()
807810
*/
@@ -817,7 +820,7 @@ pg_stop_backup(pgBackup *backup)
817820
FILE *fp;
818821
pgFile *file;
819822

820-
Assert(PQnfields(res) >= 3);
823+
Assert(PQnfields(res) >= 5);
821824

822825
pgBackupGetPath(&current, path, lengthof(path), DATABASE_DIR);
823826
join_path_components(backup_label, path, PG_BACKUP_LABEL_FILE);
@@ -863,12 +866,22 @@ pg_stop_backup(pgBackup *backup)
863866
elog(ERROR,
864867
"result of txid_snapshot_xmax() is invalid: %s",
865868
PQerrorMessage(backup_conn));
869+
if (!parse_time(PQgetvalue(res, 0, 4), &recovery_time))
870+
elog(ERROR,
871+
"result of current_timestamp is invalid: %s",
872+
PQerrorMessage(backup_conn));
866873
}
867874
else
875+
{
868876
if (sscanf(PQgetvalue(res, 0, 1), XID_FMT, &recovery_xid) != 1)
869877
elog(ERROR,
870878
"result of txid_snapshot_xmax() is invalid: %s",
871879
PQerrorMessage(backup_conn));
880+
if (!parse_time(PQgetvalue(res, 0, 2), &recovery_time))
881+
elog(ERROR,
882+
"result of current_timestamp is invalid: %s",
883+
PQerrorMessage(backup_conn));
884+
}
872885

873886
PQclear(res);
874887

0 commit comments

Comments
 (0)