Skip to content

Commit d7b5762

Browse files
authored
Add an option in psql to avoid encoding issues on some platforms (#535)
When running ICW tests, the following command has a strange behavior. shell psql ... <<EOF $(cat prehook inputfile) EOF The command has an issue on some platforms that will input unexpected data stream to psql. For example, The following first line will become to the second line: "колонка 6" int, "колонка 7" int, "колонка 8" int, "колонка 9" int, "колонка 10" int, "колонка 11" int, "колонка 6" int, "колонка 7" int, "колонка 8" int, "колонка 9" int, "колонЀ�а 10" int, "колонка 11" int, It's unknown why the input stream is changed. The other similar commands will have correct data stream to psql, like cat prehook inputfile | psql ... or for a single input file psql ... < inputfile In this commit, we convert the original command to shell psql ... -f prehook -f inputfile --ignore-log-file The new option --ignore-log-file will ignore the logging prefix for psql and filename, so the program psql will log like no input filename is provided.
1 parent ed64982 commit d7b5762

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ process_file(char *filename, bool use_relative_path)
40514051
}
40524052

40534053
oldfilename = pset.inputfile;
4054-
pset.inputfile = filename;
4054+
pset.inputfile = ignore_log_file ? NULL : filename;
40554055

40564056
pg_logging_config(pset.inputfile ? 0 : PG_LOG_FLAG_TERSE);
40574057

src/bin/psql/help.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ usage(unsigned short int pager)
100100
fprintf(output, _(" -e, --echo-queries echo commands sent to server\n"));
101101
fprintf(output, _(" -E, --echo-hidden display queries that internal commands generate\n"));
102102
fprintf(output, _(" -L, --log-file=FILENAME send session log to file\n"));
103+
fprintf(output, _(" --ignore-log-file do not log psql:filename prefix in log file\n"));
103104
fprintf(output, _(" -n, --no-readline disable enhanced command line editing (readline)\n"));
104105
fprintf(output, _(" -o, --output=FILENAME send query results to file (or |pipe)\n"));
105106
fprintf(output, _(" -q, --quiet run quietly (no messages, only query output)\n"));

src/bin/psql/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef struct _psqlSettings
152152
} PsqlSettings;
153153

154154
extern PsqlSettings pset;
155-
155+
extern bool ignore_log_file;
156156

157157
#ifndef EXIT_SUCCESS
158158
#define EXIT_SUCCESS 0

src/bin/psql/startup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static void process_psqlrc(char *argv0);
8585
static void process_psqlrc_file(char *filename);
8686
static void showVersion(void);
8787
static void EstablishVariableSpace(void);
88+
/* ignore psql:filename in log output */
89+
bool ignore_log_file = false;
8890

8991
#define NOPAGER 0
9092

@@ -498,6 +500,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
498500
{"no-psqlrc", no_argument, NULL, 'X'},
499501
{"help", optional_argument, NULL, 1},
500502
{"csv", no_argument, NULL, 2},
503+
{"ignore-log-file", no_argument, NULL, 256},
501504
{NULL, 0, NULL, 0}
502505
};
503506

@@ -694,6 +697,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
694697
case 2:
695698
pset.popt.topt.format = PRINT_CSV;
696699
break;
700+
case 256:
701+
ignore_log_file = true;
702+
break;
697703
default:
698704
unknown_option:
699705
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),

src/test/regress/pg_regress_main.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,21 @@ psql_start_test(const char *testname,
129129
* psql <<EOF
130130
* $(cat prehook infile)
131131
* EOF
132+
*
133+
* CBDB:
134+
* However the above command will have strange behavior on some platforms,
135+
* like UOS1050a, UOS1060e. The input stream is unexpectedly changed
136+
* for psql. It looks like a system-level problem that we have nothing
137+
* to do. We change the above command to
138+
*
139+
* psql -f prehook -f infile --ignore-log-file
140+
*
141+
* --ignore-log-file will suppress additional logging prefix that has
142+
* the same effect like no filename is provided.
132143
*/
133144
offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
134-
"%s \"%s%spsql\" -X -a -q -d \"%s\" %s > \"%s\" 2>&1 <<EOF\n"
135-
"$(cat \"%s\" \"%s\")\n"
136-
"EOF",
145+
"%s \"%s%spsql\" -X -a -q -d \"%s\" %s > \"%s\" 2>&1 "
146+
"-f \"%s\" -f \"%s\" --ignore-log-file\n",
137147
use_utility_mode ? "env PGOPTIONS='-c gp_role=utility'" : "",
138148
bindir ? bindir : "",
139149
bindir ? "/" : "",

0 commit comments

Comments
 (0)