Pg_upgrade displays file names during copy and database names during dump/restore. Andrew Dunstan identified three bugs:
* long file names were being truncated to 60 _leading_ characters, which often do not change for long file names * file names were truncated to 60 characters in log files * carriage returns were being output to log files The attached patch fixes these --- it prints 60 _trailing_ characters to the status display, and full path names without carriage returns to log files. -- Bruce Momjian <br...@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +
diff --git a/contrib/pg_upgrade/dump.c b/contrib/pg_upgrade/dump.c new file mode 100644 index 2c1b65b..f35852b *** a/contrib/pg_upgrade/dump.c --- b/contrib/pg_upgrade/dump.c *************** generate_old_dump(void) *** 36,42 **** char file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; ! pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_db->db_name); snprintf(file_name, sizeof(file_name), DB_DUMP_FILE_MASK, old_db->db_oid); exec_prog(RESTORE_LOG_FILE, NULL, true, --- 36,42 ---- char file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; ! pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(file_name, sizeof(file_name), DB_DUMP_FILE_MASK, old_db->db_oid); exec_prog(RESTORE_LOG_FILE, NULL, true, diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c new file mode 100644 index 63df529..2d4b678 *** a/contrib/pg_upgrade/pg_upgrade.c --- b/contrib/pg_upgrade/pg_upgrade.c *************** create_new_objects(void) *** 310,316 **** char file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; ! pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_db->db_name); snprintf(file_name, sizeof(file_name), DB_DUMP_FILE_MASK, old_db->db_oid); /* --- 310,316 ---- char file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; ! pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(file_name, sizeof(file_name), DB_DUMP_FILE_MASK, old_db->db_oid); /* diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h new file mode 100644 index d981035..972e8e9 *** a/contrib/pg_upgrade/pg_upgrade.h --- b/contrib/pg_upgrade/pg_upgrade.h *************** *** 24,32 **** #define MIGRATOR_API_VERSION 1 ! #define MESSAGE_WIDTH "60" - #define OVERWRITE_MESSAGE " %-" MESSAGE_WIDTH "." MESSAGE_WIDTH "s\r" #define GET_MAJOR_VERSION(v) ((v) / 100) /* contains both global db information and CREATE DATABASE commands */ --- 24,31 ---- #define MIGRATOR_API_VERSION 1 ! #define MESSAGE_WIDTH 60 #define GET_MAJOR_VERSION(v) ((v) / 100) /* contains both global db information and CREATE DATABASE commands */ *************** typedef enum *** 208,213 **** --- 207,213 ---- typedef enum { PG_VERBOSE, + PG_STATUS, PG_REPORT, PG_WARNING, PG_FATAL diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c new file mode 100644 index 14e66df..5fec5ad *** a/contrib/pg_upgrade/relfilenode.c --- b/contrib/pg_upgrade/relfilenode.c *************** transfer_relfile(pageCnvCtx *pageConvert *** 213,219 **** unlink(new_file); /* Copying files might take some time, so give feedback. */ ! pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_file); if ((user_opts.transfer_mode == TRANSFER_MODE_LINK) && (pageConverter != NULL)) pg_log(PG_FATAL, "This upgrade requires page-by-page conversion, " --- 213,219 ---- unlink(new_file); /* Copying files might take some time, so give feedback. */ ! pg_log(PG_STATUS, "%s", old_file); if ((user_opts.transfer_mode == TRANSFER_MODE_LINK) && (pageConverter != NULL)) pg_log(PG_FATAL, "This upgrade requires page-by-page conversion, " diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c new file mode 100644 index 0c1eccc..e3fdf3a *** a/contrib/pg_upgrade/util.c --- b/contrib/pg_upgrade/util.c *************** prep_status(const char *fmt,...) *** 75,81 **** if (strlen(message) > 0 && message[strlen(message) - 1] == '\n') pg_log(PG_REPORT, "%s", message); else ! pg_log(PG_REPORT, "%-" MESSAGE_WIDTH "s", message); } --- 75,82 ---- if (strlen(message) > 0 && message[strlen(message) - 1] == '\n') pg_log(PG_REPORT, "%s", message); else ! /* trim strings that don't end in a newline */ ! pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message); } *************** pg_log(eLogType type, char *fmt,...) *** 93,110 **** /* fopen() on log_opts.internal might have failed, so check it */ if ((type != PG_VERBOSE || log_opts.verbose) && log_opts.internal != NULL) { ! /* ! * There's nothing much we can do about it if fwrite fails, but some ! * platforms declare fwrite with warn_unused_result. Do a little ! * dance with casting to void to shut up the compiler in such cases. ! */ ! size_t rc; ! ! rc = fwrite(message, strlen(message), 1, log_opts.internal); ! /* if we are using OVERWRITE_MESSAGE, add newline to log file */ ! if (strchr(message, '\r') != NULL) ! rc = fwrite("\n", 1, 1, log_opts.internal); ! (void) rc; fflush(log_opts.internal); } --- 94,104 ---- /* fopen() on log_opts.internal might have failed, so check it */ if ((type != PG_VERBOSE || log_opts.verbose) && log_opts.internal != NULL) { ! if (type == PG_STATUS) ! /* status messages need two leading spaces and a newline */ ! fprintf(log_opts.internal, " %s\n", message); ! else ! fprintf(log_opts.internal, "%s", message); fflush(log_opts.internal); } *************** pg_log(eLogType type, char *fmt,...) *** 115,120 **** --- 109,129 ---- printf("%s", _(message)); break; + case PG_STATUS: + /* for output to a display, do leading truncation and append \r */ + if (isatty(fileno(stdout))) + /* -2 because we use a 2-space indent */ + printf(" %s%-*.*s\r", + /* prefix with "..." if we do leading truncation */ + strlen(message) <= MESSAGE_WIDTH - 2 ? "" : "...", + MESSAGE_WIDTH - 2, MESSAGE_WIDTH - 2, + /* optional leading truncation */ + strlen(message) <= MESSAGE_WIDTH - 2 ? message : + message + strlen(message) - MESSAGE_WIDTH + 3 + 2); + else + printf(" %s\n", _(message)); + break; + case PG_REPORT: case PG_WARNING: printf("%s", _(message));
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers