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

Function getRestoreCommand

src/bin/pg_rewind/pg_rewind.c:1124–1180  ·  view source on GitHub ↗

* Get value of GUC parameter restore_command from the target cluster. * * This uses a logic based on "postgres -C" to get the value from the * cluster. */

Source from the content-addressed store, hash-verified

1122 * cluster.
1123 */
1124static void
1125getRestoreCommand(const char *argv0)
1126{
1127 int rc;
1128 char postgres_exec_path[MAXPGPATH],
1129 postgres_cmd[MAXPGPATH],
1130 cmd_output[MAXPGPATH];
1131
1132 if (!restore_wal)
1133 return;
1134
1135 /* find postgres executable */
1136 rc = find_other_exec(argv0, "postgres",
1137 PG_BACKEND_VERSIONSTR,
1138 postgres_exec_path);
1139
1140 if (rc < 0)
1141 {
1142 char full_path[MAXPGPATH];
1143
1144 if (find_my_exec(argv0, full_path) < 0)
1145 strlcpy(full_path, progname, sizeof(full_path));
1146
1147 if (rc == -1)
1148 pg_log_error("The program \"%s\" is needed by %s but was not found in the\n"
1149 "same directory as \"%s\".\n"
1150 "Check your installation.",
1151 "postgres", progname, full_path);
1152 else
1153 pg_log_error("The program \"%s\" was found by \"%s\"\n"
1154 "but was not the same version as %s.\n"
1155 "Check your installation.",
1156 "postgres", full_path, progname);
1157 exit(1);
1158 }
1159
1160 /*
1161 * Build a command able to retrieve the value of GUC parameter
1162 * restore_command, if set.
1163 */
1164 snprintf(postgres_cmd, sizeof(postgres_cmd),
1165 "\"%s\" -D \"%s\" -C restore_command",
1166 postgres_exec_path, datadir_target);
1167
1168 if (!pipe_read_line(postgres_cmd, cmd_output, sizeof(cmd_output)))
1169 exit(1);
1170
1171 (void) pg_strip_crlf(cmd_output);
1172
1173 if (strcmp(cmd_output, "") == 0)
1174 pg_fatal("restore_command is not set in the target cluster");
1175
1176 restore_command = pg_strdup(cmd_output);
1177
1178 pg_log_debug("using for rewind restore_command = \'%s\'",
1179 restore_command);
1180}
1181

Callers 1

mainFunction · 0.85

Calls 7

find_other_execFunction · 0.85
find_my_execFunction · 0.85
strlcpyFunction · 0.85
pipe_read_lineFunction · 0.85
pg_strip_crlfFunction · 0.85
pg_fatalFunction · 0.85
pg_strdupFunction · 0.85

Tested by

no test coverage detected