Skip to content

Commit 5b73d8f

Browse files
committed
Fix pg_basebackup connection (#346)
The GetRestoreCommandHint() fails because libpq defaults to username for database name (which may not exist) and Greenplum blocks direct primary segment connections (this is done in [1]). Add explicit dbname=postgres and gp_session_role=utility to connection string. [1] postinit.c ```c else if ((Gp_session_role == GP_ROLE_DISPATCH) && !IS_QUERY_DISPATCHER()) { ereport(FATAL, (errcode(ERRCODE_CANNOT_CONNECT_NOW), errmsg("connections to primary segments are not allowed"), errdetail("This database instance is running as a primary segment in a Greenplum cluster and does not permit direct connections."), errhint("To force a connection anyway (dangerous!), use utility mode."))); } ```
1 parent de8beb9 commit 5b73d8f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,18 @@ GetRestoreCommandHint(PQExpBufferData conninfo_buf)
15881588
PGconn *regular_conn;
15891589
PGresult *restore_cmd_hint_res;
15901590
char *restore_cmd_hint = NULL;
1591+
PQExpBufferData conninfo_buf_copy;
15911592

1592-
regular_conn = PQconnectdb(conninfo_buf.data);
1593+
/*
1594+
* conninfo_buf doesn't include dbname. Without it, libpq defaults to connecting
1595+
* to a database with the same name as the username, which may not exist.
1596+
* Use the 'postgres' database which always exists. Also use utility mode
1597+
* to connect to primary segments.
1598+
*/
1599+
initPQExpBuffer(&conninfo_buf_copy);
1600+
appendPQExpBuffer(&conninfo_buf_copy, "%s dbname=postgres options='-c gp_session_role=utility'", conninfo_buf.data);
1601+
regular_conn = PQconnectdb(conninfo_buf_copy.data);
1602+
termPQExpBuffer(&conninfo_buf_copy);
15931603

15941604
if (PQstatus(regular_conn) != CONNECTION_OK)
15951605
{

src/test/isolation2/isolation2_schedule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ test: uao/concurrent_inserts_hash_crash_row
172172

173173
test: reorganize_after_ao_vacuum_skip_drop truncate_after_ao_vacuum_skip_drop mark_all_aoseg_await_drop
174174
# below test(s) inject faults so each of them need to be in a separate group
175-
#test: segwalrep/master_xlog_switch
175+
test: segwalrep/master_xlog_switch
176176
test: idle_gang_cleaner
177177

178178
# Tests on Append-Optimized tables (column-oriented).
@@ -254,8 +254,8 @@ test: segwalrep/dtm_recovery_on_standby
254254
test: segwalrep/commit_blocking_on_standby
255255
test: segwalrep/max_slot_wal_keep_size
256256
test: segwalrep/dtx_recovery_wait_lsn
257-
#test: pg_basebackup
258-
#test: pg_basebackup_with_tablespaces
257+
test: pg_basebackup
258+
test: pg_basebackup_with_tablespaces
259259
test: segwalrep/hintbit_throttle
260260
test: fts_manual_probe
261261
test: fts_session_reset

0 commit comments

Comments
 (0)