* Write recovery configuration contents into a fresh PQExpBuffer, and * return it. */
| 22 | * return it. |
| 23 | */ |
| 24 | PQExpBuffer |
| 25 | GenerateRecoveryConfig(PGconn *pgconn, char *replication_slot) |
| 26 | { |
| 27 | PQconninfoOption *connOptions; |
| 28 | PQExpBufferData conninfo_buf; |
| 29 | char *escaped; |
| 30 | PQExpBuffer contents; |
| 31 | |
| 32 | Assert(pgconn != NULL); |
| 33 | |
| 34 | contents = createPQExpBuffer(); |
| 35 | if (!contents) |
| 36 | { |
| 37 | pg_log_error("out of memory"); |
| 38 | exit(1); |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * In PostgreSQL 12 and newer versions, standby_mode is gone, replaced by |
| 43 | * standby.signal to trigger a standby state at recovery. |
| 44 | */ |
| 45 | if (PQserverVersion(pgconn) < MINIMUM_VERSION_FOR_RECOVERY_GUC) |
| 46 | appendPQExpBufferStr(contents, "standby_mode = 'on'\n"); |
| 47 | |
| 48 | connOptions = PQconninfo(pgconn); |
| 49 | if (connOptions == NULL) |
| 50 | { |
| 51 | pg_log_error("out of memory"); |
| 52 | exit(1); |
| 53 | } |
| 54 | |
| 55 | initPQExpBuffer(&conninfo_buf); |
| 56 | for (PQconninfoOption *opt = connOptions; opt && opt->keyword; opt++) |
| 57 | { |
| 58 | /* Omit empty settings and those libpqwalreceiver overrides. */ |
| 59 | if (strcmp(opt->keyword, "replication") == 0 || |
| 60 | strcmp(opt->keyword, "dbname") == 0 || |
| 61 | strcmp(opt->keyword, "fallback_application_name") == 0 || |
| 62 | (opt->val == NULL) || |
| 63 | (opt->val != NULL && opt->val[0] == '\0')) |
| 64 | continue; |
| 65 | |
| 66 | /* Separate key-value pairs with spaces */ |
| 67 | if (conninfo_buf.len != 0) |
| 68 | appendPQExpBufferChar(&conninfo_buf, ' '); |
| 69 | |
| 70 | /* |
| 71 | * Write "keyword=value" pieces, the value string is escaped and/or |
| 72 | * quoted if necessary. |
| 73 | */ |
| 74 | appendPQExpBuffer(&conninfo_buf, "%s=", opt->keyword); |
| 75 | appendConnStrVal(&conninfo_buf, opt->val); |
| 76 | } |
| 77 | if (PQExpBufferDataBroken(conninfo_buf)) |
| 78 | { |
| 79 | pg_log_error("out of memory"); |
| 80 | exit(1); |
| 81 | } |
no test coverage detected