{
    "content": [
        {
            "type": "text",
            "text": "# PREPARE_TRANSACTION(7) (man)\n\n**Summary:** PREPARETRANSACTION - prepare the current transaction for two-phase commit\n\n**Synopsis:** PREPARE TRANSACTION transactionid\n\n## Examples\n\n- `Prepare the current transaction for two-phase commit, using foobar as the transaction`\n- `identifier:`\n- `PREPARE TRANSACTION 'foobar';`\n\n## See Also\n\n- COMMITPREPARED(7)\n- ROLLBACKPREPARED(7)\n- TRANSACTION(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (17 lines)\n- **PARAMETERS** (6 lines)\n- **NOTES** (35 lines)\n- **EXAMPLES** (5 lines)\n- **COMPATIBILITY** (4 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nPREPARETRANSACTION - prepare the current transaction for two-phase commit\n\n### SYNOPSIS\n\nPREPARE TRANSACTION transactionid\n\n### DESCRIPTION\n\nPREPARE TRANSACTION prepares the current transaction for two-phase commit. After this\ncommand, the transaction is no longer associated with the current session; instead, its state\nis fully stored on disk, and there is a very high probability that it can be committed\nsuccessfully, even if a database crash occurs before the commit is requested.\n\nOnce prepared, a transaction can later be committed or rolled back with COMMIT PREPARED or\nROLLBACK PREPARED, respectively. Those commands can be issued from any session, not only the\none that executed the original transaction.\n\nFrom the point of view of the issuing session, PREPARE TRANSACTION is not unlike a ROLLBACK\ncommand: after executing it, there is no active current transaction, and the effects of the\nprepared transaction are no longer visible. (The effects will become visible again if the\ntransaction is committed.)\n\nIf the PREPARE TRANSACTION command fails for any reason, it becomes a ROLLBACK: the current\ntransaction is canceled.\n\n### PARAMETERS\n\ntransactionid\nAn arbitrary identifier that later identifies this transaction for COMMIT PREPARED or\nROLLBACK PREPARED. The identifier must be written as a string literal, and must be less\nthan 200 bytes long. It must not be the same as the identifier used for any currently\nprepared transaction.\n\n### NOTES\n\nPREPARE TRANSACTION is not intended for use in applications or interactive sessions. Its\npurpose is to allow an external transaction manager to perform atomic global transactions\nacross multiple databases or other transactional resources. Unless you're writing a\ntransaction manager, you probably shouldn't be using PREPARE TRANSACTION.\n\nThis command must be used inside a transaction block. Use BEGIN to start one.\n\nIt is not currently allowed to PREPARE a transaction that has executed any operations\ninvolving temporary tables or the session's temporary namespace, created any cursors WITH\nHOLD, or executed LISTEN, UNLISTEN, or NOTIFY. Those features are too tightly tied to the\ncurrent session to be useful in a transaction to be prepared.\n\nIf the transaction modified any run-time parameters with SET (without the LOCAL option),\nthose effects persist after PREPARE TRANSACTION, and will not be affected by any later COMMIT\nPREPARED or ROLLBACK PREPARED. Thus, in this one respect PREPARE TRANSACTION acts more like\nCOMMIT than ROLLBACK.\n\nAll currently available prepared transactions are listed in the pgpreparedxacts system\nview.\n\nCaution\nIt is unwise to leave transactions in the prepared state for a long time. This will\ninterfere with the ability of VACUUM to reclaim storage, and in extreme cases could cause\nthe database to shut down to prevent transaction ID wraparound (see Section 25.1.5). Keep\nin mind also that the transaction continues to hold whatever locks it held. The intended\nusage of the feature is that a prepared transaction will normally be committed or rolled\nback as soon as an external transaction manager has verified that other databases are\nalso prepared to commit.\n\nIf you have not set up an external transaction manager to track prepared transactions and\nensure they get closed out promptly, it is best to keep the prepared-transaction feature\ndisabled by setting maxpreparedtransactions to zero. This will prevent accidental\ncreation of prepared transactions that might then be forgotten and eventually cause\nproblems.\n\n### EXAMPLES\n\nPrepare the current transaction for two-phase commit, using foobar as the transaction\nidentifier:\n\nPREPARE TRANSACTION 'foobar';\n\n### COMPATIBILITY\n\nPREPARE TRANSACTION is a PostgreSQL extension. It is intended for use by external transaction\nmanagement systems, some of which are covered by standards (such as X/Open XA), but the SQL\nside of those systems is not standardized.\n\n### SEE ALSO\n\nCOMMIT PREPARED (COMMITPREPARED(7)), ROLLBACK PREPARED (ROLLBACKPREPARED(7))\n\n\n\nPostgreSQL 14.23                                2026                          PREPARE TRANSACTION(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "PREPARE_TRANSACTION",
        "section": "7",
        "mode": "man",
        "summary": "PREPARETRANSACTION - prepare the current transaction for two-phase commit",
        "synopsis": "PREPARE TRANSACTION transactionid",
        "flags": [],
        "examples": [
            "Prepare the current transaction for two-phase commit, using foobar as the transaction",
            "identifier:",
            "PREPARE TRANSACTION 'foobar';"
        ],
        "see_also": [
            {
                "name": "COMMITPREPARED",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/COMMITPREPARED/7/json"
            },
            {
                "name": "ROLLBACKPREPARED",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ROLLBACKPREPARED/7/json"
            },
            {
                "name": "TRANSACTION",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/TRANSACTION/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 35,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}