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

99 lines
8.5KB

  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>CREATE PUBLICATION</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="sql-createprocedure.html" title="CREATE PROCEDURE" /><link rel="next" href="sql-createrole.html" title="CREATE ROLE" /></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">CREATE PUBLICATION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createprocedure.html" title="CREATE PROCEDURE">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</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="sql-createrole.html" title="CREATE ROLE">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-CREATEPUBLICATION"><div class="titlepage"></div><a id="id-1.9.3.77.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE PUBLICATION</span></h2><p>CREATE PUBLICATION — define a new publication</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. CREATE PUBLICATION <em class="replaceable"><code>name</code></em>
  4. [ FOR TABLE [ ONLY ] <em class="replaceable"><code>table_name</code></em> [ * ] [, ...]
  5. | FOR ALL TABLES ]
  6. [ WITH ( <em class="replaceable"><code>publication_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] ) ]
  7. </pre></div><div class="refsect1" id="id-1.9.3.77.5"><h2>Description</h2><p>
  8. <code class="command">CREATE PUBLICATION</code> adds a new publication
  9. into the current database. The publication name must be distinct from
  10. the name of any existing publication in the current database.
  11. </p><p>
  12. A publication is essentially a group of tables whose data changes are
  13. intended to be replicated through logical replication. See
  14. <a class="xref" href="logical-replication-publication.html" title="30.1. Publication">Section 30.1</a> for details about how
  15. publications fit into the logical replication setup.
  16. </p></div><div class="refsect1" id="id-1.9.3.77.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
  17. The name of the new publication.
  18. </p></dd><dt><span class="term"><code class="literal">FOR TABLE</code></span></dt><dd><p>
  19. Specifies a list of tables to add to the publication. If
  20. <code class="literal">ONLY</code> is specified before the table name, only
  21. that table is added to the publication. If <code class="literal">ONLY</code> is not
  22. specified, the table and all its descendant tables (if any) are added.
  23. Optionally, <code class="literal">*</code> can be specified after the table name to
  24. explicitly indicate that descendant tables are included.
  25. </p><p>
  26. Only persistent base tables can be part of a publication. Temporary
  27. tables, unlogged tables, foreign tables, materialized views, regular
  28. views, and partitioned tables cannot be part of a publication. To
  29. replicate a partitioned table, add the individual partitions to the
  30. publication.
  31. </p></dd><dt><span class="term"><code class="literal">FOR ALL TABLES</code></span></dt><dd><p>
  32. Marks the publication as one that replicates changes for all tables in
  33. the database, including tables created in the future.
  34. </p></dd><dt><span class="term"><code class="literal">WITH ( <em class="replaceable"><code>publication_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] )</code></span></dt><dd><p>
  35. This clause specifies optional parameters for a publication. The
  36. following parameters are supported:
  37. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">publish</code> (<code class="type">string</code>)</span></dt><dd><p>
  38. This parameter determines which DML operations will be published by
  39. the new publication to the subscribers. The value is
  40. comma-separated list of operations. The allowed operations are
  41. <code class="literal">insert</code>, <code class="literal">update</code>,
  42. <code class="literal">delete</code>, and <code class="literal">truncate</code>.
  43. The default is to publish all actions,
  44. and so the default value for this option is
  45. <code class="literal">'insert, update, delete, truncate'</code>.
  46. </p></dd></dl></div><p>
  47. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.77.7"><h2>Notes</h2><p>
  48. If neither <code class="literal">FOR TABLE</code> nor <code class="literal">FOR ALL
  49. TABLES</code> is specified, then the publication starts out with an
  50. empty set of tables. That is useful if tables are to be added later.
  51. </p><p>
  52. The creation of a publication does not start replication. It only defines
  53. a grouping and filtering logic for future subscribers.
  54. </p><p>
  55. To create a publication, the invoking user must have the
  56. <code class="literal">CREATE</code> privilege for the current database.
  57. (Of course, superusers bypass this check.)
  58. </p><p>
  59. To add a table to a publication, the invoking user must have ownership
  60. rights on the table. The <code class="command">FOR ALL TABLES</code> clause requires
  61. the invoking user to be a superuser.
  62. </p><p>
  63. The tables added to a publication that publishes <code class="command">UPDATE</code>
  64. and/or <code class="command">DELETE</code> operations must have
  65. <code class="literal">REPLICA IDENTITY</code> defined. Otherwise those operations will be
  66. disallowed on those tables.
  67. </p><p>
  68. For an <code class="command">INSERT ... ON CONFLICT</code> command, the publication will
  69. publish the operation that actually results from the command. So depending
  70. of the outcome, it may be published as either <code class="command">INSERT</code> or
  71. <code class="command">UPDATE</code>, or it may not be published at all.
  72. </p><p>
  73. <code class="command">COPY ... FROM</code> commands are published
  74. as <code class="command">INSERT</code> operations.
  75. </p><p>
  76. <acronym class="acronym">DDL</acronym> operations are not published.
  77. </p></div><div class="refsect1" id="id-1.9.3.77.8"><h2>Examples</h2><p>
  78. Create a publication that publishes all changes in two tables:
  79. </p><pre class="programlisting">
  80. CREATE PUBLICATION mypublication FOR TABLE users, departments;
  81. </pre><p>
  82. </p><p>
  83. Create a publication that publishes all changes in all tables:
  84. </p><pre class="programlisting">
  85. CREATE PUBLICATION alltables FOR ALL TABLES;
  86. </pre><p>
  87. </p><p>
  88. Create a publication that only publishes <code class="command">INSERT</code>
  89. operations in one table:
  90. </p><pre class="programlisting">
  91. CREATE PUBLICATION insert_only FOR TABLE mydata
  92. WITH (publish = 'insert');
  93. </pre></div><div class="refsect1" id="id-1.9.3.77.9"><h2>Compatibility</h2><p>
  94. <code class="command">CREATE PUBLICATION</code> is a <span class="productname">PostgreSQL</span>
  95. extension.
  96. </p></div><div class="refsect1" id="id-1.9.3.77.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-alterpublication.html" title="ALTER PUBLICATION"><span class="refentrytitle">ALTER PUBLICATION</span></a>, <a class="xref" href="sql-droppublication.html" title="DROP PUBLICATION"><span class="refentrytitle">DROP PUBLICATION</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createprocedure.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createrole.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE PROCEDURE </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> CREATE ROLE</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1