/* If -W was given, force prompt for password, but only the first time */
need_password = (dbgetpassword == 1 && !password);
do
{ /* Get a new password if appropriate */ if (need_password)
{
free(password);
password = simple_prompt("Password: ", false);
need_password = false;
}
/* Use (or reuse, on a subsequent connection) password if we have it */ if (password)
{
keywords[i] = "password";
values[i] = password;
} else
{
keywords[i] = NULL;
values[i] = NULL;
}
/* *IfthereistoolittlememoryeventoallocatethePGconnobject *andPQconnectdbParamsreturnsNULL,wecallexit(1)directly.
*/ if (!tmpconn)
pg_fatal("could not connect to server");
/* If we need a password and -w wasn't given, loop back and get one */ if (PQstatus(tmpconn) == CONNECTION_BAD &&
PQconnectionNeedsPassword(tmpconn) &&
dbgetpassword != -1)
{
PQfinish(tmpconn);
need_password = true;
}
} while (need_password);
/* check connection existence */
Assert(conn != NULL);
/* for previous versions set the default xlog seg size */ if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_SHOW_CMD)
{
WalSegSz = DEFAULT_XLOG_SEG_SIZE; returntrue;
}
res = PQexec(conn, "SHOW wal_segment_size"); if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
pg_log_error("could not send replication command \"%s\": %s", "SHOW wal_segment_size", PQerrorMessage(conn));
PQclear(res); returnfalse;
} if (PQntuples(res) != 1 || PQnfields(res) < 1)
{
pg_log_error("could not fetch WAL segment size: got %d rows and %d fields, expected %d rows and %d or more fields",
PQntuples(res), PQnfields(res), 1, 1);
PQclear(res); returnfalse;
}
/* fetch xlog value and unit from the result */ if (sscanf(PQgetvalue(res, 0, 0), "%d%2s", &xlog_val, xlog_unit) != 2)
{
pg_log_error("WAL segment size could not be parsed");
PQclear(res); returnfalse;
}
PQclear(res);
/* set the multiplier based on unit to convert xlog_val to bytes */ if (strcmp(xlog_unit, "MB") == 0)
multiplier = 1024 * 1024; elseif (strcmp(xlog_unit, "GB") == 0)
multiplier = 1024 * 1024 * 1024;
/* convert and set WalSegSz */
WalSegSz = xlog_val * multiplier;
if (!IsValidWalSegSize(WalSegSz))
{
pg_log_error(ngettext("remote server reported invalid WAL segment size (%d byte)", "remote server reported invalid WAL segment size (%d bytes)",
WalSegSz),
WalSegSz);
pg_log_error_detail("The WAL segment size must be a power of two between 1 MB and 1 GB."); returnfalse;
}
/* check connection existence */
Assert(conn != NULL);
/* for previous versions leave the default group access */ if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_GROUP_ACCESS) returntrue;
res = PQexec(conn, "SHOW data_directory_mode"); if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
pg_log_error("could not send replication command \"%s\": %s", "SHOW data_directory_mode", PQerrorMessage(conn));
PQclear(res); returnfalse;
} if (PQntuples(res) != 1 || PQnfields(res) < 1)
{
pg_log_error("could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields",
PQntuples(res), PQnfields(res), 1, 1);
PQclear(res); returnfalse;
}
if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1)
{
pg_log_error("group access flag could not be parsed: %s",
PQgetvalue(res, 0, 0));
/* Get database name, only available in 9.4 and newer versions */ if (db_name != NULL)
{
*db_name = NULL; if (PQserverVersion(conn) >= 90400)
{ if (PQnfields(res) < 4)
{
pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
PQntuples(res), PQnfields(res), 1, 4);
/* Build base portion of query */
appendPQExpBuffer(query, "CREATE_REPLICATION_SLOT \"%s\"", slot_name); if (is_temporary)
appendPQExpBufferStr(query, " TEMPORARY"); if (is_physical)
appendPQExpBufferStr(query, " PHYSICAL"); else
appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin);
/* Add any requested options */ if (use_new_option_syntax)
appendPQExpBufferStr(query, " ("); if (is_physical)
{ if (reserve_wal)
AppendPlainCommandOption(query, use_new_option_syntax, "RESERVE_WAL");
} else
{ if (failover && PQserverVersion(conn) >= 170000)
AppendPlainCommandOption(query, use_new_option_syntax, "FAILOVER");
if (two_phase && PQserverVersion(conn) >= 150000)
AppendPlainCommandOption(query, use_new_option_syntax, "TWO_PHASE");
if (PQserverVersion(conn) >= 100000)
{ /* pg_recvlogical doesn't use an exported snapshot, so suppress */ if (use_new_option_syntax)
AppendStringCommandOption(query, use_new_option_syntax, "SNAPSHOT", "nothing"); else
AppendPlainCommandOption(query, use_new_option_syntax, "NOEXPORT_SNAPSHOT");
}
} if (use_new_option_syntax)
{ /* Suppress option list if it would be empty, otherwise terminate */ if (query->data[query->len - 1] == '(')
{
query->len -= 2;
query->data[query->len] = '\0';
} else
appendPQExpBufferChar(query, ')');
}
/* Now run the query */
res = PQexec(conn, query->data); if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ constchar *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.