mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-11-24 08:52:38 +02:00
[Issue #128] Get timeline ID via pg_control_checkpoint() function
This commit is contained in:
parent
c2d32da0a0
commit
56726b25fa
@ -245,6 +245,7 @@ GRANT EXECUTE ON FUNCTION pg_catalog.pg_last_xlog_replay_location() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_current() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_current_snapshot() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_snapshot_xmax(txid_snapshot) TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.pg_control_checkpoint() TO backup;
|
||||
COMMIT;
|
||||
```
|
||||
|
||||
@ -263,6 +264,7 @@ GRANT EXECUTE ON FUNCTION pg_catalog.pg_last_wal_replay_lsn() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_current() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_current_snapshot() TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.txid_snapshot_xmax(txid_snapshot) TO backup;
|
||||
GRANT EXECUTE ON FUNCTION pg_catalog.pg_control_checkpoint() TO backup;
|
||||
COMMIT;
|
||||
```
|
||||
|
||||
|
@ -183,7 +183,13 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo)
|
||||
}
|
||||
|
||||
/* Obtain current timeline */
|
||||
current.tli = get_current_timeline(false);
|
||||
current.tli = get_current_timeline(backup_conn);
|
||||
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
current.tli = get_current_timeline(backup_conn);
|
||||
#else
|
||||
current.tli = get_current_timeline_from_control(false);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In incremental backup mode ensure that already-validated
|
||||
|
@ -788,7 +788,8 @@ extern XLogRecPtr get_first_record_lsn(const char *archivedir, XLogRecPtr start_
|
||||
TimeLineID tli, uint32 wal_seg_size);
|
||||
|
||||
/* in util.c */
|
||||
extern TimeLineID get_current_timeline(bool safe);
|
||||
extern TimeLineID get_current_timeline(PGconn *conn);
|
||||
extern TimeLineID get_current_timeline_from_control(bool safe);
|
||||
extern XLogRecPtr get_checkpoint_location(PGconn *conn);
|
||||
extern uint64 get_system_identifier(const char *pgdata_path);
|
||||
extern uint64 get_remote_system_identifier(PGconn *conn);
|
||||
|
33
src/util.c
33
src/util.c
@ -146,7 +146,36 @@ writeControlFile(ControlFileData *ControlFile, char *path, fio_location location
|
||||
* used by a node.
|
||||
*/
|
||||
TimeLineID
|
||||
get_current_timeline(bool safe)
|
||||
get_current_timeline(PGconn *conn)
|
||||
{
|
||||
|
||||
PGresult *res;
|
||||
TimeLineID tli = 0;
|
||||
char *val;
|
||||
|
||||
res = pgut_execute_extended(conn,
|
||||
"SELECT timeline_id FROM pg_control_checkpoint()", 0, NULL, true, true);
|
||||
|
||||
if (PQresultStatus(res) == PGRES_TUPLES_OK)
|
||||
val = PQgetvalue(res, 0, 0);
|
||||
else
|
||||
return get_current_timeline_from_control(false);
|
||||
|
||||
if (!parse_uint32(val, &tli, 0))
|
||||
{
|
||||
PQclear(res);
|
||||
elog(WARNING, "Invalid value of timeline_id %s", val);
|
||||
|
||||
/* TODO 3.0 remove it and just error out */
|
||||
return get_current_timeline_from_control(false);
|
||||
}
|
||||
|
||||
return tli;
|
||||
}
|
||||
|
||||
/* Get timeline from pg_control file */
|
||||
TimeLineID
|
||||
get_current_timeline_from_control(bool safe)
|
||||
{
|
||||
ControlFileData ControlFile;
|
||||
char *buffer;
|
||||
@ -164,6 +193,8 @@ get_current_timeline(bool safe)
|
||||
return ControlFile.checkPointCopy.ThisTimeLineID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Get last check point record ptr from pg_tonrol.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user