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>ALTER 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 Vsnapshot" /><link rel="prev" href="sql-alterprocedure.html" title="ALTER PROCEDURE" /><link rel="next" href="sql-alterrole.html" title="ALTER ROLE" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ALTER PUBLICATION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterprocedure.html" title="ALTER 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 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-alterrole.html" title="ALTER ROLE">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERPUBLICATION"><div class="titlepage"></div><a id="id-1.9.3.25.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER PUBLICATION</span></h2><p>ALTER PUBLICATION — change the definition of a publication</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> ADD <em class="replaceable"><code>publication_object</code></em> [, ...]
4 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> SET <em class="replaceable"><code>publication_object</code></em> [, ...]
5 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> DROP <em class="replaceable"><code>publication_object</code></em> [, ...]
6 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> SET ( <em class="replaceable"><code>publication_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] )
7 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
8 ALTER PUBLICATION <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>
10 <span class="phrase">where <em class="replaceable"><code>publication_object</code></em> is one of:</span>
12 TABLE [ ONLY ] <em class="replaceable"><code>table_name</code></em> [ * ] [ ( <em class="replaceable"><code>column_name</code></em> [, ... ] ) ] [ WHERE ( <em class="replaceable"><code>expression</code></em> ) ] [, ... ]
13 TABLES IN SCHEMA { <em class="replaceable"><code>schema_name</code></em> | CURRENT_SCHEMA } [, ... ]
14 </pre></div><div class="refsect1" id="id-1.9.3.25.5"><h2>Description</h2><p>
15 The command <code class="command">ALTER PUBLICATION</code> can change the attributes
18 The first three variants change which tables/schemas are part of the
19 publication. The <code class="literal">SET</code> clause will replace the list of
20 tables/schemas in the publication with the specified list; the existing
21 tables/schemas that were present in the publication will be removed. The
22 <code class="literal">ADD</code> and <code class="literal">DROP</code> clauses will add and
23 remove one or more tables/schemas from the publication. Note that adding
24 tables/schemas to a publication that is already subscribed to will require an
25 <a class="link" href="sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-REFRESH-PUBLICATION">
26 <code class="literal">ALTER SUBSCRIPTION ... REFRESH PUBLICATION</code></a> action on the
27 subscribing side in order to become effective. Note also that
28 <code class="literal">DROP TABLES IN SCHEMA</code> will not drop any schema tables
29 that were specified using
30 <a class="link" href="sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-TABLE"><code class="literal">FOR TABLE</code></a>/
31 <code class="literal">ADD TABLE</code>, and the combination of <code class="literal">DROP</code>
32 with a <code class="literal">WHERE</code> clause is not allowed.
34 The fourth variant of this command listed in the synopsis can change
35 all of the publication properties specified in
36 <a class="xref" href="sql-createpublication.html" title="CREATE PUBLICATION"><span class="refentrytitle">CREATE PUBLICATION</span></a>. Properties not mentioned in the
37 command retain their previous settings.
39 The remaining variants change the owner and the name of the publication.
41 You must own the publication to use <code class="command">ALTER PUBLICATION</code>.
42 Adding a table to a publication additionally requires owning that table.
43 The <code class="literal">ADD TABLES IN SCHEMA</code> and
44 <code class="literal">SET TABLES IN SCHEMA</code> to a publication requires the
45 invoking user to be a superuser.
46 To alter the owner, you must be able to <code class="literal">SET ROLE</code> to the
47 new owning role, and that role must have <code class="literal">CREATE</code>
48 privilege on the database.
49 Also, the new owner of a
50 <a class="link" href="sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES"><code class="literal">FOR ALL TABLES</code></a>
51 or <a class="link" href="sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-TABLES-IN-SCHEMA"><code class="literal">FOR TABLES IN SCHEMA</code></a>
52 publication must be a superuser. However, a superuser can
53 change the ownership of a publication regardless of these restrictions.
55 Adding/Setting any schema when the publication also publishes a table with a
56 column list, and vice versa is not supported.
57 </p></div><div class="refsect1" id="id-1.9.3.25.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>
58 The name of an existing publication whose definition is to be altered.
59 </p></dd><dt><span class="term"><em class="replaceable"><code>table_name</code></em></span></dt><dd><p>
60 Name of an existing table. If <code class="literal">ONLY</code> is specified before the
61 table name, only that table is affected. If <code class="literal">ONLY</code> is not
62 specified, the table and all its descendant tables (if any) are
63 affected. Optionally, <code class="literal">*</code> can be specified after the table
64 name to explicitly indicate that descendant tables are included.
66 Optionally, a column list can be specified. See <a class="xref" href="sql-createpublication.html" title="CREATE PUBLICATION"><span class="refentrytitle">CREATE PUBLICATION</span></a> for details. Note that a subscription
67 having several publications in which the same table has been published
68 with different column lists is not supported. See
69 <a class="xref" href="logical-replication-col-lists.html#LOGICAL-REPLICATION-COL-LIST-COMBINING" title="Warning: Combining Column Lists from Multiple Publications">Warning: Combining Column Lists from Multiple Publications</a> for details of
70 potential problems when altering column lists.
72 If the optional <code class="literal">WHERE</code> clause is specified, rows for
73 which the <em class="replaceable"><code>expression</code></em>
74 evaluates to false or null will not be published. Note that parentheses
75 are required around the expression. The
76 <em class="replaceable"><code>expression</code></em> is evaluated with
77 the role used for the replication connection.
78 </p></dd><dt><span class="term"><em class="replaceable"><code>schema_name</code></em></span></dt><dd><p>
79 Name of an existing schema.
80 </p></dd><dt><span class="term"><code class="literal">SET ( <em class="replaceable"><code>publication_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] )</code></span></dt><dd><p>
81 This clause alters publication parameters originally set by
82 <a class="xref" href="sql-createpublication.html" title="CREATE PUBLICATION"><span class="refentrytitle">CREATE PUBLICATION</span></a>. See there for more information.
83 </p><div class="caution"><h3 class="title">Caution</h3><p>
84 Altering the <code class="literal">publish_via_partition_root</code> parameter can
85 lead to data loss or duplication at the subscriber because it changes
86 the identity and schema of the published tables. Note this happens only
87 when a partition root table is specified as the replication target.
89 This problem can be avoided by refraining from modifying partition leaf
90 tables after the <code class="command">ALTER PUBLICATION ... SET</code> until the
91 <a class="link" href="sql-altersubscription.html" title="ALTER SUBSCRIPTION"><code class="command">ALTER SUBSCRIPTION ... REFRESH PUBLICATION</code></a>
92 is executed and by only refreshing using the <code class="literal">copy_data = off</code>
94 </p></div></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>
95 The user name of the new owner of the publication.
96 </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
97 The new name for the publication.
98 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.25.7"><h2>Examples</h2><p>
99 Change the publication to publish only deletes and updates:
100 </p><pre class="programlisting">
101 ALTER PUBLICATION noinsert SET (publish = 'update, delete');
104 Add some tables to the publication:
105 </p><pre class="programlisting">
106 ALTER PUBLICATION mypublication ADD TABLE users (user_id, firstname), departments;
108 Change the set of columns published for a table:
109 </p><pre class="programlisting">
110 ALTER PUBLICATION mypublication SET TABLE users (user_id, firstname, lastname), TABLE departments;
112 Add schemas <code class="structname">marketing</code> and
113 <code class="structname">sales</code> to the publication
114 <code class="structname">sales_publication</code>:
115 </p><pre class="programlisting">
116 ALTER PUBLICATION sales_publication ADD TABLES IN SCHEMA marketing, sales;
119 Add tables <code class="structname">users</code>,
120 <code class="structname">departments</code> and schema
121 <code class="structname">production</code> to the publication
122 <code class="structname">production_publication</code>:
123 </p><pre class="programlisting">
124 ALTER PUBLICATION production_publication ADD TABLE users, departments, TABLES IN SCHEMA production;
125 </pre></div><div class="refsect1" id="id-1.9.3.25.8"><h2>Compatibility</h2><p>
126 <code class="command">ALTER PUBLICATION</code> is a <span class="productname">PostgreSQL</span>
128 </p></div><div class="refsect1" id="id-1.9.3.25.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createpublication.html" title="CREATE PUBLICATION"><span class="refentrytitle">CREATE PUBLICATION</span></a>, <a class="xref" href="sql-droppublication.html" title="DROP PUBLICATION"><span class="refentrytitle">DROP PUBLICATION</span></a>, <a class="xref" href="sql-createsubscription.html" title="CREATE SUBSCRIPTION"><span class="refentrytitle">CREATE SUBSCRIPTION</span></a>, <a class="xref" href="sql-altersubscription.html" title="ALTER SUBSCRIPTION"><span class="refentrytitle">ALTER SUBSCRIPTION</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-alterprocedure.html" title="ALTER PROCEDURE">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-alterrole.html" title="ALTER ROLE">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER PROCEDURE </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER ROLE</td></tr></table></div></body></html>