mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Include more status information in walsender results
Add the current xlog insert location to the response of IDENTIFY_SYSTEM, and adds result sets containing start and stop location of backups to BASE_BACKUP responses.
This commit is contained in:
@@ -52,6 +52,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);
|
||||
|
||||
/*
|
||||
* Size of each block sent into the tar stream for larger files.
|
||||
@@ -92,6 +93,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
||||
char *labelfile;
|
||||
|
||||
startptr = do_pg_start_backup(opt->label, opt->fastcheckpoint, &labelfile);
|
||||
SendXlogRecPtrResult(startptr);
|
||||
|
||||
PG_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0);
|
||||
{
|
||||
@@ -239,6 +241,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
||||
/* Send CopyDone message for the last tar file */
|
||||
pq_putemptymessage('c');
|
||||
}
|
||||
SendXlogRecPtrResult(endptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -431,6 +434,42 @@ SendBackupHeader(List *tablespaces)
|
||||
pq_puttextmessage('C', "SELECT");
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a single resultset containing just a single
|
||||
* XlogRecPtr record (in text format)
|
||||
*/
|
||||
static void
|
||||
SendXlogRecPtrResult(XLogRecPtr ptr)
|
||||
{
|
||||
StringInfoData buf;
|
||||
char str[MAXFNAMELEN];
|
||||
|
||||
snprintf(str, sizeof(str), "%X/%X", ptr.xlogid, ptr.xrecoff);
|
||||
|
||||
pq_beginmessage(&buf, 'T'); /* RowDescription */
|
||||
pq_sendint(&buf, 1, 2); /* 1 field */
|
||||
|
||||
/* Field header */
|
||||
pq_sendstring(&buf, "recptr");
|
||||
pq_sendint(&buf, 0, 4); /* table oid */
|
||||
pq_sendint(&buf, 0, 2); /* attnum */
|
||||
pq_sendint(&buf, TEXTOID, 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, strlen(str), 4); /* length */
|
||||
pq_sendbytes(&buf, str, strlen(str));
|
||||
pq_endmessage(&buf);
|
||||
|
||||
/* Send a CommandComplete message */
|
||||
pq_puttextmessage('C', "SELECT");
|
||||
}
|
||||
|
||||
/*
|
||||
* Inject a file with given name and content in the output tar stream.
|
||||
*/
|
||||
|
||||
@@ -258,19 +258,26 @@ IdentifySystem(void)
|
||||
StringInfoData buf;
|
||||
char sysid[32];
|
||||
char tli[11];
|
||||
char xpos[MAXFNAMELEN];
|
||||
XLogRecPtr logptr;
|
||||
|
||||
/*
|
||||
* Reply with a result set with one row, two columns. First col is system
|
||||
* ID, and second is timeline ID
|
||||
* Reply with a result set with one row, three columns. First col is system
|
||||
* ID, second is timeline ID, and third is current xlog location.
|
||||
*/
|
||||
|
||||
snprintf(sysid, sizeof(sysid), UINT64_FORMAT,
|
||||
GetSystemIdentifier());
|
||||
snprintf(tli, sizeof(tli), "%u", ThisTimeLineID);
|
||||
|
||||
logptr = GetInsertRecPtr();
|
||||
|
||||
snprintf(xpos, sizeof(xpos), "%X/%X",
|
||||
logptr.xlogid, logptr.xrecoff);
|
||||
|
||||
/* Send a RowDescription message */
|
||||
pq_beginmessage(&buf, 'T');
|
||||
pq_sendint(&buf, 2, 2); /* 2 fields */
|
||||
pq_sendint(&buf, 3, 2); /* 3 fields */
|
||||
|
||||
/* first field */
|
||||
pq_sendstring(&buf, "systemid"); /* col name */
|
||||
@@ -289,15 +296,27 @@ IdentifySystem(void)
|
||||
pq_sendint(&buf, 4, 2); /* typlen */
|
||||
pq_sendint(&buf, 0, 4); /* typmod */
|
||||
pq_sendint(&buf, 0, 2); /* format code */
|
||||
|
||||
/* third field */
|
||||
pq_sendstring(&buf, "xlogpos");
|
||||
pq_sendint(&buf, 0, 4);
|
||||
pq_sendint(&buf, 0, 2);
|
||||
pq_sendint(&buf, TEXTOID, 4);
|
||||
pq_sendint(&buf, -1, 2);
|
||||
pq_sendint(&buf, 0, 4);
|
||||
pq_sendint(&buf, 0, 2);
|
||||
pq_endmessage(&buf);
|
||||
|
||||
/* Send a DataRow message */
|
||||
pq_beginmessage(&buf, 'D');
|
||||
pq_sendint(&buf, 2, 2); /* # of columns */
|
||||
pq_sendint(&buf, 3, 2); /* # of columns */
|
||||
pq_sendint(&buf, strlen(sysid), 4); /* col1 len */
|
||||
pq_sendbytes(&buf, (char *) &sysid, strlen(sysid));
|
||||
pq_sendint(&buf, strlen(tli), 4); /* col2 len */
|
||||
pq_sendbytes(&buf, (char *) tli, strlen(tli));
|
||||
pq_sendint(&buf, strlen(xpos), 4); /* col3 len */
|
||||
pq_sendbytes(&buf, (char *) xpos, strlen(xpos));
|
||||
|
||||
pq_endmessage(&buf);
|
||||
|
||||
/* Send CommandComplete and ReadyForQuery messages */
|
||||
|
||||
Reference in New Issue
Block a user