Jump to content

Adjusting the waiting time in transaction


lightning

Recommended Posts

I created 2 sets of transactions in php with a sleep command in between. The sleep command is to simulate a transaction taking a long time.

 

Transaction1 in 1 php page:

BEGIN

Query1

sleep(100)

Query2

COMMIT;

 

Transaction2 in another php page:

BEGIN

Query1

Query2

COMMIT;

 

As soon as the Transaction 1 is executed from 1 php page, I tried to execute the Transaction2 php from another php page. Transaction 2 waited till Transaction 1 completed and then it executed. I want Transaction 2 to end after a few tries. It is because I have a cron job that might take about half an hour and therefore Transaction 2 should end after a few tries with some error messages. How is it done? Is it possible to set the number of tries or the waiting time through the Postgre SQL code?         

Link to comment
Share on other sites

  • 2 weeks later...

You can set statement_timeout to speed up failure: http://www.postgresql.org/docs/8.2/interactive/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-STATEMENT

 

Another option is to try to take an explicit lock on the resources your transaction needs with the nowait option: http://www.postgresql.org/docs/8.2/interactive/sql-lock.html

 

Deadlock detection timeout is set here: http://www.postgresql.org/docs/8.2/interactive/runtime-config-locks.html

 

But your situation is not a deadlock, so that will not affect you.  I'm just pointing it out for completeness :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.