Skip to content

Commit 81301b8

Browse files
committed
Check that the pg_upgrade user specified is a super-user.
Also report the error message when the post-pg_ctl connection fails. Per private bug report from EnterpriseDB.
1 parent 71932ec commit 81301b8

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

contrib/pg_upgrade/check.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static void check_new_cluster_is_empty(void);
1515
static void check_old_cluster_has_new_cluster_dbs(void);
1616
static void check_locale_and_encoding(ControlData *oldctrl,
1717
ControlData *newctrl);
18+
static void check_is_super_user(ClusterInfo *cluster);
1819
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
1920
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
2021

@@ -63,7 +64,7 @@ check_old_cluster(bool live_check,
6364
/*
6465
* Check for various failure cases
6566
*/
66-
67+
check_is_super_user(&old_cluster);
6768
check_for_reg_data_type_usage(&old_cluster);
6869
check_for_isn_and_int8_passing_mismatch(&old_cluster);
6970

@@ -472,6 +473,32 @@ create_script_for_old_cluster_deletion(
472473
}
473474

474475

476+
/*
477+
* check_is_super_user()
478+
*
479+
* Make sure we are the super-user.
480+
*/
481+
static void
482+
check_is_super_user(ClusterInfo *cluster)
483+
{
484+
PGresult *res;
485+
PGconn *conn = connectToServer(cluster, "template1");
486+
487+
/* Can't use pg_authid because only superusers can view it. */
488+
res = executeQueryOrDie(conn,
489+
"SELECT rolsuper "
490+
"FROM pg_catalog.pg_roles "
491+
"WHERE rolname = current_user");
492+
493+
if (PQntuples(res) != 1 || strcmp(PQgetvalue(res, 0, 0), "t") != 0)
494+
pg_log(PG_FATAL, "the database user is not a superuser\n");
495+
496+
PQclear(res);
497+
498+
PQfinish(conn);
499+
}
500+
501+
475502
/*
476503
* check_for_isn_and_int8_passing_mismatch()
477504
*

contrib/pg_upgrade/server.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
2727

2828
if (conn == NULL || PQstatus(conn) != CONNECTION_OK)
2929
{
30-
pg_log(PG_REPORT, "Connection to database failed: %s\n",
30+
pg_log(PG_REPORT, "connection to database failed: %s\n",
3131
PQerrorMessage(conn));
3232

3333
if (conn)
@@ -189,7 +189,9 @@ start_postmaster(ClusterInfo *cluster)
189189
if ((conn = get_db_conn(cluster, "template1")) == NULL ||
190190
PQstatus(conn) != CONNECTION_OK)
191191
{
192-
if (conn)
192+
pg_log(PG_REPORT, "\nconnection to database failed: %s\n",
193+
PQerrorMessage(conn));
194+
if (conn)
193195
PQfinish(conn);
194196
pg_log(PG_FATAL, "unable to connect to %s postmaster started with the command: %s\n"
195197
"Perhaps pg_hba.conf was not set to \"trust\".\n",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy