1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.74 2010/06/22 02:57:50 rhaas Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.75 2010/06/24 19:50:25 rhaas Exp $ -->
2
2
3
3
<chapter id="high-availability">
4
4
<title>High Availability, Load Balancing, and Replication</title>
@@ -1150,52 +1150,32 @@ if (!triggered)
1150
1150
<title>User's Overview</title>
1151
1151
1152
1152
<para>
1153
- Users can connect to the database server while it is in recovery
1154
- mode and perform read-only queries. Read-only access to system
1155
- catalogs and views will also occur as normal.
1153
+ When the <xref linkend="guc-hot-standby"> parameter is set to true on a
1154
+ standby server, it will begin accepting connections once the recovery has
1155
+ brought the system to a consistent state. All such connections are
1156
+ strictly read-only; not even temporary tables may be written.
1156
1157
</para>
1157
1158
1158
1159
<para>
1159
1160
The data on the standby takes some time to arrive from the primary server
1160
1161
so there will be a measurable delay between primary and standby. Running the
1161
1162
same query nearly simultaneously on both primary and standby might therefore
1162
1163
return differing results. We say that data on the standby is
1163
- <firstterm>eventually consistent</firstterm> with the primary.
1164
- Queries executed on the standby will be correct with regard to the transactions
1165
- that had been recovered at the start of the query, or start of first statement
1166
- in the case of serializable transactions. In comparison with the primary,
1167
- the standby returns query results that could have been obtained on the primary
1168
- at some moment in the past .
1164
+ <firstterm>eventually consistent</firstterm> with the primary. Once the
1165
+ commit record for a transaction is replayed on the standby, the changes
1166
+ made by that transaction will be visible to any new snapshots taken on
1167
+ the standby. Snapshots may be taken at the start of each query or at the
1168
+ start of each transaction, depending on the current transaction isolation
1169
+ level. For more details, see <xref linkend="transaction-iso"> .
1169
1170
</para>
1170
1171
1171
1172
<para>
1172
- When a transaction is started in recovery, the parameter
1173
- <varname>transaction_read_only</> will be forced to be true, regardless of the
1174
- <varname>default_transaction_read_only</> setting in <filename>postgresql.conf</>.
1175
- It can't be manually set to false either. As a result, all transactions
1176
- started during recovery will be limited to read-only actions. In all
1177
- other ways, connected sessions will appear identical to sessions
1178
- initiated during normal processing mode. There are no special commands
1179
- required to initiate a connection so all interfaces
1180
- work unchanged. After recovery finishes, the session
1181
- will allow normal read-write transactions at the start of the next
1182
- transaction, if these are requested.
1183
- </para>
1184
-
1185
- <para>
1186
- "Read-only" above means no writes to the permanent or temporary database
1187
- tables. There are no problems with queries that use transient sort and
1188
- work files.
1189
- </para>
1190
-
1191
- <para>
1192
- The following actions are allowed:
1173
+ Transactions started during recovery may issue the following commands:
1193
1174
1194
1175
<itemizedlist>
1195
1176
<listitem>
1196
1177
<para>
1197
- Query access - <command>SELECT</>, <command>COPY TO</> including views and
1198
- <command>SELECT</> rules
1178
+ Query access - <command>SELECT</>, <command>COPY TO</>
1199
1179
</para>
1200
1180
</listitem>
1201
1181
<listitem>
@@ -1251,7 +1231,9 @@ if (!triggered)
1251
1231
</para>
1252
1232
1253
1233
<para>
1254
- These actions produce error messages:
1234
+ Transactions started during recovery may never be assigned a transaction ID
1235
+ and may not write to the system write-ahead log. Therefore, the following
1236
+ actions will produce error messages:
1255
1237
1256
1238
<itemizedlist>
1257
1239
<listitem>
@@ -1260,20 +1242,24 @@ if (!triggered)
1260
1242
<command>UPDATE</>, <command>DELETE</>, <command>COPY FROM</>,
1261
1243
<command>TRUNCATE</>.
1262
1244
Note that there are no allowed actions that result in a trigger
1263
- being executed during recovery.
1245
+ being executed during recovery. This restriction applies even to
1246
+ temporary tables, because table rows cannot be read or written without
1247
+ assigning a transaction ID, which is currently not possible in a
1248
+ Hot Standby environment.
1264
1249
</para>
1265
1250
</listitem>
1266
1251
<listitem>
1267
1252
<para>
1268
1253
Data Definition Language (DDL) - <command>CREATE</>,
1269
1254
<command>DROP</>, <command>ALTER</>, <command>COMMENT</>.
1270
- This also applies to temporary tables also because currently their
1271
- definition causes writes to catalog tables.
1255
+ This restriction applies even to temporary tables, because carrying
1256
+ out these operations would require updating the system catalog tables.
1272
1257
</para>
1273
1258
</listitem>
1274
1259
<listitem>
1275
1260
<para>
1276
- <command>SELECT ... FOR SHARE | UPDATE</> which cause row locks to be written
1261
+ <command>SELECT ... FOR SHARE | UPDATE</>, because row locks cannot be
1262
+ taken without updating the underlying data files.
1277
1263
</para>
1278
1264
</listitem>
1279
1265
<listitem>
@@ -1337,20 +1323,22 @@ if (!triggered)
1337
1323
</para>
1338
1324
1339
1325
<para>
1340
- Note that the current behavior of read only transactions when not in
1341
- recovery is to allow the last two actions, so there are small and
1342
- subtle differences in behavior between read-only transactions
1343
- run on a standby and run during normal operation.
1344
- It is possible that <command>LISTEN</>, <command>UNLISTEN</>,
1345
- and temporary tables might be allowed in a future release.
1326
+ Outside of recovery, read-only transactions are allowed to update sequences
1327
+ and to use <command>LISTEN</>, <command>UNLISTEN</>, and
1328
+ <command>NOTIFY</>, so Hot Standby sessions operate under slightly tighter
1329
+ restrictions than ordinary read-only sessions. It is possible that some
1330
+ of these restrictions might be loosened in a future release.
1346
1331
</para>
1347
1332
1348
1333
<para>
1349
- If failover or switchover occurs the database will switch to normal
1350
- processing mode. Sessions will remain connected while the server
1351
- changes mode. Current transactions will continue, though will remain
1352
- read-only. After recovery is complete, it will be possible to initiate
1353
- read-write transactions.
1334
+ During recovery, the parameter <varname>transaction_read_only</> is always
1335
+ true and may not be changed. But as long as no attempt is made to modify
1336
+ the database, connections during recovery will act much like any other
1337
+ database connection. If failover or switchover occurs, the database will
1338
+ switch to normal processing mode. Sessions will remain connected while the
1339
+ server changes mode. Once recovery finishes, it will be possible to
1340
+ initiate read-write transactions (even from a session begun during
1341
+ recovery).
1354
1342
</para>
1355
1343
1356
1344
<para>
@@ -1364,15 +1352,7 @@ if (!triggered)
1364
1352
</para>
1365
1353
1366
1354
<para>
1367
- In recovery, transactions will not be permitted to take any table lock
1368
- higher than <literal>RowExclusiveLock</>. In addition, transactions may never assign
1369
- a TransactionId and may never write WAL.
1370
- Any <command>LOCK TABLE</> command that runs on the standby and requests
1371
- a specific lock mode higher than <literal>ROW EXCLUSIVE MODE</> will be rejected.
1372
- </para>
1373
-
1374
- <para>
1375
- In general queries will not experience lock conflicts from the database
1355
+ In general, queries will not experience lock conflicts from the database
1376
1356
changes made by recovery. This is because recovery follows normal
1377
1357
concurrency control mechanisms, known as <acronym>MVCC</>. There are
1378
1358
some types of change that will cause conflicts, covered in the following
@@ -1397,8 +1377,7 @@ if (!triggered)
1397
1377
These conflicts are <emphasis>hard conflicts</> in the sense that queries
1398
1378
might need to be cancelled and, in some cases, sessions disconnected to resolve them.
1399
1379
The user is provided with several ways to handle these
1400
- conflicts, though it is important to first understand the possible causes
1401
- of conflicts:
1380
+ conflicts. Conflicts can be caused by:
1402
1381
1403
1382
<itemizedlist>
1404
1383
<listitem>
@@ -1427,7 +1406,7 @@ if (!triggered)
1427
1406
</listitem>
1428
1407
<listitem>
1429
1408
<para>
1430
- Early cleanup of data still visible to the current query's snapshot
1409
+ Early cleanup of data still visible to the current query's snapshot.
1431
1410
</para>
1432
1411
</listitem>
1433
1412
</itemizedlist>
@@ -1503,16 +1482,16 @@ if (!triggered)
1503
1482
If the conflict is caused by cleanup records, the standby query is informed
1504
1483
a conflict has occurred and that it must cancel itself to avoid the
1505
1484
risk that it silently fails to read relevant data because
1506
- that data has been removed. (This is regrettably similar to the
1507
- much feared and iconic error message "snapshot too old"). Some cleanup
1485
+ that data has been removed. Some cleanup
1508
1486
records only conflict with older queries, while others
1509
1487
can affect all queries.
1510
1488
</para>
1511
1489
1512
1490
<para>
1513
- If cancellation does occur, the query and/or transaction can always
1514
- be re-executed. The error is dynamic and will not necessarily reoccur
1515
- if the query is executed again.
1491
+ Cancelled queries may be retried immediately (after beginning a new
1492
+ transaction, of course). Since query cancellation depends on
1493
+ the nature of the WAL records being replayed, a query that was
1494
+ cancelled may succeed if it is executed again.
1516
1495
</para>
1517
1496
</listitem>
1518
1497
</itemizedlist>
@@ -1533,7 +1512,7 @@ if (!triggered)
1533
1512
<para>
1534
1513
Be sure that the primary and standby servers' clocks are kept in sync;
1535
1514
otherwise the values compared to <varname>max_standby_delay</> will be
1536
- erroneous, possibly leading to undesirable query cancellations.
1515
+ erroneous, possibly leading to additional query cancellations.
1537
1516
If the clocks are intentionally not in sync, or if there is a large
1538
1517
propagation delay from primary to standby, it is advisable to set
1539
1518
<varname>max_standby_delay</> to -1. In any case the value should be
@@ -1557,10 +1536,10 @@ if (!triggered)
1557
1536
as described above. This could be done using <filename>contrib/dblink</>
1558
1537
and <function>pg_sleep()</>, or via other mechanisms. If you do this, you
1559
1538
should note that this will delay cleanup of dead rows on the primary by
1560
- vacuum or HOT, and people might find this undesirable. However, remember
1539
+ vacuum or HOT, which may be undesirable. However, remember
1561
1540
that the primary and standby nodes are linked via the WAL, so the cleanup
1562
1541
situation is no different from the case where the query ran on the primary
1563
- node itself. And you are still getting the benefit of off-loading the
1542
+ node itself, and you are still getting the benefit of off-loading the
1564
1543
execution onto the standby. <varname>max_standby_delay</> should
1565
1544
not be used in this case because delayed WAL files might already
1566
1545
contain entries that invalidate the current snapshot.
0 commit comments