Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit717f6d6

Browse files
committed
In pg_upgrade, add various logging improvements:
add ability to control permissions of created fileshave psql echo its queries for easier debuggingoutput four separate log files, and delete them on successadd -r/--retain option to keep log files after successmake logs file append-onlyremove -g/-G/-l logging optionssugggest tailing appropriate log file on failureenhance -v/--verbose behavior
1 parentb4af1c2 commit717f6d6

File tree

16 files changed

+259
-236
lines changed

16 files changed

+259
-236
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ issue_warnings(char *sequence_script_file_name)
165165
if (sequence_script_file_name)
166166
{
167167
prep_status("Adjusting sequences");
168-
exec_prog(true,
169-
SYSTEMQUOTE"\"%s/psql\" --set ON_ERROR_STOP=on "
168+
exec_prog(true, true,UTILITY_LOG_FILE,
169+
SYSTEMQUOTE"\"%s/psql\" --echo-queries "
170+
"--set ON_ERROR_STOP=on "
170171
"--no-psqlrc --port %d --username \"%s\" "
171-
"-f \"%s\" --dbname template1 >> \"%s\""SYSTEMQUOTE,
172+
"-f \"%s\" --dbname template1 >> \"%s\" 2>&1"SYSTEMQUOTE,
172173
new_cluster.bindir,new_cluster.port,os_info.user,
173-
sequence_script_file_name,log_opts.filename2);
174+
sequence_script_file_name,UTILITY_LOG_FILE);
174175
unlink(sequence_script_file_name);
175176
check_ok();
176177
}
@@ -393,10 +394,10 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
393394

394395
prep_status("Creating script to delete old cluster");
395396

396-
snprintf(*deletion_script_file_name,MAXPGPATH,"%s/delete_old_cluster.%s",
397-
os_info.cwd,SCRIPT_EXT);
397+
snprintf(*deletion_script_file_name,MAXPGPATH,"delete_old_cluster.%s",
398+
SCRIPT_EXT);
398399

399-
if ((script=fopen(*deletion_script_file_name,"w"))==NULL)
400+
if ((script=fopen_priv(*deletion_script_file_name,"w"))==NULL)
400401
pg_log(PG_FATAL,"Could not open file \"%s\": %s\n",
401402
*deletion_script_file_name,getErrorText(errno));
402403

@@ -541,8 +542,8 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
541542
return;
542543
}
543544

544-
snprintf(output_path,sizeof(output_path),"%s/contrib_isn_and_int8_pass_by_value.txt",
545-
os_info.cwd);
545+
snprintf(output_path,sizeof(output_path),
546+
"contrib_isn_and_int8_pass_by_value.txt");
546547

547548
for (dbnum=0;dbnum<cluster->dbarr.ndbs;dbnum++)
548549
{
@@ -569,7 +570,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
569570
for (rowno=0;rowno<ntups;rowno++)
570571
{
571572
found= true;
572-
if (script==NULL&& (script=fopen(output_path,"w"))==NULL)
573+
if (script==NULL&& (script=fopen_priv(output_path,"w"))==NULL)
573574
pg_log(PG_FATAL,"Could not open file \"%s\": %s\n",
574575
output_path,getErrorText(errno));
575576
if (!db_used)
@@ -628,8 +629,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
628629

629630
prep_status("Checking for reg* system OID user data types");
630631

631-
snprintf(output_path,sizeof(output_path),"%s/tables_using_reg.txt",
632-
os_info.cwd);
632+
snprintf(output_path,sizeof(output_path),"tables_using_reg.txt");
633633

634634
for (dbnum=0;dbnum<cluster->dbarr.ndbs;dbnum++)
635635
{
@@ -675,7 +675,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
675675
for (rowno=0;rowno<ntups;rowno++)
676676
{
677677
found= true;
678-
if (script==NULL&& (script=fopen(output_path,"w"))==NULL)
678+
if (script==NULL&& (script=fopen_priv(output_path,"w"))==NULL)
679679
pg_log(PG_FATAL,"Could not open file \"%s\": %s\n",
680680
output_path,getErrorText(errno));
681681
if (!db_used)

‎contrib/pg_upgrade/controldata.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ get_control_data(ClusterInfo *cluster, bool live_check)
126126
/* we have the result of cmd in "output". so parse it line by line now */
127127
while (fgets(bufin,sizeof(bufin),output))
128128
{
129-
if (log_opts.debug)
130-
fputs(bufin,log_opts.debug_fd);
129+
pg_log(PG_VERBOSE,"%s",bufin);
131130

132131
#ifdefWIN32
133-
134132
/*
135133
* Due to an installer bug, LANG=C doesn't work for PG 8.3.3, but does
136134
* work 8.2.6 and 8.3.7, so check for non-ASCII output and suggest a

‎contrib/pg_upgrade/dump.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include"pg_upgrade.h"
1313

14+
#include<sys/types.h>
1415

1516
void
1617
generate_old_dump(void)
@@ -22,10 +23,12 @@ generate_old_dump(void)
2223
* --binary-upgrade records the width of dropped columns in pg_class, and
2324
* restores the frozenid's for databases and relations.
2425
*/
25-
exec_prog(true,
26+
exec_prog(true, true,UTILITY_LOG_FILE,
2627
SYSTEMQUOTE"\"%s/pg_dumpall\" --port %d --username \"%s\" "
27-
"--schema-only --binary-upgrade > \"%s/"ALL_DUMP_FILE"\""
28-
SYSTEMQUOTE,new_cluster.bindir,old_cluster.port,os_info.user,os_info.cwd);
28+
"--schema-only --binary-upgrade %s > \"%s\" 2>> \"%s\""
29+
SYSTEMQUOTE,new_cluster.bindir,old_cluster.port,os_info.user,
30+
log_opts.verbose ?"--verbose" :"",
31+
ALL_DUMP_FILE,UTILITY_LOG_FILE);
2932
check_ok();
3033
}
3134

@@ -56,15 +59,16 @@ split_old_dump(void)
5659
charfilename[MAXPGPATH];
5760
boolsuppressed_username= false;
5861

59-
snprintf(filename,sizeof(filename),"%s/%s",os_info.cwd,ALL_DUMP_FILE);
62+
snprintf(filename,sizeof(filename),"%s",ALL_DUMP_FILE);
6063
if ((all_dump=fopen(filename,"r"))==NULL)
6164
pg_log(PG_FATAL,"Could not open dump file \"%s\": %s\n",filename,getErrorText(errno));
62-
snprintf(filename,sizeof(filename),"%s/%s",os_info.cwd,GLOBALS_DUMP_FILE);
63-
if ((globals_dump=fopen(filename,"w"))==NULL)
65+
snprintf(filename,sizeof(filename),"%s",GLOBALS_DUMP_FILE);
66+
if ((globals_dump=fopen_priv(filename,"w"))==NULL)
6467
pg_log(PG_FATAL,"Could not write to dump file \"%s\": %s\n",filename,getErrorText(errno));
65-
snprintf(filename,sizeof(filename),"%s/%s",os_info.cwd,DB_DUMP_FILE);
66-
if ((db_dump=fopen(filename,"w"))==NULL)
68+
snprintf(filename,sizeof(filename),"%s",DB_DUMP_FILE);
69+
if ((db_dump=fopen_priv(filename,"w"))==NULL)
6770
pg_log(PG_FATAL,"Could not write to dump file \"%s\": %s\n",filename,getErrorText(errno));
71+
6872
current_output=globals_dump;
6973

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

‎contrib/pg_upgrade/exec.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include<fcntl.h>
1515
#include<unistd.h>
16-
16+
#include<sys/types.h>
1717

1818
staticvoidcheck_data_dir(constchar*pg_data);
1919
staticvoidcheck_bin_dir(ClusterInfo*cluster);
@@ -34,24 +34,37 @@ static int win32_check_directory_write_permissions(void);
3434
*instead of returning should an error occur.
3535
*/
3636
int
37-
exec_prog(boolthrow_error,constchar*fmt,...)
37+
exec_prog(boolthrow_error,boolis_priv,
38+
constchar*log_file,constchar*fmt,...)
3839
{
3940
va_listargs;
4041
intresult;
4142
charcmd[MAXPGPATH];
43+
mode_told_umask;
44+
45+
if (is_priv)
46+
old_umask=umask(S_IRWXG |S_IRWXO);
4247

4348
va_start(args,fmt);
4449
vsnprintf(cmd,MAXPGPATH,fmt,args);
4550
va_end(args);
4651

47-
pg_log(PG_INFO,"%s\n",cmd);
52+
pg_log(PG_VERBOSE,"%s\n",cmd);
4853

4954
result=system(cmd);
5055

56+
if (is_priv)
57+
umask(old_umask);
58+
5159
if (result!=0)
5260
{
53-
pg_log(throw_error ?PG_FATAL :PG_INFO,
54-
"There were problems executing \"%s\"\n",cmd);
61+
report_status(PG_REPORT,"*failure*");
62+
fflush(stdout);
63+
pg_log(PG_VERBOSE,"There were problems executing \"%s\"\n",cmd);
64+
pg_log(throw_error ?PG_FATAL :PG_REPORT,
65+
"Consult the last few lines of \"%s\" for\n"
66+
"the probable cause of the failure.\n",
67+
log_file);
5568
return1;
5669
}
5770

‎contrib/pg_upgrade/file.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,19 @@ win32_pghardlink(const char *src, const char *dst)
316316
}
317317

318318
#endif
319+
320+
321+
/* fopen() file with no group/other permissions */
322+
FILE*
323+
fopen_priv(constchar*path,constchar*mode)
324+
{
325+
mode_told_umask=umask(S_IRWXG |S_IRWXO);
326+
FILE*fp;
327+
328+
fp=fopen(path,mode);
329+
umask(old_umask);
330+
331+
returnfp;
332+
}
333+
334+

‎contrib/pg_upgrade/function.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ check_loadable_libraries(void)
218218

219219
prep_status("Checking for presence of required libraries");
220220

221-
snprintf(output_path,sizeof(output_path),"%s/loadable_libraries.txt",
222-
os_info.cwd);
221+
snprintf(output_path,sizeof(output_path),"loadable_libraries.txt");
223222

224223
for (libnum=0;libnum<os_info.num_libraries;libnum++)
225224
{
@@ -257,7 +256,7 @@ check_loadable_libraries(void)
257256
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
258257
{
259258
found= true;
260-
if (script==NULL&& (script=fopen(output_path,"w"))==NULL)
259+
if (script==NULL&& (script=fopen_priv(output_path,"w"))==NULL)
261260
pg_log(PG_FATAL,"Could not open file \"%s\": %s\n",
262261
output_path,getErrorText(errno));
263262
fprintf(script,"Could not load library \"%s\"\n%s\n",

‎contrib/pg_upgrade/info.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ create_rel_filename_map(const char *old_data, const char *new_data,
132132
void
133133
print_maps(FileNameMap*maps,intn_maps,constchar*db_name)
134134
{
135-
if (log_opts.debug)
135+
if (log_opts.verbose)
136136
{
137137
intmapnum;
138138

139-
pg_log(PG_DEBUG,"mappings for database \"%s\":\n",db_name);
139+
pg_log(PG_VERBOSE,"mappings for database \"%s\":\n",db_name);
140140

141141
for (mapnum=0;mapnum<n_maps;mapnum++)
142-
pg_log(PG_DEBUG,"%s.%s: %u to %u\n",
142+
pg_log(PG_VERBOSE,"%s.%s: %u to %u\n",
143143
maps[mapnum].nspname,maps[mapnum].relname,
144144
maps[mapnum].old_relfilenode,
145145
maps[mapnum].new_relfilenode);
146146

147-
pg_log(PG_DEBUG,"\n\n");
147+
pg_log(PG_VERBOSE,"\n\n");
148148
}
149149
}
150150

@@ -168,11 +168,9 @@ get_db_and_rel_infos(ClusterInfo *cluster)
168168
for (dbnum=0;dbnum<cluster->dbarr.ndbs;dbnum++)
169169
get_rel_infos(cluster,&cluster->dbarr.dbs[dbnum]);
170170

171-
if (log_opts.debug)
172-
{
173-
pg_log(PG_DEBUG,"\n%s databases:\n",CLUSTER_NAME(cluster));
171+
pg_log(PG_VERBOSE,"\n%s databases:\n",CLUSTER_NAME(cluster));
172+
if (log_opts.verbose)
174173
print_db_infos(&cluster->dbarr);
175-
}
176174
}
177175

178176

@@ -368,9 +366,9 @@ print_db_infos(DbInfoArr *db_arr)
368366

369367
for (dbnum=0;dbnum<db_arr->ndbs;dbnum++)
370368
{
371-
pg_log(PG_DEBUG,"Database: %s\n",db_arr->dbs[dbnum].db_name);
369+
pg_log(PG_VERBOSE,"Database: %s\n",db_arr->dbs[dbnum].db_name);
372370
print_rel_infos(&db_arr->dbs[dbnum].rel_arr);
373-
pg_log(PG_DEBUG,"\n\n");
371+
pg_log(PG_VERBOSE,"\n\n");
374372
}
375373
}
376374

@@ -381,7 +379,7 @@ print_rel_infos(RelInfoArr *arr)
381379
intrelnum;
382380

383381
for (relnum=0;relnum<arr->nrels;relnum++)
384-
pg_log(PG_DEBUG,"relname: %s.%s: reloid: %u reltblspace: %s\n",
382+
pg_log(PG_VERBOSE,"relname: %s.%s: reloid: %u reltblspace: %s\n",
385383
arr->rels[relnum].nspname,arr->rels[relnum].relname,
386384
arr->rels[relnum].reloid,arr->rels[relnum].tablespace);
387385
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp