#include "pg_upgrade.h"
-static void set_locale_and_encoding(Cluster whichCluster);
+static void set_locale_and_encoding(ClusterInfo *cluster);
static void check_new_db_is_empty(void);
static void check_locale_and_encoding(ControlData *oldctrl,
ControlData *newctrl);
-static void check_for_isn_and_int8_passing_mismatch(
- Cluster whichCluster);
-static void check_for_reg_data_type_usage(Cluster whichCluster);
+static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
+static void check_for_reg_data_type_usage(ClusterInfo *cluster);
void
/* -- OLD -- */
if (!live_check)
- start_postmaster(CLUSTER_OLD, false);
+ start_postmaster(&old_cluster, false);
- set_locale_and_encoding(CLUSTER_OLD);
+ set_locale_and_encoding(&old_cluster);
- get_pg_database_relfilenode(CLUSTER_OLD);
+ get_pg_database_relfilenode(&old_cluster);
/* Extract a list of databases and tables from the old cluster */
- get_db_and_rel_infos(&old_cluster.dbarr, CLUSTER_OLD);
+ get_db_and_rel_infos(&old_cluster);
init_tablespaces();
* Check for various failure cases
*/
- check_for_reg_data_type_usage(CLUSTER_OLD);
- check_for_isn_and_int8_passing_mismatch(CLUSTER_OLD);
+ check_for_reg_data_type_usage(&old_cluster);
+ check_for_isn_and_int8_passing_mismatch(&old_cluster);
/* old = PG 8.3 checks? */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
{
- old_8_3_check_for_name_data_type_usage(CLUSTER_OLD);
- old_8_3_check_for_tsquery_usage(CLUSTER_OLD);
+ old_8_3_check_for_name_data_type_usage(&old_cluster);
+ old_8_3_check_for_tsquery_usage(&old_cluster);
if (user_opts.check)
{
- old_8_3_rebuild_tsvector_tables(true, CLUSTER_OLD);
- old_8_3_invalidate_hash_gin_indexes(true, CLUSTER_OLD);
- old_8_3_invalidate_bpchar_pattern_ops_indexes(true, CLUSTER_OLD);
+ old_8_3_rebuild_tsvector_tables(&old_cluster, true);
+ old_8_3_invalidate_hash_gin_indexes(&old_cluster, true);
+ old_8_3_invalidate_bpchar_pattern_ops_indexes(&old_cluster, true);
}
else
* end.
*/
*sequence_script_file_name =
- old_8_3_create_sequence_script(CLUSTER_OLD);
+ old_8_3_create_sequence_script(&old_cluster);
}
/* Pre-PG 9.0 had no large object permissions */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
- new_9_0_populate_pg_largeobject_metadata(true, CLUSTER_OLD);
+ new_9_0_populate_pg_largeobject_metadata(&old_cluster, true);
/*
* While not a check option, we do this now because this is the only time
void
check_new_cluster(void)
{
- set_locale_and_encoding(CLUSTER_NEW);
+ set_locale_and_encoding(&new_cluster);
check_new_db_is_empty();
/* old = PG 8.3 warnings? */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
{
- start_postmaster(CLUSTER_NEW, true);
+ start_postmaster(&new_cluster, true);
/* restore proper sequence values using file created from old server */
if (sequence_script_file_name)
check_ok();
}
- old_8_3_rebuild_tsvector_tables(false, CLUSTER_NEW);
- old_8_3_invalidate_hash_gin_indexes(false, CLUSTER_NEW);
- old_8_3_invalidate_bpchar_pattern_ops_indexes(false, CLUSTER_NEW);
+ old_8_3_rebuild_tsvector_tables(&new_cluster, false);
+ old_8_3_invalidate_hash_gin_indexes(&new_cluster, false);
+ old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false);
stop_postmaster(false, true);
}
/* Create dummy large object permissions for old < PG 9.0? */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
{
- start_postmaster(CLUSTER_NEW, true);
- new_9_0_populate_pg_largeobject_metadata(false, CLUSTER_NEW);
+ start_postmaster(&new_cluster, true);
+ new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
stop_postmaster(false, true);
}
}
check_cluster_versions(void)
{
/* get old and new cluster versions */
- old_cluster.major_version = get_major_server_version(&old_cluster.major_version_str, CLUSTER_OLD);
- new_cluster.major_version = get_major_server_version(&new_cluster.major_version_str, CLUSTER_NEW);
+ old_cluster.major_version = get_major_server_version(&old_cluster, &old_cluster.major_version_str);
+ new_cluster.major_version = get_major_server_version(&new_cluster, &new_cluster.major_version_str);
/* We allow upgrades from/to the same major version for alpha/beta upgrades */
* query the database to get the template0 locale
*/
static void
-set_locale_and_encoding(Cluster whichCluster)
+set_locale_and_encoding(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
- ControlData *ctrl = &active_cluster->controldata;
+ ControlData *ctrl = &cluster->controldata;
PGconn *conn;
PGresult *res;
int i_encoding;
- int cluster_version = active_cluster->major_version;
+ int cluster_version = cluster->major_version;
- conn = connectToServer("template1", whichCluster);
+ conn = connectToServer(cluster, "template1");
/* for pg < 80400, we got the values from pg_controldata */
if (cluster_version >= 80400)
int dbnum;
bool found = false;
- get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
+ get_db_and_rel_infos(&new_cluster);
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
{
* it must match for the old and new servers.
*/
void
-check_for_isn_and_int8_passing_mismatch(Cluster whichCluster)
+check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/contrib_isn_and_int8_pass_by_value.txt",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int rowno;
int i_nspname,
i_proname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* Find any functions coming from contrib/isn */
res = executeQueryOrDie(conn,
* tables upgraded by pg_upgrade.
*/
void
-check_for_reg_data_type_usage(Cluster whichCluster)
+check_for_reg_data_type_usage(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/tables_using_reg.txt",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int i_nspname,
i_relname,
i_attname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
res = executeQueryOrDie(conn,
"SELECT n.nspname, c.relname, a.attname "
static void check_data_dir(const char *pg_data);
-static void check_bin_dir(ClusterInfo *cluster, Cluster whichCluster);
+static void check_bin_dir(ClusterInfo *cluster);
static int check_exec(const char *dir, const char *cmdName);
static const char *validate_exec(const char *path);
check_ok();
prep_status("Checking old bin directory (%s)", old_cluster.bindir);
- check_bin_dir(&old_cluster, CLUSTER_OLD);
+ check_bin_dir(&old_cluster);
check_ok();
prep_status("Checking new data directory (%s)", new_cluster.pgdata);
check_ok();
prep_status("Checking new bin directory (%s)", new_cluster.bindir);
- check_bin_dir(&new_cluster, CLUSTER_NEW);
+ check_bin_dir(&new_cluster);
check_ok();
}
* exit().
*/
static void
-check_bin_dir(ClusterInfo *cluster, Cluster whichCluster)
+check_bin_dir(ClusterInfo *cluster)
{
check_exec(cluster->bindir, "postgres");
check_exec(cluster->bindir, "pg_ctl");
check_exec(cluster->bindir, "pg_resetxlog");
- if (whichCluster == CLUSTER_NEW)
+ if (cluster == &new_cluster)
{
/* these are only needed in the new cluster */
check_exec(cluster->bindir, "pg_config");
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
{
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
+ PGconn *conn = connectToServer(&new_cluster, newdb->db_name);
/* suppress NOTICE of dropped objects */
PQclear(executeQueryOrDie(conn,
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
{
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
+ PGconn *conn = connectToServer(&new_cluster, newdb->db_name);
/* suppress NOTICE of dropped objects */
PQclear(executeQueryOrDie(conn,
void
get_loadable_libraries(void)
{
- ClusterInfo *active_cluster = &old_cluster;
PGresult **ress;
int totaltups;
int dbnum;
ress = (PGresult **)
- pg_malloc(active_cluster->dbarr.ndbs * sizeof(PGresult *));
+ pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
totaltups = 0;
/* Fetch all library names, removing duplicates within each DB */
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
{
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, CLUSTER_OLD);
+ DbInfo *active_db = &old_cluster.dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(&old_cluster, active_db->db_name);
/* Fetch all libraries referenced in this DB */
ress[dbnum] = executeQueryOrDie(conn,
*/
totaltups = 0;
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
{
PGresult *res = ress[dbnum];
int ntups;
void
check_loadable_libraries(void)
{
- PGconn *conn = connectToServer("template1", CLUSTER_NEW);
+ PGconn *conn = connectToServer(&new_cluster, "template1");
int libnum;
FILE *script = NULL;
bool found = false;
#include "access/transam.h"
-static void get_db_infos(DbInfoArr *dbinfos,
- Cluster whichCluster);
-static void dbarr_print(DbInfoArr *arr,
- Cluster whichCluster);
+static void get_db_infos(ClusterInfo *cluster);
+static void dbarr_print(ClusterInfo *cluster);
static void relarr_print(RelInfoArr *arr);
-static void get_rel_infos(const DbInfo *dbinfo,
- RelInfoArr *relarr, Cluster whichCluster);
+static void get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo,
+ RelInfoArr *relarr);
static void relarr_free(RelInfoArr *rel_arr);
static void map_rel(const RelInfo *oldrel,
const RelInfo *newrel, const DbInfo *old_db,
const char *old_tablespace, const DbInfo *old_db,
const DbInfo *new_db, const char *olddata,
const char *newdata, FileNameMap *map);
-static RelInfo *relarr_lookup_reloid(RelInfoArr *rel_arr,
- Oid oid, Cluster whichCluster);
-static RelInfo *relarr_lookup_rel(RelInfoArr *rel_arr,
- const char *nspname, const char *relname,
- Cluster whichCluster);
+static RelInfo *relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr,
+ Oid oid);
+static RelInfo *relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
+ const char *nspname, const char *relname);
/*
if (strcmp(newrel->nspname, "pg_toast") == 0)
continue;
- oldrel = relarr_lookup_rel(&old_db->rel_arr, newrel->nspname,
- newrel->relname, CLUSTER_OLD);
+ oldrel = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
+ newrel->nspname, newrel->relname);
map_rel(oldrel, newrel, old_db, new_db, old_pgdata, new_pgdata,
maps + num_maps);
newrel->reloid);
/* look them up in their respective arrays */
- old_toast = relarr_lookup_reloid(&old_db->rel_arr,
- oldrel->toastrelid, CLUSTER_OLD);
- new_toast = relarr_lookup_rel(&new_db->rel_arr,
- "pg_toast", new_name, CLUSTER_NEW);
+ old_toast = relarr_lookup_reloid(&old_cluster, &old_db->rel_arr,
+ oldrel->toastrelid);
+ new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
+ "pg_toast", new_name);
/* finally create a mapping for them */
map_rel(old_toast, new_toast, old_db, new_db, old_pgdata, new_pgdata,
/* look them up in their respective arrays */
/* we lose our cache location here */
- old_toast = relarr_lookup_rel(&old_db->rel_arr,
- "pg_toast", old_name, CLUSTER_OLD);
- new_toast = relarr_lookup_rel(&new_db->rel_arr,
- "pg_toast", new_name, CLUSTER_NEW);
+ old_toast = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
+ "pg_toast", old_name);
+ new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
+ "pg_toast", new_name);
/* finally create a mapping for them */
map_rel(old_toast, new_toast, old_db, new_db, old_pgdata,
/*
* get_db_infos()
*
- * Scans pg_database system catalog and returns (in dbinfs_arr) all user
+ * Scans pg_database system catalog and populates all user
* databases.
*/
static void
-get_db_infos(DbInfoArr *dbinfs_arr, Cluster whichCluster)
+get_db_infos(ClusterInfo *cluster)
{
- PGconn *conn = connectToServer("template1", whichCluster);
+ PGconn *conn = connectToServer(cluster, "template1");
PGresult *res;
int ntups;
int tupnum;
PQfinish(conn);
- dbinfs_arr->dbs = dbinfos;
- dbinfs_arr->ndbs = ntups;
+ cluster->dbarr.dbs = dbinfos;
+ cluster->dbarr.ndbs = ntups;
}
* on the given "port". Assumes that server is already running.
*/
void
-get_db_and_rel_infos(DbInfoArr *db_arr, Cluster whichCluster)
+get_db_and_rel_infos(ClusterInfo *cluster)
{
int dbnum;
- get_db_infos(db_arr, whichCluster);
+ get_db_infos(cluster);
- for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
- get_rel_infos(&db_arr->dbs[dbnum],
- &db_arr->dbs[dbnum].rel_arr, whichCluster);
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
+ get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum],
+ &cluster->dbarr.dbs[dbnum].rel_arr);
if (log_opts.debug)
- dbarr_print(db_arr, whichCluster);
+ dbarr_print(cluster);
}
* FirstNormalObjectId belongs to the user
*/
static void
-get_rel_infos(const DbInfo *dbinfo, RelInfoArr *relarr, Cluster whichCluster)
+get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
{
- PGconn *conn = connectToServer(dbinfo->db_name, whichCluster);
+ PGconn *conn = connectToServer(cluster, dbinfo->db_name);
PGresult *res;
RelInfo *relinfos;
int ntups;
* RelInfo structure.
*/
static RelInfo *
-relarr_lookup_rel(RelInfoArr *rel_arr, const char *nspname,
- const char *relname, Cluster whichCluster)
+relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
+ const char *nspname, const char *relname)
{
int relnum;
}
}
pg_log(PG_FATAL, "Could not find %s.%s in %s cluster\n",
- nspname, relname, CLUSTER_NAME(whichCluster));
+ nspname, relname, CLUSTER_NAME(cluster));
return NULL;
}
* found.
*/
static RelInfo *
-relarr_lookup_reloid(RelInfoArr *rel_arr, Oid oid,
- Cluster whichCluster)
+relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
{
int relnum;
return &rel_arr->rels[relnum];
}
pg_log(PG_FATAL, "Could not find %d in %s cluster\n",
- oid, CLUSTER_NAME(whichCluster));
+ oid, CLUSTER_NAME(cluster));
return NULL;
}
static void
-dbarr_print(DbInfoArr *arr, Cluster whichCluster)
+dbarr_print(ClusterInfo *cluster)
{
int dbnum;
- pg_log(PG_DEBUG, "%s databases\n", CLUSTER_NAME(whichCluster));
+ pg_log(PG_DEBUG, "%s databases\n", CLUSTER_NAME(cluster));
- for (dbnum = 0; dbnum < arr->ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
- pg_log(PG_DEBUG, "Database: %s\n", arr->dbs[dbnum].db_name);
- relarr_print(&arr->dbs[dbnum].rel_arr);
+ pg_log(PG_DEBUG, "Database: %s\n", cluster->dbarr.dbs[dbnum].db_name);
+ relarr_print(&cluster->dbarr.dbs[dbnum].rel_arr);
pg_log(PG_DEBUG, "\n\n");
}
}
static void setup(char *argv0, bool live_check);
static void cleanup(void);
-ClusterInfo old_cluster,
- new_cluster;
+ClusterInfo old_cluster, new_cluster;
OSInfo os_info;
int
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
check_new_cluster();
report_clusters_compatible();
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
check_ok();
- get_pg_database_relfilenode(CLUSTER_NEW);
+ get_pg_database_relfilenode(&new_cluster);
}
prepare_new_databases(void)
{
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
/*
* We set autovacuum_freeze_max_age to its maximum value so autovacuum
GLOBALS_DUMP_FILE, log_opts.filename);
check_ok();
- get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
+ get_db_and_rel_infos(&new_cluster);
stop_postmaster(false, false);
}
create_new_objects(void)
{
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
install_support_functions();
/* regenerate now that we have db schemas */
dbarr_free(&new_cluster.dbarr);
- get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
+ get_db_and_rel_infos(&new_cluster);
uninstall_support_functions();
prep_status("Setting frozenxid counters in new cluster");
- conn_template1 = connectToServer("template1", CLUSTER_NEW);
+ conn_template1 = connectToServer(&new_cluster, "template1");
/* set pg_database.datfrozenxid */
PQclear(executeQueryOrDie(conn_template1,
"SET datallowconn = true "
"WHERE datname = '%s'", datname));
- conn = connectToServer(datname, CLUSTER_NEW);
+ conn = connectToServer(&new_cluster, datname);
/* set pg_class.relfrozenxid */
PQclear(executeQueryOrDie(conn,
#define EXE_EXT ".exe"
#endif
-#define CLUSTER_NAME(cluster) ((cluster) == CLUSTER_OLD ? "old" : "new")
-#define ACTIVE_CLUSTER(cluster) (((cluster) == CLUSTER_OLD) ? \
- &old_cluster : &new_cluster)
+#define CLUSTER_NAME(cluster) ((cluster) == &old_cluster ? "old" : \
+ (cluster) == &new_cluster ? "new" : "none")
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
PG_DEBUG
} eLogType;
-/*
- * Enumeration to distinguish between old cluster and new cluster
- */
-typedef enum
-{
- NONE = 0, /* used for no running servers */
- CLUSTER_OLD,
- CLUSTER_NEW
-} Cluster;
typedef long pgpid_t;
char **libraries; /* loadable libraries */
int num_libraries;
pgpid_t postmasterPID; /* PID of currently running postmaster */
- Cluster running_cluster;
+ ClusterInfo *running_cluster;
} OSInfo;
*/
extern LogOpts log_opts;
extern UserOpts user_opts;
-extern ClusterInfo old_cluster,
- new_cluster;
+extern ClusterInfo old_cluster, new_cluster;
extern OSInfo os_info;
extern char scandir_file_pattern[];
FileNameMap *gen_db_file_maps(DbInfo *old_db,
DbInfo *new_db, int *nmaps, const char *old_pgdata,
const char *new_pgdata);
-void get_db_and_rel_infos(DbInfoArr *db_arr,
- Cluster whichCluster);
+void get_db_and_rel_infos(ClusterInfo *cluster);
DbInfo *dbarr_lookup_db(DbInfoArr *db_arr, const char *db_name);
void dbarr_free(DbInfoArr *db_arr);
void print_maps(FileNameMap *maps, int n,
/* relfilenode.c */
-void get_pg_database_relfilenode(Cluster whichCluster);
+void get_pg_database_relfilenode(ClusterInfo *cluster);
const char *transfer_all_new_dbs(DbInfoArr *olddb_arr,
DbInfoArr *newdb_arr, char *old_pgdata, char *new_pgdata);
/* server.c */
-PGconn *connectToServer(const char *db_name,
- Cluster whichCluster);
-PGresult *executeQueryOrDie(PGconn *conn,
- const char *fmt,...);
+PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
+PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
-void start_postmaster(Cluster whichCluster, bool quiet);
+void start_postmaster(ClusterInfo *cluster, bool quiet);
void stop_postmaster(bool fast, bool quiet);
-uint32 get_major_server_version(char **verstr, Cluster whichCluster);
+uint32 get_major_server_version(ClusterInfo *cluster, char **verstr);
void check_for_libpq_envvars(void);
/* version.c */
-void new_9_0_populate_pg_largeobject_metadata(
- bool check_mode, Cluster whichCluster);
+void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
+ bool check_mode);
/* version_old_8_3.c */
-void old_8_3_check_for_name_data_type_usage(Cluster whichCluster);
-void old_8_3_check_for_tsquery_usage(Cluster whichCluster);
-void old_8_3_rebuild_tsvector_tables(bool check_mode,
- Cluster whichCluster);
-void old_8_3_invalidate_hash_gin_indexes(bool check_mode,
- Cluster whichCluster);
-void old_8_3_invalidate_bpchar_pattern_ops_indexes(bool check_mode,
- Cluster whichCluster);
-char *old_8_3_create_sequence_script(Cluster whichCluster);
+void old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster);
+void old_8_3_check_for_tsquery_usage(ClusterInfo *cluster);
+void old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode);
+void old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode);
+void old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,
+ bool check_mode);
+char *old_8_3_create_sequence_script(ClusterInfo *cluster);
* relfilenodes later in the upgrade process.
*/
void
-get_pg_database_relfilenode(Cluster whichCluster)
+get_pg_database_relfilenode(ClusterInfo *cluster)
{
- PGconn *conn = connectToServer("template1", whichCluster);
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
+ PGconn *conn = connectToServer(cluster, "template1");
PGresult *res;
int i_relfile;
"ORDER BY c.relname");
i_relfile = PQfnumber(res, "relfilenode");
- active_cluster->pg_database_oid = atooid(PQgetvalue(res, 0, i_relfile));
+ cluster->pg_database_oid = atooid(PQgetvalue(res, 0, i_relfile));
PQclear(res);
PQfinish(conn);
static pgpid_t get_postmaster_pid(const char *datadir);
-static bool test_server_conn(int timeout,
- Cluster whichCluster);
+static bool test_server_conn(ClusterInfo *cluster, int timeout);
/*
* message and calls exit_nicely() to kill the program.
*/
PGconn *
-connectToServer(const char *db_name,
- Cluster whichCluster)
+connectToServer(ClusterInfo *cluster, const char *db_name)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
- unsigned short port = active_cluster->port;
+ unsigned short port = cluster->port;
char connectString[MAXPGPATH];
PGconn *conn;
* is retrieved by reading the PG_VERSION file.
*/
uint32
-get_major_server_version(char **verstr, Cluster whichCluster)
+get_major_server_version(ClusterInfo *cluster, char **verstr)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
- const char *datadir = active_cluster->pgdata;
+ const char *datadir = cluster->pgdata;
FILE *version_fd;
char ver_file[MAXPGPATH];
int integer_version = 0;
void
-start_postmaster(Cluster whichCluster, bool quiet)
+start_postmaster(ClusterInfo *cluster, bool quiet)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
char cmd[MAXPGPATH];
const char *bindir;
const char *datadir;
unsigned short port;
- bindir = active_cluster->bindir;
- datadir = active_cluster->pgdata;
- port = active_cluster->port;
+ bindir = cluster->bindir;
+ datadir = cluster->pgdata;
+ port = cluster->port;
/*
* On Win32, we can't send both pg_upgrade output and pg_ctl output to the
/* wait for the server to start properly */
- if (test_server_conn(POSTMASTER_UPTIME, whichCluster) == false)
+ if (test_server_conn(cluster, POSTMASTER_UPTIME) == false)
pg_log(PG_FATAL, " Unable to start %s postmaster with the command: %s\nPerhaps pg_hba.conf was not set to \"trust\".",
- CLUSTER_NAME(whichCluster), cmd);
+ CLUSTER_NAME(cluster), cmd);
if ((os_info.postmasterPID = get_postmaster_pid(datadir)) == 0)
pg_log(PG_FATAL, " Unable to get postmaster pid\n");
- os_info.running_cluster = whichCluster;
+ os_info.running_cluster = cluster;
}
const char *bindir;
const char *datadir;
- if (os_info.running_cluster == CLUSTER_OLD)
+ if (os_info.running_cluster == &old_cluster)
{
bindir = old_cluster.bindir;
datadir = old_cluster.pgdata;
}
- else if (os_info.running_cluster == CLUSTER_NEW)
+ else if (os_info.running_cluster == &new_cluster)
{
bindir = new_cluster.bindir;
datadir = new_cluster.pgdata;
exec_prog(fast ? false : true, "%s", cmd);
os_info.postmasterPID = 0;
- os_info.running_cluster = NONE;
+ os_info.running_cluster = NULL;
}
* Returns true if the connection attempt was successfull, false otherwise.
*/
static bool
-test_server_conn(int timeout, Cluster whichCluster)
+test_server_conn(ClusterInfo *cluster, int timeout)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
- unsigned short port = active_cluster->port;
+ unsigned short port = cluster->port;
PGconn *conn = NULL;
char con_opts[MAX_STRING];
int tries;
if (tries == STARTUP_WARNING_TRIES)
prep_status("Trying to start %s server ",
- CLUSTER_NAME(whichCluster));
+ CLUSTER_NAME(cluster));
else if (tries > STARTUP_WARNING_TRIES)
pg_log(PG_REPORT, ".");
}
#include "pg_upgrade.h"
static void get_tablespace_paths(void);
-static void set_tablespace_directory_suffix(
- Cluster whichCluster);
+static void set_tablespace_directory_suffix(ClusterInfo *cluster);
void
{
get_tablespace_paths();
- set_tablespace_directory_suffix(CLUSTER_OLD);
- set_tablespace_directory_suffix(CLUSTER_NEW);
+ set_tablespace_directory_suffix(&old_cluster);
+ set_tablespace_directory_suffix(&new_cluster);
if (os_info.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
static void
get_tablespace_paths(void)
{
- PGconn *conn = connectToServer("template1", CLUSTER_OLD);
+ PGconn *conn = connectToServer(&old_cluster, "template1");
PGresult *res;
int tblnum;
int i_spclocation;
static void
-set_tablespace_directory_suffix(Cluster whichCluster)
+set_tablespace_directory_suffix(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
-
- if (GET_MAJOR_VERSION(active_cluster->major_version) <= 804)
- active_cluster->tablespace_suffix = pg_strdup("");
+ if (GET_MAJOR_VERSION(cluster->major_version) <= 804)
+ cluster->tablespace_suffix = pg_strdup("");
else
{
/* This cluster has a version-specific subdirectory */
- active_cluster->tablespace_suffix = pg_malloc(4 +
- strlen(active_cluster->major_version_str) +
+ cluster->tablespace_suffix = pg_malloc(4 +
+ strlen(cluster->major_version_str) +
10 /* OIDCHARS */ + 1);
/* The leading slash is needed to start a new directory. */
- sprintf(active_cluster->tablespace_suffix, "/PG_%s_%d", active_cluster->major_version_str,
- active_cluster->controldata.cat_ver);
+ sprintf(cluster->tablespace_suffix, "/PG_%s_%d", cluster->major_version_str,
+ cluster->controldata.cat_ver);
}
}
* 9.0 has a new pg_largeobject permission table
*/
void
-new_9_0_populate_pg_largeobject_metadata(bool check_mode,
- Cluster whichCluster)
+new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/pg_largeobject.sql",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
int i_count;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* find if there are any large objects */
res = executeQueryOrDie(conn,
* checks tables and indexes.
*/
void
-old_8_3_check_for_name_data_type_usage(Cluster whichCluster)
+old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/tables_using_name.txt",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int i_nspname,
i_relname,
i_attname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/*
* With a smaller alignment in 8.4, 'name' cannot be used in a
* so upgrading of such fields is impossible.
*/
void
-old_8_3_check_for_tsquery_usage(Cluster whichCluster)
+old_8_3_check_for_tsquery_usage(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/tables_using_tsquery.txt",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int i_nspname,
i_relname,
i_attname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* Find any user-defined tsquery columns */
res = executeQueryOrDie(conn,
* 'c' 'bb' 'aaa' -- 8.3
*/
void
-old_8_3_rebuild_tsvector_tables(bool check_mode,
- Cluster whichCluster)
+old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/rebuild_tsvector_tables.sql",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int i_nspname,
i_relname,
i_attname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* Find any user-defined tsvector columns */
res = executeQueryOrDie(conn,
* Hash, Gin, and GiST index binary format has changes from 8.3->8.4
*/
void
-old_8_3_invalidate_hash_gin_indexes(bool check_mode,
- Cluster whichCluster)
+old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/reindex_hash_and_gin.sql",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int rowno;
int i_nspname,
i_relname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* find hash and gin indexes */
res = executeQueryOrDie(conn,
* 8.4 bpchar_pattern_ops no longer sorts based on trailing spaces
*/
void
-old_8_3_invalidate_bpchar_pattern_ops_indexes(bool check_mode,
- Cluster whichCluster)
+old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,
+ bool check_mode)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
snprintf(output_path, sizeof(output_path), "%s/reindex_bpchar_ops.sql",
os_info.cwd);
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int rowno;
int i_nspname,
i_relname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* find bpchar_pattern_ops indexes */
* server, even in link mode.
*/
char *
-old_8_3_create_sequence_script(Cluster whichCluster)
+old_8_3_create_sequence_script(ClusterInfo *cluster)
{
- ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
int dbnum;
FILE *script = NULL;
bool found = false;
prep_status("Creating script to adjust sequences");
- for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
+ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
{
PGresult *res;
bool db_used = false;
int rowno;
int i_nspname,
i_relname;
- DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
- PGconn *conn = connectToServer(active_db->db_name, whichCluster);
+ DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
+ PGconn *conn = connectToServer(cluster, active_db->db_name);
/* Find any sequences */
res = executeQueryOrDie(conn,