4 * server checks and output routines
6 * Copyright (c) 2010-2012, PostgreSQL Global Development Group
7 * contrib/pg_upgrade/check.c
12 #include "pg_upgrade.h"
15 static void set_locale_and_encoding(ClusterInfo *cluster);
16 static void check_new_cluster_is_empty(void);
17 static void check_locale_and_encoding(ControlData *oldctrl,
18 ControlData *newctrl);
19 static void check_is_super_user(ClusterInfo *cluster);
20 static void check_for_prepared_transactions(ClusterInfo *cluster);
21 static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
22 static void check_for_reg_data_type_usage(ClusterInfo *cluster);
23 static void get_bin_version(ClusterInfo *cluster);
28 * For non-Windows, just return the argument.
29 * For Windows convert any forward slash to a backslash
30 * such as is suitable for arguments to builtin commands
33 static char *fix_path_separator(char *path)
40 result = pg_strdup(path);
42 for (c = result; *c != '\0'; c++)
56 output_check_banner(bool *live_check)
58 if (user_opts.check && is_server_running(old_cluster.pgdata))
61 if (old_cluster.port == DEF_PGUPORT)
62 pg_log(PG_FATAL, "When checking a live old server, "
63 "you must specify the old server's port number.\n");
64 if (old_cluster.port == new_cluster.port)
65 pg_log(PG_FATAL, "When checking a live server, "
66 "the old and new port numbers must be different.\n");
67 pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n");
68 pg_log(PG_REPORT, "------------------------------------------------\n");
72 pg_log(PG_REPORT, "Performing Consistency Checks\n");
73 pg_log(PG_REPORT, "-----------------------------\n");
79 check_old_cluster(bool live_check, char **sequence_script_file_name)
84 start_postmaster(&old_cluster);
86 set_locale_and_encoding(&old_cluster);
88 get_pg_database_relfilenode(&old_cluster);
90 /* Extract a list of databases and tables from the old cluster */
91 get_db_and_rel_infos(&old_cluster);
95 get_loadable_libraries();
99 * Check for various failure cases
101 check_is_super_user(&old_cluster);
102 check_for_prepared_transactions(&old_cluster);
103 check_for_reg_data_type_usage(&old_cluster);
104 check_for_isn_and_int8_passing_mismatch(&old_cluster);
106 /* old = PG 8.3 checks? */
107 if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
109 old_8_3_check_for_name_data_type_usage(&old_cluster);
110 old_8_3_check_for_tsquery_usage(&old_cluster);
111 old_8_3_check_ltree_usage(&old_cluster);
114 old_8_3_rebuild_tsvector_tables(&old_cluster, true);
115 old_8_3_invalidate_hash_gin_indexes(&old_cluster, true);
116 old_8_3_invalidate_bpchar_pattern_ops_indexes(&old_cluster, true);
121 * While we have the old server running, create the script to
122 * properly restore its sequence values but we report this at the
125 *sequence_script_file_name =
126 old_8_3_create_sequence_script(&old_cluster);
129 /* Pre-PG 9.0 had no large object permissions */
130 if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
131 new_9_0_populate_pg_largeobject_metadata(&old_cluster, true);
134 * While not a check option, we do this now because this is the only time
135 * the old server is running.
137 if (!user_opts.check)
144 stop_postmaster(false);
149 check_new_cluster(void)
151 set_locale_and_encoding(&new_cluster);
153 check_locale_and_encoding(&old_cluster.controldata, &new_cluster.controldata);
155 get_db_and_rel_infos(&new_cluster);
157 check_new_cluster_is_empty();
159 check_loadable_libraries();
161 if (user_opts.transfer_mode == TRANSFER_MODE_LINK)
164 check_is_super_user(&new_cluster);
167 * We don't restore our own user, so both clusters must match have
168 * matching install-user oids.
170 if (old_cluster.install_role_oid != new_cluster.install_role_oid)
172 "Old and new cluster install users have different values for pg_authid.oid.\n");
175 * We only allow the install user in the new cluster because other
176 * defined users might match users defined in the old cluster and
177 * generate an error during pg_dump restore.
179 if (new_cluster.role_count != 1)
180 pg_log(PG_FATAL, "Only the install user can be defined in the new cluster.\n");
182 check_for_prepared_transactions(&new_cluster);
187 report_clusters_compatible(void)
191 pg_log(PG_REPORT, "\n*Clusters are compatible*\n");
192 /* stops new cluster */
193 stop_postmaster(false);
197 pg_log(PG_REPORT, "\n"
198 "If pg_upgrade fails after this point, you must re-initdb the\n"
199 "new cluster before continuing.\n");
204 issue_warnings(char *sequence_script_file_name)
206 /* old = PG 8.3 warnings? */
207 if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
209 start_postmaster(&new_cluster);
211 /* restore proper sequence values using file created from old server */
212 if (sequence_script_file_name)
214 prep_status("Adjusting sequences");
215 exec_prog(UTILITY_LOG_FILE, NULL, true,
216 "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"",
217 new_cluster.bindir, cluster_conn_opts(&new_cluster),
218 sequence_script_file_name);
219 unlink(sequence_script_file_name);
223 old_8_3_rebuild_tsvector_tables(&new_cluster, false);
224 old_8_3_invalidate_hash_gin_indexes(&new_cluster, false);
225 old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false);
226 stop_postmaster(false);
229 /* Create dummy large object permissions for old < PG 9.0? */
230 if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
232 start_postmaster(&new_cluster);
233 new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
234 stop_postmaster(false);
240 output_completion_banner(char *analyze_script_file_name,
241 char *deletion_script_file_name)
243 /* Did we copy the free space files? */
244 if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
246 "Optimizer statistics are not transferred by pg_upgrade so,\n"
247 "once you start the new server, consider running:\n"
248 " %s\n\n", analyze_script_file_name);
251 "Optimizer statistics and free space information are not transferred\n"
252 "by pg_upgrade so, once you start the new server, consider running:\n"
253 " %s\n\n", analyze_script_file_name);
256 "Running this script will delete the old cluster's data files:\n"
258 deletion_script_file_name);
263 check_cluster_versions(void)
265 prep_status("Checking cluster versions");
267 /* get old and new cluster versions */
268 old_cluster.major_version = get_major_server_version(&old_cluster);
269 new_cluster.major_version = get_major_server_version(&new_cluster);
272 * We allow upgrades from/to the same major version for alpha/beta
276 if (GET_MAJOR_VERSION(old_cluster.major_version) < 803)
277 pg_log(PG_FATAL, "This utility can only upgrade from PostgreSQL version 8.3 and later.\n");
279 /* Only current PG version is supported as a target */
280 if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
281 pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version %s.\n",
285 * We can't allow downgrading because we use the target pg_dumpall, and
286 * pg_dumpall cannot operate on new database versions, only older
289 if (old_cluster.major_version > new_cluster.major_version)
290 pg_log(PG_FATAL, "This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
292 /* get old and new binary versions */
293 get_bin_version(&old_cluster);
294 get_bin_version(&new_cluster);
296 /* Ensure binaries match the designated data directories */
297 if (GET_MAJOR_VERSION(old_cluster.major_version) !=
298 GET_MAJOR_VERSION(old_cluster.bin_version))
300 "Old cluster data and binary directories are from different major versions.\n");
301 if (GET_MAJOR_VERSION(new_cluster.major_version) !=
302 GET_MAJOR_VERSION(new_cluster.bin_version))
304 "New cluster data and binary directories are from different major versions.\n");
311 check_cluster_compatibility(bool live_check)
313 /* get/check pg_control data of servers */
314 get_control_data(&old_cluster, live_check);
315 get_control_data(&new_cluster, false);
316 check_control_data(&old_cluster.controldata, &new_cluster.controldata);
318 /* Is it 9.0 but without tablespace directories? */
319 if (GET_MAJOR_VERSION(new_cluster.major_version) == 900 &&
320 new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER)
321 pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
322 "because of backend API changes made during development.\n");
327 * set_locale_and_encoding()
329 * query the database to get the template0 locale
332 set_locale_and_encoding(ClusterInfo *cluster)
334 ControlData *ctrl = &cluster->controldata;
338 int cluster_version = cluster->major_version;
340 conn = connectToServer(cluster, "template1");
342 /* for pg < 80400, we got the values from pg_controldata */
343 if (cluster_version >= 80400)
348 res = executeQueryOrDie(conn,
349 "SELECT datcollate, datctype "
350 "FROM pg_catalog.pg_database "
351 "WHERE datname = 'template0' ");
352 assert(PQntuples(res) == 1);
354 i_datcollate = PQfnumber(res, "datcollate");
355 i_datctype = PQfnumber(res, "datctype");
357 ctrl->lc_collate = pg_strdup(PQgetvalue(res, 0, i_datcollate));
358 ctrl->lc_ctype = pg_strdup(PQgetvalue(res, 0, i_datctype));
363 res = executeQueryOrDie(conn,
364 "SELECT pg_catalog.pg_encoding_to_char(encoding) "
365 "FROM pg_catalog.pg_database "
366 "WHERE datname = 'template0' ");
367 assert(PQntuples(res) == 1);
369 i_encoding = PQfnumber(res, "pg_encoding_to_char");
370 ctrl->encoding = pg_strdup(PQgetvalue(res, 0, i_encoding));
379 * check_locale_and_encoding()
381 * locale is not in pg_controldata in 8.4 and later so
382 * we probably had to get via a database query.
385 check_locale_and_encoding(ControlData *oldctrl,
386 ControlData *newctrl)
388 /* These are often defined with inconsistent case, so use pg_strcasecmp(). */
389 if (pg_strcasecmp(oldctrl->lc_collate, newctrl->lc_collate) != 0)
391 "old and new cluster lc_collate values do not match\n");
392 if (pg_strcasecmp(oldctrl->lc_ctype, newctrl->lc_ctype) != 0)
394 "old and new cluster lc_ctype values do not match\n");
395 if (pg_strcasecmp(oldctrl->encoding, newctrl->encoding) != 0)
397 "old and new cluster encoding values do not match\n");
402 check_new_cluster_is_empty(void)
406 for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
409 RelInfoArr *rel_arr = &new_cluster.dbarr.dbs[dbnum].rel_arr;
411 for (relnum = 0; relnum < rel_arr->nrels;
414 /* pg_largeobject and its index should be skipped */
415 if (strcmp(rel_arr->rels[relnum].nspname, "pg_catalog") != 0)
416 pg_log(PG_FATAL, "New cluster database \"%s\" is not empty\n",
417 new_cluster.dbarr.dbs[dbnum].db_name);
425 * create_script_for_cluster_analyze()
427 * This incrementally generates better optimizer statistics
430 create_script_for_cluster_analyze(char **analyze_script_file_name)
434 *analyze_script_file_name = pg_malloc(MAXPGPATH);
436 prep_status("Creating script to analyze new cluster");
438 snprintf(*analyze_script_file_name, MAXPGPATH, "analyze_new_cluster.%s",
441 if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
442 pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
443 *analyze_script_file_name, getErrorText(errno));
446 /* add shebang header */
447 fprintf(script, "#!/bin/sh\n\n");
450 fprintf(script, "echo %sThis script will generate minimal optimizer statistics rapidly%s\n",
451 ECHO_QUOTE, ECHO_QUOTE);
452 fprintf(script, "echo %sso your system is usable, and then gather statistics twice more%s\n",
453 ECHO_QUOTE, ECHO_QUOTE);
454 fprintf(script, "echo %swith increasing accuracy. When it is done, your system will%s\n",
455 ECHO_QUOTE, ECHO_QUOTE);
456 fprintf(script, "echo %shave the default level of optimizer statistics.%s\n",
457 ECHO_QUOTE, ECHO_QUOTE);
458 fprintf(script, "echo\n\n");
460 fprintf(script, "echo %sIf you have used ALTER TABLE to modify the statistics target for%s\n",
461 ECHO_QUOTE, ECHO_QUOTE);
462 fprintf(script, "echo %sany tables, you might want to remove them and restore them after%s\n",
463 ECHO_QUOTE, ECHO_QUOTE);
464 fprintf(script, "echo %srunning this script because they will delay fast statistics generation.%s\n",
465 ECHO_QUOTE, ECHO_QUOTE);
466 fprintf(script, "echo\n\n");
468 fprintf(script, "echo %sIf you would like default statistics as quickly as possible, cancel%s\n",
469 ECHO_QUOTE, ECHO_QUOTE);
470 fprintf(script, "echo %sthis script and run:%s\n",
471 ECHO_QUOTE, ECHO_QUOTE);
472 fprintf(script, "echo %s vacuumdb --all %s%s\n", ECHO_QUOTE,
473 /* Did we copy the free space files? */
474 (GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
475 "--analyze-only" : "--analyze", ECHO_QUOTE);
476 fprintf(script, "echo\n\n");
479 fprintf(script, "sleep 2\n");
480 fprintf(script, "PGOPTIONS='-c default_statistics_target=1 -c vacuum_cost_delay=0'\n");
481 /* only need to export once */
482 fprintf(script, "export PGOPTIONS\n");
484 fprintf(script, "REM simulate sleep 2\n");
485 fprintf(script, "PING 1.1.1.1 -n 1 -w 2000 > nul\n");
486 fprintf(script, "SET PGOPTIONS=-c default_statistics_target=1 -c vacuum_cost_delay=0\n");
489 fprintf(script, "echo %sGenerating minimal optimizer statistics (1 target)%s\n",
490 ECHO_QUOTE, ECHO_QUOTE);
491 fprintf(script, "echo %s--------------------------------------------------%s\n",
492 ECHO_QUOTE, ECHO_QUOTE);
493 fprintf(script, "vacuumdb --all --analyze-only\n");
494 fprintf(script, "echo\n");
495 fprintf(script, "echo %sThe server is now available with minimal optimizer statistics.%s\n",
496 ECHO_QUOTE, ECHO_QUOTE);
497 fprintf(script, "echo %sQuery performance will be optimal once this script completes.%s\n",
498 ECHO_QUOTE, ECHO_QUOTE);
499 fprintf(script, "echo\n\n");
502 fprintf(script, "sleep 2\n");
503 fprintf(script, "PGOPTIONS='-c default_statistics_target=10'\n");
505 fprintf(script, "REM simulate sleep\n");
506 fprintf(script, "PING 1.1.1.1 -n 1 -w 2000 > nul\n");
507 fprintf(script, "SET PGOPTIONS=-c default_statistics_target=10\n");
510 fprintf(script, "echo %sGenerating medium optimizer statistics (10 targets)%s\n",
511 ECHO_QUOTE, ECHO_QUOTE);
512 fprintf(script, "echo %s---------------------------------------------------%s\n",
513 ECHO_QUOTE, ECHO_QUOTE);
514 fprintf(script, "vacuumdb --all --analyze-only\n");
515 fprintf(script, "echo\n\n");
518 fprintf(script, "unset PGOPTIONS\n");
520 fprintf(script, "SET PGOPTIONS\n");
523 fprintf(script, "echo %sGenerating default (full) optimizer statistics (100 targets?)%s\n",
524 ECHO_QUOTE, ECHO_QUOTE);
525 fprintf(script, "echo %s-------------------------------------------------------------%s\n",
526 ECHO_QUOTE, ECHO_QUOTE);
527 fprintf(script, "vacuumdb --all %s\n",
528 /* Did we copy the free space files? */
529 (GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
530 "--analyze-only" : "--analyze");
532 fprintf(script, "echo\n\n");
533 fprintf(script, "echo %sDone%s\n",
534 ECHO_QUOTE, ECHO_QUOTE);
539 if (chmod(*analyze_script_file_name, S_IRWXU) != 0)
540 pg_log(PG_FATAL, "Could not add execute permission to file \"%s\": %s\n",
541 *analyze_script_file_name, getErrorText(errno));
549 * create_script_for_old_cluster_deletion()
551 * This is particularly useful for tablespace deletion.
554 create_script_for_old_cluster_deletion(char **deletion_script_file_name)
559 *deletion_script_file_name = pg_malloc(MAXPGPATH);
561 prep_status("Creating script to delete old cluster");
563 snprintf(*deletion_script_file_name, MAXPGPATH, "delete_old_cluster.%s",
566 if ((script = fopen_priv(*deletion_script_file_name, "w")) == NULL)
567 pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
568 *deletion_script_file_name, getErrorText(errno));
571 /* add shebang header */
572 fprintf(script, "#!/bin/sh\n\n");
575 /* delete old cluster's default tablespace */
576 fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(old_cluster.pgdata));
578 /* delete old cluster's alternate tablespaces */
579 for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
582 * Do the old cluster's per-database directories share a directory
583 * with a new version-specific tablespace?
585 if (strlen(old_cluster.tablespace_suffix) == 0)
587 /* delete per-database directories */
590 fprintf(script, "\n");
591 /* remove PG_VERSION? */
592 if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
593 fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
594 fix_path_separator(os_info.tablespaces[tblnum]),
595 fix_path_separator(old_cluster.tablespace_suffix),
598 for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
600 fprintf(script, RMDIR_CMD " %s%s%c%d\n",
601 fix_path_separator(os_info.tablespaces[tblnum]),
602 fix_path_separator(old_cluster.tablespace_suffix),
603 PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
609 * Simply delete the tablespace directory, which might be ".old"
610 * or a version-specific subdirectory.
612 fprintf(script, RMDIR_CMD " %s%s\n",
613 fix_path_separator(os_info.tablespaces[tblnum]),
614 fix_path_separator(old_cluster.tablespace_suffix));
620 if (chmod(*deletion_script_file_name, S_IRWXU) != 0)
621 pg_log(PG_FATAL, "Could not add execute permission to file \"%s\": %s\n",
622 *deletion_script_file_name, getErrorText(errno));
630 * check_is_super_user()
632 * Check we are superuser, and out user id and user count
635 check_is_super_user(ClusterInfo *cluster)
638 PGconn *conn = connectToServer(cluster, "template1");
640 prep_status("Checking database user is a superuser");
642 /* Can't use pg_authid because only superusers can view it. */
643 res = executeQueryOrDie(conn,
644 "SELECT rolsuper, oid "
645 "FROM pg_catalog.pg_roles "
646 "WHERE rolname = current_user");
648 if (PQntuples(res) != 1 || strcmp(PQgetvalue(res, 0, 0), "t") != 0)
649 pg_log(PG_FATAL, "database user \"%s\" is not a superuser\n",
652 cluster->install_role_oid = atooid(PQgetvalue(res, 0, 1));
656 res = executeQueryOrDie(conn,
658 "FROM pg_catalog.pg_roles ");
660 if (PQntuples(res) != 1)
661 pg_log(PG_FATAL, "could not determine the number of users\n");
663 cluster->role_count = atoi(PQgetvalue(res, 0, 0));
674 * check_for_prepared_transactions()
676 * Make sure there are no prepared transactions because the storage format
677 * might have changed.
680 check_for_prepared_transactions(ClusterInfo *cluster)
683 PGconn *conn = connectToServer(cluster, "template1");
685 prep_status("Checking for prepared transactions");
687 res = executeQueryOrDie(conn,
689 "FROM pg_catalog.pg_prepared_xacts");
691 if (PQntuples(res) != 0)
692 pg_log(PG_FATAL, "The %s cluster contains prepared transactions\n",
693 CLUSTER_NAME(cluster));
704 * check_for_isn_and_int8_passing_mismatch()
706 * contrib/isn relies on data type int8, and in 8.4 int8 can now be passed
707 * by value. The schema dumps the CREATE TYPE PASSEDBYVALUE setting so
708 * it must match for the old and new servers.
711 check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
716 char output_path[MAXPGPATH];
718 prep_status("Checking for contrib/isn with bigint-passing mismatch");
720 if (old_cluster.controldata.float8_pass_by_value ==
721 new_cluster.controldata.float8_pass_by_value)
728 snprintf(output_path, sizeof(output_path),
729 "contrib_isn_and_int8_pass_by_value.txt");
731 for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
734 bool db_used = false;
739 DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
740 PGconn *conn = connectToServer(cluster, active_db->db_name);
742 /* Find any functions coming from contrib/isn */
743 res = executeQueryOrDie(conn,
744 "SELECT n.nspname, p.proname "
745 "FROM pg_catalog.pg_proc p, "
746 " pg_catalog.pg_namespace n "
747 "WHERE p.pronamespace = n.oid AND "
748 " p.probin = '$libdir/isn'");
750 ntups = PQntuples(res);
751 i_nspname = PQfnumber(res, "nspname");
752 i_proname = PQfnumber(res, "proname");
753 for (rowno = 0; rowno < ntups; rowno++)
756 if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
757 pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
758 output_path, getErrorText(errno));
761 fprintf(script, "Database: %s\n", active_db->db_name);
764 fprintf(script, " %s.%s\n",
765 PQgetvalue(res, rowno, i_nspname),
766 PQgetvalue(res, rowno, i_proname));
779 pg_log(PG_REPORT, "fatal\n");
781 "Your installation contains \"contrib/isn\" functions which rely on the\n"
782 "bigint data type. Your old and new clusters pass bigint values\n"
783 "differently so this cluster cannot currently be upgraded. You can\n"
784 "manually upgrade databases that use \"contrib/isn\" facilities and remove\n"
785 "\"contrib/isn\" from the old cluster and restart the upgrade. A list of\n"
786 "the problem functions is in the file:\n"
787 " %s\n\n", output_path);
795 * check_for_reg_data_type_usage()
796 * pg_upgrade only preserves these system values:
801 * Many of the reg* data types reference system catalog info that is
802 * not preserved, and hence these data types cannot be used in user
803 * tables upgraded by pg_upgrade.
806 check_for_reg_data_type_usage(ClusterInfo *cluster)
811 char output_path[MAXPGPATH];
813 prep_status("Checking for reg* system OID user data types");
815 snprintf(output_path, sizeof(output_path), "tables_using_reg.txt");
817 for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
820 bool db_used = false;
826 DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
827 PGconn *conn = connectToServer(cluster, active_db->db_name);
830 * While several relkinds don't store any data, e.g. views, they can
831 * be used to define data types of other columns, so we check all
834 res = executeQueryOrDie(conn,
835 "SELECT n.nspname, c.relname, a.attname "
836 "FROM pg_catalog.pg_class c, "
837 " pg_catalog.pg_namespace n, "
838 " pg_catalog.pg_attribute a "
839 "WHERE c.oid = a.attrelid AND "
840 " NOT a.attisdropped AND "
842 " 'pg_catalog.regproc'::pg_catalog.regtype, "
843 " 'pg_catalog.regprocedure'::pg_catalog.regtype, "
844 " 'pg_catalog.regoper'::pg_catalog.regtype, "
845 " 'pg_catalog.regoperator'::pg_catalog.regtype, "
846 /* regclass.oid is preserved, so 'regclass' is OK */
847 /* regtype.oid is preserved, so 'regtype' is OK */
848 " 'pg_catalog.regconfig'::pg_catalog.regtype, "
849 " 'pg_catalog.regdictionary'::pg_catalog.regtype) AND "
850 " c.relnamespace = n.oid AND "
851 " n.nspname != 'pg_catalog' AND "
852 " n.nspname != 'information_schema'");
854 ntups = PQntuples(res);
855 i_nspname = PQfnumber(res, "nspname");
856 i_relname = PQfnumber(res, "relname");
857 i_attname = PQfnumber(res, "attname");
858 for (rowno = 0; rowno < ntups; rowno++)
861 if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
862 pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
863 output_path, getErrorText(errno));
866 fprintf(script, "Database: %s\n", active_db->db_name);
869 fprintf(script, " %s.%s.%s\n",
870 PQgetvalue(res, rowno, i_nspname),
871 PQgetvalue(res, rowno, i_relname),
872 PQgetvalue(res, rowno, i_attname));
885 pg_log(PG_REPORT, "fatal\n");
887 "Your installation contains one of the reg* data types in user tables.\n"
888 "These data types reference system OIDs that are not preserved by\n"
889 "pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
890 "remove the problem tables and restart the upgrade. A list of the problem\n"
891 "columns is in the file:\n"
892 " %s\n\n", output_path);
900 get_bin_version(ClusterInfo *cluster)
903 cmd_output[MAX_STRING];
908 snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir);
910 if ((output = popen(cmd, "r")) == NULL ||
911 fgets(cmd_output, sizeof(cmd_output), output) == NULL)
912 pg_log(PG_FATAL, "Could not get pg_ctl version data using %s: %s\n",
913 cmd, getErrorText(errno));
917 /* Remove trailing newline */
918 if (strchr(cmd_output, '\n') != NULL)
919 *strchr(cmd_output, '\n') = '\0';
921 if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) != 2)
922 pg_log(PG_FATAL, "could not get version from %s\n", cmd);
924 cluster->bin_version = (pre_dot * 100 + post_dot) * 100;