CREATE_PUBLICATION(7pg14)
π CREATE_PUBLICATION π
okay so bestie, this is the PostgreSQL 14.24 documentation page for CREATE_PUBLICATION, and we're gonna get you fluent in it, no cap β¨
πΈ NAME πΈ
CREATE_PUBLICATION β define a new publication π
β¨ SYNOPSIS β¨
CREATE PUBLICATION name
[ FOR TABLE [ ONLY ] table_name [ * ] [, ...]
| FOR ALL TABLES ]
[ WITH ( publication_parameter [= value] [, ... ] ) ]
π¦ DESCRIPTION π¦
So CREATE PUBLICATION adds a brand-new publication into the current database. And the name? It has to be distinct from the name of any existing publication in the current database β no duplicate names, periodt. π
A publication is basically a group of tables whose data changes are meant to be replicated through logical replication. Like, that's the whole vibe of it. If you wanna see how publications fit into the logical replication setup long-form, Section 31.1 has the details, iykyk. π
π PARAMETERS π
nameβ the name of the new publication, obviously π«ΆFOR TABLEβ specifies a list of tables to add to the publication. IfONLYis written before the table name, then only that table gets added. IfONLYis not specified, the table and all its descendant tables (if any) get added too. Optionally you can slap a*after the table name to explicitly indicate that descendant tables are included. β
Heads up though: this does not apply to a partitioned table. The partitions of a partitioned table are always implicitly considered part of the publication, so they are never explicitly added to it. π
Only persistent base tables and partitioned tables can be part of a publication. Temporary tables, unlogged tables, foreign tables, materialized views, and regular views cannot be part of a publication. Not them. π
When a partitioned table is added to a publication, all of its existing and future partitions are implicitly considered to be part of the publication. So even operations performed directly on a partition are also published via publications that its ancestors are part of. It's giving family tree energy. π
FOR ALL TABLESβ marks the publication as one that replicates changes for all tables in the database, including tables created in the future πWITH ( publication_parameter [= value] [, ... ] )β this clause specifies optional parameters for a publication. The following parameters are supported:publish(string) β this parameter determines which DML operations will be published by the new publication to the subscribers. The value is a comma-separated list of operations. The allowed operations areinsert,update,delete, andtruncate. The default is to publish all actions, so the default value for this option is'insert, update, delete, truncate'. πpublish_via_partition_root(boolean) β this parameter controls how changes to a partitioned table (or any of its partitions) are published. When set totrue, changes are published using the identity and schema of the root partitioned table. When set tofalse(the default), changes are published using the identity and schema of the individual partitions where the changes actually occurred. Enabling this option allows the changes to be replicated into a non-partitioned table or into a partitioned table whose partition structure differs from that of the publisher. π§
If this is enabled, TRUNCATE operations performed directly on partitions are not replicated. Important, don't forget π
π₯ NOTES π₯
If neither FOR TABLE nor FOR ALL TABLES is specified, then the publication starts out with an empty set of tables. That's actually useful if tables are gonna be added later. π
Creating a publication does not start replication. It only defines a grouping and filtering logic for future subscribers. Like, it's the blueprint, not the build. π
To create a publication, the invoking user must have the CREATE privilege for the current database. (Of course, superusers bypass this check. main character energy π)
To add a table to a publication, the invoking user must have ownership rights on the table. And the FOR ALL TABLES clause requires the invoking user to be a superuser. β
The tables added to a publication that publishes UPDATE and/or DELETE operations must have REPLICA IDENTITY defined. Otherwise those operations will be disallowed on those tables. No identity, no updates, fr fr. π
For an INSERT ... ON CONFLICT command, the publication will publish the operation that results from the command. Depending on the outcome, it may be published as either INSERT or UPDATE, or it may not be published at all. It's giving chaotic neutral. π
ATTACHing a table into a partition tree whose root is published using a publication with publish_via_partition_root set to true does not result in the table's existing contents being replicated. Just so you know. π
COPY ... FROM commands are published as INSERT operations. π¦
DDL operations are not published. Periodt. β¨
π EXAMPLES π
Create a publication that publishes all changes in two tables:
CREATE PUBLICATION mypublication FOR TABLE users, departments;
Create a publication that publishes all changes in all tables:
CREATE PUBLICATION alltables FOR ALL TABLES;
Create a publication that only publishes INSERT operations in one table:
CREATE PUBLICATION insert_only FOR TABLE mydata
WITH (publish = 'insert');
π COMPATIBILITY π
CREATE PUBLICATION is a PostgreSQL extension. That's it, that's the whole section. π«Ά
π SEE ALSO π
ALTER PUBLICATION(ALTER_PUBLICATION(7))DROP PUBLICATION(DROP_PUBLICATION(7))CREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7))ALTER SUBSCRIPTION(ALTER_SUBSCRIPTION(7))
okay bestie you made it to the end, iconic behavior honestly π this was PostgreSQL 14.24 documentation, dated 2026, and the page you just read is CREATE_PUBLICATION(7) β go forth and publish, slay πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms