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

Commit27b02e0

Browse files
committed
pg_upgrade: Don't print progress status when output is not a tty.
Until this change pg_upgrade with output redirected to a file / pipe would endup printing all files in the cluster. This has made check-world outputexceedingly verbose.Author: Andres Freund <andres@anarazel.de>Reviewed-By: Justin Pryzby <pryzby@telsasoft.com>Reviewed-By: Daniel Gustafsson <daniel@yesql.se>Discussion:https://postgr.es/m/CA+hUKGKjrV61ZVJ8OSag+3rKRmCZXPc03bDyWMqhXg3rdZ=fOw@mail.gmail.com
1 parent3f64966 commit27b02e0

File tree

6 files changed

+59
-16
lines changed

6 files changed

+59
-16
lines changed

‎src/bin/pg_upgrade/dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ generate_old_dump(void)
2929
GLOBALS_DUMP_FILE);
3030
check_ok();
3131

32-
prep_status("Creating dump of database schemas\n");
32+
prep_status_progress("Creating dump of database schemas");
3333

3434
/* create per-db dump files */
3535
for (dbnum=0;dbnum<old_cluster.dbarr.ndbs;dbnum++)

‎src/bin/pg_upgrade/option.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ parseCommandLine(int argc, char *argv[])
207207
if (log_opts.verbose)
208208
pg_log(PG_REPORT,"Running in verbose mode\n");
209209

210+
log_opts.isatty=isatty(fileno(stdout));
211+
210212
/* Turn off read-only mode; add prefix to PGOPTIONS? */
211213
if (getenv("PGOPTIONS"))
212214
{

‎src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ create_new_objects(void)
381381
{
382382
intdbnum;
383383

384-
prep_status("Restoring database schemas in the new cluster\n");
384+
prep_status_progress("Restoring database schemas in the new cluster");
385385

386386
/*
387387
* We cannot process the template1 database concurrently with others,

‎src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ typedef struct
274274
char*basedir;/* Base output directory */
275275
char*dumpdir;/* Dumps */
276276
char*logdir;/* Log files */
277+
boolisatty;/* is stdout a tty */
277278
}LogOpts;
278279

279280

@@ -427,6 +428,7 @@ voidpg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3);
427428
voidpg_fatal(constchar*fmt,...)pg_attribute_printf(1,2)pg_attribute_noreturn();
428429
voidend_progress_output(void);
429430
voidprep_status(constchar*fmt,...)pg_attribute_printf(1,2);
431+
voidprep_status_progress(constchar*fmt,...)pg_attribute_printf(1,2);
430432
voidcheck_ok(void);
431433
unsignedintstr2uint(constchar*str);
432434

‎src/bin/pg_upgrade/relfilenode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
3232
switch (user_opts.transfer_mode)
3333
{
3434
caseTRANSFER_MODE_CLONE:
35-
pg_log(PG_REPORT,"Cloning user relation files\n");
35+
prep_status_progress("Cloning user relation files");
3636
break;
3737
caseTRANSFER_MODE_COPY:
38-
pg_log(PG_REPORT,"Copying user relation files\n");
38+
prep_status_progress("Copying user relation files");
3939
break;
4040
caseTRANSFER_MODE_LINK:
41-
pg_log(PG_REPORT,"Linking user relation files\n");
41+
prep_status_progress("Linking user relation files");
4242
break;
4343
}
4444

‎src/bin/pg_upgrade/util.c

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ report_status(eLogType type, const char *fmt,...)
3838
}
3939

4040

41-
/* force blank output for progress display */
4241
void
4342
end_progress_output(void)
4443
{
4544
/*
46-
* In case nothing printed; pass a space so gcc doesn't complain about
47-
* empty format string.
45+
* For output to a tty, erase prior contents of progress line. When either
46+
* tty or verbose, indent so that report_status() output will align
47+
* nicely.
4848
*/
49-
prep_status(" ");
49+
if (log_opts.isatty)
50+
pg_log(PG_REPORT,"\r%-*s",MESSAGE_WIDTH,"");
51+
elseif (log_opts.verbose)
52+
pg_log(PG_REPORT,"%-*s",MESSAGE_WIDTH,"");
5053
}
5154

5255

@@ -75,14 +78,43 @@ prep_status(const char *fmt,...)
7578
vsnprintf(message,sizeof(message),fmt,args);
7679
va_end(args);
7780

78-
if (strlen(message)>0&&message[strlen(message)-1]=='\n')
79-
pg_log(PG_REPORT,"%s",message);
81+
/* trim strings */
82+
pg_log(PG_REPORT,"%-*s",MESSAGE_WIDTH,message);
83+
}
84+
85+
/*
86+
* prep_status_progress
87+
*
88+
* Like prep_status(), but for potentially longer running operations.
89+
* Details about what item is currently being processed can be displayed
90+
* with pg_log(PG_STATUS, ...). A typical sequence would look like this:
91+
*
92+
* prep_status_progress("copying files");
93+
* for (...)
94+
* pg_log(PG_STATUS, "%s", filename);
95+
* end_progress_output();
96+
* report_status(PG_REPORT, "ok");
97+
*/
98+
void
99+
prep_status_progress(constchar*fmt,...)
100+
{
101+
va_listargs;
102+
charmessage[MAX_STRING];
103+
104+
va_start(args,fmt);
105+
vsnprintf(message,sizeof(message),fmt,args);
106+
va_end(args);
107+
108+
/*
109+
* If outputting to a tty or in verbose, append newline. pg_log_v() will
110+
* put the individual progress items onto the next line.
111+
*/
112+
if (log_opts.isatty||log_opts.verbose)
113+
pg_log(PG_REPORT,"%-*s\n",MESSAGE_WIDTH,message);
80114
else
81-
/* trim strings that don't end in a newline */
82115
pg_log(PG_REPORT,"%-*s",MESSAGE_WIDTH,message);
83116
}
84117

85-
86118
staticvoid
87119
pg_log_v(eLogTypetype,constchar*fmt,va_listap)
88120
{
@@ -111,8 +143,15 @@ pg_log_v(eLogType type, const char *fmt, va_list ap)
111143
break;
112144

113145
casePG_STATUS:
114-
/* for output to a display, do leading truncation and append \r */
115-
if (isatty(fileno(stdout)))
146+
/*
147+
* For output to a display, do leading truncation. Append \r so
148+
* that the next message is output at the start of the line.
149+
*
150+
* If going to non-interactive output, only display progress if
151+
* verbose is enabled. Otherwise the output gets unreasonably
152+
* large by default.
153+
*/
154+
if (log_opts.isatty)
116155
/* -2 because we use a 2-space indent */
117156
printf(" %s%-*.*s\r",
118157
/* prefix with "..." if we do leading truncation */
@@ -121,7 +160,7 @@ pg_log_v(eLogType type, const char *fmt, va_list ap)
121160
/* optional leading truncation */
122161
strlen(message) <=MESSAGE_WIDTH-2 ?message :
123162
message+strlen(message)-MESSAGE_WIDTH+3+2);
124-
else
163+
elseif (log_opts.verbose)
125164
printf(" %s\n",message);
126165
break;
127166

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp