Re: How to Force Transactions to Process Serially on A Table

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Lane Van Ingen <lvaningen(at)esncc(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to Force Transactions to Process Serially on A Table
Date: 2005-12-19 14:25:13
Message-ID: Pine.LNX.4.44.0512191615510.7853-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

O Lane Van Ingen έγραψε στις Dec 19, 2005 :

> I am using PL/SQL functions on Windows 2003, version 8.0.1.
>
> I have not used explicit PostgreSQL LOCKing before, but I need some advice
> on how properly to use some explicit locking. I think that duplicate key
> violations I am now getting are the result.
>
> I want to force transactions being used to update a table to be processed on
> a first-come, first-served basis. I want my Pl/sql function to execute to
> completion on each transaction before another starts.
>
> Need some advice on how to do this. From what I can read in the docs, it
> looks like I need to solve the problem by using the following, but doing so
> gives me an SPI_execution error:
> BEGIN;
> LOCK <table> IN SHARE ROW EXCLUSIVE MODE;
> lock adns_report_hour_history in share row exclusive mode;
> INSERT INTO <table> VALUES ... - or - UPDATE <table> SET ....
> COMMIT;
> Will this make the next transaction wait until the previous transaction has
> completed? Do I need to set any config parameters?
>
> If you can include an actual code snippet in the response, it would help ...

what you want is to set the xaction isolation level.

BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
......
COMMIT;

Be prepared for serialization failures though.

>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

--
-Achilleus

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2005-12-19 14:28:10 Re: How to Force Transactions to Process Serially on A Table
Previous Message Lane Van Ingen 2005-12-19 13:46:39 Re: How to Force Transactions to Process Serially on A Table