1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Adjust behavior of single-user -j mode for better initdb error reporting.

Previously, -j caused the entire input file to be read in and executed as
a single command string.  That's undesirable, not least because any error
causes the entire file to be regurgitated as the "failing query".  Some
experimentation suggests a better rule: end the command string when we see
a semicolon immediately followed by two newlines, ie, an empty line after
a query.  This serves nicely to break up the existing examples such as
information_schema.sql and system_views.sql.  A limitation is that it's
no longer possible to write such a sequence within a string literal or
multiline comment in a file meant to be read with -j; but there are no
instances of such a problem within the data currently used by initdb.
(If someone does make such a mistake in future, it'll be obvious because
they'll get an unterminated-literal or unterminated-comment syntax error.)
Other than that, there shouldn't be any negative consequences; you're not
forced to end statements that way, it's just a better idea in most cases.

In passing, remove src/include/tcop/tcopdebug.h, which is dead code
because it's not included anywhere, and hasn't been for more than
ten years.  One of the debug-support symbols it purported to describe
has been unreferenced for at least the same amount of time, and the
other is removed by this commit on the grounds that it was useless:
forcing -j mode all the time would have broken initdb.  The lack of
complaints about that, or about the missing inclusion, shows that
no one has tried to use TCOP_DONTUSENEWLINE in many years.
This commit is contained in:
Tom Lane
2015-12-17 19:34:15 -05:00
parent aee7705be5
commit 66d947b9d3
7 changed files with 116 additions and 109 deletions

View File

@ -529,7 +529,9 @@ PostgreSQL documentation
</indexterm>
<para>
The following options only apply to the single-user mode.
The following options only apply to the single-user mode
(see <xref linkend="app-postgres-single-user"
endterm="app-postgres-single-user-title">).
</para>
<variablelist>
@ -558,7 +560,7 @@ PostgreSQL documentation
<term><option>-E</option></term>
<listitem>
<para>
Echo all commands.
Echo all commands to standard output before executing them.
</para>
</listitem>
</varlistentry>
@ -567,7 +569,8 @@ PostgreSQL documentation
<term><option>-j</option></term>
<listitem>
<para>
Disables use of newline as a statement delimiter.
Use semicolon followed by two newlines, rather than just newline,
as the command entry terminator.
</para>
</listitem>
</varlistentry>
@ -760,8 +763,8 @@ PostgreSQL documentation
</para>
</refsect1>
<refsect1>
<title>Usage</title>
<refsect1 id="app-postgres-single-user">
<title id="app-postgres-single-user-title">Single-User Mode</title>
<para>
To start a single-user mode server, use a command like
@ -778,30 +781,40 @@ PostgreSQL documentation
entry terminator; there is no intelligence about semicolons,
as there is in <application>psql</>. To continue a command
across multiple lines, you must type backslash just before each
newline except the last one.
newline except the last one. The backslash and adjacent newline are
both dropped from the input command. Note that this will happen even
when within a string literal or comment.
</para>
<para>
But if you use the <option>-j</> command line switch, then newline does
not terminate command entry. In this case, the server will read the standard input
until the end-of-file (<acronym>EOF</>) marker, then
process the input as a single command string. Backslash-newline is not
treated specially in this case.
But if you use the <option>-j</> command line switch, a single newline
does not terminate command entry; instead, the sequence
semicolon-newline-newline does. That is, type a semicolon immediately
followed by a completely empty line. Backslash-newline is not
treated specially in this mode. Again, there is no intelligence about
such a sequence appearing within a string literal or comment.
</para>
<para>
In either input mode, if you type a semicolon that is not just before or
part of a command entry terminator, it is considered a command separator.
When you do type a command entry terminator, the multiple statements
you've entered will be executed as a single transaction.
</para>
<para>
To quit the session, type <acronym>EOF</acronym>
(<keycombo action="simul"><keycap>Control</><keycap>D</></>, usually).
If you've
used <option>-j</>, two consecutive <acronym>EOF</>s are needed to exit.
If you've entered any text since the last command entry terminator,
then <acronym>EOF</acronym> will be taken as a command entry terminator,
and another <acronym>EOF</> will be needed to exit.
</para>
<para>
Note that the single-user mode server does not provide sophisticated
line-editing features (no command history, for example).
Single-User mode also does not do any background processing, like
automatic checkpoints.
Single-user mode also does not do any background processing, such as
automatic checkpoints or replication.
</para>
</refsect1>