Thread: transactions

transactions

From
"Viorel Dragomir"
Date:
Is there any known issues regarding transactions.
I got something like:
 
begin transaction
select function1()
select into v1 function2()
if v1='ok' then commit else rollback end if
 
To notice that both functions have about 100 lines of code.
And both functions uses the same tables but in different modes.
function1 deletes && function2 inserts
 
The problem is that my web browser hangs on this query and stays that way a lot [like 30 minutes -- i forgot about it and after 30 minutes it was still trying to open the result page]
 
I hope tomorrow I'll resolv this and if is primary my fault I just shut up and say nothing.
 
regards,
vioss

Re: transactions

From
Josh Berkus
Date:
Viorel,

> The problem is that my web browser hangs on this query and stays that way a
> lot [like 30 minutes -- i forgot about it and after 30 minutes it was still
> trying to open the result page]

I think this is a problem inside one of the functions; either you have an 
endless loop, or you are doing a huge unindexed join operation or something 
similar.   Enclosing the two functions inside a transaction by itself 
shouldn't cause a time-out.

One thing that can mess things up vis-a-vis transactions:

If you have a function which does a series of large cascading updates -- that 
is, the function uses the updated table from step #2 to perform step #3, and 
step #3 to do step #4, and each update is 1000's of rows -- then execution 
can really bog down due to the lack of VACUUMing between updates.   However, 
you can't VACUUM without committing the transaction.

Just in case, I'd suggest doing a VACUUM ANALYZE right before running your big 
transaction.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco