1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-03 14:01:57 +02:00

Bug fix: Get restore_lsn from pg_create_restore_point result

This commit is contained in:
Arthur Zakirov 2018-09-21 14:21:43 +03:00
parent b4e0eaef3e
commit a8b5e540d4

View File

@ -1071,8 +1071,8 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
{ {
PGresult *res; PGresult *res;
const char *params[2]; const char *params[2];
uint32 xlogid; uint32 lsn_hi;
uint32 xrecoff; uint32 lsn_lo;
PGconn *conn; PGconn *conn;
params[0] = label; params[0] = label;
@ -1100,9 +1100,9 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
backup_in_progress = true; backup_in_progress = true;
/* Extract timeline and LSN from results of pg_start_backup() */ /* Extract timeline and LSN from results of pg_start_backup() */
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff); XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
/* Calculate LSN */ /* Calculate LSN */
backup->start_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff; backup->start_lsn = ((uint64) lsn_hi )<< 32 | lsn_lo;
PQclear(res); PQclear(res);
@ -1585,8 +1585,8 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
while (true) while (true)
{ {
PGresult *res; PGresult *res;
uint32 xlogid; uint32 lsn_hi;
uint32 xrecoff; uint32 lsn_lo;
XLogRecPtr replica_lsn; XLogRecPtr replica_lsn;
/* /*
@ -1617,9 +1617,9 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
} }
/* Extract timeline and LSN from result */ /* Extract timeline and LSN from result */
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff); XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
/* Calculate LSN */ /* Calculate LSN */
replica_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff; replica_lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
PQclear(res); PQclear(res);
/* target lsn was replicated */ /* target lsn was replicated */
@ -1653,8 +1653,8 @@ pg_stop_backup(pgBackup *backup)
PGconn *conn; PGconn *conn;
PGresult *res; PGresult *res;
PGresult *tablespace_map_content = NULL; PGresult *tablespace_map_content = NULL;
uint32 xlogid; uint32 lsn_hi;
uint32 xrecoff; uint32 lsn_lo;
XLogRecPtr restore_lsn = InvalidXLogRecPtr; XLogRecPtr restore_lsn = InvalidXLogRecPtr;
int pg_stop_backup_timeout = 0; int pg_stop_backup_timeout = 0;
char path[MAXPGPATH]; char path[MAXPGPATH];
@ -1699,6 +1699,10 @@ pg_stop_backup(pgBackup *backup)
res = pgut_execute(conn, "SELECT pg_catalog.pg_create_restore_point($1)", res = pgut_execute(conn, "SELECT pg_catalog.pg_create_restore_point($1)",
1, params); 1, params);
/* Extract timeline and LSN from the result */
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
/* Calculate LSN */
restore_lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
PQclear(res); PQclear(res);
} }
@ -1731,7 +1735,6 @@ pg_stop_backup(pgBackup *backup)
} }
else else
{ {
stop_backup_query = "SELECT" stop_backup_query = "SELECT"
" pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot())," " pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
" current_timestamp(0)::timestamptz," " current_timestamp(0)::timestamptz,"
@ -1750,6 +1753,8 @@ pg_stop_backup(pgBackup *backup)
*/ */
if (pg_stop_backup_is_sent && !in_cleanup) if (pg_stop_backup_is_sent && !in_cleanup)
{ {
res = NULL;
while (1) while (1)
{ {
if (!PQconsumeInput(conn) || PQisBusy(conn)) if (!PQconsumeInput(conn) || PQisBusy(conn))
@ -1791,8 +1796,11 @@ pg_stop_backup(pgBackup *backup)
{ {
switch (PQresultStatus(res)) switch (PQresultStatus(res))
{ {
/*
* We should expect only PGRES_TUPLES_OK since pg_stop_backup
* returns tuples.
*/
case PGRES_TUPLES_OK: case PGRES_TUPLES_OK:
case PGRES_COMMAND_OK:
break; break;
default: default:
elog(ERROR, "query failed: %s query was: %s", elog(ERROR, "query failed: %s query was: %s",
@ -1804,9 +1812,9 @@ pg_stop_backup(pgBackup *backup)
backup_in_progress = false; backup_in_progress = false;
/* Extract timeline and LSN from results of pg_stop_backup() */ /* Extract timeline and LSN from results of pg_stop_backup() */
XLogDataFromLSN(PQgetvalue(res, 0, 2), &xlogid, &xrecoff); XLogDataFromLSN(PQgetvalue(res, 0, 2), &lsn_hi, &lsn_lo);
/* Calculate LSN */ /* Calculate LSN */
stop_backup_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff; stop_backup_lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
if (!XRecOffIsValid(stop_backup_lsn)) if (!XRecOffIsValid(stop_backup_lsn))
{ {
@ -2617,16 +2625,16 @@ get_last_ptrack_lsn(void)
{ {
PGresult *res; PGresult *res;
uint32 xlogid; uint32 lsn_hi;
uint32 xrecoff; uint32 lsn_lo;
XLogRecPtr lsn; XLogRecPtr lsn;
res = pgut_execute(backup_conn, "select pg_catalog.pg_ptrack_control_lsn()", 0, NULL); res = pgut_execute(backup_conn, "select pg_catalog.pg_ptrack_control_lsn()", 0, NULL);
/* Extract timeline and LSN from results of pg_start_backup() */ /* Extract timeline and LSN from results of pg_start_backup() */
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff); XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
/* Calculate LSN */ /* Calculate LSN */
lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff; lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
PQclear(res); PQclear(res);
return lsn; return lsn;