Re: savepoints with the same name

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: pgsql-general(at)postgresql(dot)org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1(dot)0(dot)1 X-Mailing-List: pgsql-general List-Archive: <http://archives(dot)postgresql(dot)org/pgsql-general> List-Help: <mailto:majordomo(at)postgresql(dot)org?body=help> List-ID: <pgsql-general(dot)postgresql(dot)org> List-Owner: <mailto:pgsql-general-owner(at)postgresql(dot)org> List-Post: <mailto:pgsql-general(at)postgresql(dot)org> List-Subscribe: <mailto:majordomo(at)postgresql(dot)org?body=sub%20pgsql-general> List-Unsubscribe: <mailto:mhgonzalez(at)gmail(dot)com
Subject: Re: savepoints with the same name
Date: 2010-04-30 16:46:37
Message-ID: 76452bddd8edd81e1aec6dd0fdcaad42@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

> I was thinking thinking about the issue asked here, about an error in
> a query causing the whole transaction to abort,
...
> I wonder if the suggestion I ("leonbloy") gave, of adding a SAVEPOINT
> after each insert (when doing interactive work)
> is reasonable.

Not only reasonable, but already implemented inside of psql. Just type:

\set ON_ERROR_ROLLBACK on

inside your psql session, and it will automatically create a savepoint
before each command, and thus allow your transaction to continue
even if you encounter errors.

> "If you savepoint every single insert, you'll wind up begin much
> much slower..."
>
> Does that also apply when I issue a SAVEPOINT with the same name? Does
> the new savepoint release the previous and create a new
> one, or does it "move" the previous? Or it's just that a new one is
> created and the name "shadows" the previous, so that there are still N
> active savepoints in the transaction, taking up memory/resources ?

Yes, savepoints will slow things down, but probably not as much as you
are fearing. Savepoints will nest (or shadow). The ON_ERROR_ROLLBACK
feature creates the savepoint before the query, then either does a
ROLLBACK TO or a RELEASE depending on the success of the query, so there
is no build up of savepoints.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201004301245
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAkvbCVIACgkQvJuQZxSWSsi4nwCdH8xwQ3RpVlD65I239hs/eAbW
V3oAniaEv2VWFkrrhqDU9HDlCRMv1ROx
=i0P6
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Glyn Astill 2010-04-30 16:49:15 Re: pg_restore: [custom archiver] dumping a specific TOC data block out of order is not supported without ID on this input stream (fseek required)
Previous Message Tom Lane 2010-04-30 16:43:58 Re: Function to Table reference