Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 912bc4f

Browse files
committed
Make pg_upgrade output more consistent with project style
Add errno-based output to error messages where appropriate, reformat blocks to about 72 characters per line, use spaces instead of tabs for indentation, and other style adjustments.
1 parent afc9635 commit 912bc4f

14 files changed

+155
-176
lines changed

contrib/pg_upgrade/check.c

+37-40
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ report_clusters_compatible(void)
147147
}
148148

149149
pg_log(PG_REPORT, "\n"
150-
"| If pg_upgrade fails after this point, you must\n"
151-
"| re-initdb the new cluster before continuing.\n"
152-
"| You will also need to remove the \".old\" suffix\n"
153-
"| from %s/global/pg_control.old.\n", old_cluster.pgdata);
150+
"If pg_upgrade fails after this point, you must re-initdb the new cluster\n"
151+
"before continuing. You will also need to remove the \".old\" suffix from\n"
152+
"%s/global/pg_control.old.\n", old_cluster.pgdata);
154153
}
155154

156155

@@ -198,21 +197,20 @@ output_completion_banner(char *deletion_script_file_name)
198197
/* Did we copy the free space files? */
199198
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
200199
pg_log(PG_REPORT,
201-
"| Optimizer statistics are not transferred by pg_upgrade\n"
202-
"| so consider running:\n"
203-
"| \tvacuumdb --all --analyze-only\n"
204-
"| on the newly-upgraded cluster.\n\n");
200+
"Optimizer statistics are not transferred by pg_upgrade so consider\n"
201+
"running:\n"
202+
" vacuumdb --all --analyze-only\n"
203+
"on the newly-upgraded cluster.\n\n");
205204
else
206205
pg_log(PG_REPORT,
207-
"| Optimizer statistics and free space information\n"
208-
"| are not transferred by pg_upgrade so consider\n"
209-
"| running:\n"
210-
"| \tvacuumdb --all --analyze\n"
211-
"| on the newly-upgraded cluster.\n\n");
206+
"Optimizer statistics and free space information are not transferred\n"
207+
"by pg_upgrade so consider running:\n"
208+
" vacuumdb --all --analyze\n"
209+
"on the newly-upgraded cluster.\n\n");
212210

213211
pg_log(PG_REPORT,
214-
"| Running this script will delete the old cluster's data files:\n"
215-
"| \t%s\n",
212+
"Running this script will delete the old cluster's data files:\n"
213+
" %s\n",
216214
deletion_script_file_name);
217215
}
218216

@@ -427,8 +425,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
427425
os_info.cwd, SCRIPT_EXT);
428426

429427
if ((script = fopen(*deletion_script_file_name, "w")) == NULL)
430-
pg_log(PG_FATAL, "Could not create necessary file: %s\n",
431-
*deletion_script_file_name);
428+
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
429+
*deletion_script_file_name, getErrorText(errno));
432430

433431
#ifndef WIN32
434432
/* add shebang header */
@@ -477,8 +475,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
477475

478476
#ifndef WIN32
479477
if (chmod(*deletion_script_file_name, S_IRWXU) != 0)
480-
pg_log(PG_FATAL, "Could not add execute permission to file: %s\n",
481-
*deletion_script_file_name);
478+
pg_log(PG_FATAL, "Could not add execute permission to file \"%s\": %s\n",
479+
*deletion_script_file_name, getErrorText(errno));
482480
#endif
483481

484482
check_ok();
@@ -600,10 +598,11 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
600598
{
601599
found = true;
602600
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
603-
pg_log(PG_FATAL, "Could not create necessary file: %s\n", output_path);
601+
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
602+
output_path, getErrorText(errno));
604603
if (!db_used)
605604
{
606-
fprintf(script, "Database: %s\n", active_db->db_name);
605+
fprintf(script, "Database: %s\n", active_db->db_name);
607606
db_used = true;
608607
}
609608
fprintf(script, " %s.%s\n",
@@ -623,15 +622,13 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
623622
{
624623
pg_log(PG_REPORT, "fatal\n");
625624
pg_log(PG_FATAL,
626-
"| Your installation contains \"contrib/isn\" functions\n"
627-
"| which rely on the bigint data type. Your old and\n"
628-
"| new clusters pass bigint values differently so this\n"
629-
"| cluster cannot currently be upgraded. You can\n"
630-
"| manually upgrade data that use \"contrib/isn\"\n"
631-
"| facilities and remove \"contrib/isn\" from the\n"
632-
"| old cluster and restart the upgrade. A list\n"
633-
"| of the problem functions is in the file:\n"
634-
"| \t%s\n\n", output_path);
625+
"Your installation contains \"contrib/isn\" functions which rely on the\n"
626+
"bigint data type. Your old and new clusters pass bigint values\n"
627+
"differently so this cluster cannot currently be upgraded. You can\n"
628+
"manually upgrade databases that use \"contrib/isn\" facilities and remove\n"
629+
"\"contrib/isn\" from the old cluster and restart the upgrade. A list of\n"
630+
"the problem functions is in the file:\n"
631+
" %s\n\n", output_path);
635632
}
636633
else
637634
check_ok();
@@ -657,7 +654,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
657654
bool found = false;
658655
char output_path[MAXPGPATH];
659656

660-
prep_status("Checking for reg* system oid user data types");
657+
prep_status("Checking for reg* system OID user data types");
661658

662659
snprintf(output_path, sizeof(output_path), "%s/tables_using_reg.txt",
663660
os_info.cwd);
@@ -702,10 +699,11 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
702699
{
703700
found = true;
704701
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
705-
pg_log(PG_FATAL, "Could not create necessary file: %s\n", output_path);
702+
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
703+
output_path, getErrorText(errno));
706704
if (!db_used)
707705
{
708-
fprintf(script, "Database: %s\n", active_db->db_name);
706+
fprintf(script, "Database: %s\n", active_db->db_name);
709707
db_used = true;
710708
}
711709
fprintf(script, " %s.%s.%s\n",
@@ -726,13 +724,12 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
726724
{
727725
pg_log(PG_REPORT, "fatal\n");
728726
pg_log(PG_FATAL,
729-
"| Your installation contains one of the reg* data types in\n"
730-
"| user tables. These data types reference system oids that\n"
731-
"| are not preserved by pg_upgrade, so this cluster cannot\n"
732-
"| currently be upgraded. You can remove the problem tables\n"
733-
"| and restart the upgrade. A list of the problem columns\n"
734-
"| is in the file:\n"
735-
"| \t%s\n\n", output_path);
727+
"Your installation contains one of the reg* data types in user tables.\n"
728+
"These data types reference system OIDs that are not preserved by\n"
729+
"pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
730+
"remove the problem tables and restart the upgrade. A list of the problem\n"
731+
"columns is in the file:\n"
732+
" %s\n\n", output_path);
736733
}
737734
else
738735
check_ok();

contrib/pg_upgrade/controldata.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
451451
pg_log(PG_REPORT, " float8 argument passing method\n");
452452

453453
pg_log(PG_FATAL,
454-
"Unable to continue without required control information, terminating\n");
454+
"Cannot continue without required control information, terminating\n");
455455
}
456456
}
457457

@@ -506,9 +506,9 @@ check_control_data(ControlData *oldctrl,
506506
* This is a common 8.3 -> 8.4 upgrade problem, so we are more verbose
507507
*/
508508
pg_log(PG_FATAL,
509-
"You will need to rebuild the new server with configure\n"
510-
"--disable-integer-datetimes or get server binaries built\n"
511-
"with those options.\n");
509+
"You will need to rebuild the new server with configure option\n"
510+
"--disable-integer-datetimes or get server binaries built with those\n"
511+
"options.\n");
512512
}
513513
}
514514

contrib/pg_upgrade/dump.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ split_old_dump(void)
5656

5757
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, ALL_DUMP_FILE);
5858
if ((all_dump = fopen(filename, "r")) == NULL)
59-
pg_log(PG_FATAL, "Cannot open dump file %s\n", filename);
59+
pg_log(PG_FATAL, "Could not open dump file \"%s\": %s\n", filename, getErrorText(errno));
6060
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, GLOBALS_DUMP_FILE);
6161
if ((globals_dump = fopen(filename, "w")) == NULL)
62-
pg_log(PG_FATAL, "Cannot write to dump file %s\n", filename);
62+
pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno));
6363
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, DB_DUMP_FILE);
6464
if ((db_dump = fopen(filename, "w")) == NULL)
65-
pg_log(PG_FATAL, "Cannot write to dump file %s\n", filename);
65+
pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno));
6666
current_output = globals_dump;
6767

6868
/* patterns used to prevent our own username from being recreated */

contrib/pg_upgrade/exec.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exec_prog(bool throw_error, const char *fmt,...)
4646
if (result != 0)
4747
{
4848
pg_log(throw_error ? PG_FATAL : PG_INFO,
49-
"There were problems executing %s\n", cmd);
49+
"There were problems executing \"%s\"\n", cmd);
5050
return 1;
5151
}
5252

@@ -72,8 +72,8 @@ is_server_running(const char *datadir)
7272
{
7373
/* ENOTDIR means we will throw a more useful error later */
7474
if (errno != ENOENT && errno != ENOTDIR)
75-
pg_log(PG_FATAL, "could not open file \"%s\" for reading\n",
76-
path);
75+
pg_log(PG_FATAL, "could not open file \"%s\" for reading: %s\n",
76+
path, getErrorText(errno));
7777

7878
return false;
7979
}
@@ -149,7 +149,7 @@ check_data_dir(const char *pg_data)
149149
requiredSubdirs[subdirnum]);
150150

151151
if (stat(subDirName, &statBuf) != 0)
152-
report_status(PG_FATAL, "check for %s failed: %s\n",
152+
report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
153153
subDirName, getErrorText(errno));
154154
else if (!S_ISDIR(statBuf.st_mode))
155155
report_status(PG_FATAL, "%s is not a directory\n",
@@ -173,7 +173,7 @@ check_bin_dir(ClusterInfo *cluster)
173173

174174
/* check bindir */
175175
if (stat(cluster->bindir, &statBuf) != 0)
176-
report_status(PG_FATAL, "check for %s failed: %s\n",
176+
report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
177177
cluster->bindir, getErrorText(errno));
178178
else if (!S_ISDIR(statBuf.st_mode))
179179
report_status(PG_FATAL, "%s is not a directory\n",
@@ -216,10 +216,10 @@ validate_exec(const char *dir, const char *cmdName)
216216
* Ensure that the file exists and is a regular file.
217217
*/
218218
if (stat(path, &buf) < 0)
219-
pg_log(PG_FATAL, "check for %s failed - %s\n",
219+
pg_log(PG_FATAL, "check for \"%s\" failed: %s\n",
220220
path, getErrorText(errno));
221221
else if (!S_ISREG(buf.st_mode))
222-
pg_log(PG_FATAL, "check for %s failed - not an executable file\n",
222+
pg_log(PG_FATAL, "check for \"%s\" failed: not an executable file\n",
223223
path);
224224

225225
/*
@@ -231,14 +231,14 @@ validate_exec(const char *dir, const char *cmdName)
231231
#else
232232
if ((buf.st_mode & S_IRUSR) == 0)
233233
#endif
234-
pg_log(PG_FATAL, "check for %s failed - cannot read file (permission denied)\n",
234+
pg_log(PG_FATAL, "check for \"%s\" failed: cannot read file (permission denied)\n",
235235
path);
236236

237237
#ifndef WIN32
238238
if (access(path, X_OK) != 0)
239239
#else
240240
if ((buf.st_mode & S_IXUSR) == 0)
241241
#endif
242-
pg_log(PG_FATAL, "check for %s failed - cannot execute (permission denied)\n",
242+
pg_log(PG_FATAL, "check for \"%s\" failed: cannot execute (permission denied)\n",
243243
path);
244244
}

contrib/pg_upgrade/file.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ copyAndUpdateFile(pageCnvCtx *pageConverter,
6969
const char *msg = NULL;
7070

7171
if ((src_fd = open(src, O_RDONLY, 0)) < 0)
72-
return "can't open source file";
72+
return "could not open source file";
7373

7474
if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
7575
{
7676
close(src_fd);
77-
return "can't create destination file";
77+
return "could not create destination file";
7878
}
7979

8080
while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ)
@@ -85,7 +85,7 @@ copyAndUpdateFile(pageCnvCtx *pageConverter,
8585
#endif
8686
if (write(dstfd, buf, BLCKSZ) != BLCKSZ)
8787
{
88-
msg = "can't write new page to destination";
88+
msg = "could not write new page to destination";
8989
break;
9090
}
9191
}
@@ -118,7 +118,7 @@ linkAndUpdateFile(pageCnvCtx *pageConverter,
118118
const char *src, const char *dst)
119119
{
120120
if (pageConverter != NULL)
121-
return "Can't in-place update this cluster, page-by-page conversion is required";
121+
return "Cannot in-place update this cluster, page-by-page conversion is required";
122122

123123
if (pg_link_file(src, dst) == -1)
124124
return getErrorText(errno);
@@ -360,7 +360,7 @@ check_hard_link(void)
360360
if (pg_link_file(existing_file, new_link_file) == -1)
361361
{
362362
pg_log(PG_FATAL,
363-
"Could not create hard link between old and new data directories: %s\n"
363+
"Could not create hard link between old and new data directories: %s\n"
364364
"In link mode the old and new data directories must be on the same file system volume.\n",
365365
getErrorText(errno));
366366
}

contrib/pg_upgrade/function.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ check_loadable_libraries(void)
237237
{
238238
found = true;
239239
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
240-
pg_log(PG_FATAL, "Could not create necessary file: %s\n",
241-
output_path);
242-
fprintf(script, "Failed to load library: %s\n%s\n",
240+
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
241+
output_path, getErrorText(errno));
242+
fprintf(script, "Could not load library \"%s\"\n%s\n",
243243
lib,
244244
PQerrorMessage(conn));
245245
}
@@ -255,12 +255,11 @@ check_loadable_libraries(void)
255255
fclose(script);
256256
pg_log(PG_REPORT, "fatal\n");
257257
pg_log(PG_FATAL,
258-
"| Your installation references loadable libraries that are missing\n"
259-
"| from the new installation. You can add these libraries to\n"
260-
"| the new installation, or remove the functions using them\n"
261-
"| from the old installation. A list of the problem libraries\n"
262-
"| is in the file\n"
263-
"| \"%s\".\n\n", output_path);
258+
"Your installation references loadable libraries that are missing from the\n"
259+
"new installation. You can add these libraries to the new installation,\n"
260+
"or remove the functions using them from the old installation. A list of\n"
261+
"problem libraries is in the file:\n"
262+
" %s\n\n", output_path);
264263
}
265264
else
266265
check_ok();

contrib/pg_upgrade/info.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
5151
RelInfo *new_rel = &new_db->rel_arr.rels[relnum];
5252

5353
if (old_rel->reloid != new_rel->reloid)
54-
pg_log(PG_FATAL, "Mismatch of relation id: database \"%s\", old relid %d, new relid %d\n",
54+
pg_log(PG_FATAL, "Mismatch of relation OID in database \"%s\": old OID %d, new OID %d\n",
5555
old_db->db_name, old_rel->reloid, new_rel->reloid);
5656

5757
/*
@@ -63,8 +63,8 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
6363
((GET_MAJOR_VERSION(old_cluster.major_version) >= 804 ||
6464
strcmp(old_rel->nspname, "pg_toast") != 0) &&
6565
strcmp(old_rel->relname, new_rel->relname) != 0))
66-
pg_log(PG_FATAL, "Mismatch of relation names: database \"%s\", "
67-
"old rel %s.%s, new rel %s.%s\n",
66+
pg_log(PG_FATAL, "Mismatch of relation names in database \"%s\": "
67+
"old name \"%s.%s\", new name \"%s.%s\"\n",
6868
old_db->db_name, old_rel->nspname, old_rel->relname,
6969
new_rel->nspname, new_rel->relname);
7070

@@ -131,7 +131,7 @@ print_maps(FileNameMap *maps, int n_maps, const char *db_name)
131131
{
132132
int mapnum;
133133

134-
pg_log(PG_DEBUG, "mappings for db %s:\n", db_name);
134+
pg_log(PG_DEBUG, "mappings for database \"%s\":\n", db_name);
135135

136136
for (mapnum = 0; mapnum < n_maps; mapnum++)
137137
pg_log(PG_DEBUG, "%s.%s: %u to %u\n",

contrib/pg_upgrade/option.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ check_required_directory(char **dirpath, char *envVarName,
294294
if ((envVar = getenv(envVarName)) && strlen(envVar))
295295
*dirpath = pg_strdup(envVar);
296296
else
297-
pg_log(PG_FATAL, "You must identify the directory where the %s\n"
298-
"Please use the %s command-line option or the %s environment variable\n",
297+
pg_log(PG_FATAL, "You must identify the directory where the %s.\n"
298+
"Please use the %s command-line option or the %s environment variable.\n",
299299
description, cmdLineOption, envVarName);
300300
}
301301

contrib/pg_upgrade/page.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ setupPageConverter(pageCnvCtx **result)
7474
*/
7575

7676
if ((converter = loadConverterPlugin(newPageVersion, oldPageVersion)) == NULL)
77-
return "can't find plugin to convert from old page layout to new page layout";
77+
return "could not find plugin to convert from old page layout to new page layout";
7878
else
7979
{
8080
*result = converter;
@@ -100,12 +100,12 @@ getPageVersion(uint16 *version, const char *pathName)
100100
ssize_t bytesRead;
101101

102102
if ((relfd = open(pathName, O_RDONLY, 0)) < 0)
103-
return "can't open relation";
103+
return "could not open relation";
104104

105105
if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page))
106106
{
107107
close(relfd);
108-
return "can't read page header";
108+
return "could not read page header";
109109
}
110110

111111
*version = PageGetPageLayoutVersion(&page);

0 commit comments

Comments
 (0)