views:

291

answers:

2

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 rollback, the table goes away. It works for adding and removing columns as well. Obviously this is very nice.

We're about to make some changes to the way we deploy schema deltas that rely on this feature. Before we do, I'd like to find out how far the transactional guarantee extends, but I can't find any information on it in the documentation. I assume I'm just using the wrong search terms - my searches just go to big lists of commands which include the words 'transaction', 'create' and 'table'.

Can anyone give me some pointers to docs or discussions about transactional schema changes in Postgres? (We're using 8.2.13, although we'll be upgrading in the not too distant future.) Or just some details about statement that won't be included in the transaction?

+2  A: 

According to quick grep on docs, these commands cannot be executed in transactions:

  • cluster
  • commit prepared
  • create database
  • create tablespace
  • discard
  • drop database
  • drop tablespace
  • rollback prepared
  • vacuum
depesz
Care to share your grep command?
Stephen Denne
sure: grep 'cannot be executed inside a transaction' sql-*html
depesz
Thanks. The reindex docs have more whitespace between exactly those words.
Stephen Denne
CLUSTER can run inside a transaction block as long as you specify which tables to CLUSTER.
Magnus Hagander
+4  A: 
  • nextval and setval operations on sequences are never rolled back.
  • REINDEX DATABASE
  • REINDEX SYSTEM

There's an article about transactional DDL on the PostgreSQL Wiki

Stephen Denne