{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_PUBLICATION (man)\n\n## NAME\n\nCREATEPUBLICATION - define a new publication\n\n## SYNOPSIS\n\nCREATE PUBLICATION name\n[ FOR TABLE [ ONLY ] tablename [ * ] [, ...]\n| FOR ALL TABLES ]\n[ WITH ( publicationparameter [= value] [, ... ] ) ]\n\n## DESCRIPTION\n\nCREATE 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\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_PUBLICATION",
        "section": "",
        "mode": "man",
        "summary": "CREATEPUBLICATION - define a new publication",
        "synopsis": "CREATE PUBLICATION name\n[ FOR TABLE [ ONLY ] tablename [ * ] [, ...]\n| FOR ALL TABLES ]\n[ WITH ( publicationparameter [= value] [, ... ] ) ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "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 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');"
        ],
        "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"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 48,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CREATEPUBLICATION - define a new publication\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "CREATE PUBLICATION name\n[ FOR TABLE [ ONLY ] tablename [ * ] [, ...]\n| FOR ALL TABLES ]\n[ WITH ( publicationparameter [= value] [, ... ] ) ]\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\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\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\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\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\nIf this is enabled, TRUNCATE operations performed directly on partitions are not\nreplicated.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "If neither FOR TABLE nor FOR ALL TABLES is specified, then the publication starts out with an\nempty set of tables. That is useful if tables are to be added later.\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 clause requires the invoking user to be a superuser.\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\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\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",
                "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 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",
                "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\n\n\nPostgreSQL 14.23                                2026                           CREATE PUBLICATION(7)",
                "subsections": []
            }
        }
    }
}