Limits on PostgreSQL schema changes inside transactions?

后端 未结 5 1280
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 09:59

My database background is with Oracle, so I was surprised to discover that Postgres includes schema changes in transactions - if you begin one, create a table and then rollb

5条回答
  •  [愿得一人]
    2021-01-11 11:03

    From the manual, section 13.5 (Currency Control: Caveats):

    Some DDL commands, currently only TRUNCATE and the table-rewriting forms of ALTER TABLE, are not MVCC-safe. This means that after the truncation or rewrite commits, the table will appear empty to concurrent transactions, if they are using a snapshot taken before the DDL command committed. This will only be an issue for a transaction that did not access the table in question before the DDL command started […]

    Regarding table rewriting the ALTER TABLE section mentions

    Adding a column with a DEFAULT clause or changing the type of an existing column will require the entire table […] to be rewritten. As an exception when changing the type of an existing column, if the USING clause does not change the column contents and the old type is either binary coercible to the new type or an unconstrained domain over the new type, a table rewrite is not needed […] Adding or removing a system oid column also requires rewriting the entire table.

提交回复
热议问题