gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

95 lines
7.8KB

  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>Chapter 62. Generic WAL Records</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="index-cost-estimation.html" title="61.6. Index Cost Estimation Functions" /><link rel="next" href="btree.html" title="Chapter 63. B-Tree Indexes" /></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">Chapter 62. Generic WAL Records</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="index-cost-estimation.html" title="61.6. Index Cost Estimation Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="internals.html" title="Part VII. Internals">Up</a></td><th width="60%" align="center">Part VII. Internals</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="btree.html" title="Chapter 63. B-Tree Indexes">Next</a></td></tr></table><hr></hr></div><div class="chapter" id="GENERIC-WAL"><div class="titlepage"><div><div><h2 class="title">Chapter 62. Generic WAL Records</h2></div></div></div><p>
  3. Although all built-in WAL-logged modules have their own types of WAL
  4. records, there is also a generic WAL record type, which describes changes
  5. to pages in a generic way. This is useful for extensions that provide
  6. custom access methods, because they cannot register their own WAL redo
  7. routines.
  8. </p><p>
  9. The API for constructing generic WAL records is defined in
  10. <code class="filename">access/generic_xlog.h</code> and implemented
  11. in <code class="filename">access/transam/generic_xlog.c</code>.
  12. </p><p>
  13. To perform a WAL-logged data update using the generic WAL record
  14. facility, follow these steps:
  15. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
  16. <code class="function">state = GenericXLogStart(relation)</code> — start
  17. construction of a generic WAL record for the given relation.
  18. </p></li><li class="listitem"><p>
  19. <code class="function">page = GenericXLogRegisterBuffer(state, buffer, flags)</code>
  20. — register a buffer to be modified within the current generic WAL
  21. record. This function returns a pointer to a temporary copy of the
  22. buffer's page, where modifications should be made. (Do not modify the
  23. buffer's contents directly.) The third argument is a bit mask of flags
  24. applicable to the operation. Currently the only such flag is
  25. <code class="literal">GENERIC_XLOG_FULL_IMAGE</code>, which indicates that a full-page
  26. image rather than a delta update should be included in the WAL record.
  27. Typically this flag would be set if the page is new or has been
  28. rewritten completely.
  29. <code class="function">GenericXLogRegisterBuffer</code> can be repeated if the
  30. WAL-logged action needs to modify multiple pages.
  31. </p></li><li class="listitem"><p>
  32. Apply modifications to the page images obtained in the previous step.
  33. </p></li><li class="listitem"><p>
  34. <code class="function">GenericXLogFinish(state)</code> — apply the changes to
  35. the buffers and emit the generic WAL record.
  36. </p></li></ol></div><p>
  37. </p><p>
  38. WAL record construction can be canceled between any of the above steps by
  39. calling <code class="function">GenericXLogAbort(state)</code>. This will discard all
  40. changes to the page image copies.
  41. </p><p>
  42. Please note the following points when using the generic WAL record
  43. facility:
  44. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  45. No direct modifications of buffers are allowed! All modifications must
  46. be done in copies acquired from <code class="function">GenericXLogRegisterBuffer()</code>.
  47. In other words, code that makes generic WAL records should never call
  48. <code class="function">BufferGetPage()</code> for itself. However, it remains the
  49. caller's responsibility to pin/unpin and lock/unlock the buffers at
  50. appropriate times. Exclusive lock must be held on each target buffer
  51. from before <code class="function">GenericXLogRegisterBuffer()</code> until after
  52. <code class="function">GenericXLogFinish()</code>.
  53. </p></li><li class="listitem"><p>
  54. Registrations of buffers (step 2) and modifications of page images
  55. (step 3) can be mixed freely, i.e., both steps may be repeated in any
  56. sequence. Keep in mind that buffers should be registered in the same
  57. order in which locks are to be obtained on them during replay.
  58. </p></li><li class="listitem"><p>
  59. The maximum number of buffers that can be registered for a generic WAL
  60. record is <code class="literal">MAX_GENERIC_XLOG_PAGES</code>. An error will be thrown
  61. if this limit is exceeded.
  62. </p></li><li class="listitem"><p>
  63. Generic WAL assumes that the pages to be modified have standard
  64. layout, and in particular that there is no useful data between
  65. <code class="structfield">pd_lower</code> and <code class="structfield">pd_upper</code>.
  66. </p></li><li class="listitem"><p>
  67. Since you are modifying copies of buffer
  68. pages, <code class="function">GenericXLogStart()</code> does not start a critical
  69. section. Thus, you can safely do memory allocation, error throwing,
  70. etc. between <code class="function">GenericXLogStart()</code> and
  71. <code class="function">GenericXLogFinish()</code>. The only actual critical section is
  72. present inside <code class="function">GenericXLogFinish()</code>. There is no need to
  73. worry about calling <code class="function">GenericXLogAbort()</code> during an error
  74. exit, either.
  75. </p></li><li class="listitem"><p>
  76. <code class="function">GenericXLogFinish()</code> takes care of marking buffers dirty
  77. and setting their LSNs. You do not need to do this explicitly.
  78. </p></li><li class="listitem"><p>
  79. For unlogged relations, everything works the same except that no
  80. actual WAL record is emitted. Thus, you typically do not need to do
  81. any explicit checks for unlogged relations.
  82. </p></li><li class="listitem"><p>
  83. The generic WAL redo function will acquire exclusive locks to buffers
  84. in the same order as they were registered. After redoing all changes,
  85. the locks will be released in the same order.
  86. </p></li><li class="listitem"><p>
  87. If <code class="literal">GENERIC_XLOG_FULL_IMAGE</code> is not specified for a
  88. registered buffer, the generic WAL record contains a delta between
  89. the old and the new page images. This delta is based on byte-by-byte
  90. comparison. This is not very compact for the case of moving data
  91. within a page, and might be improved in the future.
  92. </p></li></ul></div><p>
  93. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index-cost-estimation.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="internals.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="btree.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">61.6. Index Cost Estimation Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 63. B-Tree Indexes</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1