gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
8.7KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>48.2. Logical Decoding Concepts</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="logicaldecoding-example.html" title="48.1. Logical Decoding Examples" /><link rel="next" href="logicaldecoding-walsender.html" title="48.3. Streaming Replication Protocol Interface" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">48.2. Logical Decoding Concepts</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="logicaldecoding-example.html" title="48.1. Logical Decoding Examples">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="logicaldecoding.html" title="Chapter 48. Logical Decoding">Up</a></td><th width="60%" align="center">Chapter 48. Logical Decoding</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="logicaldecoding-walsender.html" title="48.3. Streaming Replication Protocol Interface">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LOGICALDECODING-EXPLANATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">48.2. Logical Decoding Concepts</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="logicaldecoding-explanation.html#id-1.8.14.8.2">48.2.1. Logical Decoding</a></span></dt><dt><span class="sect2"><a href="logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS">48.2.2. Replication Slots</a></span></dt><dt><span class="sect2"><a href="logicaldecoding-explanation.html#id-1.8.14.8.4">48.2.3. Output Plugins</a></span></dt><dt><span class="sect2"><a href="logicaldecoding-explanation.html#id-1.8.14.8.5">48.2.4. Exported Snapshots</a></span></dt></dl></div><div class="sect2" id="id-1.8.14.8.2"><div class="titlepage"><div><div><h3 class="title">48.2.1. Logical Decoding</h3></div></div></div><a id="id-1.8.14.8.2.2" class="indexterm"></a><p>
  3. Logical decoding is the process of extracting all persistent changes
  4. to a database's tables into a coherent, easy to understand format which
  5. can be interpreted without detailed knowledge of the database's internal
  6. state.
  7. </p><p>
  8. In <span class="productname">PostgreSQL</span>, logical decoding is implemented
  9. by decoding the contents of the <a class="link" href="wal.html" title="Chapter 29. Reliability and the Write-Ahead Log">write-ahead
  10. log</a>, which describe changes on a storage level, into an
  11. application-specific form such as a stream of tuples or SQL statements.
  12. </p></div><div class="sect2" id="LOGICALDECODING-REPLICATION-SLOTS"><div class="titlepage"><div><div><h3 class="title">48.2.2. Replication Slots</h3></div></div></div><a id="id-1.8.14.8.3.2" class="indexterm"></a><p>
  13. In the context of logical replication, a slot represents a stream of
  14. changes that can be replayed to a client in the order they were made on
  15. the origin server. Each slot streams a sequence of changes from a single
  16. database.
  17. </p><div class="note"><h3 class="title">Note</h3><p><span class="productname">PostgreSQL</span> also has streaming replication slots
  18. (see <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="26.2.5. Streaming Replication">Section 26.2.5</a>), but they are used somewhat
  19. differently there.
  20. </p></div><p>
  21. A replication slot has an identifier that is unique across all databases
  22. in a <span class="productname">PostgreSQL</span> cluster. Slots persist
  23. independently of the connection using them and are crash-safe.
  24. </p><p>
  25. A logical slot will emit each change just once in normal operation.
  26. The current position of each slot is persisted only at checkpoint, so in
  27. the case of a crash the slot may return to an earlier LSN, which will
  28. then cause recent changes to be resent when the server restarts.
  29. Logical decoding clients are responsible for avoiding ill effects from
  30. handling the same message more than once. Clients may wish to record
  31. the last LSN they saw when decoding and skip over any repeated data or
  32. (when using the replication protocol) request that decoding start from
  33. that LSN rather than letting the server determine the start point.
  34. The Replication Progress Tracking feature is designed for this purpose,
  35. refer to <a class="link" href="replication-origins.html" title="Chapter 49. Replication Progress Tracking">replication origins</a>.
  36. </p><p>
  37. Multiple independent slots may exist for a single database. Each slot has
  38. its own state, allowing different consumers to receive changes from
  39. different points in the database change stream. For most applications, a
  40. separate slot will be required for each consumer.
  41. </p><p>
  42. A logical replication slot knows nothing about the state of the
  43. receiver(s). It's even possible to have multiple different receivers using
  44. the same slot at different times; they'll just get the changes following
  45. on from when the last receiver stopped consuming them. Only one receiver
  46. may consume changes from a slot at any given time.
  47. </p><div class="caution"><h3 class="title">Caution</h3><p>
  48. Replication slots persist across crashes and know nothing about the state
  49. of their consumer(s). They will prevent removal of required resources
  50. even when there is no connection using them. This consumes storage
  51. because neither required WAL nor required rows from the system catalogs
  52. can be removed by <code class="command">VACUUM</code> as long as they are required by a replication
  53. slot. In extreme cases this could cause the database to shut down to prevent
  54. transaction ID wraparound (see <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-WRAPAROUND" title="24.1.5. Preventing Transaction ID Wraparound Failures">Section 24.1.5</a>).
  55. So if a slot is no longer required it should be dropped.
  56. </p></div></div><div class="sect2" id="id-1.8.14.8.4"><div class="titlepage"><div><div><h3 class="title">48.2.3. Output Plugins</h3></div></div></div><p>
  57. Output plugins transform the data from the write-ahead log's internal
  58. representation into the format the consumer of a replication slot desires.
  59. </p></div><div class="sect2" id="id-1.8.14.8.5"><div class="titlepage"><div><div><h3 class="title">48.2.4. Exported Snapshots</h3></div></div></div><p>
  60. When a new replication slot is created using the streaming replication
  61. interface (see <a class="xref" href="protocol-replication.html#PROTOCOL-REPLICATION-CREATE-SLOT">CREATE_REPLICATION_SLOT</a>), a
  62. snapshot is exported
  63. (see <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION" title="9.26.5. Snapshot Synchronization Functions">Section 9.26.5</a>), which will show
  64. exactly the state of the database after which all changes will be
  65. included in the change stream. This can be used to create a new replica by
  66. using <a class="link" href="sql-set-transaction.html" title="SET TRANSACTION"><code class="literal">SET TRANSACTION
  67. SNAPSHOT</code></a> to read the state of the database at the moment
  68. the slot was created. This transaction can then be used to dump the
  69. database's state at that point in time, which afterwards can be updated
  70. using the slot's contents without losing any changes.
  71. </p><p>
  72. Creation of a snapshot is not always possible. In particular, it will
  73. fail when connected to a hot standby. Applications that do not require
  74. snapshot export may suppress it with the <code class="literal">NOEXPORT_SNAPSHOT</code>
  75. option.
  76. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="logicaldecoding-example.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="logicaldecoding.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="logicaldecoding-walsender.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">48.1. Logical Decoding Examples </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 48.3. Streaming Replication Protocol Interface</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1