Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
1bee1a37
Commit
1bee1a37
authored
Feb 18, 2010
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wordsmithing of HS and SR documentation, with some wording improvements
from Erik Rijkers too.
parent
7981c342
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
252 additions
and
235 deletions
+252
-235
doc/src/sgml/high-availability.sgml
doc/src/sgml/high-availability.sgml
+252
-235
No files found.
doc/src/sgml/high-availability.sgml
View file @
1bee1a37
<!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.4
4 2010/02/17 04:19:37 tgl
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.4
5 2010/02/18 03:16:09 momjian
Exp $ -->
<chapter id="high-availability">
<chapter id="high-availability">
<title>High Availability, Load Balancing, and Replication</title>
<title>High Availability, Load Balancing, and Replication</title>
...
@@ -497,7 +497,7 @@ protocol to make nodes agree on a serializable transactional order.
...
@@ -497,7 +497,7 @@ protocol to make nodes agree on a serializable transactional order.
continuous recovery mode, reading the WAL files from the primary. No
continuous recovery mode, reading the WAL files from the primary. No
changes to the database tables are required to enable this capability,
changes to the database tables are required to enable this capability,
so it offers low administration overhead compared to some other
so it offers low administration overhead compared to some other
replication
approache
s. This configuration also has relatively low
replication
solution
s. This configuration also has relatively low
performance impact on the primary server.
performance impact on the primary server.
</para>
</para>
...
@@ -516,14 +516,14 @@ protocol to make nodes agree on a serializable transactional order.
...
@@ -516,14 +516,14 @@ protocol to make nodes agree on a serializable transactional order.
<para>
<para>
It should be noted that the log shipping is asynchronous, i.e., the WAL
It should be noted that the log shipping is asynchronous, i.e., the WAL
records are shipped after transaction commit. As a result there is a
records are shipped after transaction commit. As a result
,
there is a
window for data loss should the primary server suffer a catastrophic
window for data loss should the primary server suffer a catastrophic
failure
: transactions not yet shipped will be lost. The length
of the
failure
; transactions not yet shipped will be lost. The size
of the
window of data loss
can be limited by use of the
data loss window
can be limited by use of the
<varname>archive_timeout</varname> parameter, which can be set as low
<varname>archive_timeout</varname> parameter, which can be set as low
as a few seconds
if required
. However such a low setting will
as a few seconds. However such a low setting will
substantially increase the bandwidth required for file shipping.
substantially increase the bandwidth required for file shipping.
If you need a window of less than a minute or so, it
'
s probably better
If you need a window of less than a minute or so, it
i
s probably better
to consider record-based log shipping.
to consider record-based log shipping.
</para>
</para>
...
@@ -531,8 +531,8 @@ protocol to make nodes agree on a serializable transactional order.
...
@@ -531,8 +531,8 @@ protocol to make nodes agree on a serializable transactional order.
The standby server is not available for access, since it is continually
The standby server is not available for access, since it is continually
performing recovery processing. Recovery performance is sufficiently
performing recovery processing. Recovery performance is sufficiently
good that the standby will typically be only moments away from full
good that the standby will typically be only moments away from full
availability once it has been activated. As a result,
we refer to this
availability once it has been activated. As a result,
this is called
capability as a warm standby configuration that
offers high
a warm standby configuration which
offers high
availability. Restoring a server from an archived base backup and
availability. Restoring a server from an archived base backup and
rollforward will take considerably longer, so that technique only
rollforward will take considerably longer, so that technique only
offers a solution for disaster recovery, not high availability.
offers a solution for disaster recovery, not high availability.
...
@@ -592,7 +592,7 @@ protocol to make nodes agree on a serializable transactional order.
...
@@ -592,7 +592,7 @@ protocol to make nodes agree on a serializable transactional order.
<filename>recovery.conf</> file on the standby server. Normal recovery
<filename>recovery.conf</> file on the standby server. Normal recovery
processing would request a file from the WAL archive, reporting failure
processing would request a file from the WAL archive, reporting failure
if the file was unavailable. For standby processing it is normal for
if the file was unavailable. For standby processing it is normal for
the next WAL file to be unavailable, so
we must be patient and
wait for
the next WAL file to be unavailable, so
the standby must
wait for
it to appear. For files ending in <literal>.backup</> or
it to appear. For files ending in <literal>.backup</> or
<literal>.history</> there is no need to wait, and a non-zero return
<literal>.history</> there is no need to wait, and a non-zero return
code must be returned. A waiting <varname>restore_command</> can be
code must be returned. A waiting <varname>restore_command</> can be
...
@@ -639,8 +639,8 @@ if (!triggered)
...
@@ -639,8 +639,8 @@ if (!triggered)
and design. One potential option is the <varname>restore_command</>
and design. One potential option is the <varname>restore_command</>
command. It is executed once for each WAL file, but the process
command. It is executed once for each WAL file, but the process
running the <varname>restore_command</> is created and dies for
running the <varname>restore_command</> is created and dies for
each file, so there is no daemon or server process, and
we cannot
each file, so there is no daemon or server process, and
use signals or a signal handler
. Therefore, the
signals or a signal handler cannot be used
. Therefore, the
<varname>restore_command</> is not suitable to trigger failover.
<varname>restore_command</> is not suitable to trigger failover.
It is possible to use a simple timeout facility, especially if
It is possible to use a simple timeout facility, especially if
used in conjunction with a known <varname>archive_timeout</>
used in conjunction with a known <varname>archive_timeout</>
...
@@ -749,7 +749,7 @@ if (!triggered)
...
@@ -749,7 +749,7 @@ if (!triggered)
<para>
<para>
Starting with <productname>PostgreSQL</> version 9.0, you can use
Starting with <productname>PostgreSQL</> version 9.0, you can use
streaming replication (see <xref linkend="streaming-replication">) to
streaming replication (see <xref linkend="streaming-replication">) to
achieve the same with less effort.
achieve the same
benefits
with less effort.
</para>
</para>
</sect2>
</sect2>
</sect1>
</sect1>
...
@@ -763,17 +763,18 @@ if (!triggered)
...
@@ -763,17 +763,18 @@ if (!triggered)
<para>
<para>
<productname>PostgreSQL</> includes a simple streaming replication
<productname>PostgreSQL</> includes a simple streaming replication
mechanism, which
let
s the standby server to stay more up-to-date than
mechanism, which
allow
s the standby server to stay more up-to-date than
file-based log shipping
allows
. The standby connects to the primary
file-based log shipping. The standby connects to the primary
and the primary starts streaming WAL records from where the standby
and the primary starts streaming WAL records from where the standby
left off, and continues streaming them as they are generated, without
left off, and continues streaming them as they are generated, without
waiting for the WAL file to be filled. So with streaming replication,
waiting for the WAL file to be filled. So with streaming replication,
<varname>archive_timeout</> does not need to be configured.
<varname>archive_timeout</> does not need to be changed to reduce
possible data loss.
</para>
</para>
<para>
<para>
Streaming replication relies on file-based continuous archiving for
Streaming replication relies on file-based continuous archiving for
making the base backup and for allowing a standby to catch up if it
'
s
making the base backup and for allowing a standby to catch up if it
i
s
disconnected from the primary for long enough for the primary to
disconnected from the primary for long enough for the primary to
delete old WAL files still required by the standby.
delete old WAL files still required by the standby.
</para>
</para>
...
@@ -783,6 +784,7 @@ if (!triggered)
...
@@ -783,6 +784,7 @@ if (!triggered)
<para>
<para>
The short procedure for configuring streaming replication is as follows.
The short procedure for configuring streaming replication is as follows.
For full details of each step, refer to other sections as noted.
For full details of each step, refer to other sections as noted.
<orderedlist>
<orderedlist>
<listitem>
<listitem>
<para>
<para>
...
@@ -806,16 +808,16 @@ if (!triggered)
...
@@ -806,16 +808,16 @@ if (!triggered)
<listitem>
<listitem>
<para>
<para>
Set <xref linkend="guc-listen-addresses"> and authentication options
Set <xref linkend="guc-listen-addresses"> and authentication options
(see <filename>pg_hba.conf</>) so th
at th
e standby server can connect to
(see <filename>pg_hba.conf</>) so the standby server can connect to
the
pseudo <literal>replication</> database of
the primary server (see
the
<literal>replication</> pseudo-database on
the primary server (see
<xref linkend="streaming-replication-authentication">).
<xref linkend="streaming-replication-authentication">).
</para>
</para>
<para>
<para>
On systems that support the keepalive socket option, setting
On systems that support the keepalive socket option, setting
<xref linkend="guc-tcp-keepalives-idle">,
<xref linkend="guc-tcp-keepalives-idle">,
<xref linkend="guc-tcp-keepalives-interval"> and
<xref linkend="guc-tcp-keepalives-interval"> and
<xref linkend="guc-tcp-keepalives-count"> helps the master
to notice
<xref linkend="guc-tcp-keepalives-count"> helps the master
promptly
a broken connection promptly
.
notice a broken connection
.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
...
@@ -843,7 +845,7 @@ if (!triggered)
...
@@ -843,7 +845,7 @@ if (!triggered)
If you're setting up the standby server for high availability purposes,
If you're setting up the standby server for high availability purposes,
set up WAL archiving, connections and authentication like the primary
set up WAL archiving, connections and authentication like the primary
server, because the standby server will work as a primary server after
server, because the standby server will work as a primary server after
failover. If you're setting up the standby server for
e.g
reporting
failover. If you're setting up the standby server for reporting
purposes, with no plans to fail over to it, configure the standby
purposes, with no plans to fail over to it, configure the standby
accordingly.
accordingly.
</para>
</para>
...
@@ -863,7 +865,7 @@ if (!triggered)
...
@@ -863,7 +865,7 @@ if (!triggered)
a standby. If this parameter is <literal>on</>, the server will
a standby. If this parameter is <literal>on</>, the server will
not end recovery when the end of archived WAL is reached, but
not end recovery when the end of archived WAL is reached, but
will keep trying to continue recovery using <varname>restore_command</>
will keep trying to continue recovery using <varname>restore_command</>
and by connecting to the primary server as specified by
and by connecting to the primary server as specified by
the
<varname>primary_conninfo</> setting.
<varname>primary_conninfo</> setting.
</para>
</para>
</listitem>
</listitem>
...
@@ -873,9 +875,10 @@ if (!triggered)
...
@@ -873,9 +875,10 @@ if (!triggered)
<term><varname>restore_end_command</varname> (<type>string</type>)</term>
<term><varname>restore_end_command</varname> (<type>string</type>)</term>
<listitem>
<listitem>
<para>
<para>
In standby-mode, <varname>restore_command</> (and <varname>restore_end_command</>) is set to a
With <varname>standby_mode</> enabled, <varname>restore_command</>
simple command or script like in PITR. pg_standby or similar tools
(and <varname>restore_end_command</>) should be set to a
that wait for the next WAL file to arrive, cannot be used with
simple command or script like in PITR. <literal>pg_standby</> or similar tools
that wait for the next WAL file to arrive cannot be used with
streaming replication, as the server handles retries and waiting
streaming replication, as the server handles retries and waiting
itself. Set <varname>restore_command</> as you would if you were
itself. Set <varname>restore_command</> as you would if you were
recovering using a Continuous archiving backup (see <xref linkend="backup-pitr-recovery">).
recovering using a Continuous archiving backup (see <xref linkend="backup-pitr-recovery">).
...
@@ -886,18 +889,18 @@ if (!triggered)
...
@@ -886,18 +889,18 @@ if (!triggered)
<term><varname>primary_conninfo</varname> (<type>string</type>)</term>
<term><varname>primary_conninfo</varname> (<type>string</type>)</term>
<listitem>
<listitem>
<para>
<para>
Specifies a connection string
which is
used for the standby server
Specifies a connection string
to be
used for the standby server
to connect with the primary. This string is in the same format as
to connect with the primary. This string is in the same format as
described in <xref linkend="libpq-connect">. If any option is
described in <xref linkend="libpq-connect">. If any option is
unspecified in this string, then the corresponding environment
unspecified in this string, then the corresponding environment
variable (see <xref linkend="libpq-envars">) is checked. If the
variable (see <xref linkend="libpq-envars">) is checked. If the
environment variable is not set either, then
the indicated built-in
environment variable is not set either, then
defaults are used.
defaults are used.
</para>
</para>
<para>
<para>
The built-in replication requires that a host name (or host address)
The built-in replication requires that a host name (or host address)
or port number which the primary server listens on
should
be
or port number which the primary server listens on be
specified in this string
, respectively
. Also ensure that a role with
specified in this string. Also ensure that a role with
the <literal>SUPERUSER</> and <literal>LOGIN</> privileges on the
the <literal>SUPERUSER</> and <literal>LOGIN</> privileges on the
primary is set (see
primary is set (see
<xref linkend="streaming-replication-authentication">). Note that
<xref linkend="streaming-replication-authentication">). Note that
...
@@ -916,8 +919,6 @@ if (!triggered)
...
@@ -916,8 +919,6 @@ if (!triggered)
Specifies a trigger file whose presence ends recovery in the
Specifies a trigger file whose presence ends recovery in the
standby. If no trigger file is specified, the standby never exits
standby. If no trigger file is specified, the standby never exits
recovery.
recovery.
</para>
<para>
This setting has no effect if <varname>standby_mode</> is <literal>off</>.
This setting has no effect if <varname>standby_mode</> is <literal>off</>.
</para>
</para>
</listitem>
</listitem>
...
@@ -927,22 +928,23 @@ if (!triggered)
...
@@ -927,22 +928,23 @@ if (!triggered)
<listitem>
<listitem>
<para>
<para>
Start the <productname>PostgreSQL</> server on the standby. The standby
Start the <productname>PostgreSQL</> server on the standby. The standby
server will go into recovery mode and proceed
s
to receive WAL records
server will go into recovery mode and proceed to receive WAL records
from the primary and apply them continuously.
from the primary and apply them continuously.
</para>
</para>
</listitem>
</listitem>
</orderedlist>
</orderedlist>
</para>
</para>
</sect2>
</sect2>
<sect2 id="streaming-replication-authentication">
<sect2 id="streaming-replication-authentication">
<title>Authentication</title>
<title>Authentication</title>
<para>
<para>
It
's very important that the access privilege for replication are set
It
is very important that the access privilege for replication be setup
properly so that only trusted users can read the WAL stream, because it
'
s
properly so that only trusted users can read the WAL stream, because it
i
s
easy to extract
serious
information from it.
easy to extract
privileged
information from it.
</para>
</para>
<para>
<para>
Only superuser is allowed to connect to the primary as the replication
Only
the
superuser is allowed to connect to the primary as the replication
standby. So a role with the <literal>SUPERUSER</> and <literal>LOGIN</>
standby. So a role with the <literal>SUPERUSER</> and <literal>LOGIN</>
privileges needs to be created in the primary.
privileges needs to be created in the primary.
</para>
</para>
...
@@ -963,7 +965,7 @@ host replication foo 192.168.1.100/32 md5
...
@@ -963,7 +965,7 @@ host replication foo 192.168.1.100/32 md5
</programlisting>
</programlisting>
</para>
</para>
<para>
<para>
The host name and port number of the primary,
user name to connect as
,
The host name and port number of the primary,
connection user name
,
and password are specified in the <filename>recovery.conf</> file or
and password are specified in the <filename>recovery.conf</> file or
the corresponding environment variable on the standby.
the corresponding environment variable on the standby.
For example, if the primary is running on host IP <literal>192.168.1.50</>,
For example, if the primary is running on host IP <literal>192.168.1.50</>,
...
@@ -992,7 +994,7 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -992,7 +994,7 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
If the standby server fails then no failover need take place. If the
If the standby server fails then no failover need take place. If the
standby server can be restarted, even some time later, then the recovery
standby server can be restarted, even some time later, then the recovery
process can also be
immediately restarted
, taking advantage of
process can also be
restarted immediately
, taking advantage of
restartable recovery. If the standby server cannot be restarted, then a
restartable recovery. If the standby server cannot be restarted, then a
full new standby server instance should be created.
full new standby server instance should be created.
</para>
</para>
...
@@ -1000,8 +1002,8 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1000,8 +1002,8 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
If the primary server fails and the standby server becomes the
If the primary server fails and the standby server becomes the
new primary, and then the old primary restarts, you must have
new primary, and then the old primary restarts, you must have
a mechanism for informing old primary that it is no longer the primary. This is
a mechanism for informing
the
old primary that it is no longer the primary. This is
sometimes known as
STONITH
(Shoot The Other Node In The Head), which is
sometimes known as
<acronym>STONITH</>
(Shoot The Other Node In The Head), which is
necessary to avoid situations where both systems think they are the
necessary to avoid situations where both systems think they are the
primary, which will lead to confusion and ultimately data loss.
primary, which will lead to confusion and ultimately data loss.
</para>
</para>
...
@@ -1017,11 +1019,11 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1017,11 +1019,11 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</para>
</para>
<para>
<para>
Once failover to the standby occurs,
we have
only a
Once failover to the standby occurs,
there is
only a
single server in operation. This is known as a degenerate state.
single server in operation. This is known as a degenerate state.
The former standby is now the primary, but the former primary is down
The former standby is now the primary, but the former primary is down
and might stay down. To return to normal operation
we must
and might stay down. To return to normal operation
, a standby server
fully recreate a standby server
,
must be recreated
,
either on the former primary system when it comes up, or on a third,
either on the former primary system when it comes up, or on a third,
possibly new, system. Once complete the primary and standby can be
possibly new, system. Once complete the primary and standby can be
considered to have switched roles. Some people choose to use a third
considered to have switched roles. Some people choose to use a third
...
@@ -1059,31 +1061,31 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1059,31 +1061,31 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</para>
</para>
<para>
<para>
Running queries in recovery
is in many ways the same as normal running
Running queries in recovery
mode is similar to normal query operation,
though there are a
large number of usage and administrative point
s
though there are a
several usage and administrative difference
s
to note
.
noted below
.
</para>
</para>
<sect2 id="hot-standby-users">
<sect2 id="hot-standby-users">
<title>User's Overview</title>
<title>User's Overview</title>
<para>
<para>
Users can connect to the database
while the server
is in recovery
Users can connect to the database
server while it
is in recovery
and perform read-only queries. Read-only access to catalogs and views
mode and perform read-only queries. Read-only access to system
will also occur as normal.
catalogs and views
will also occur as normal.
</para>
</para>
<para>
<para>
The data on the standby takes some time to arrive from the primary server
The data on the standby takes some time to arrive from the primary server
so there will be a measurable delay between primary and standby. Running the
so there will be a measurable delay between primary and standby. Running the
same query nearly simultaneously on both primary and standby might therefore
same query nearly simultaneously on both primary and standby might therefore
return differing results.
We say that data on the standby is eventually
return differing results.
Eventually, the standby will be
consistent with the primary.
consistent with the primary.
Queries executed on the standby will be correct with regard to the transactions
Queries executed on the standby will be correct with regard to the transactions
that had been recovered at the start of the query, or start of first statement,
that had been recovered at the start of the query, or start of first statement,
in the case of serializable transactions. In comparison with the primary,
in the case of serializable transactions. In comparison with the primary,
the standby returns query results that could have been obtained on the primary
the standby returns query results that could have been obtained on the primary
at some
exact
moment in the past.
at some moment in the past.
</para>
</para>
<para>
<para>
...
@@ -1091,38 +1093,39 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1091,38 +1093,39 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<varname>transaction_read_only</> will be forced to be true, regardless of the
<varname>transaction_read_only</> will be forced to be true, regardless of the
<varname>default_transaction_read_only</> setting in <filename>postgresql.conf</>.
<varname>default_transaction_read_only</> setting in <filename>postgresql.conf</>.
It can't be manually set to false either. As a result, all transactions
It can't be manually set to false either. As a result, all transactions
started during recovery will be limited to read-only actions
only
. In all
started during recovery will be limited to read-only actions. In all
other ways, connected sessions will appear identical to sessions
other ways, connected sessions will appear identical to sessions
initiated during normal processing mode. There are no special commands
initiated during normal processing mode. There are no special commands
required to initiate a connection
at this time,
so all interfaces
required to initiate a connection so all interfaces
work
normally without change
. After recovery finishes, the session
work
unchanged
. After recovery finishes, the session
will allow normal read-write transactions at the start of the next
will allow normal read-write transactions at the start of the next
transaction, if these are requested.
transaction, if these are requested.
</para>
</para>
<para>
<para>
Read-only here means "no writes to the permanent database tables"
.
"Read-only" above means no writes to the permanent database tables
.
There are no problems with queries that
make use of
transient sort and
There are no problems with queries that
use
transient sort and
work files.
work files.
</para>
</para>
<para>
<para>
The following actions are allowed
The following actions are allowed
:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
Query access - SELECT, COPY TO including views and SELECT RULEs
Query access - <command>SELECT</>, <command>COPY TO</> including views and
<command>SELECT</> rules
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Cursor commands -
DECLARE, FETCH, CLOSE,
Cursor commands -
<command>DECLARE</>, <command>FETCH</>, <command>CLOSE</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Parameters -
SHOW, SET, RESET
Parameters -
<command>SHOW</>, <command>SET</>, <command>RESET</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
...
@@ -1131,17 +1134,17 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1131,17 +1134,17 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
BEGIN, END, ABORT, START TRANSACTION
<command>BEGIN</>, <command>END</>, <command>ABORT</>, <command>START TRANSACTION</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
SAVEPOINT, RELEASE, ROLLBACK TO SAVEPOINT
<command>SAVEPOINT</>, <command>RELEASE</>, <command>ROLLBACK TO SAVEPOINT</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
EXCEPTION
blocks and other internal subtransactions
<command>EXCEPTION</>
blocks and other internal subtransactions
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
@@ -1149,76 +1152,80 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1149,76 +1152,80 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
LOCK TABLE
, though only when explicitly in one of these modes:
<command>LOCK TABLE</>
, though only when explicitly in one of these modes:
ACCESS SHARE, ROW SHARE or ROW EXCLUSIVE
.
<literal>ACCESS SHARE</>, <literal>ROW SHARE</> or <literal>ROW EXCLUSIVE</>
.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Plans and resources - PREPARE, EXECUTE, DEALLOCATE, DISCARD
Plans and resources - <command>PREPARE</>, <command>EXECUTE</>,
<command>DEALLOCATE</>, <command>DISCARD</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Plugins and extensions -
LOAD
Plugins and extensions -
<command>LOAD</>
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
</para>
</para>
<para>
<para>
These actions produce error messages
These actions produce error messages
:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
Data Manipulation Language (DML) - INSERT, UPDATE, DELETE, COPY FROM, TRUNCATE.
Data Manipulation Language (DML) - <command>INSERT</>,
<command>UPDATE</>, <command>DELETE</>, <command>COPY FROM</>,
<command>TRUNCATE</>.
Note that there are no allowed actions that result in a trigger
Note that there are no allowed actions that result in a trigger
being executed during recovery.
being executed during recovery.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Data Definition Language (DDL) - CREATE, DROP, ALTER, COMMENT.
Data Definition Language (DDL) - <command>CREATE</>,
This also applies to temporary tables currently because currently their
<command>DROP</>, <command>ALTER</>, <command>COMMENT</>.
This also applies to temporary tables also because currently their
definition causes writes to catalog tables.
definition causes writes to catalog tables.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
SELECT ... FOR SHARE | UPDATE
which cause row locks to be written
<command>SELECT ... FOR SHARE | UPDATE</>
which cause row locks to be written
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
R
ULEs on SELECT
statements that generate DML commands.
R
ules on <command>SELECT</>
statements that generate DML commands.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
LOCK TABLE, in short default form, since it requests ACCESS EXCLUSIVE MODE
.
<command>LOCK TABLE</>, in short default form, since it requests <literal>ACCESS EXCLUSIVE MODE</>
.
LOCK TABLE that explicitly requests a mode higher than ROW EXCLUSIVE MODE
.
<command>LOCK TABLE</> that explicitly requests a mode higher than <literal>ROW EXCLUSIVE MODE</>
.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Transaction management commands that explicitly set non-read
only state
Transaction management commands that explicitly set non-read
-only state:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
BEGIN READ WRITE
,
<command>BEGIN READ WRITE</>
,
START TRANSACTION READ WRITE
<command>START TRANSACTION READ WRITE</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
SET TRANSACTION READ WRITE
,
<command>SET TRANSACTION READ WRITE</>
,
SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE
<command>SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
SET transaction_read_only = off
<command>SET transaction_read_only = off</>
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
@@ -1226,9 +1233,10 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1226,9 +1233,10 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Two-phase commit commands - PREPARE TRANSACTION, COMMIT PREPARED,
Two-phase commit commands - <command>PREPARE TRANSACTION</>,
ROLLBACK PREPARED because even read-only transactions need to write
<command>COMMIT PREPARED</>, <command>ROLLBACK PREPARED</>
WAL in the prepare phase (the first phase of two phase commit).
because even read-only transactions need to write WAL in the
prepare phase (the first phase of two phase commit).
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
...
@@ -1238,20 +1246,20 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1238,20 +1246,20 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
LISTEN, UNLISTEN, NOTIFY
since they currently write to system tables
LISTEN, UNLISTEN, NOTIFY
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
</para>
</para>
<para>
<para>
Note that current behaviour of read only transactions when not in
Note that
the
current behaviour of read only transactions when not in
recovery is to allow the last two actions, so there are small and
recovery is to allow the last two actions, so there are small and
subtle differences in behaviour between read-only transactions
subtle differences in behaviour between read-only transactions
run on
standby and during normal running
.
run on
a standby and run during normal operation
.
It is possible that
the restrictions on LISTEN, UNLISTEN, NOTIFY and
It is possible that
<command>LISTEN, <command>UNLISTEN</>,
temporary tables may be lifted in a future release, if their internal
<command>NOTIFY</>, and temporary tables might be allowed in a
implementation is altered to make this possibl
e.
future releas
e.
</para>
</para>
<para>
<para>
...
@@ -1264,9 +1272,9 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1264,9 +1272,9 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
Users will be able to tell whether their session is read-only by
Users will be able to tell whether their session is read-only by
issuing
SHOW transaction_read_only. In addition
a set of
issuing
<command>SHOW transaction_read_only</>. In addition,
a set of
functions
<xref linkend="functions-recovery-info-table">
allow users to
functions
(<xref linkend="functions-recovery-info-table">)
allow users to
access information about
Hot Standby
. These allow you to write
access information about
the standby server
. These allow you to write
functions that are aware of the current state of the database. These
functions that are aware of the current state of the database. These
can be used to monitor the progress of recovery, or to allow you to
can be used to monitor the progress of recovery, or to allow you to
write complex programs that restore the database to particular states.
write complex programs that restore the database to particular states.
...
@@ -1274,15 +1282,15 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1274,15 +1282,15 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
In recovery, transactions will not be permitted to take any table lock
In recovery, transactions will not be permitted to take any table lock
higher than
RowExclusiveLock
. In addition, transactions may never assign
higher than
<literal>RowExclusiveLock</>
. In addition, transactions may never assign
a TransactionId and may never write WAL.
a TransactionId and may never write WAL.
Any <command>LOCK TABLE</> command that runs on the standby and requests
Any <command>LOCK TABLE</> command that runs on the standby and requests
a specific lock mode higher than
ROW EXCLUSIVE MODE
will be rejected.
a specific lock mode higher than
<literal>ROW EXCLUSIVE MODE</>
will be rejected.
</para>
</para>
<para>
<para>
In general queries will not experience lock conflicts
with
the database
In general queries will not experience lock conflicts
from
the database
changes made by recovery. This is becase recovery follows normal
changes made by recovery. This is beca
u
se recovery follows normal
concurrency control mechanisms, known as <acronym>MVCC</>. There are
concurrency control mechanisms, known as <acronym>MVCC</>. There are
some types of change that will cause conflicts, covered in the following
some types of change that will cause conflicts, covered in the following
section.
section.
...
@@ -1303,22 +1311,23 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1303,22 +1311,23 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
There are also additional types of conflict that can occur with Hot Standby.
There are also additional types of conflict that can occur with Hot Standby.
These conflicts are <emphasis>hard conflicts</> in the sense that we may
These conflicts are <emphasis>hard conflicts</> in the sense that queries
need to cancel queries and in some cases disconnect sessions to resolve them.
might need to be cancelled and, in some cases, sessions disconnected to resolve them.
The user is provided with a number of optional ways to handle these
The user is provided with several ways to handle these
conflicts, though we must first understand the possible reasons behind a conflict.
conflicts, though it is important to first understand the possible causes
of conflicts:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
Access Exclusive Locks from primary node, including both explicit
Access Exclusive Locks from primary node, including both explicit
LOCK commands and various kinds of DDL action
<command>LOCK</> commands and various <acronym>DDL</> actions
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Dropping tablespaces on the primary while standby queries are using
Dropping tablespaces on the primary while standby queries are using
those tablespaces for temporary work files (
work_mem
overflow)
those tablespaces for temporary work files (
<varname>work_mem</>
overflow)
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
...
@@ -1341,40 +1350,40 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1341,40 +1350,40 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</para>
</para>
<para>
<para>
Some WAL redo actions will be for
DDL
actions. These DDL actions are
Some WAL redo actions will be for
<acronym>DDL</>
actions. These DDL actions are
repeating actions that have already committed on the primary node, so
repeating actions that have already committed on the primary node, so
they must not fail on the standby node. These DDL locks take priority
they must not fail on the standby node. These DDL locks take priority
and will automatically *cancel* any read-only transactions that get in
and will automatically *cancel* any read-only transactions that get in
their way, after a grace period. This is similar to the possibility of
their way, after a grace period. This is similar to the possibility of
being canceled by the deadlock detector, but in this case the standby
being canceled by the deadlock detector, but in this case the standby
process always wins, since the replayed actions must not fail. This
process always wins, since the replayed actions must not fail. This
also ensures that replication does
n't fall behind while we wait
for a
also ensures that replication does
not fall behind while waiting
for a
query to complete. Again,
we assume that the standby is there for high
query to complete. Again,
the assumption is that the standby is
availability purposes primaril
y.
primarily for high availabilit
y.
</para>
</para>
<para>
<para>
An example of the above would be an Administrator on Primary server
An example of the above would be an Administrator on Primary server
run
s a <command>DROP TABLE</> on a table that'
s currently being queried
run
ning <command>DROP TABLE</> on a table that i
s currently being queried
i
n the standby server.
o
n the standby server.
Clearly the query cannot continue if
we let the
<command>DROP TABLE</>
Clearly the query cannot continue if <command>DROP TABLE</>
proceed. If this situation occurred on the primary, the <command>DROP TABLE</>
proceed
s
. If this situation occurred on the primary, the <command>DROP TABLE</>
would wait until the query ha
s finished. When the query is on the standby
would wait until the query ha
d finished. When <command>DROP TABLE</> is
and the <command>DROP TABLE</> is
on the primary, the primary doesn't have
run
on the primary, the primary doesn't have
information about which queries are running on the standby and so
the query
information about which queries are running on the standby and so
does not wait on the primary
. The WAL change records come through to the
cannot wait for any of the standby queries
. The WAL change records come through to the
standby while the standby query is still running, causing a conflict.
standby while the standby query is still running, causing a conflict.
</para>
</para>
<para>
<para>
The most common reason for conflict between standby queries and WAL redo is
The most common reason for conflict between standby queries and WAL redo is
"early cleanup". Normally, <productname>PostgreSQL</> allows cleanup of old
"early cleanup". Normally, <productname>PostgreSQL</> allows cleanup of old
row versions when there are no users who
may
need to see them to ensure correct
row versions when there are no users who need to see them to ensure correct
visibility of data (the heart of MVCC). If there is a standby query that has
visibility of data (the heart of MVCC). If there is a standby query that has
been running for longer than any query on the primary then it is possible
been running for longer than any query on the primary then it is possible
for old row versions to be removed by either a vacuum or HOT. This will
for old row versions to be removed by either a vacuum or HOT. This will
then generate WAL records that, if applied, would remove data on the
then generate WAL records that, if applied, would remove data on the
standby that might
*potentially*
be required by the standby query.
standby that might
<emphasis>potentially</>
be required by the standby query.
In more technical language, the primary's xmin horizon is later than
In more technical language, the primary's xmin horizon is later than
the standby's xmin horizon, allowing dead rows to be removed.
the standby's xmin horizon, allowing dead rows to be removed.
</para>
</para>
...
@@ -1387,37 +1396,37 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1387,37 +1396,37 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</para>
</para>
<para>
<para>
We hav
e a number of choices for resolving query conflicts. The default
There ar
e a number of choices for resolving query conflicts. The default
is t
hat we wait and hope the query complet
es. The server will wait
is t
o wait and hope the query finish
es. The server will wait
automatically until the lag between primary and standby is at most
automatically until the lag between primary and standby is at most
<varname>max_standby_delay</> seconds. Once that grace period expires,
<varname>max_standby_delay</> seconds. Once that grace period expires,
we take one of the following actions
:
one of the following actions is taken
:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
If the conflict is caused by a lock,
we cancel
the conflicting standby
If the conflict is caused by a lock, the conflicting standby
transaction i
mmediately. If the transaction is idle-in-transaction
transaction i
s cancelled immediately. If the transaction is
then currently we abort the session instead, though this may change
idle-in-transaction then the session is aborted
in the future.
in
stead, though this might change in
the future.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
If the conflict is caused by cleanup records
we tell the standby query
If the conflict is caused by cleanup records
, the standby query is informed
that
a conflict has occurred and that it must cancel itself to avoid the
a conflict has occurred and that it must cancel itself to avoid the
risk that it silently fails to read relevant data because
risk that it silently fails to read relevant data because
that data has been removed. (This is regrettably
very
similar to the
that data has been removed. (This is regrettably similar to the
much feared and iconic error message "snapshot too old"). Some cleanup
much feared and iconic error message "snapshot too old"). Some cleanup
records only c
ause conflict with older queries, though some types of
records only c
onflict with older queries, while others
c
leanup record
affect all queries.
c
an
affect all queries.
</para>
</para>
<para>
<para>
If cancellation does occur, the query and/or transaction can always
If cancellation does occur, the query and/or transaction can always
be re-executed. The error is dynamic and will not necessarily occur
be re-executed. The error is dynamic and will not necessarily
re
occur
the same way
if the query is executed again.
if the query is executed again.
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
@@ -1425,48 +1434,49 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1425,48 +1434,49 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<para>
<para>
<varname>max_standby_delay</> is set in <filename>postgresql.conf</>.
<varname>max_standby_delay</> is set in <filename>postgresql.conf</>.
The parameter applies to the server as a whole
so if the delay is all us
ed
The parameter applies to the server as a whole
, so if the delay is consum
ed
up
by a single query then there may be little or no waiting for queries that
by a single query then there may be little or no waiting for queries that
follow
immediately
, though they will have benefited equally from the initial
follow, though they will have benefited equally from the initial
waiting period. The server may take time to catch up again before the grace
waiting period. The server may take time to catch up again before the grace
period is available again, though if there is a heavy and constant stream
period is available again, though if there is a heavy and constant stream
of conflicts it may seldom catch up fully.
of conflicts it may seldom catch up fully.
</para>
</para>
<para>
<para>
Users should be clear that tables that are regularly and heavily updated on
Users should be clear that tables that are regularly and heavily updated on
the
primary server will quickly cause cancellation of longer running queries on
primary server will quickly cause cancellation of longer running queries on
the standby. In those cases <varname>max_standby_delay</> can be
the standby. In those cases <varname>max_standby_delay</> can be
considered s
omewhat but not exactly the same as
setting
considered s
imilar to
setting
<varname>statement_timeout</>.
<varname>statement_timeout</>.
</para>
</para>
<para>
<para>
Other remedial actions exist if the number of cancellations is unacceptable.
Other remedial actions exist if the number of cancellations is unacceptable.
The first option is to connect to primary server and keep a query active
The first option is to connect to
the
primary server and keep a query active
for as long as
we ne
ed to run queries on the standby. This guarantees that
for as long as
need
ed to run queries on the standby. This guarantees that
a WAL cleanup record is never generated and
we don't ever get query
a WAL cleanup record is never generated and
query conflicts do not occur,
conflicts as described above. This could be done using contrib/dblink
as described above. This could be done using <filename>contrib/dblink</>
and
pg_sleep()
, or via other mechanisms. If you do this, you should note
and
<function>pg_sleep()</>
, or via other mechanisms. If you do this, you should note
that this will delay cleanup of dead rows by vacuum or HOT and
many
that this will delay cleanup of dead rows by vacuum or HOT and
people m
ay find this undesirable. However, we should remember that
people m
ight find this undesirable. However, remember that the
primary and standby nodes are linked via the WAL, so this situation is no
primary and standby nodes are linked via the WAL, so this situation is no
different
to the case where we ran the query
on the primary node itself
different
from the case where the query ran
on the primary node itself
except
we have
the benefit of off-loading the execution onto the standby.
except
for
the benefit of off-loading the execution onto the standby.
</para>
</para>
<para>
<para>
It is also possible to set <varname>vacuum_defer_cleanup_age</> on the primary
It is also possible to set <varname>vacuum_defer_cleanup_age</> on the primary
to defer the cleanup of records by autovacuum, vacuum and HOT. This may allow
to defer the cleanup of records by autovacuum, <command>VACUUM</>
and HOT. This might allow
more time for queries to execute before they are cancelled on the standby,
more time for queries to execute before they are cancelled on the standby,
without the need for setting a high <varname>max_standby_delay</>.
without the need for setting a high <varname>max_standby_delay</>.
</para>
</para>
<para>
<para>
Three-way deadlocks are possible between
AccessExclusiveLocks
arriving from
Three-way deadlocks are possible between
<literal>AccessExclusiveLocks</>
arriving from
the primary, cleanup WAL records that require buffer cleanup locks and
the primary, cleanup WAL records that require buffer cleanup locks
,
and
user requests that are waiting behind replayed
AccessExclusiveLocks
. Deadlocks
user requests that are waiting behind replayed
<literal>AccessExclusiveLocks</>
. Deadlocks
are resolved by time-out when
we
exceed <varname>max_standby_delay</>.
are resolved by time-out when
they
exceed <varname>max_standby_delay</>.
</para>
</para>
<para>
<para>
...
@@ -1479,13 +1489,13 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
...
@@ -1479,13 +1489,13 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
<title>Administrator's Overview</title>
<title>Administrator's Overview</title>
<para>
<para>
If there is a <filename>recovery.conf</> file present the server will start
If there is a <filename>recovery.conf</> file present
,
the server will start
in Hot Standby mode by default, though <varname>recovery_connections</> can
in Hot Standby mode by default, though <varname>recovery_connections</> can
be disabled via <filename>postgresql.conf</>
, if required. The server may
take
be disabled via <filename>postgresql.conf</>
. The server might
take
some time to enable recovery connections since the server must first complete
some time to enable recovery connections since the server must first complete
sufficient recovery to provide a consistent state against which queries
sufficient recovery to provide a consistent state against which queries
can run before enabling read only connections. Look for these messages
can run before enabling read only connections. Look for these messages
in the server logs
in the server logs
:
<programlisting>
<programlisting>
LOG: entering standby mode
LOG: entering standby mode
...
@@ -1497,36 +1507,38 @@ LOG: database system is ready to accept read only connections
...
@@ -1497,36 +1507,38 @@ LOG: database system is ready to accept read only connections
</programlisting>
</programlisting>
Consistency information is recorded once per checkpoint on the primary, as long
Consistency information is recorded once per checkpoint on the primary, as long
as <varname>recovery_connections</> is enabled (on the primary). If this parameter
as <varname>recovery_connections</> is enabled on the primary. If this parameter
is disabled, it will not be possible to enable recovery connections on the standby.
is disabled, it is not possible to enable recovery connections on the standby.
The consistent state can also be delayed in the presence of both of these conditions
Reaching a consistent state can also be delayed in the presence
of both of these conditions:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
a
write transaction has more than 64 subtransactions
A
write transaction has more than 64 subtransactions
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
v
ery long-lived write transactions
V
ery long-lived write transactions
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
If you are running file-based log shipping ("warm standby"), you m
ay
need
If you are running file-based log shipping ("warm standby"), you m
ight
need
to wait until the next WAL file arrives, which could be as long as the
to wait until the next WAL file arrives, which could be as long as the
<varname>archive_timeout</> setting on the primary.
<varname>archive_timeout</> setting on the primary.
</para>
</para>
<para>
<para>
The setting of some parameters on the standby will need reconfiguration
The setting of some parameters on the standby will need reconfiguration
if they have been changed on the primary. The value on the standby must
if they have been changed on the primary. For these parameters,
the value on the standby must
be equal to or greater than the value on the primary. If these parameters
be equal to or greater than the value on the primary. If these parameters
are not set high enough then the standby will not be able to
track work
are not set high enough then the standby will not be able to
process
correctly from recovering transactions. If these values are set too low the
recovering transactions properly. If these values are set too low
the server will halt. Higher values can then be supplied and the server
the server will halt. Higher values can then be supplied and the server
restarted to begin recovery again.
restarted to begin recovery again.
The parameters are:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
...
@@ -1550,109 +1562,114 @@ LOG: database system is ready to accept read only connections
...
@@ -1550,109 +1562,114 @@ LOG: database system is ready to accept read only connections
<para>
<para>
It is important that the administrator consider the appropriate setting
It is important that the administrator consider the appropriate setting
of <varname>max_standby_delay</>, set in <filename>postgresql.conf</>.
of <varname>max_standby_delay</>, set in <filename>postgresql.conf</>.
There is no optimal setting
and
should be set according to business
There is no optimal setting
, so it
should be set according to business
priorities. For example if the server is primarily tasked as a High
priorities. For example if the server is primarily tasked as a High
Availability server, then you may wish to lower
Availability server, then you may wish to lower
<varname>max_standby_delay</> or even set it to zero, though that is a
<varname>max_standby_delay</> or even set it to zero, though that is a
very aggressive setting. If the standby server is tasked as an additional
very aggressive setting. If the standby server is tasked as an additional
server for decision support queries then it m
ay
be acceptable to set this
server for decision support queries then it m
ight
be acceptable to set this
to a value of many hours (in seconds).
to a value of many hours (in seconds).
</para>
</para>
<para>
<para>
Transaction status "hint bits" written on primary are not WAL-logged,
Transaction status "hint bits" written on the primary are not WAL-logged,
so data on standby will likely re-write the hints again on the standby.
so data on the standby will likely re-write the hints again on the standby.
Thus the main database blocks will produce write I/Os even though
Thus, the standby server will still perform disk writes even though
all users are read-only; no changes have occurred to the data values
all users are read-only; no changes occur to the data values
themselves. Users will be able to write large sort temp files and
themselves. Users will still write large sort temporary files and
re-generate relcache info files, so there is no part of the database
re-generate relcache info files, so no part of the database
that is truly read-only during hot standby mode. There is no restriction
is truly read-only during hot standby mode. There is no restriction
on the use of set returning functions, or other users of tuplestore/tuplesort
on the use of set returning functions, or other users of
<function>tuplestore</>/<function>tuplesort</>
code. Note also that writes to remote databases will still be possible,
code. Note also that writes to remote databases will still be possible,
even though the transaction is read-only locally.
even though the transaction is read-only locally.
</para>
</para>
<para>
<para>
The following types of administrat
or command
are not accepted
The following types of administrat
ion commands
are not accepted
during recovery mode
during recovery mode
:
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
Data Definition Language (DDL) - e.g.
CREATE INDEX
Data Definition Language (DDL) - e.g.
<command>CREATE INDEX</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Privilege and Ownership - GRANT, REVOKE, REASSIGN
Privilege and Ownership - <command>GRANT</>, <command>REVOKE</>,
<command>REASSIGN</>
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Maintenance commands - ANALYZE, VACUUM, CLUSTER, REINDEX
Maintenance commands - <command>ANALYZE</>, <command>VACUUM</>,
<command>CLUSTER</>, <command>REINDEX</>
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
</para>
</para>
<para>
<para>
Note again
that some of these commands are actually allowed during
Again, note
that some of these commands are actually allowed during
"read only" mode transactions on the primary.
"read only" mode transactions on the primary.
</para>
</para>
<para>
<para>
As a result, you cannot create additional indexes that exist solely
As a result, you cannot create additional indexes that exist solely
on the standby, nor can statistics
that
exist solely on the standby.
on the standby, nor can statistics exist solely on the standby.
If these administrat
or
commands are needed they should be executed
If these administrat
ion
commands are needed they should be executed
on the primary so that the changes will propagate t
hrough t
o the
on the primary so that the changes will propagate to the
standby.
standby.
</para>
</para>
<para>
<para>
<function>pg_cancel_backend()</> will work on user backends, but not the
<function>pg_cancel_backend()</> will work on user backends, but not the
Startup process, which performs recovery.
pg_stat_activity
does not
Startup process, which performs recovery.
<structname>pg_stat_activity</structname>
does not
show an entry for the Startup process, nor do recovering transactions
show an entry for the Startup process, nor do recovering transactions
show as active. As a result,
pg_prepared_xacts
is always empty during
show as active. As a result,
<structname>pg_prepared_xacts</structname>
is always empty during
recovery. If you wish to resolve in-doubt prepared transactions
recovery. If you wish to resolve in-doubt prepared transactions
,
then look at pg_prepared_xacts
on the primary and issue commands to
view <literal>pg_prepared_xacts</>
on the primary and issue commands to
resolve t
hose t
ransactions there.
resolve transactions there.
</para>
</para>
<para>
<para>
pg_locks will show locks held by backends as normal. pg_locks also shows
<structname>pg_locks</structname> will show locks held by backends,
as normal. <structname>pg_locks</structname> also shows
a virtual transaction managed by the Startup process that owns all
a virtual transaction managed by the Startup process that owns all
AccessExclusiveLocks
held by transactions being replayed by recovery.
<literal>AccessExclusiveLocks</>
held by transactions being replayed by recovery.
Note that Startup process does not acquire locks to
Note that
the
Startup process does not acquire locks to
make database changes
and thus locks other than AccessExclusiveLocks
make database changes
, and thus locks other than <literal>AccessExclusiveLocks</>
do not show in
pg_locks for the Startup process, they are just presumed
do not show in
<structname>pg_locks</structname> for the Startup
to exist.
process; they are just presumed
to exist.
</para>
</para>
<para>
<para>
<productname>check_pgsql</> will work, but it is very simple.
The <productname>Nagios</> plugin <productname>check_pgsql</> will
<productname>check_postgres</> will also work, though many some actions
work, but it is very simple.
<productname>check_postgres</> will also work, though some actions
could give different or confusing results.
could give different or confusing results.
e.g. last vacuum time will not be maintained for example
, since no
For example, last vacuum time will not be maintained
, since no
vacuum occurs on the standby (though vacuums running on the primary do
vacuum occurs on the standby (though vacuums running on the primary do
send their changes to the standby).
send their changes to the standby).
</para>
</para>
<para>
<para>
WAL file control commands will not work during recovery
WAL file control commands will not work during recovery
,
e.g. <function>pg_start_backup</>, <function>pg_switch_xlog</> etc.
.
e.g. <function>pg_start_backup</>, <function>pg_switch_xlog</> etc.
</para>
</para>
<para>
<para>
Dynamically loadable modules work, including
pg_stat_statements
.
Dynamically loadable modules work, including
<structname>pg_stat_statements</>
.
</para>
</para>
<para>
<para>
Advisory locks work normally in recovery, including deadlock detection.
Advisory locks work normally in recovery, including deadlock detection.
Note that advisory locks are never WAL logged, so it is
not
possible for
Note that advisory locks are never WAL logged, so it is
im
possible for
an advisory lock on either the primary or the standby to conflict with WAL
an advisory lock on either the primary or the standby to conflict with WAL
replay. Nor is it possible to acquire an advisory lock on the primary
replay. Nor is it possible to acquire an advisory lock on the primary
and have it initiate a similar advisory lock on the standby. Advisory
and have it initiate a similar advisory lock on the standby. Advisory
locks relate only to
a singl
e server on which they are acquired.
locks relate only to
th
e server on which they are acquired.
</para>
</para>
<para>
<para>
...
@@ -1671,19 +1688,19 @@ LOG: database system is ready to accept read only connections
...
@@ -1671,19 +1688,19 @@ LOG: database system is ready to accept read only connections
</para>
</para>
<para>
<para>
Currently, temp table creation is not allowed during read only
Currently, temp
orary
table creation is not allowed during read only
transactions, so in some cases existing scripts will not run correctly.
transactions, so in some cases existing scripts will not run correctly.
It is possible we may relax that restriction
in a later release. This is
This restriction might be relaxed
in a later release. This is
both a SQL Standard compliance issue and a technical issue.
both a SQL Standard compliance issue and a technical issue.
</para>
</para>
<para>
<para>
<command>DROP TABLESPACE</> can only succeed if the tablespace is empty.
<command>DROP TABLESPACE</> can only succeed if the tablespace is empty.
Some standby users may be actively using the tablespace via their
Some standby users may be actively using the tablespace via their
<varname>temp_tablespaces</> parameter. If there are temp files in the
<varname>temp_tablespaces</> parameter. If there are temp
orary
files in the
tablespace
we currently cancel all active queries to ensure that temp
tablespace
, all active queries are cancelled to ensure that temporary
files are removed, so th
at we can remove the tablespace and continue with
files are removed, so th
e tablespace can be removed and WAL replay
WAL replay
.
can continue
.
</para>
</para>
<para>
<para>
...
@@ -1695,7 +1712,7 @@ LOG: database system is ready to accept read only connections
...
@@ -1695,7 +1712,7 @@ LOG: database system is ready to accept read only connections
</para>
</para>
<para>
<para>
In normal
running
, if you issue <command>DROP USER</> or <command>DROP ROLE</>
In normal
(non-recovery) mode
, if you issue <command>DROP USER</> or <command>DROP ROLE</>
for a role with login capability while that user is still connected then
for a role with login capability while that user is still connected then
nothing happens to the connected user - they remain connected. The user cannot
nothing happens to the connected user - they remain connected. The user cannot
reconnect however. This behaviour applies in recovery also, so a
reconnect however. This behaviour applies in recovery also, so a
...
@@ -1703,24 +1720,26 @@ LOG: database system is ready to accept read only connections
...
@@ -1703,24 +1720,26 @@ LOG: database system is ready to accept read only connections
</para>
</para>
<para>
<para>
Stat
s collector is active during recovery. All scans, reads, blocks,
The statististic
s collector is active during recovery. All scans, reads, blocks,
index usage
etc will a
ll be recorded normally on the standby. Replayed
index usage
, etc., wi
ll be recorded normally on the standby. Replayed
actions will not duplicate their effects on primary, so replaying an
actions will not duplicate their effects on primary, so replaying an
insert will not increment the Inserts column of pg_stat_user_tables.
insert will not increment the Inserts column of pg_stat_user_tables.
The stats file is deleted at start of recovery, so stats from primary
The stats file is deleted at
the
start of recovery, so stats from primary
and standby will differ; this is considered a feature not a bug.
and standby will differ; this is considered a feature
,
not a bug.
</para>
</para>
<para>
<para>
Autovacuum is not active during recovery, though will start normally
Autovacuum is not active during recovery, though
it
will start normally
at the end of recovery.
at the end of recovery.
</para>
</para>
<para>
<para>
Background writer is active during recovery and will perform
The background writer is active during recovery and will perform
restartpoints (similar to checkpoints on primary) and normal block
restartpoints (similar to checkpoints on the primary) and normal block
cleaning activities. The <command>CHECKPOINT</> command is accepted during recovery,
cleaning activities. (Remember, hint bits will cause blocks to
though performs a restartpoint rather than a new checkpoint.
be modified on the standby server.)
The <command>CHECKPOINT</> command is accepted during recovery,
though it performs a restartpoint rather than a new checkpoint.
</para>
</para>
</sect2>
</sect2>
...
@@ -1728,21 +1747,19 @@ LOG: database system is ready to accept read only connections
...
@@ -1728,21 +1747,19 @@ LOG: database system is ready to accept read only connections
<title>Hot Standby Parameter Reference</title>
<title>Hot Standby Parameter Reference</title>
<para>
<para>
Various parameters have been mentioned above in
the
<xref linkend="hot-standby-admin">
Various parameters have been mentioned above in <xref linkend="hot-standby-admin">
and <xref linkend="hot-standby-conflict">
sections
.
and <xref linkend="hot-standby-conflict">.
</para>
</para>
<para>
<para>
On the primary, parameters <varname>recovery_connections</> and
On the primary, parameters <varname>recovery_connections</> and
<varname>vacuum_defer_cleanup_age</> can be used to enable and control the
<varname>vacuum_defer_cleanup_age</> can be used.
primary server to assist the successful configuration of Hot Standby servers.
<varname>max_standby_delay</> has no effect if set on the primary.
<varname>max_standby_delay</> has no effect if set on the primary.
</para>
</para>
<para>
<para>
On the standby, parameters <varname>recovery_connections</> and
On the standby, parameters <varname>recovery_connections</> and
<varname>max_standby_delay</> can be used to enable and control Hot Standby.
<varname>max_standby_delay</> can be used.
standby server to assist the successful configuration of Hot Standby servers.
<varname>vacuum_defer_cleanup_age</> has no effect during recovery.
<varname>vacuum_defer_cleanup_age</> has no effect during recovery.
</para>
</para>
</sect2>
</sect2>
...
@@ -1751,7 +1768,7 @@ LOG: database system is ready to accept read only connections
...
@@ -1751,7 +1768,7 @@ LOG: database system is ready to accept read only connections
<title>Caveats</title>
<title>Caveats</title>
<para>
<para>
At this writing, t
here are several limitations of Hot Standby.
T
here are several limitations of Hot Standby.
These can and probably will be fixed in future releases:
These can and probably will be fixed in future releases:
<itemizedlist>
<itemizedlist>
...
@@ -1765,33 +1782,33 @@ LOG: database system is ready to accept read only connections
...
@@ -1765,33 +1782,33 @@ LOG: database system is ready to accept read only connections
<listitem>
<listitem>
<para>
<para>
Full knowledge of running transactions is required before snapshots
Full knowledge of running transactions is required before snapshots
may be taken. Transactions that take
use large numbers of subtransactions
can be taken. Transactions that
use large numbers of subtransactions
(currently greater than 64) will delay the start of read only
(currently greater than 64) will delay the start of read only
connections until the completion of the longest running write transaction.
connections until the completion of the longest running write transaction.
If this situation occurs
explanatory messages will be sent to
server log.
If this situation occurs
, explanatory messages will be sent to the
server log.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
Valid starting points for recovery connections are generated at each
Valid starting points for recovery connections are generated at each
checkpoint on the master. If the standby is shutdown while the master
checkpoint on the master. If the standby is shut
down while the master
is in a shutdown state it m
ay
not be possible to re-enter Hot Standby
is in a shutdown state it m
ight
not be possible to re-enter Hot Standby
until the primary is started up so that it generates further starting
until the primary is started up so that it generates further starting
points in the WAL logs. This is not considered a serious issue
points in the WAL logs. This is not considered a serious issue
because the standby is usually switched
into the primary role while
because the standby is usually switched
to act as primary when
the first node is taken down.
the first node is taken down.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
At the end of recovery,
AccessExclusiveLocks
held by prepared transactions
At the end of recovery,
<literal>AccessExclusiveLocks</>
held by prepared transactions
will require twice the normal number of lock table entries. If you plan
will require twice the normal number of lock table entries. If you plan
on running either a large number of concurrent prepared transactions
on running either a large number of concurrent prepared transactions
that normally take
AccessExclusiveLocks
, or you plan on having one
that normally take
<literal>AccessExclusiveLocks</>
, or you plan on having one
large transaction that takes many
AccessExclusiveLocks then
you are
large transaction that takes many
<literal>AccessExclusiveLocks</>,
you are
advised to select a larger value of <varname>max_locks_per_transaction</>,
advised to select a larger value of <varname>max_locks_per_transaction</>,
up to, but never more than twice the value of the parameter setting on
up to, but never more than twice the value of the parameter setting on
the primary server
in rare extremes
. You need not consider this at all if
the primary server. You need not consider this at all if
your setting of <varname>max_prepared_transactions</> is <literal>0</>.
your setting of <varname>max_prepared_transactions</> is <literal>0</>.
</para>
</para>
</listitem>
</listitem>
...
@@ -1828,7 +1845,7 @@ LOG: database system is ready to accept read only connections
...
@@ -1828,7 +1845,7 @@ LOG: database system is ready to accept read only connections
logs shipped from the primary, we will be able to reload that backup and
logs shipped from the primary, we will be able to reload that backup and
restart the standby's recovery process from the last restart point.
restart the standby's recovery process from the last restart point.
We no longer need to keep WAL files from before the standby's restart point.
We no longer need to keep WAL files from before the standby's restart point.
If
we need to recover
, it will be faster to recover from the incrementally
If
recovery is needed
, it will be faster to recover from the incrementally
updated backup than from the original base backup.
updated backup than from the original base backup.
</para>
</para>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment