X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BAFFF475C3D for ; Fri, 25 Apr 2003 22:18:31 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id E2273474E42 for ; Fri, 25 Apr 2003 22:18:30 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3Q2IZU6009958; Fri, 25 Apr 2003 22:18:35 -0400 (EDT) To: Forest Wilkinson Cc: pgsql-sql@postgresql.org Subject: Re: create/alter/drop within transactions? In-reply-to: References: Comments: In-reply-to Forest Wilkinson message dated "Fri, 25 Apr 2003 17:58:46 -0700" Date: Fri, 25 Apr 2003 22:18:34 -0400 Message-ID: <9957.1051323514@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.5 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/386 X-Sequence-Number: 13087 Forest Wilkinson writes: > Sorry if this is a FAQ, but I didn't find a definitive and recent > answer in the list archives or the postgres docs. Do transactions > work on create / alter / drop statements? In other words, can I > choose to commit or rollback after a bunch of schema changes? Yes. AFAIR, the only non-rollback-able command in Postgres is TRUNCATE TABLE --- and that's fixed for 7.4 ;-) In any case, anything you might try to do inside a transaction block will error out if it cannot roll back. For example, in 7.3: regression=# create table foo(f1 int); CREATE TABLE regression=# begin; BEGIN regression=# truncate table foo; ERROR: TRUNCATE TABLE cannot run inside a transaction block at which point your transaction is aborted and nothing has happened. If Postgres lets you do it inside BEGIN, we can roll it back. regards, tom lane PS: the only real disadvantage of doing tons-of-schema-changes inside a BEGIN is that you will be grabbing exclusive locks on each table you change the schema of. This means you are running a nontrivial risk of deadlock against other transactions --- in which case you probably lose your work and have to do it over.