{
    "mode": "man",
    "parameter": "CREATE_PUBLICATION",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_PUBLICATION/7/json",
    "generated": "2026-10-08T09:21:28Z",
    "synopsis": "CREATE PUBLICATION name\n[ FOR ALL TABLES\n| FOR publicationobject [, ... ] ]\n[ WITH ( publicationparameter [= value] [, ... ] ) ]\nwhere publicationobject is one of:\nTABLE tableandcolumns [, ... ]\nTABLES IN SCHEMA { schemaname | CURRENTSCHEMA } [, ... ]\nand tableandcolumns is:\n[ ONLY ] tablename [ * ] [ ( columnname [, ... ] ) ] [ WHERE ( expression ) ]",
    "sections": {
        "NAME": {
            "content": "CREATEPUBLICATION - define a new publication\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE PUBLICATION name\n[ FOR ALL TABLES\n| FOR publicationobject [, ... ] ]\n[ WITH ( publicationparameter [= value] [, ... ] ) ]\n\nwhere publicationobject is one of:\n\nTABLE tableandcolumns [, ... ]\nTABLES IN SCHEMA { schemaname | CURRENTSCHEMA } [, ... ]\n\nand tableandcolumns is:\n\n[ ONLY ] tablename [ * ] [ ( columnname [, ... ] ) ] [ WHERE ( expression ) ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE PUBLICATION adds a new publication into the current database. The publication name\nmust be distinct from the name of any existing publication in the current database.\n\nA publication is essentially a group of tables whose data changes are intended to be\nreplicated through logical replication. See Section 31.1 for details about how publications\nfit into the logical replication setup.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name of the new publication.\n\nFOR TABLE\nSpecifies a list of tables to add to the publication. If ONLY is specified before the\ntable name, only that table is added to the publication. If ONLY is not specified, the\ntable and all its descendant tables (if any) are added. Optionally, * can be specified\nafter the table name to explicitly indicate that descendant tables are included. This\ndoes not apply to a partitioned table, however. The partitions of a partitioned table are\nalways implicitly considered part of the publication, so they are never explicitly added\nto the publication.\n\nIf the optional WHERE clause is specified, it defines a row filter expression. Rows for\nwhich the expression evaluates to false or null will not be published. Note that\nparentheses are required around the expression. It has no effect on TRUNCATE commands.\n\nWhen a column list is specified, only the named columns are replicated. If no column list\nis specified, all columns of the table are replicated through this publication, including\nany columns added later. It has no effect on TRUNCATE commands. See Section 31.4 for\ndetails about column lists.\n\nOnly persistent base tables and partitioned tables can be part of a publication.\nTemporary tables, unlogged tables, foreign tables, materialized views, and regular views\ncannot be part of a publication.\n\nSpecifying a column list when the publication also publishes FOR TABLES IN SCHEMA is not\nsupported.\n\nWhen a partitioned table is added to a publication, all of its existing and future\npartitions are implicitly considered to be part of the publication. So, even operations\nthat are performed directly on a partition are also published via publications that its\nancestors are part of.\n\nFOR ALL TABLES\nMarks the publication as one that replicates changes for all tables in the database,\nincluding tables created in the future.\n\nFOR TABLES IN SCHEMA\nMarks the publication as one that replicates changes for all tables in the specified list\nof schemas, including tables created in the future.\n\nSpecifying a schema when the publication also publishes a table with a column list is not\nsupported.\n\nOnly persistent base tables and partitioned tables present in the schema will be included\nas part of the publication. Temporary tables, unlogged tables, foreign tables,\nmaterialized views, and regular views from the schema will not be part of the\npublication.\n\nWhen a partitioned table is published via a schema-level publication, all of its existing\nand future partitions are implicitly considered to be part of the publication, regardless\nof whether they are from the publication schema or not. So, even operations that are\nperformed directly on a partition are also published via publications that its ancestors\nare part of.\n\nWITH ( publicationparameter [= value] [, ... ] )\nThis clause specifies optional parameters for a publication. The following parameters are\nsupported:\n\npublish (string)\nThis parameter determines which DML operations will be published by the new\npublication to the subscribers. The value is a comma-separated list of operations.\nThe allowed operations are insert, update, delete, and truncate. The default is to\npublish all actions, and so the default value for this option is 'insert, update,\ndelete, truncate'.\n\nThis parameter only affects DML operations. In particular, the initial data\nsynchronization (see Section 31.7.1) for logical replication does not take this\nparameter into account when copying existing table data.\n\npublishviapartitionroot (boolean)\nThis parameter controls how changes to a partitioned table (or any of its partitions)\nare published. When set to true, changes are published using the identity and schema\nof the root partitioned table. When set to false (the default), changes are published\nusing the identity and schema of the individual partitions where the changes actually\noccurred. Enabling this option allows the changes to be replicated into a\nnon-partitioned table or into a partitioned table whose partition structure differs\nfrom that of the publisher.\n\nThere can be a case where a subscription combines multiple publications. If a\npartitioned table is published by any subscribed publications which set\npublishviapartitionroot = true, changes on this partitioned table (or on its\npartitions) will be published using the identity and schema of this partitioned table\nrather than that of the individual partitions.\n\nThis parameter also affects how row filters and column lists are chosen for\npartitions; see below for details.\n\nIf this is enabled, TRUNCATE operations performed directly on partitions are not\nreplicated.\n\nWhen specifying a parameter of type boolean, the = value part can be omitted, which is\nequivalent to specifying TRUE.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "If FOR TABLE, FOR ALL TABLES or FOR TABLES IN SCHEMA are not specified, then the publication\nstarts out with an empty set of tables. That is useful if tables or schemas are to be added\nlater.\n\nThe creation of a publication does not start replication. It only defines a grouping and\nfiltering logic for future subscribers.\n\nTo create a publication, the invoking user must have the CREATE privilege for the current\ndatabase. (Of course, superusers bypass this check.)\n\nTo add a table to a publication, the invoking user must have ownership rights on the table.\nThe FOR ALL TABLES and FOR TABLES IN SCHEMA clauses require the invoking user to be a\nsuperuser.\n\nThe tables added to a publication that publishes UPDATE and/or DELETE operations must have\nREPLICA IDENTITY defined. Otherwise those operations will be disallowed on those tables.\n\nAny column list must include the REPLICA IDENTITY columns in order for UPDATE or DELETE\noperations to be published. There are no column list restrictions if the publication\npublishes only INSERT operations.\n\nA row filter expression (i.e., the WHERE clause) must contain only columns that are covered\nby the REPLICA IDENTITY, in order for UPDATE and DELETE operations to be published. For\npublication of INSERT operations, any column may be used in the WHERE expression. The row\nfilter allows simple expressions that don't have user-defined functions, user-defined\noperators, user-defined types, user-defined collations, non-immutable built-in functions, or\nreferences to system columns.\n\nThe row filter on a table becomes redundant if FOR TABLES IN SCHEMA is specified and the\ntable belongs to the referred schema.\n\nFor published partitioned tables, the row filter for each partition is taken from the\npublished partitioned table if the publication parameter publishviapartitionroot is true,\nor from the partition itself if it is false (the default). See Section 31.3 for details about\nrow filters. Similarly, for published partitioned tables, the column list for each partition\nis taken from the published partitioned table if the publication parameter\npublishviapartitionroot is true, or from the partition itself if it is false.\n\nFor an INSERT ... ON CONFLICT command, the publication will publish the operation that\nresults from the command. Depending on the outcome, it may be published as either INSERT or\nUPDATE, or it may not be published at all.\n\nFor a MERGE command, the publication will publish an INSERT, UPDATE, or DELETE for each row\ninserted, updated, or deleted.\n\nATTACHing a table into a partition tree whose root is published using a publication with\npublishviapartitionroot set to true does not result in the table's existing contents being\nreplicated.\n\nCOPY ... FROM commands are published as INSERT operations.\n\nDDL operations are not published.\n\nThe WHERE clause expression is executed with the role used for the replication connection.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Create a publication that publishes all changes in two tables:\n\nCREATE PUBLICATION mypublication FOR TABLE users, departments;\n\nCreate a publication that publishes all changes from active departments:\n\nCREATE PUBLICATION activedepartments FOR TABLE departments WHERE (active IS TRUE);\n\nCreate a publication that publishes all changes in all tables:\n\nCREATE PUBLICATION alltables FOR ALL TABLES;\n\nCreate a publication that only publishes INSERT operations in one table:\n\nCREATE PUBLICATION insertonly FOR TABLE mydata\nWITH (publish = 'insert');\n\nCreate a publication that publishes all changes for tables users, departments and all changes\nfor all the tables present in the schema production:\n\nCREATE PUBLICATION productionpublication FOR TABLE users, departments, TABLES IN SCHEMA production;\n\nCreate a publication that publishes all changes for all the tables present in the schemas\nmarketing and sales:\n\nCREATE PUBLICATION salespublication FOR TABLES IN SCHEMA marketing, sales;\n\nCreate a publication that publishes all changes for table users, but replicates only columns\nuserid and firstname:\n\nCREATE PUBLICATION usersfiltered FOR TABLE users (userid, firstname);\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "CREATE PUBLICATION is a PostgreSQL extension.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ALTER PUBLICATION (ALTERPUBLICATION(7)), DROP PUBLICATION (DROPPUBLICATION(7)), CREATE\nSUBSCRIPTION (CREATESUBSCRIPTION(7)), ALTER SUBSCRIPTION (ALTERSUBSCRIPTION(7))\n\nPostgreSQL 16.14                                2026                           CREATE PUBLICATION(7)",
            "subsections": []
        }
    },
    "summary": "CREATEPUBLICATION - define a new publication",
    "flags": [],
    "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 from active departments:",
        "CREATE PUBLICATION activedepartments FOR TABLE departments WHERE (active IS TRUE);",
        "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 insertonly FOR TABLE mydata",
        "WITH (publish = 'insert');",
        "Create a publication that publishes all changes for tables users, departments and all changes",
        "for all the tables present in the schema production:",
        "CREATE PUBLICATION productionpublication FOR TABLE users, departments, TABLES IN SCHEMA production;",
        "Create a publication that publishes all changes for all the tables present in the schemas",
        "marketing and sales:",
        "CREATE PUBLICATION salespublication FOR TABLES IN SCHEMA marketing, sales;",
        "Create a publication that publishes all changes for table users, but replicates only columns",
        "userid and firstname:",
        "CREATE PUBLICATION usersfiltered FOR TABLE users (userid, firstname);"
    ],
    "see_also": [
        {
            "name": "ALTERPUBLICATION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERPUBLICATION/7/json"
        },
        {
            "name": "DROPPUBLICATION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPPUBLICATION/7/json"
        },
        {
            "name": "CREATESUBSCRIPTION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATESUBSCRIPTION/7/json"
        },
        {
            "name": "ALTERSUBSCRIPTION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERSUBSCRIPTION/7/json"
        },
        {
            "name": "PUBLICATION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/PUBLICATION/7/json"
        }
    ]
}