Re: Nested transaction - I am a bank ??

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: "Thapliyal, Deepak" <dthapliyal(at)soe(dot)sony(dot)com>
Cc: 'Richard Huxton' <dev(at)archonet(dot)com>, Anton(dot)Nikiforov(at)loteco(dot)ru, pgsql-general(at)postgresql(dot)org
Subject: Re: Nested transaction - I am a bank ??
Date: 2004-01-15 06:04:25
Message-ID: 40062D69.4090506@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thapliyal, Deepak wrote:
> Hi,
>
> Assume I have a bank app.. When customer withdraws $10 from his accouint I
> have to do following
> --> update account_summary table [subtract $10 from his account]
> --> update account detail_table [with other transaction details]
>
> Requirement:
> either both transactions should succeed or both transactions should
> be rolled back in case of failure.

Both actions you mentioned are not [or are unlikely to be implemented
as] two separate transactions, but a single transaction (and thus the
subject "nested transaction" has nothing to do with this.

Nested transaction are usually used in complex operations.

Save points can be used to implement nested transaction.

Since we're using a bank as example, consider a bank with 1 million
accounts. At the end of the month, it needs to calculate and post
interest for each account. The whole operation takes 10 hours. If we use
a single transaction for this, then if the machine/database crashes, the
whole unfinished transaction will be rolled back. If the db is back up,
but then fails again in the middle of this giant transaction, it will be
rolled back again. And perhaps again... and again... and thus it will
never finishes.

With save points (and nested transactions) we can save in the middle of
transaction and later rolls back to the last save point instead of
beginning the transaction all over.

--
dave

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Garamond 2004-01-15 06:09:02 embedded/"serverless" (Re: serverless postgresql)
Previous Message Joshua D. Drake 2004-01-15 06:02:19 Re: about postgres odbc on wondows