* Start the log streaming */
| 201 | * Start the log streaming |
| 202 | */ |
| 203 | static void |
| 204 | StreamLogicalLog(void) |
| 205 | { |
| 206 | PGresult *res; |
| 207 | char *copybuf = NULL; |
| 208 | TimestampTz last_status = -1; |
| 209 | int i; |
| 210 | PQExpBuffer query; |
| 211 | |
| 212 | output_written_lsn = InvalidXLogRecPtr; |
| 213 | output_fsync_lsn = InvalidXLogRecPtr; |
| 214 | |
| 215 | /* |
| 216 | * Connect in replication mode to the server |
| 217 | */ |
| 218 | if (!conn) |
| 219 | conn = GetConnection(); |
| 220 | if (!conn) |
| 221 | /* Error message already written in GetConnection() */ |
| 222 | return; |
| 223 | |
| 224 | /* |
| 225 | * Start the replication |
| 226 | */ |
| 227 | if (verbose) |
| 228 | pg_log_info("starting log streaming at %X/%X (slot %s)", |
| 229 | LSN_FORMAT_ARGS(startpos), |
| 230 | replication_slot); |
| 231 | |
| 232 | /* Initiate the replication stream at specified location */ |
| 233 | query = createPQExpBuffer(); |
| 234 | appendPQExpBuffer(query, "START_REPLICATION SLOT \"%s\" LOGICAL %X/%X", |
| 235 | replication_slot, LSN_FORMAT_ARGS(startpos)); |
| 236 | |
| 237 | /* print options if there are any */ |
| 238 | if (noptions) |
| 239 | appendPQExpBufferStr(query, " ("); |
| 240 | |
| 241 | for (i = 0; i < noptions; i++) |
| 242 | { |
| 243 | /* separator */ |
| 244 | if (i > 0) |
| 245 | appendPQExpBufferStr(query, ", "); |
| 246 | |
| 247 | /* write option name */ |
| 248 | appendPQExpBuffer(query, "\"%s\"", options[(i * 2)]); |
| 249 | |
| 250 | /* write option value if specified */ |
| 251 | if (options[(i * 2) + 1] != NULL) |
| 252 | appendPQExpBuffer(query, " '%s'", options[(i * 2) + 1]); |
| 253 | } |
| 254 | |
| 255 | if (noptions) |
| 256 | appendPQExpBufferChar(query, ')'); |
| 257 | |
| 258 | res = PQexec(conn, query->data); |
| 259 | if (PQresultStatus(res) != PGRES_COPY_BOTH) |
| 260 | { |
no test coverage detected