MCPcopy Create free account
hub / github.com/apache/cloudberry / GenerateRecoveryConfig

Function GenerateRecoveryConfig

src/fe_utils/recovery_gen.c:24–110  ·  view source on GitHub ↗

* Write recovery configuration contents into a fresh PQExpBuffer, and * return it. */

Source from the content-addressed store, hash-verified

22 * return it.
23 */
24PQExpBuffer
25GenerateRecoveryConfig(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 }

Callers 3

mainFunction · 0.85
BaseBackupFunction · 0.85
mainFunction · 0.85

Calls 11

createPQExpBufferFunction · 0.85
PQserverVersionFunction · 0.85
appendPQExpBufferStrFunction · 0.85
PQconninfoFunction · 0.85
initPQExpBufferFunction · 0.85
appendPQExpBufferCharFunction · 0.85
appendPQExpBufferFunction · 0.85
termPQExpBufferFunction · 0.85
PQconninfoFreeFunction · 0.85
appendConnStrValFunction · 0.70
escape_quotesFunction · 0.70

Tested by

no test coverage detected