]> granicus.if.org Git - postgresql/commitdiff
Check that the pg_upgrade user specified is a super-user.
authorBruce Momjian <bruce@momjian.us>
Sat, 7 May 2011 12:55:13 +0000 (08:55 -0400)
committerBruce Momjian <bruce@momjian.us>
Sat, 7 May 2011 12:55:45 +0000 (08:55 -0400)
Also report the error message when the post-pg_ctl connection fails.

Per private bug report from EnterpriseDB.

contrib/pg_upgrade/check.c
contrib/pg_upgrade/server.c

index 35b178e8286e7d0cf4c07fe50f159e45a06bce14..26dec39b35b6acdc9e71283aa28d60dbebe26afc 100644 (file)
@@ -15,6 +15,7 @@ static void check_new_cluster_is_empty(void);
 static void check_old_cluster_has_new_cluster_dbs(void);
 static void check_locale_and_encoding(ControlData *oldctrl,
                                                  ControlData *newctrl);
+static void check_is_super_user(ClusterInfo *cluster);
 static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
 static void check_for_reg_data_type_usage(ClusterInfo *cluster);
 
@@ -63,7 +64,7 @@ check_old_cluster(bool live_check,
        /*
         * Check for various failure cases
         */
-
+       check_is_super_user(&old_cluster);
        check_for_reg_data_type_usage(&old_cluster);
        check_for_isn_and_int8_passing_mismatch(&old_cluster);
 
@@ -472,6 +473,32 @@ create_script_for_old_cluster_deletion(
 }
 
 
+/*
+ *     check_is_super_user()
+ *
+ *     Make sure we are the super-user.
+ */
+static void
+check_is_super_user(ClusterInfo *cluster)
+{
+       PGresult   *res;
+       PGconn     *conn = connectToServer(cluster, "template1");
+
+       /* Can't use pg_authid because only superusers can view it. */
+       res = executeQueryOrDie(conn,
+                                                       "SELECT rolsuper "
+                                                       "FROM pg_catalog.pg_roles "
+                                                       "WHERE rolname = current_user");
+
+       if (PQntuples(res) != 1 || strcmp(PQgetvalue(res, 0, 0), "t") != 0)
+               pg_log(PG_FATAL, "the database user is not a superuser\n");
+
+       PQclear(res);
+
+       PQfinish(conn);
+}
+
+
 /*
  *     check_for_isn_and_int8_passing_mismatch()
  *
index 9a550756e56acffd115465a2febf35525ef44123..d6efe9af6b43f39fbca0210292cd3bb8d11f15a5 100644 (file)
@@ -27,7 +27,7 @@ connectToServer(ClusterInfo *cluster, const char *db_name)
 
        if (conn == NULL || PQstatus(conn) != CONNECTION_OK)
        {
-               pg_log(PG_REPORT, "Connection to database failed: %s\n",
+               pg_log(PG_REPORT, "connection to database failed: %s\n",
                           PQerrorMessage(conn));
 
                if (conn)
@@ -189,7 +189,9 @@ start_postmaster(ClusterInfo *cluster)
        if ((conn = get_db_conn(cluster, "template1")) == NULL ||
                PQstatus(conn) != CONNECTION_OK)
        {
-               if (conn)
+               pg_log(PG_REPORT, "\nconnection to database failed: %s\n",
+                          PQerrorMessage(conn));
+               if (conn)
                        PQfinish(conn);
                pg_log(PG_FATAL, "unable to connect to %s postmaster started with the command: %s\n"
                           "Perhaps pg_hba.conf was not set to \"trust\".\n",