mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Extend the abilities of libpq's target_session_attrs parameter.
In addition to the existing options of "any" and "read-write", we now support "read-only", "primary", "standby", and "prefer-standby". "read-write" retains its previous meaning of "transactions are read-write by default", and "read-only" inverts that. The other three modes test specifically for hot-standby status, which is not quite the same thing. (Setting default_transaction_read_only on a primary server renders it read-only to this logic, but not a standby.) Furthermore, if talking to a v14 or later server, no extra network round trip is needed to detect the session's status; the GUC_REPORT variables delivered by the server are enough. When talking to an older server, a SHOW or SELECT query is issued to detect session read-only-ness or server hot-standby state, as needed. Haribabu Kommi, Greg Nancarrow, Vignesh C, Tom Lane; reviewed at various times by Laurenz Albe, Takayuki Tsunakawa, Peter Smith. Discussion: https://postgr.es/m/CAF3+xM+8-ztOkaV9gHiJ3wfgENTq97QcjXQt+rbFQ6F7oNzt9A@mail.gmail.com
This commit is contained in:
@ -1877,18 +1877,75 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
|
||||
<term><literal>target_session_attrs</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
If this parameter is set to <literal>read-write</literal>, only a
|
||||
connection in which read-write transactions are accepted by default
|
||||
is considered acceptable. The query
|
||||
<literal>SHOW transaction_read_only</literal> will be sent upon any
|
||||
successful connection; if it returns <literal>on</literal>, the connection
|
||||
will be closed. If multiple hosts were specified in the connection
|
||||
string, any remaining servers will be tried just as if the connection
|
||||
attempt had failed. The default value of this parameter,
|
||||
<literal>any</literal>, regards all connections as acceptable.
|
||||
</para>
|
||||
This option determines whether the session must have certain
|
||||
properties to be acceptable. It's typically used in combination
|
||||
with multiple host names to select the first acceptable alternative
|
||||
among several hosts. There are six modes:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><literal>any</literal> (default)</term>
|
||||
<listitem>
|
||||
<para>
|
||||
any successful connection is acceptable
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>read-write</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
session must accept read-write transactions by default (that
|
||||
is, the server must not be in hot standby mode and
|
||||
the <varname>default_transaction_read_only</varname> parameter
|
||||
must be <literal>off</literal>)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>read-only</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
session must not accept read-write transactions by default (the
|
||||
converse)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>primary</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
server must not be in hot standby mode
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>standby</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
server must be in hot standby mode
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>prefer-standby</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
first try to find a standby server, but if none of the listed
|
||||
hosts is a standby server, try again in <literal>all</literal>
|
||||
mode
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</sect2>
|
||||
|
Reference in New Issue
Block a user