log_consistent_lsn_type.patch
text/x-patch
Filename: log_consistent_lsn_type.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/bin/pg_basebackup/pg_createsubscriber.c | 43 | 0 |
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 7f13f147762..e5b0d2ebbf2 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -622,6 +622,47 @@ get_primary_sysid(const char *conninfo)
return sysid;
}
+static void
+check_consistent_lsn_is_commit(const char *conninfo, char *consistent_lsn)
+{
+ PGconn *conn;
+ PGresult *res;
+ PQExpBuffer query = createPQExpBuffer();
+ char *lsn;
+ char *recordtype;
+
+ /* This hack is to prevent "could not find a valid record after" error */
+ sleep(1);
+
+ conn = connect_database(conninfo, true);
+
+ lsn = PQescapeLiteral(conn, consistent_lsn, strlen(consistent_lsn));
+ appendPQExpBuffer(query, "SELECT (public.pg_get_wal_record_info(%s::pg_lsn)).record_type",
+ lsn);
+
+ res = PQexec(conn, query->data);
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ {
+ pg_log_error("could not get record type of consistent lsn: %s",
+ PQresultErrorMessage(res));
+ disconnect_database(conn, true);
+ }
+ if (PQntuples(res) != 1)
+ {
+ pg_log_error("could not get record type of consistent lsn: got %d rows, expected %d row",
+ PQntuples(res), 1);
+ disconnect_database(conn, true);
+ }
+
+ recordtype = pg_strdup(PQgetvalue(res, 0, 0));
+
+ pg_log_info("consistent point lsn record type is %s", recordtype);
+
+ PQclear(res);
+ disconnect_database(conn, false);
+ destroyPQExpBuffer(query);
+}
+
/*
* Obtain the system identifier from control file. It will be used to compare
* if a data directory is a clone of another one. This routine is used locally
@@ -2417,6 +2458,8 @@ main(int argc, char **argv)
/* Create the required objects for each database on publisher */
consistent_lsn = setup_publisher(dbinfos.dbinfo);
+ check_consistent_lsn_is_commit(dbinfos.dbinfo[0].pubconninfo, consistent_lsn);
+
/* Write the required recovery parameters */
setup_recovery(dbinfos.dbinfo, subscriber_dir, consistent_lsn);