2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* check.c
|
|
|
|
*
|
|
|
|
* server checks and output routines
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2014-01-08 05:05:30 +08:00
|
|
|
* Copyright (c) 2010-2014, PostgreSQL Global Development Group
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/pg_upgrade/check.c
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
Create libpgcommon, and move pg_malloc et al to it
libpgcommon is a new static library to allow sharing code among the
various frontend programs and backend; this lets us eliminate duplicate
implementations of common routines. We avoid libpgport, because that's
intended as a place for porting issues; per discussion, it seems better
to keep them separate.
The first use case, and the only implemented by this patch, is pg_malloc
and friends, which many frontend programs were already using.
At the same time, we can use this to provide palloc emulation functions
for the frontend; this way, some palloc-using files in the backend can
also be used by the frontend cleanly. To do this, we change palloc() in
the backend to be a function instead of a macro on top of
MemoryContextAlloc(). This was previously believed to cause loss of
performance, but this implementation has been tweaked by Tom and Andres
so that on modern compilers it provides a slight improvement over the
previous one.
This lets us clean up some places that were already with
localized hacks.
Most of the pg_malloc/palloc changes in this patch were authored by
Andres Freund. Zoltán Böszörményi also independently provided a form of
that. libpgcommon infrastructure was authored by Álvaro.
2013-02-12 21:33:40 +08:00
|
|
|
#include "postgres_fe.h"
|
2011-08-27 09:16:24 +08:00
|
|
|
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
#include "mb/pg_wchar.h"
|
2010-05-12 10:19:11 +08:00
|
|
|
#include "pg_upgrade.h"
|
|
|
|
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
static void set_locale_and_encoding(ClusterInfo *cluster);
|
2011-04-20 09:00:29 +08:00
|
|
|
static void check_new_cluster_is_empty(void);
|
2010-10-20 05:38:16 +08:00
|
|
|
static void check_locale_and_encoding(ControlData *oldctrl,
|
2010-05-12 10:19:11 +08:00
|
|
|
ControlData *newctrl);
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
static bool equivalent_locale(const char *loca, const char *locb);
|
|
|
|
static bool equivalent_encoding(const char *chara, const char *charb);
|
2011-05-07 20:55:13 +08:00
|
|
|
static void check_is_super_user(ClusterInfo *cluster);
|
2011-06-15 02:53:35 +08:00
|
|
|
static void check_for_prepared_transactions(ClusterInfo *cluster);
|
2011-01-02 01:06:36 +08:00
|
|
|
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
|
|
|
|
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
|
2011-06-23 08:48:34 +08:00
|
|
|
static void get_bin_version(ClusterInfo *cluster);
|
2012-10-02 23:42:34 +08:00
|
|
|
static char *get_canonical_locale_name(int category, const char *locale);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
2012-09-04 06:06:47 +08:00
|
|
|
/*
|
|
|
|
* fix_path_separator
|
|
|
|
* For non-Windows, just return the argument.
|
|
|
|
* For Windows convert any forward slash to a backslash
|
2013-05-30 04:58:43 +08:00
|
|
|
* such as is suitable for arguments to builtin commands
|
2012-09-04 06:06:47 +08:00
|
|
|
* like RMDIR and DEL.
|
|
|
|
*/
|
2012-09-04 10:59:19 +08:00
|
|
|
static char *
|
|
|
|
fix_path_separator(char *path)
|
2012-09-04 06:06:47 +08:00
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
|
2013-05-30 04:58:43 +08:00
|
|
|
char *result;
|
|
|
|
char *c;
|
2012-09-04 06:06:47 +08:00
|
|
|
|
|
|
|
result = pg_strdup(path);
|
|
|
|
|
|
|
|
for (c = result; *c != '\0'; c++)
|
|
|
|
if (*c == '/')
|
|
|
|
*c = '\\';
|
|
|
|
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
|
|
|
|
return path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
void
|
2013-01-25 04:20:11 +08:00
|
|
|
output_check_banner(bool live_check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2013-01-25 04:20:11 +08:00
|
|
|
if (user_opts.check && live_check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-06-23 02:48:59 +08:00
|
|
|
pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n");
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "------------------------------------------------\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "Performing Consistency Checks\n");
|
|
|
|
pg_log(PG_REPORT, "-----------------------------\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-12-01 05:30:13 +08:00
|
|
|
check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/* -- OLD -- */
|
|
|
|
|
|
|
|
if (!live_check)
|
2013-01-25 04:20:11 +08:00
|
|
|
start_postmaster(&old_cluster, true);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
set_locale_and_encoding(&old_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
get_pg_database_relfilenode(&old_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* Extract a list of databases and tables from the old cluster */
|
2011-01-02 01:06:36 +08:00
|
|
|
get_db_and_rel_infos(&old_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
init_tablespaces();
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
get_loadable_libraries();
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for various failure cases
|
|
|
|
*/
|
2011-05-07 20:55:13 +08:00
|
|
|
check_is_super_user(&old_cluster);
|
2011-06-15 02:53:35 +08:00
|
|
|
check_for_prepared_transactions(&old_cluster);
|
2011-01-02 01:06:36 +08:00
|
|
|
check_for_reg_data_type_usage(&old_cluster);
|
|
|
|
check_for_isn_and_int8_passing_mismatch(&old_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* old = PG 8.3 checks? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:06:36 +08:00
|
|
|
old_8_3_check_for_name_data_type_usage(&old_cluster);
|
|
|
|
old_8_3_check_for_tsquery_usage(&old_cluster);
|
2011-09-08 02:42:34 +08:00
|
|
|
old_8_3_check_ltree_usage(&old_cluster);
|
2010-10-20 05:38:16 +08:00
|
|
|
if (user_opts.check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:06:36 +08:00
|
|
|
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);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While we have the old server running, create the script to
|
|
|
|
* properly restore its sequence values but we report this at the
|
|
|
|
* end.
|
|
|
|
*/
|
|
|
|
*sequence_script_file_name =
|
2011-01-02 01:06:36 +08:00
|
|
|
old_8_3_create_sequence_script(&old_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pre-PG 9.0 had no large object permissions */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
|
2011-01-02 01:06:36 +08:00
|
|
|
new_9_0_populate_pg_largeobject_metadata(&old_cluster, true);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* While not a check option, we do this now because this is the only time
|
|
|
|
* the old server is running.
|
|
|
|
*/
|
2010-10-20 05:38:16 +08:00
|
|
|
if (!user_opts.check)
|
|
|
|
generate_old_dump();
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!live_check)
|
2011-04-26 08:17:48 +08:00
|
|
|
stop_postmaster(false);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
check_new_cluster(void)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:06:36 +08:00
|
|
|
set_locale_and_encoding(&new_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2012-06-14 00:19:18 +08:00
|
|
|
check_locale_and_encoding(&old_cluster.controldata, &new_cluster.controldata);
|
|
|
|
|
2011-04-20 09:00:29 +08:00
|
|
|
get_db_and_rel_infos(&new_cluster);
|
|
|
|
|
|
|
|
check_new_cluster_is_empty();
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
check_loadable_libraries();
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
if (user_opts.transfer_mode == TRANSFER_MODE_LINK)
|
|
|
|
check_hard_link();
|
2012-06-14 00:19:18 +08:00
|
|
|
|
|
|
|
check_is_super_user(&new_cluster);
|
|
|
|
|
|
|
|
/*
|
2013-05-30 04:58:43 +08:00
|
|
|
* We don't restore our own user, so both clusters must match have
|
|
|
|
* matching install-user oids.
|
2012-06-14 00:19:18 +08:00
|
|
|
*/
|
|
|
|
if (old_cluster.install_role_oid != new_cluster.install_role_oid)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Old and new cluster install users have different values for pg_authid.oid.\n");
|
2012-06-14 00:19:18 +08:00
|
|
|
|
|
|
|
/*
|
2013-05-30 04:58:43 +08:00
|
|
|
* We only allow the install user in the new cluster because other defined
|
|
|
|
* users might match users defined in the old cluster and generate an
|
|
|
|
* error during pg_dump restore.
|
2012-06-14 00:19:18 +08:00
|
|
|
*/
|
|
|
|
if (new_cluster.role_count != 1)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Only the install user can be defined in the new cluster.\n");
|
2013-05-30 04:58:43 +08:00
|
|
|
|
2012-06-14 00:19:18 +08:00
|
|
|
check_for_prepared_transactions(&new_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
report_clusters_compatible(void)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
if (user_opts.check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "\n*Clusters are compatible*\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
/* stops new cluster */
|
2011-04-26 08:17:48 +08:00
|
|
|
stop_postmaster(false);
|
2011-04-07 04:00:44 +08:00
|
|
|
exit(0);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "\n"
|
2012-03-06 10:19:54 +08:00
|
|
|
"If pg_upgrade fails after this point, you must re-initdb the\n"
|
|
|
|
"new cluster before continuing.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
issue_warnings(char *sequence_script_file_name)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/* old = PG 8.3 warnings? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2013-01-25 04:20:11 +08:00
|
|
|
start_postmaster(&new_cluster, true);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* restore proper sequence values using file created from old server */
|
|
|
|
if (sequence_script_file_name)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
prep_status("Adjusting sequences");
|
2012-08-28 02:21:09 +08:00
|
|
|
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
2012-09-04 01:52:34 +08:00
|
|
|
"\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"",
|
|
|
|
new_cluster.bindir, cluster_conn_opts(&new_cluster),
|
2012-08-28 02:21:09 +08:00
|
|
|
sequence_script_file_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
unlink(sequence_script_file_name);
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
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);
|
2011-04-26 08:17:48 +08:00
|
|
|
stop_postmaster(false);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create dummy large object permissions for old < PG 9.0? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2013-01-25 04:20:11 +08:00
|
|
|
start_postmaster(&new_cluster, true);
|
2011-01-02 01:06:36 +08:00
|
|
|
new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
|
2011-04-26 08:17:48 +08:00
|
|
|
stop_postmaster(false);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-03-17 06:54:11 +08:00
|
|
|
output_completion_banner(char *analyze_script_file_name,
|
|
|
|
char *deletion_script_file_name)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2010-12-15 20:11:31 +08:00
|
|
|
/* Did we copy the free space files? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
|
|
|
|
pg_log(PG_REPORT,
|
2012-03-17 06:54:11 +08:00
|
|
|
"Optimizer statistics are not transferred by pg_upgrade so,\n"
|
|
|
|
"once you start the new server, consider running:\n"
|
|
|
|
" %s\n\n", analyze_script_file_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
else
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT,
|
2011-07-12 12:13:51 +08:00
|
|
|
"Optimizer statistics and free space information are not transferred\n"
|
2012-06-11 03:20:04 +08:00
|
|
|
"by pg_upgrade so, once you start the new server, consider running:\n"
|
2012-03-17 06:54:11 +08:00
|
|
|
" %s\n\n", analyze_script_file_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2013-02-14 23:53:03 +08:00
|
|
|
|
|
|
|
if (deletion_script_file_name)
|
|
|
|
pg_log(PG_REPORT,
|
2013-05-30 04:58:43 +08:00
|
|
|
"Running this script will delete the old cluster's data files:\n"
|
2013-02-14 23:53:03 +08:00
|
|
|
" %s\n",
|
|
|
|
deletion_script_file_name);
|
|
|
|
else
|
|
|
|
pg_log(PG_REPORT,
|
|
|
|
"Could not create a script to delete the old cluster's data\n"
|
2013-05-30 04:58:43 +08:00
|
|
|
"files because user-defined tablespaces exist in the old cluster\n"
|
|
|
|
"directory. The old cluster's contents must be deleted manually.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
check_cluster_versions(void)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-06-23 08:48:34 +08:00
|
|
|
prep_status("Checking cluster versions");
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/* get old and new cluster versions */
|
2011-01-02 01:28:48 +08:00
|
|
|
old_cluster.major_version = get_major_server_version(&old_cluster);
|
|
|
|
new_cluster.major_version = get_major_server_version(&new_cluster);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-04-10 23:42:00 +08:00
|
|
|
/*
|
|
|
|
* We allow upgrades from/to the same major version for alpha/beta
|
|
|
|
* upgrades
|
|
|
|
*/
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) < 803)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("This utility can only upgrade from PostgreSQL version 8.3 and later.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* Only current PG version is supported as a target */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("This utility can only upgrade to PostgreSQL version %s.\n",
|
2010-07-07 03:19:02 +08:00
|
|
|
PG_MAJORVERSION);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't allow downgrading because we use the target pg_dumpall, and
|
2012-06-11 03:20:04 +08:00
|
|
|
* pg_dumpall cannot operate on new database versions, only older
|
|
|
|
* versions.
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
2010-10-20 05:38:16 +08:00
|
|
|
if (old_cluster.major_version > new_cluster.major_version)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
|
2011-06-23 08:48:34 +08:00
|
|
|
|
|
|
|
/* get old and new binary versions */
|
|
|
|
get_bin_version(&old_cluster);
|
|
|
|
get_bin_version(&new_cluster);
|
|
|
|
|
|
|
|
/* Ensure binaries match the designated data directories */
|
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) !=
|
|
|
|
GET_MAJOR_VERSION(old_cluster.bin_version))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Old cluster data and binary directories are from different major versions.\n");
|
2011-06-23 08:48:34 +08:00
|
|
|
if (GET_MAJOR_VERSION(new_cluster.major_version) !=
|
|
|
|
GET_MAJOR_VERSION(new_cluster.bin_version))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("New cluster data and binary directories are from different major versions.\n");
|
2011-06-23 08:48:34 +08:00
|
|
|
|
|
|
|
check_ok();
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
check_cluster_compatibility(bool live_check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/* get/check pg_control data of servers */
|
2010-10-20 05:38:16 +08:00
|
|
|
get_control_data(&old_cluster, live_check);
|
|
|
|
get_control_data(&new_cluster, false);
|
|
|
|
check_control_data(&old_cluster.controldata, &new_cluster.controldata);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* Is it 9.0 but without tablespace directories? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(new_cluster.major_version) == 900 &&
|
2011-04-26 00:00:21 +08:00
|
|
|
new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
|
2010-05-12 10:19:11 +08:00
|
|
|
"because of backend API changes made during development.\n");
|
2012-09-04 10:15:09 +08:00
|
|
|
|
|
|
|
/* We read the real port number for PG >= 9.1 */
|
|
|
|
if (live_check && GET_MAJOR_VERSION(old_cluster.major_version) < 901 &&
|
|
|
|
old_cluster.port == DEF_PGUPORT)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("When checking a pre-PG 9.1 live old server, "
|
2013-05-30 04:58:43 +08:00
|
|
|
"you must specify the old server's port number.\n");
|
2012-09-04 10:15:09 +08:00
|
|
|
|
|
|
|
if (live_check && old_cluster.port == new_cluster.port)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("When checking a live server, "
|
2012-09-04 10:15:09 +08:00
|
|
|
"the old and new port numbers must be different.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_locale_and_encoding()
|
|
|
|
*
|
|
|
|
* query the database to get the template0 locale
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-02 01:06:36 +08:00
|
|
|
set_locale_and_encoding(ClusterInfo *cluster)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
2011-01-02 01:06:36 +08:00
|
|
|
ControlData *ctrl = &cluster->controldata;
|
2010-05-12 10:19:11 +08:00
|
|
|
PGconn *conn;
|
|
|
|
PGresult *res;
|
|
|
|
int i_encoding;
|
2011-01-02 01:06:36 +08:00
|
|
|
int cluster_version = cluster->major_version;
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
conn = connectToServer(cluster, "template1");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* for pg < 80400, we got the values from pg_controldata */
|
|
|
|
if (cluster_version >= 80400)
|
|
|
|
{
|
|
|
|
int i_datcollate;
|
|
|
|
int i_datctype;
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
res = executeQueryOrDie(conn,
|
2010-05-12 10:19:11 +08:00
|
|
|
"SELECT datcollate, datctype "
|
2013-11-17 00:35:44 +08:00
|
|
|
"FROM pg_catalog.pg_database "
|
2010-05-12 10:19:11 +08:00
|
|
|
"WHERE datname = 'template0' ");
|
|
|
|
assert(PQntuples(res) == 1);
|
|
|
|
|
|
|
|
i_datcollate = PQfnumber(res, "datcollate");
|
|
|
|
i_datctype = PQfnumber(res, "datctype");
|
|
|
|
|
2012-10-02 23:42:34 +08:00
|
|
|
if (GET_MAJOR_VERSION(cluster->major_version) < 902)
|
|
|
|
{
|
|
|
|
/*
|
2013-05-30 04:58:43 +08:00
|
|
|
* Pre-9.2 did not canonicalize the supplied locale names to match
|
|
|
|
* what the system returns, while 9.2+ does, so convert pre-9.2 to
|
|
|
|
* match.
|
2012-10-02 23:42:34 +08:00
|
|
|
*/
|
|
|
|
ctrl->lc_collate = get_canonical_locale_name(LC_COLLATE,
|
2013-05-30 04:58:43 +08:00
|
|
|
pg_strdup(PQgetvalue(res, 0, i_datcollate)));
|
2012-10-02 23:42:34 +08:00
|
|
|
ctrl->lc_ctype = get_canonical_locale_name(LC_CTYPE,
|
2013-05-30 04:58:43 +08:00
|
|
|
pg_strdup(PQgetvalue(res, 0, i_datctype)));
|
|
|
|
}
|
2012-10-02 23:42:34 +08:00
|
|
|
else
|
|
|
|
{
|
2013-05-30 04:58:43 +08:00
|
|
|
ctrl->lc_collate = pg_strdup(PQgetvalue(res, 0, i_datcollate));
|
2012-10-02 23:42:34 +08:00
|
|
|
ctrl->lc_ctype = pg_strdup(PQgetvalue(res, 0, i_datctype));
|
|
|
|
}
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
}
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
res = executeQueryOrDie(conn,
|
2010-05-12 10:19:11 +08:00
|
|
|
"SELECT pg_catalog.pg_encoding_to_char(encoding) "
|
2013-11-17 00:35:44 +08:00
|
|
|
"FROM pg_catalog.pg_database "
|
2010-05-12 10:19:11 +08:00
|
|
|
"WHERE datname = 'template0' ");
|
|
|
|
assert(PQntuples(res) == 1);
|
|
|
|
|
|
|
|
i_encoding = PQfnumber(res, "pg_encoding_to_char");
|
2010-10-20 05:38:16 +08:00
|
|
|
ctrl->encoding = pg_strdup(PQgetvalue(res, 0, i_encoding));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_locale_and_encoding()
|
|
|
|
*
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
* Check that old and new locale and encoding match. Even though the backend
|
|
|
|
* tries to canonicalize stored locale names, the platform often doesn't
|
|
|
|
* cooperate, so it's entirely possible that one DB thinks its locale is
|
|
|
|
* "en_US.UTF-8" while the other says "en_US.utf8". Try to be forgiving.
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
static void
|
2010-10-20 05:38:16 +08:00
|
|
|
check_locale_and_encoding(ControlData *oldctrl,
|
2010-05-12 10:19:11 +08:00
|
|
|
ControlData *newctrl)
|
|
|
|
{
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
if (!equivalent_locale(oldctrl->lc_collate, newctrl->lc_collate))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("lc_collate cluster values do not match: old \"%s\", new \"%s\"\n",
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
oldctrl->lc_collate, newctrl->lc_collate);
|
|
|
|
if (!equivalent_locale(oldctrl->lc_ctype, newctrl->lc_ctype))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("lc_ctype cluster values do not match: old \"%s\", new \"%s\"\n",
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
oldctrl->lc_ctype, newctrl->lc_ctype);
|
|
|
|
if (!equivalent_encoding(oldctrl->encoding, newctrl->encoding))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("encoding cluster values do not match: old \"%s\", new \"%s\"\n",
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
oldctrl->encoding, newctrl->encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* equivalent_locale()
|
|
|
|
*
|
|
|
|
* Best effort locale-name comparison. Return false if we are not 100% sure
|
|
|
|
* the locales are equivalent.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
equivalent_locale(const char *loca, const char *locb)
|
|
|
|
{
|
|
|
|
const char *chara = strrchr(loca, '.');
|
|
|
|
const char *charb = strrchr(locb, '.');
|
|
|
|
int lencmp;
|
|
|
|
|
|
|
|
/* If they don't both contain an encoding part, just do strcasecmp(). */
|
|
|
|
if (!chara || !charb)
|
|
|
|
return (pg_strcasecmp(loca, locb) == 0);
|
|
|
|
|
2014-01-31 15:03:30 +08:00
|
|
|
/*
|
|
|
|
* Compare the encoding parts. Windows tends to use code page numbers for
|
|
|
|
* the encoding part, which equivalent_encoding() won't like, so accept if
|
|
|
|
* the strings are case-insensitive equal; otherwise use
|
|
|
|
* equivalent_encoding() to compare.
|
|
|
|
*/
|
|
|
|
if (pg_strcasecmp(chara + 1, charb + 1) != 0 &&
|
|
|
|
!equivalent_encoding(chara + 1, charb + 1))
|
Be forgiving of variant spellings of locale names in pg_upgrade.
Even though the server tries to canonicalize stored locale names, the
platform often doesn't cooperate, so it's entirely possible that one DB
thinks its locale is, say, "en_US.UTF-8" while the other has "en_US.utf8".
Rather than failing, we should try to allow this where it's clearly OK.
There is already pretty robust encoding lookup in encnames.c, so make
use of that to compare the encoding parts of the names. The locale
identifier parts are just compared case-insensitively, which we were
already doing. The major problem known to exist in the field is variant
encoding-name spellings, so hopefully this will be Good Enough. If not,
we can try being even laxer.
Pavel Raiskup, reviewed by Rushabh Lathia
2014-01-31 08:07:06 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, compare the locale identifiers (e.g. en_US part of en_US.utf8).
|
|
|
|
*
|
|
|
|
* It's tempting to ignore non-alphanumeric chars here, but for now it's
|
|
|
|
* not clear that that's necessary; just do case-insensitive comparison.
|
|
|
|
*/
|
|
|
|
lencmp = chara - loca;
|
|
|
|
if (lencmp != charb - locb)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (pg_strncasecmp(loca, locb, lencmp) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* equivalent_encoding()
|
|
|
|
*
|
|
|
|
* Best effort encoding-name comparison. Return true only if the encodings
|
|
|
|
* are valid server-side encodings and known equivalent.
|
|
|
|
*
|
|
|
|
* Because the lookup in pg_valid_server_encoding() does case folding and
|
|
|
|
* ignores non-alphanumeric characters, this will recognize many popular
|
|
|
|
* variant spellings as equivalent, eg "utf8" and "UTF-8" will match.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
equivalent_encoding(const char *chara, const char *charb)
|
|
|
|
{
|
|
|
|
int enca = pg_valid_server_encoding(chara);
|
|
|
|
int encb = pg_valid_server_encoding(charb);
|
|
|
|
|
|
|
|
if (enca < 0 || encb < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (enca == encb);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-04-20 09:00:29 +08:00
|
|
|
check_new_cluster_is_empty(void)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int relnum;
|
2010-10-20 05:38:16 +08:00
|
|
|
RelInfoArr *rel_arr = &new_cluster.dbarr.dbs[dbnum].rel_arr;
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
for (relnum = 0; relnum < rel_arr->nrels;
|
|
|
|
relnum++)
|
|
|
|
{
|
|
|
|
/* pg_largeobject and its index should be skipped */
|
|
|
|
if (strcmp(rel_arr->rels[relnum].nspname, "pg_catalog") != 0)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("New cluster database \"%s\" is not empty\n",
|
2011-06-10 02:32:50 +08:00
|
|
|
new_cluster.dbarr.dbs[dbnum].db_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 09:00:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 06:54:11 +08:00
|
|
|
/*
|
|
|
|
* create_script_for_cluster_analyze()
|
|
|
|
*
|
|
|
|
* This incrementally generates better optimizer statistics
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
create_script_for_cluster_analyze(char **analyze_script_file_name)
|
|
|
|
{
|
|
|
|
FILE *script = NULL;
|
2013-06-29 07:11:51 +08:00
|
|
|
char *user_specification = "";
|
|
|
|
|
2012-03-17 06:54:11 +08:00
|
|
|
prep_status("Creating script to analyze new cluster");
|
|
|
|
|
2013-10-13 12:09:18 +08:00
|
|
|
if (os_info.user_specified)
|
2013-10-23 07:40:26 +08:00
|
|
|
user_specification = psprintf("-U \"%s\" ", os_info.user);
|
2013-10-13 12:09:18 +08:00
|
|
|
|
2013-10-23 07:40:26 +08:00
|
|
|
*analyze_script_file_name = psprintf("analyze_new_cluster.%s", SCRIPT_EXT);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not open file \"%s\": %s\n",
|
2012-03-17 06:54:11 +08:00
|
|
|
*analyze_script_file_name, getErrorText(errno));
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
/* add shebang header */
|
|
|
|
fprintf(script, "#!/bin/sh\n\n");
|
2012-09-04 17:49:22 +08:00
|
|
|
#else
|
|
|
|
/* suppress command echoing */
|
2012-09-04 21:39:49 +08:00
|
|
|
fprintf(script, "@echo off\n");
|
2012-03-17 06:54:11 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
fprintf(script, "echo %sThis script will generate minimal optimizer statistics rapidly%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sso your system is usable, and then gather statistics twice more%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %swith increasing accuracy. When it is done, your system will%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %shave the default level of optimizer statistics.%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
fprintf(script, "echo %sIf you have used ALTER TABLE to modify the statistics target for%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sany tables, you might want to remove them and restore them after%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %srunning this script because they will delay fast statistics generation.%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
fprintf(script, "echo %sIf you would like default statistics as quickly as possible, cancel%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sthis script and run:%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2013-06-29 07:11:51 +08:00
|
|
|
fprintf(script, "echo %s \"%s/vacuumdb\" %s--all %s%s\n", ECHO_QUOTE,
|
|
|
|
new_cluster.bindir, user_specification,
|
2012-06-11 03:20:04 +08:00
|
|
|
/* Did we copy the free space files? */
|
|
|
|
(GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
|
|
|
|
"--analyze-only" : "--analyze", ECHO_QUOTE);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
fprintf(script, "sleep 2\n");
|
|
|
|
fprintf(script, "PGOPTIONS='-c default_statistics_target=1 -c vacuum_cost_delay=0'\n");
|
|
|
|
/* only need to export once */
|
|
|
|
fprintf(script, "export PGOPTIONS\n");
|
|
|
|
#else
|
|
|
|
fprintf(script, "REM simulate sleep 2\n");
|
|
|
|
fprintf(script, "PING 1.1.1.1 -n 1 -w 2000 > nul\n");
|
|
|
|
fprintf(script, "SET PGOPTIONS=-c default_statistics_target=1 -c vacuum_cost_delay=0\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fprintf(script, "echo %sGenerating minimal optimizer statistics (1 target)%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %s--------------------------------------------------%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2013-06-29 07:11:51 +08:00
|
|
|
fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-only\n",
|
|
|
|
new_cluster.bindir, user_specification);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sThe server is now available with minimal optimizer statistics.%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sQuery performance will be optimal once this script completes.%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
fprintf(script, "sleep 2\n");
|
|
|
|
fprintf(script, "PGOPTIONS='-c default_statistics_target=10'\n");
|
|
|
|
#else
|
|
|
|
fprintf(script, "REM simulate sleep\n");
|
|
|
|
fprintf(script, "PING 1.1.1.1 -n 1 -w 2000 > nul\n");
|
|
|
|
fprintf(script, "SET PGOPTIONS=-c default_statistics_target=10\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fprintf(script, "echo %sGenerating medium optimizer statistics (10 targets)%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %s---------------------------------------------------%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2013-06-29 07:11:51 +08:00
|
|
|
fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-only\n",
|
|
|
|
new_cluster.bindir, user_specification);
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
fprintf(script, "unset PGOPTIONS\n");
|
|
|
|
#else
|
|
|
|
fprintf(script, "SET PGOPTIONS\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fprintf(script, "echo %sGenerating default (full) optimizer statistics (100 targets?)%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %s-------------------------------------------------------------%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2013-06-29 07:11:51 +08:00
|
|
|
fprintf(script, "\"%s/vacuumdb\" %s--all %s\n", new_cluster.bindir,
|
|
|
|
user_specification,
|
2012-06-11 03:20:04 +08:00
|
|
|
/* Did we copy the free space files? */
|
|
|
|
(GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
|
|
|
|
"--analyze-only" : "--analyze");
|
2012-03-17 06:54:11 +08:00
|
|
|
|
2012-09-04 17:49:22 +08:00
|
|
|
fprintf(script, "echo%s\n\n", ECHO_BLANK);
|
2012-03-17 06:54:11 +08:00
|
|
|
fprintf(script, "echo %sDone%s\n",
|
2012-06-11 03:20:04 +08:00
|
|
|
ECHO_QUOTE, ECHO_QUOTE);
|
2012-03-17 06:54:11 +08:00
|
|
|
|
|
|
|
fclose(script);
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
if (chmod(*analyze_script_file_name, S_IRWXU) != 0)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not add execute permission to file \"%s\": %s\n",
|
2012-03-17 06:54:11 +08:00
|
|
|
*analyze_script_file_name, getErrorText(errno));
|
|
|
|
#endif
|
|
|
|
|
2013-06-29 07:11:51 +08:00
|
|
|
if (os_info.user_specified)
|
|
|
|
pg_free(user_specification);
|
|
|
|
|
2012-03-17 06:54:11 +08:00
|
|
|
check_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* create_script_for_old_cluster_deletion()
|
|
|
|
*
|
|
|
|
* This is particularly useful for tablespace deletion.
|
|
|
|
*/
|
|
|
|
void
|
2011-06-23 05:50:40 +08:00
|
|
|
create_script_for_old_cluster_deletion(char **deletion_script_file_name)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
FILE *script = NULL;
|
|
|
|
int tblnum;
|
2013-02-14 23:53:03 +08:00
|
|
|
char old_cluster_pgdata[MAXPGPATH];
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2013-10-23 07:40:26 +08:00
|
|
|
*deletion_script_file_name = psprintf("delete_old_cluster.%s", SCRIPT_EXT);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2013-02-14 23:53:03 +08:00
|
|
|
/*
|
2013-05-30 04:58:43 +08:00
|
|
|
* Some users (oddly) create tablespaces inside the cluster data
|
|
|
|
* directory. We can't create a proper old cluster delete script in that
|
|
|
|
* case.
|
2013-02-14 23:53:03 +08:00
|
|
|
*/
|
|
|
|
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
|
|
|
|
canonicalize_path(old_cluster_pgdata);
|
|
|
|
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
|
|
|
|
{
|
|
|
|
char old_tablespace_dir[MAXPGPATH];
|
2013-05-30 04:58:43 +08:00
|
|
|
|
2013-02-14 23:53:03 +08:00
|
|
|
strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
|
|
|
|
canonicalize_path(old_tablespace_dir);
|
|
|
|
if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
|
|
|
|
{
|
|
|
|
/* Unlink file in case it is left over from a previous run. */
|
|
|
|
unlink(*deletion_script_file_name);
|
|
|
|
pg_free(*deletion_script_file_name);
|
|
|
|
*deletion_script_file_name = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prep_status("Creating script to delete old cluster");
|
|
|
|
|
2012-03-13 07:47:54 +08:00
|
|
|
if ((script = fopen_priv(*deletion_script_file_name, "w")) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not open file \"%s\": %s\n",
|
2011-07-12 12:13:51 +08:00
|
|
|
*deletion_script_file_name, getErrorText(errno));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
/* add shebang header */
|
|
|
|
fprintf(script, "#!/bin/sh\n\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* delete old cluster's default tablespace */
|
2012-09-04 06:06:47 +08:00
|
|
|
fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(old_cluster.pgdata));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* delete old cluster's alternate tablespaces */
|
2013-01-09 21:57:47 +08:00
|
|
|
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Do the old cluster's per-database directories share a directory
|
|
|
|
* with a new version-specific tablespace?
|
|
|
|
*/
|
2010-10-20 05:38:16 +08:00
|
|
|
if (strlen(old_cluster.tablespace_suffix) == 0)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
/* delete per-database directories */
|
|
|
|
int dbnum;
|
|
|
|
|
|
|
|
fprintf(script, "\n");
|
2010-10-19 23:52:43 +08:00
|
|
|
/* remove PG_VERSION? */
|
2010-10-20 05:38:16 +08:00
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
|
2014-02-13 05:35:24 +08:00
|
|
|
fprintf(script, RM_CMD " %s%cPG_VERSION\n",
|
2013-05-30 04:58:43 +08:00
|
|
|
fix_path_separator(os_info.old_tablespaces[tblnum]),
|
2012-09-04 06:06:47 +08:00
|
|
|
PATH_SEPARATOR);
|
2010-10-19 23:52:43 +08:00
|
|
|
|
2011-11-02 01:49:03 +08:00
|
|
|
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
|
2014-02-13 05:35:24 +08:00
|
|
|
fprintf(script, RMDIR_CMD " %s%c%d\n",
|
2013-01-09 21:57:47 +08:00
|
|
|
fix_path_separator(os_info.old_tablespaces[tblnum]),
|
2012-09-04 06:06:47 +08:00
|
|
|
PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
else
|
2014-02-13 05:35:24 +08:00
|
|
|
{
|
|
|
|
char *suffix_path = pg_strdup(old_cluster.tablespace_suffix);
|
2010-07-07 03:19:02 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* Simply delete the tablespace directory, which might be ".old"
|
|
|
|
* or a version-specific subdirectory.
|
|
|
|
*/
|
|
|
|
fprintf(script, RMDIR_CMD " %s%s\n",
|
2013-05-30 04:58:43 +08:00
|
|
|
fix_path_separator(os_info.old_tablespaces[tblnum]),
|
2014-02-13 05:35:24 +08:00
|
|
|
fix_path_separator(suffix_path));
|
|
|
|
pfree(suffix_path);
|
|
|
|
}
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(script);
|
|
|
|
|
2010-05-13 23:58:15 +08:00
|
|
|
#ifndef WIN32
|
2010-05-12 10:19:11 +08:00
|
|
|
if (chmod(*deletion_script_file_name, S_IRWXU) != 0)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not add execute permission to file \"%s\": %s\n",
|
2011-07-12 12:13:51 +08:00
|
|
|
*deletion_script_file_name, getErrorText(errno));
|
2010-05-13 23:58:15 +08:00
|
|
|
#endif
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
2010-07-25 11:28:32 +08:00
|
|
|
|
|
|
|
|
2011-05-07 20:55:13 +08:00
|
|
|
/*
|
|
|
|
* check_is_super_user()
|
|
|
|
*
|
2012-06-14 00:19:18 +08:00
|
|
|
* Check we are superuser, and out user id and user count
|
2011-05-07 20:55:13 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_is_super_user(ClusterInfo *cluster)
|
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
PGconn *conn = connectToServer(cluster, "template1");
|
|
|
|
|
2011-05-09 20:55:36 +08:00
|
|
|
prep_status("Checking database user is a superuser");
|
|
|
|
|
2011-05-07 20:55:13 +08:00
|
|
|
/* Can't use pg_authid because only superusers can view it. */
|
|
|
|
res = executeQueryOrDie(conn,
|
2012-06-14 00:19:18 +08:00
|
|
|
"SELECT rolsuper, oid "
|
2011-05-07 20:55:13 +08:00
|
|
|
"FROM pg_catalog.pg_roles "
|
|
|
|
"WHERE rolname = current_user");
|
|
|
|
|
|
|
|
if (PQntuples(res) != 1 || strcmp(PQgetvalue(res, 0, 0), "t") != 0)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("database user \"%s\" is not a superuser\n",
|
2011-06-10 02:32:50 +08:00
|
|
|
os_info.user);
|
2011-05-07 20:55:13 +08:00
|
|
|
|
2012-06-14 00:19:18 +08:00
|
|
|
cluster->install_role_oid = atooid(PQgetvalue(res, 0, 1));
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
res = executeQueryOrDie(conn,
|
|
|
|
"SELECT COUNT(*) "
|
|
|
|
"FROM pg_catalog.pg_roles ");
|
|
|
|
|
|
|
|
if (PQntuples(res) != 1)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("could not determine the number of users\n");
|
2012-06-14 00:19:18 +08:00
|
|
|
|
|
|
|
cluster->role_count = atoi(PQgetvalue(res, 0, 0));
|
|
|
|
|
2011-05-07 20:55:13 +08:00
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
2011-05-09 20:55:36 +08:00
|
|
|
|
|
|
|
check_ok();
|
2011-05-07 20:55:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 02:53:35 +08:00
|
|
|
/*
|
|
|
|
* check_for_prepared_transactions()
|
|
|
|
*
|
|
|
|
* Make sure there are no prepared transactions because the storage format
|
|
|
|
* might have changed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_for_prepared_transactions(ClusterInfo *cluster)
|
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
PGconn *conn = connectToServer(cluster, "template1");
|
|
|
|
|
|
|
|
prep_status("Checking for prepared transactions");
|
|
|
|
|
|
|
|
res = executeQueryOrDie(conn,
|
|
|
|
"SELECT * "
|
2011-08-31 05:15:00 +08:00
|
|
|
"FROM pg_catalog.pg_prepared_xacts");
|
2011-06-15 02:53:35 +08:00
|
|
|
|
|
|
|
if (PQntuples(res) != 0)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("The %s cluster contains prepared transactions\n",
|
2011-06-15 02:53:35 +08:00
|
|
|
CLUSTER_NAME(cluster));
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
|
|
|
|
check_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-25 11:47:29 +08:00
|
|
|
/*
|
2010-10-20 06:37:04 +08:00
|
|
|
* check_for_isn_and_int8_passing_mismatch()
|
2010-07-25 11:47:29 +08:00
|
|
|
*
|
2011-05-19 05:30:31 +08:00
|
|
|
* contrib/isn relies on data type int8, and in 8.4 int8 can now be passed
|
2010-07-25 11:47:29 +08:00
|
|
|
* by value. The schema dumps the CREATE TYPE PASSEDBYVALUE setting so
|
|
|
|
* it must match for the old and new servers.
|
|
|
|
*/
|
2011-03-07 09:14:01 +08:00
|
|
|
static void
|
2011-01-02 01:06:36 +08:00
|
|
|
check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
|
2010-07-25 11:47:29 +08:00
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
FILE *script = NULL;
|
|
|
|
bool found = false;
|
|
|
|
char output_path[MAXPGPATH];
|
|
|
|
|
2011-05-19 05:30:31 +08:00
|
|
|
prep_status("Checking for contrib/isn with bigint-passing mismatch");
|
2010-07-25 11:47:29 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
if (old_cluster.controldata.float8_pass_by_value ==
|
|
|
|
new_cluster.controldata.float8_pass_by_value)
|
2010-07-25 11:47:29 +08:00
|
|
|
{
|
|
|
|
/* no mismatch */
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-07-25 11:47:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 07:47:54 +08:00
|
|
|
snprintf(output_path, sizeof(output_path),
|
|
|
|
"contrib_isn_and_int8_pass_by_value.txt");
|
2010-07-25 11:47:29 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
|
2010-07-25 11:47:29 +08:00
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
bool db_used = false;
|
|
|
|
int ntups;
|
|
|
|
int rowno;
|
|
|
|
int i_nspname,
|
|
|
|
i_proname;
|
2011-01-02 01:06:36 +08:00
|
|
|
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
|
|
|
|
PGconn *conn = connectToServer(cluster, active_db->db_name);
|
2010-07-25 11:47:29 +08:00
|
|
|
|
|
|
|
/* Find any functions coming from contrib/isn */
|
2010-10-20 05:38:16 +08:00
|
|
|
res = executeQueryOrDie(conn,
|
2010-07-25 11:47:29 +08:00
|
|
|
"SELECT n.nspname, p.proname "
|
|
|
|
"FROM pg_catalog.pg_proc p, "
|
|
|
|
" pg_catalog.pg_namespace n "
|
|
|
|
"WHERE p.pronamespace = n.oid AND "
|
|
|
|
" p.probin = '$libdir/isn'");
|
|
|
|
|
|
|
|
ntups = PQntuples(res);
|
|
|
|
i_nspname = PQfnumber(res, "nspname");
|
|
|
|
i_proname = PQfnumber(res, "proname");
|
|
|
|
for (rowno = 0; rowno < ntups; rowno++)
|
|
|
|
{
|
|
|
|
found = true;
|
2012-03-13 07:47:54 +08:00
|
|
|
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not open file \"%s\": %s\n",
|
2011-07-12 12:13:51 +08:00
|
|
|
output_path, getErrorText(errno));
|
2010-07-25 11:47:29 +08:00
|
|
|
if (!db_used)
|
|
|
|
{
|
2011-07-12 12:13:51 +08:00
|
|
|
fprintf(script, "Database: %s\n", active_db->db_name);
|
2010-07-25 11:47:29 +08:00
|
|
|
db_used = true;
|
|
|
|
}
|
|
|
|
fprintf(script, " %s.%s\n",
|
|
|
|
PQgetvalue(res, rowno, i_nspname),
|
|
|
|
PQgetvalue(res, rowno, i_proname));
|
|
|
|
}
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
}
|
|
|
|
|
2011-03-09 10:35:42 +08:00
|
|
|
if (script)
|
2011-04-10 23:42:00 +08:00
|
|
|
fclose(script);
|
2011-03-09 10:35:42 +08:00
|
|
|
|
2010-07-25 11:47:29 +08:00
|
|
|
if (found)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "fatal\n");
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Your installation contains \"contrib/isn\" functions which rely on the\n"
|
2012-06-11 03:20:04 +08:00
|
|
|
"bigint data type. Your old and new clusters pass bigint values\n"
|
|
|
|
"differently so this cluster cannot currently be upgraded. You can\n"
|
2011-07-12 12:13:51 +08:00
|
|
|
"manually upgrade databases that use \"contrib/isn\" facilities and remove\n"
|
|
|
|
"\"contrib/isn\" from the old cluster and restart the upgrade. A list of\n"
|
|
|
|
"the problem functions is in the file:\n"
|
|
|
|
" %s\n\n", output_path);
|
2010-07-25 11:47:29 +08:00
|
|
|
}
|
|
|
|
else
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-07-25 11:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-25 11:28:32 +08:00
|
|
|
/*
|
|
|
|
* check_for_reg_data_type_usage()
|
|
|
|
* pg_upgrade only preserves these system values:
|
2011-12-06 05:45:19 +08:00
|
|
|
* pg_class.oid
|
2010-07-25 11:28:32 +08:00
|
|
|
* pg_type.oid
|
|
|
|
* pg_enum.oid
|
|
|
|
*
|
2011-12-06 05:45:19 +08:00
|
|
|
* Many of the reg* data types reference system catalog info that is
|
2010-07-25 11:28:32 +08:00
|
|
|
* not preserved, and hence these data types cannot be used in user
|
|
|
|
* tables upgraded by pg_upgrade.
|
|
|
|
*/
|
2011-03-07 09:14:01 +08:00
|
|
|
static void
|
2011-01-02 01:06:36 +08:00
|
|
|
check_for_reg_data_type_usage(ClusterInfo *cluster)
|
2010-07-25 11:28:32 +08:00
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
FILE *script = NULL;
|
|
|
|
bool found = false;
|
|
|
|
char output_path[MAXPGPATH];
|
|
|
|
|
2011-07-12 12:13:51 +08:00
|
|
|
prep_status("Checking for reg* system OID user data types");
|
2010-07-25 11:28:32 +08:00
|
|
|
|
2012-03-13 07:47:54 +08:00
|
|
|
snprintf(output_path, sizeof(output_path), "tables_using_reg.txt");
|
2010-07-25 11:28:32 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
|
2010-07-25 11:28:32 +08:00
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
bool db_used = false;
|
|
|
|
int ntups;
|
|
|
|
int rowno;
|
|
|
|
int i_nspname,
|
|
|
|
i_relname,
|
|
|
|
i_attname;
|
2011-01-02 01:06:36 +08:00
|
|
|
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
|
|
|
|
PGconn *conn = connectToServer(cluster, active_db->db_name);
|
2010-07-25 11:28:32 +08:00
|
|
|
|
2012-01-20 05:04:34 +08:00
|
|
|
/*
|
2012-06-11 03:20:04 +08:00
|
|
|
* While several relkinds don't store any data, e.g. views, they can
|
|
|
|
* be used to define data types of other columns, so we check all
|
|
|
|
* relkinds.
|
2012-01-20 05:04:34 +08:00
|
|
|
*/
|
2010-10-20 05:38:16 +08:00
|
|
|
res = executeQueryOrDie(conn,
|
2010-07-25 11:28:32 +08:00
|
|
|
"SELECT n.nspname, c.relname, a.attname "
|
|
|
|
"FROM pg_catalog.pg_class c, "
|
|
|
|
" pg_catalog.pg_namespace n, "
|
|
|
|
" pg_catalog.pg_attribute a "
|
|
|
|
"WHERE c.oid = a.attrelid AND "
|
|
|
|
" NOT a.attisdropped AND "
|
|
|
|
" a.atttypid IN ( "
|
2010-10-20 06:37:04 +08:00
|
|
|
" 'pg_catalog.regproc'::pg_catalog.regtype, "
|
2012-06-11 03:20:04 +08:00
|
|
|
" 'pg_catalog.regprocedure'::pg_catalog.regtype, "
|
2010-10-20 06:37:04 +08:00
|
|
|
" 'pg_catalog.regoper'::pg_catalog.regtype, "
|
2012-06-11 03:20:04 +08:00
|
|
|
" 'pg_catalog.regoperator'::pg_catalog.regtype, "
|
2011-12-06 05:45:19 +08:00
|
|
|
/* regclass.oid is preserved, so 'regclass' is OK */
|
2010-10-20 06:37:04 +08:00
|
|
|
/* regtype.oid is preserved, so 'regtype' is OK */
|
2012-06-11 03:20:04 +08:00
|
|
|
" 'pg_catalog.regconfig'::pg_catalog.regtype, "
|
|
|
|
" 'pg_catalog.regdictionary'::pg_catalog.regtype) AND "
|
|
|
|
" c.relnamespace = n.oid AND "
|
|
|
|
" n.nspname != 'pg_catalog' AND "
|
|
|
|
" n.nspname != 'information_schema'");
|
2010-07-25 11:28:32 +08:00
|
|
|
|
|
|
|
ntups = PQntuples(res);
|
|
|
|
i_nspname = PQfnumber(res, "nspname");
|
|
|
|
i_relname = PQfnumber(res, "relname");
|
|
|
|
i_attname = PQfnumber(res, "attname");
|
|
|
|
for (rowno = 0; rowno < ntups; rowno++)
|
|
|
|
{
|
|
|
|
found = true;
|
2012-03-13 07:47:54 +08:00
|
|
|
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not open file \"%s\": %s\n",
|
2011-07-12 12:13:51 +08:00
|
|
|
output_path, getErrorText(errno));
|
2010-07-25 11:28:32 +08:00
|
|
|
if (!db_used)
|
|
|
|
{
|
2011-07-12 12:13:51 +08:00
|
|
|
fprintf(script, "Database: %s\n", active_db->db_name);
|
2010-07-25 11:28:32 +08:00
|
|
|
db_used = true;
|
|
|
|
}
|
|
|
|
fprintf(script, " %s.%s.%s\n",
|
|
|
|
PQgetvalue(res, rowno, i_nspname),
|
|
|
|
PQgetvalue(res, rowno, i_relname),
|
|
|
|
PQgetvalue(res, rowno, i_attname));
|
|
|
|
}
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
}
|
|
|
|
|
2011-03-09 10:35:42 +08:00
|
|
|
if (script)
|
|
|
|
fclose(script);
|
|
|
|
|
2010-07-25 11:28:32 +08:00
|
|
|
if (found)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, "fatal\n");
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Your installation contains one of the reg* data types in user tables.\n"
|
2012-06-11 03:20:04 +08:00
|
|
|
"These data types reference system OIDs that are not preserved by\n"
|
|
|
|
"pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
|
2011-07-12 12:13:51 +08:00
|
|
|
"remove the problem tables and restart the upgrade. A list of the problem\n"
|
|
|
|
"columns is in the file:\n"
|
|
|
|
" %s\n\n", output_path);
|
2010-07-25 11:28:32 +08:00
|
|
|
}
|
|
|
|
else
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-07-25 11:28:32 +08:00
|
|
|
}
|
2011-06-23 05:47:23 +08:00
|
|
|
|
|
|
|
|
2011-06-23 08:48:34 +08:00
|
|
|
static void
|
|
|
|
get_bin_version(ClusterInfo *cluster)
|
|
|
|
{
|
2012-06-11 03:20:04 +08:00
|
|
|
char cmd[MAXPGPATH],
|
|
|
|
cmd_output[MAX_STRING];
|
2011-06-23 08:48:34 +08:00
|
|
|
FILE *output;
|
2012-06-11 03:20:04 +08:00
|
|
|
int pre_dot,
|
|
|
|
post_dot;
|
2011-06-23 08:48:34 +08:00
|
|
|
|
|
|
|
snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir);
|
|
|
|
|
2011-10-07 07:37:29 +08:00
|
|
|
if ((output = popen(cmd, "r")) == NULL ||
|
|
|
|
fgets(cmd_output, sizeof(cmd_output), output) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("Could not get pg_ctl version data using %s: %s\n",
|
2011-10-07 07:37:29 +08:00
|
|
|
cmd, getErrorText(errno));
|
2011-06-23 08:48:34 +08:00
|
|
|
|
|
|
|
pclose(output);
|
|
|
|
|
|
|
|
/* Remove trailing newline */
|
|
|
|
if (strchr(cmd_output, '\n') != NULL)
|
|
|
|
*strchr(cmd_output, '\n') = '\0';
|
|
|
|
|
|
|
|
if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) != 2)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("could not get version from %s\n", cmd);
|
2011-06-23 08:48:34 +08:00
|
|
|
|
|
|
|
cluster->bin_version = (pre_dot * 100 + post_dot) * 100;
|
|
|
|
}
|
2012-10-02 23:42:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_canonical_locale_name
|
|
|
|
*
|
|
|
|
* Send the locale name to the system, and hope we get back a canonical
|
|
|
|
* version. This should match the backend's check_locale() function.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
get_canonical_locale_name(int category, const char *locale)
|
|
|
|
{
|
|
|
|
char *save;
|
|
|
|
char *res;
|
|
|
|
|
2014-01-31 07:10:01 +08:00
|
|
|
/* get the current setting, so we can restore it. */
|
2012-10-02 23:42:34 +08:00
|
|
|
save = setlocale(category, NULL);
|
|
|
|
if (!save)
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("failed to get the current locale\n");
|
2012-10-02 23:42:34 +08:00
|
|
|
|
|
|
|
/* 'save' may be pointing at a modifiable scratch variable, so copy it. */
|
|
|
|
save = pg_strdup(save);
|
|
|
|
|
|
|
|
/* set the locale with setlocale, to see if it accepts it. */
|
|
|
|
res = setlocale(category, locale);
|
|
|
|
|
|
|
|
if (!res)
|
2014-01-31 07:10:01 +08:00
|
|
|
pg_fatal("failed to get system locale name for \"%s\"\n", locale);
|
2012-10-02 23:42:34 +08:00
|
|
|
|
|
|
|
res = pg_strdup(res);
|
|
|
|
|
|
|
|
/* restore old value. */
|
|
|
|
if (!setlocale(category, save))
|
2013-10-02 09:24:56 +08:00
|
|
|
pg_fatal("failed to restore old locale \"%s\"\n", save);
|
2012-10-02 23:42:34 +08:00
|
|
|
|
2012-11-25 11:12:39 +08:00
|
|
|
pg_free(save);
|
2012-10-02 23:42:34 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|