Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that provider has set wal_level=logical and otherwise immediately fail in pglogical.create_subscription. #301

Open
wants to merge 1 commit into
base: REL2_x_STABLE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pglogical_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ PG_FUNCTION_INFO_V1(pglogical_show_repset_table_info_by_target);
static void gen_slot_name(Name slot_name, char *dbname,
const char *provider_name,
const char *subscriber_name);
static void check_provider_wal_level_is_logical(PGconn *conn);

bool in_pglogical_replicate_ddl_command = false;

Expand Down Expand Up @@ -415,6 +416,7 @@ pglogical_create_subscription(PG_FUNCTION_ARGS)

/* Now, fetch info about remote node. */
conn = pglogical_connect(provider_dsn, sub_name, "create");
check_provider_wal_level_is_logical(conn);
pglogical_remote_node_info(conn, &origin.id, &origin.name, NULL, NULL, NULL);
PQfinish(conn);

Expand Down Expand Up @@ -534,6 +536,29 @@ pglogical_create_subscription(PG_FUNCTION_ARGS)
PG_RETURN_OID(sub.id);
}

/*
* Make sure the provider has set wal_level=logical.
*/
static void
check_provider_wal_level_is_logical(PGconn *conn)
{
PGresult *res;
const char *wal_level;

res = PQexec(conn, "SHOW wal_level");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
elog(ERROR, "could not fetch provider wal_level flag: %s\n", PQerrorMessage(conn));

if (PQntuples(res) != 1)
elog(ERROR, "unexpected result from 'SHOW wal_level'.\n");

wal_level = pstrdup(PQgetvalue(res, 0, 0));
if (strcmp("logical", wal_level) != 0)
elog(ERROR, "provider must have set wal_level=logical (currently %s)\n", wal_level);

PQclear(res);
}

/*
* Remove subscribption.
*/
Expand Down