diff options
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r-- | src/backend/replication/basebackup.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 2330fcc23ad..57946a9fa97 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -55,7 +55,7 @@ static void SendBackupHeader(List *tablespaces); static void base_backup_cleanup(int code, Datum arg); static void perform_base_backup(basebackup_options *opt, DIR *tblspcdir); static void parse_basebackup_options(List *options, basebackup_options *opt); -static void SendXlogRecPtrResult(XLogRecPtr ptr); +static void SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli); static int compareWalFileNames(const void *a, const void *b); /* Was the backup currently in-progress initiated in recovery mode? */ @@ -94,13 +94,16 @@ static void perform_base_backup(basebackup_options *opt, DIR *tblspcdir) { XLogRecPtr startptr; + TimeLineID starttli; XLogRecPtr endptr; + TimeLineID endtli; char *labelfile; backup_started_in_recovery = RecoveryInProgress(); - startptr = do_pg_start_backup(opt->label, opt->fastcheckpoint, &labelfile); - SendXlogRecPtrResult(startptr); + startptr = do_pg_start_backup(opt->label, opt->fastcheckpoint, &starttli, + &labelfile); + SendXlogRecPtrResult(startptr, starttli); PG_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0); { @@ -218,7 +221,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) } PG_END_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0); - endptr = do_pg_stop_backup(labelfile, !opt->nowait); + endptr = do_pg_stop_backup(labelfile, !opt->nowait, &endtli); if (opt->includewal) { @@ -426,7 +429,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) /* Send CopyDone message for the last tar file */ pq_putemptymessage('c'); } - SendXlogRecPtrResult(endptr); + SendXlogRecPtrResult(endptr, endtli); } /* @@ -635,17 +638,15 @@ SendBackupHeader(List *tablespaces) * XlogRecPtr record (in text format) */ static void -SendXlogRecPtrResult(XLogRecPtr ptr) +SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli) { StringInfoData buf; char str[MAXFNAMELEN]; - snprintf(str, sizeof(str), "%X/%X", (uint32) (ptr >> 32), (uint32) ptr); - pq_beginmessage(&buf, 'T'); /* RowDescription */ - pq_sendint(&buf, 1, 2); /* 1 field */ + pq_sendint(&buf, 2, 2); /* 2 fields */ - /* Field header */ + /* Field headers */ pq_sendstring(&buf, "recptr"); pq_sendint(&buf, 0, 4); /* table oid */ pq_sendint(&buf, 0, 2); /* attnum */ @@ -653,11 +654,29 @@ SendXlogRecPtrResult(XLogRecPtr ptr) pq_sendint(&buf, -1, 2); pq_sendint(&buf, 0, 4); pq_sendint(&buf, 0, 2); + + pq_sendstring(&buf, "tli"); + pq_sendint(&buf, 0, 4); /* table oid */ + pq_sendint(&buf, 0, 2); /* attnum */ + /* + * int8 may seem like a surprising data type for this, but in thory int4 + * would not be wide enough for this, as TimeLineID is unsigned. + */ + pq_sendint(&buf, INT8OID, 4); /* type oid */ + pq_sendint(&buf, -1, 2); + pq_sendint(&buf, 0, 4); + pq_sendint(&buf, 0, 2); pq_endmessage(&buf); /* Data row */ pq_beginmessage(&buf, 'D'); - pq_sendint(&buf, 1, 2); /* number of columns */ + pq_sendint(&buf, 2, 2); /* number of columns */ + + snprintf(str, sizeof(str), "%X/%X", (uint32) (ptr >> 32), (uint32) ptr); + pq_sendint(&buf, strlen(str), 4); /* length */ + pq_sendbytes(&buf, str, strlen(str)); + + snprintf(str, sizeof(str), "%u", tli); pq_sendint(&buf, strlen(str), 4); /* length */ pq_sendbytes(&buf, str, strlen(str)); pq_endmessage(&buf); |