pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed25P02, current transaction is aborted, commands ignored until end of transaction block
15+ messages / 6 participants
[nested] [flat]
* 25P02, current transaction is aborted, commands ignored until end of transaction block
@ 2006-04-02 05:01 babu_moshay <babu_moshay@indiatimes.com>
0 siblings, 2 replies; 15+ messages in thread
From: babu_moshay @ 2006-04-02 05:01 UTC (permalink / raw)
To: pgsql-jdbc
Deal all,
I am trying to port my application from MySql to PostgreSQL 8.X. It seems PostgreSQL does not give full control to programmer even when they have opted to handle the transaction themselves by setting AUTOCOMMIT=FALSE in code.
Scenario:
1.Several records are to be inserted in different tables as a result of taking an order via web form. This activity must be atomic i.e it must succeed or fail completely.
2. Autocommit is set to off before an anonymous transaction is started in JDBC.
3.In one of the inserts we must ignore the failure due to duplicate rows i.e Error state 23505 and continue with remainder set of inserts. Presence of duplicate rows will not be treated as an error condition in this context and system must function normally without aborting the whole transaction (This is what PostgreSQL is doing currently after first failure I get 25P02 and all other inserts are ignored completely). I get following error:
org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
Technical details:
I don't think this is specific to hardware/software version I am currently using but giving here for the sake of completeness:
PostgreSQL version tried : 8.1.3 and 8.0, 8.0.1
JDBC: 8.2dev-501.jdbc3, 8.0-315.jdbc3, 8.1-404.jdbc3
JDK: 1.4 and 1.5
OS: Windows XP
Case:
The general expectation is that when a programmer is setting autocommit explicitly to off then they want to be in control of the transactions and 'THEY' should decided when to rollback or commit instead of others. This is the case with Oracle, SQL Server and MySQL and I think this is a fair expectation. I am sure this is fairly common scenario with people who do frequent backend coding.
I went through archives as it seems this was not a problem in version 8.0.1, unfortunately I have tried with 3 different 8.x.x versions available and similarly for JDBC drivers and the problem/condition still exists.
By looking at the error code 25P02, I feel this may not be treated as problem/error by PostgreSQL community. What is the work-around in such event?
In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
Any help/suggestion much appreciated!!!
Best regards,
Amaresh Wakkar
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 06:41 Oliver Jowett <oliver@opencloud.com>
parent: babu_moshay <babu_moshay@indiatimes.com>
1 sibling, 0 replies; 15+ messages in thread
From: Oliver Jowett @ 2006-04-02 06:41 UTC (permalink / raw)
To: babu_moshay <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
babu_moshay wrote:
> In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
Create a savepoint before the possibly-failing query. If the query fails
in the way you were expecting, roll back to the savepoint and continue.
-O
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored until end of transaction block
@ 2006-04-02 08:58 Regász Imre <linimi@gmail.com>
parent: babu_moshay <babu_moshay@indiatimes.com>
1 sibling, 0 replies; 15+ messages in thread
From: Regász Imre @ 2006-04-02 08:58 UTC (permalink / raw)
To: babu_moshay <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
You need use SAVEPOINT in transaction:
do {
String savepointName = "any string"+class.hasCode();
Savepoint savePoint = conn.setSavepoint(savepointName);
try {
stmt.execute();
success = true;
} catch (SQLException sqle) {
conn.rollback(savePoint);
}
} while (!success);
http://www.postgresql.org/docs/8.1/interactive/sql-savepoint.html
http://www.postgresql.org/docs/8.1/interactive/sql-rollback-to.html
On 4/2/06, babu_moshay <babu_moshay@indiatimes.com> wrote:
> Deal all,
> I am trying to port my application from MySql to PostgreSQL 8.X. It seems PostgreSQL does not give full control to programmer even when they have opted to handle the transaction themselves by setting AUTOCOMMIT=FALSE in code.
>
>
> Scenario:
> 1.Several records are to be inserted in different tables as a result of taking an order via web form. This activity must be atomic i.e it must succeed or fail completely.
>
> 2. Autocommit is set to off before an anonymous transaction is started in JDBC.
>
> 3.In one of the inserts we must ignore the failure due to duplicate rows i.e Error state 23505 and continue with remainder set of inserts. Presence of duplicate rows will not be treated as an error condition in this context and system must function normally without aborting the whole transaction (This is what PostgreSQL is doing currently after first failure I get 25P02 and all other inserts are ignored completely). I get following error:
>
> org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
>
> Technical details:
> I don't think this is specific to hardware/software version I am currently using but giving here for the sake of completeness:
> PostgreSQL version tried : 8.1.3 and 8.0, 8.0.1
> JDBC: 8.2dev-501.jdbc3, 8.0-315.jdbc3, 8.1-404.jdbc3
> JDK: 1.4 and 1.5
> OS: Windows XP
>
> Case:
> The general expectation is that when a programmer is setting autocommit explicitly to off then they want to be in control of the transactions and 'THEY' should decided when to rollback or commit instead of others. This is the case with Oracle, SQL Server and MySQL and I think this is a fair expectation. I am sure this is fairly common scenario with people who do frequent backend coding.
>
> I went through archives as it seems this was not a problem in version 8.0.1, unfortunately I have tried with 3 different 8.x.x versions available and similarly for JDBC drivers and the problem/condition still exists.
>
> By looking at the error code 25P02, I feel this may not be treated as problem/error by PostgreSQL community. What is the work-around in such event?
>
> In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
>
> Any help/suggestion much appreciated!!!
>
> Best regards,
> Amaresh Wakkar
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 12:08 Amaresh Wakkar <babu_moshay@indiatimes.com>
0 siblings, 2 replies; 15+ messages in thread
From: Amaresh Wakkar @ 2006-04-02 12:08 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; babu_moshay <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
Thanks!!
The code works fine after I added savepoints around "Okay,even if fails" statement.
What is the idea behind taking this route(i.e all statements ignored till end of block) though? Is there any archive thread discussing this? In this particular case, the autocommit is off and the statement has failed so there is no risk of changes being made permanent(presumable PG would rollback at database level the changed buffers etc.,) unless the commit() method is invoked. Why then explicit rollback is needed? Is it not best if it is left to programmer to handle this in exception handling code?
I just had to add two lines of savepoints but I added them for making my code work rather than using them for some application logic purpose.
Cheers!!
Amaresh Wakkar
"Oliver Jowett" wrote:
babu_moshay wrote:
> In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
Create a savepoint before the possibly-failing query. If the query fails
in the way you were expecting, roll back to the savepoint and continue.
-O
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Indiatimes Email now powered by APIC Advantage. Help!
" " Help
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored until end of transaction block
@ 2006-04-02 12:10 Amaresh Wakkar <babu_moshay@indiatimes.com>
0 siblings, 0 replies; 15+ messages in thread
From: Amaresh Wakkar @ 2006-04-02 12:10 UTC (permalink / raw)
To: ISO-8859-1QRegE1sz_Imre <linimi@gmail.com>; babu_moshay <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
Thanks!!!
It works fine now. Savepoints were saviours :-)
Amaresh Wakkar
"=?ISO-8859-1?Q?Reg=E1sz_Imre?=" wrote:
You need use SAVEPOINT in transaction:
do {
String savepointName = "any string"+class.hasCode();
Savepoint savePoint = conn.setSavepoint(savepointName);
try {
stmt.execute();
success = true;
} catch (SQLException sqle) {
conn.rollback(savePoint);
}
} while (!success);
http://www.postgresql.org/docs/8.1/interactive/sql-savepoint.html
http://www.postgresql.org/docs/8.1/interactive/sql-rollback-to.html
On 4/2/06, babu_moshay wrote:
> Deal all,
> I am trying to port my application from MySql to PostgreSQL 8.X. It seems PostgreSQL does not give full control to programmer even when they have opted to handle the transaction themselves by setting AUTOCOMMIT=FALSE in code.
>
>
> Scenario:
> 1.Several records are to be inserted in different tables as a result of taking an order via web form. This activity must be atomic i.e it must succeed or fail completely.
>
> 2. Autocommit is set to off before an anonymous transaction is started in JDBC.
>
> 3.In one of the inserts we must ignore the failure due to duplicate rows i.e Error state 23505 and continue with remainder set of inserts. Presence of duplicate rows will not be treated as an error condition in this context and system must function normally without aborting the whole transaction (This is what PostgreSQL is doing currently after first failure I get 25P02 and all other inserts are ignored completely). I get following error:
>
> org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
>
> Technical details:
> I don't think this is specific to hardware/software version I am currently using but giving here for the sake of completeness:
> PostgreSQL version tried : 8.1.3 and 8.0, 8.0.1
> JDBC: 8.2dev-501.jdbc3, 8.0-315.jdbc3, 8.1-404.jdbc3
> JDK: 1.4 and 1.5
> OS: Windows XP
>
> Case:
> The general expectation is that when a programmer is setting autocommit explicitly to off then they want to be in control of the transactions and 'THEY' should decided when to rollback or commit instead of others. This is the case with Oracle, SQL Server and MySQL and I think this is a fair expectation. I am sure this is fairly common scenario with people who do frequent backend coding.
>
> I went through archives as it seems this was not a problem in version 8.0.1, unfortunately I have tried with 3 different 8.x.x versions available and similarly for JDBC drivers and the problem/condition still exists.
>
> By looking at the error code 25P02, I feel this may not be treated as problem/error by PostgreSQL community. What is the work-around in such event?
>
> In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
>
> Any help/suggestion much appreciated!!!
>
> Best regards,
> Amaresh Wakkar
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
Indiatimes Email now powered by APIC Advantage. Help!
" " Help
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 12:36 Dave Cramer <pg@fastcrypt.com>
parent: Amaresh Wakkar <babu_moshay@indiatimes.com>
1 sibling, 1 reply; 15+ messages in thread
From: Dave Cramer @ 2006-04-02 12:36 UTC (permalink / raw)
To: Amaresh Wakkar <babu_moshay@indiatimes.com>; +Cc: Oliver Jowett <oliver@opencloud.com>; pgsql-jdbc
Well,
The concept of an atomic transaction means that it must either
succeed completely or fail completely. PostgreSQL does this.
Dave
On 2-Apr-06, at 8:08 AM, Amaresh Wakkar wrote:
> Thanks!!
>
> The code works fine after I added savepoints around "Okay,even if
> fails" statement.
>
> What is the idea behind taking this route(i.e all statements
> ignored till end of block) though? Is there any archive thread
> discussing this? In this particular case, the autocommit is off and
> the statement has failed so there is no risk of changes being made
> permanent(presumable PG would rollback at database level the
> changed buffers etc.,) unless the commit() method is invoked. Why
> then explicit rollback is needed? Is it not best if it is left to
> programmer to handle this in exception handling code?
>
> I just had to add two lines of savepoints but I added them for
> making my code work rather than using them for some application
> logic purpose.
>
> Cheers!!
>
> Amaresh Wakkar
>
>
>
> "Oliver Jowett" wrote:
>
>
> babu_moshay wrote:
>
> > In my opinion, if there are reasons to throw 25P02 and abort
> transaction unilaterally, then there are also good reasons not to
> abort it and let programmer take the decision. A switching
> mechanism would have been ideal.
>
> Create a savepoint before the possibly-failing query. If the query
> fails
> in the way you were expecting, roll back to the savepoint and
> continue.
>
> -O
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
> Indiatimes Email now powered by APIC Advantage. Help!
> Help
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 12:55 Oliver Jowett <oliver@opencloud.com>
parent: Amaresh Wakkar <babu_moshay@indiatimes.com>
1 sibling, 0 replies; 15+ messages in thread
From: Oliver Jowett @ 2006-04-02 12:55 UTC (permalink / raw)
To: Amaresh Wakkar <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
Amaresh Wakkar wrote:
> Thanks!!
>
> The code works fine after I added savepoints around "Okay,even if
> fails" statement.
>
> What is the idea behind taking this route(i.e all statements ignored
> till end of block) though? Is there any archive thread discussing this?
There should be tons, it comes up regularly whenever someone ports an
app from Oracle..
> In this particular case, the autocommit is off and the statement has
> failed so there is no risk of changes being made permanent(presumable PG
> would rollback at database level the changed buffers etc.,) unless the
> commit() method is invoked. Why then explicit rollback is needed? Is it
> not best if it is left to programmer to handle this in exception
> handling code?
There are arguments both ways. To some extent it depends on who you
trust more to get the code right: the DB developer (once) or the app
developer (once per query).
-O
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 14:54 Amaresh Wakkar <babu_moshay@indiatimes.com>
0 siblings, 0 replies; 15+ messages in thread
From: Amaresh Wakkar @ 2006-04-02 14:54 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; +Cc: Oliver Jowett <oliver@opencloud.com>; pgsql-jdbc
Sure,
So
try{
1. Set autocommit off at the beginning of transaction
2.Do all bulky DML operations including statements which may fail e.g unique constraint violation, but do not amount to an transaction failure(for specific errors like 23505) from functional point of view.
3.
} catch(Exceptions){
Rollback fully for all other exceptions which were not chosen to be ignored.
}
**Must** an atomic transaction use savepoints to recover from acceptable errors? There is no stopping in between, we either succeed or fail fully. Ideally,in current scenario there is no need to rollback to a savepoint , statement just needed to be ignored and next statement executed. If I am not wrong then savepoints are best utilised when we do not want to lose the heavy dbms activity carried out in executing SQL statements just because one simple DML statement threw error. The focus is on successfully **committing** changes to DB and in that process sometimes we have to rollback to a savepoint and then try an alternative route to successful completion of block of statements. In my code I am not rolling back to a savepoint for any of these reasons, I am rolling back to avoid getting 25P02 and losing transaction completely.
Cheers,
Amaresh
Amaresh
"Dave Cramer" wrote:
Well,
The concept of an atomic transaction means that it must either succeed completely or fail completely. PostgreSQL does this.?
Dave
On 2-Apr-06, at 8:08 AM, Amaresh Wakkar wrote:
Thanks!!
The code?works fine after I added savepoints around??"Okay,even if fails" statement.
What is the idea behind taking this route(i.e all statements ignored till end of block) though? Is there any archive thread discussing this? In this particular case, the autocommit is off and the statement has failed so there is no risk of changes being made permanent(presumable PG would rollback at database level the changed buffers etc.,) unless the commit() method is invoked. Why then explicit rollback is needed? Is it not best if it is left to programmer to handle this in exception handling code?
I just had to add two lines of savepoints but I added them for making my code work rather than using them for some?application logic?purpose.
Cheers!!
Amaresh Wakkar
"Oliver Jowett" wrote:
babu_moshay wrote:
> In my opinion, if there are reasons to throw 25P02 and abort transaction unilaterally, then there are also good reasons not to abort it and let programmer take the decision. A switching mechanism would have been ideal.
Create a savepoint before the possibly-failing query. If the query fails
in the way you were expecting, roll back to the savepoint and continue.
-O
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Indiatimes Email now powered by APIC Advantage. Help!
" target=_blank" order="0" b!=""Help
Indiatimes Email now powered by APIC Advantage. Help!
" " Help
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-02 15:03 Amaresh Wakkar <babu_moshay@indiatimes.com>
0 siblings, 0 replies; 15+ messages in thread
From: Amaresh Wakkar @ 2006-04-02 15:03 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; +Cc: pgsql-jdbc
"Oliver Jowett" wrote:
Amaresh Wakkar wrote:
> Thanks!!
>
> The code works fine after I added savepoints around "Okay,even if
> fails" statement.
>
> What is the idea behind taking this route(i.e all statements ignored
> till end of block) though? Is there any archive thread discussing this?
There should be tons, it comes up regularly whenever someone ports an
app from Oracle..
>>>>Ok, Thanks!!
> In this particular case, the autocommit is off and the statement has
> failed so there is no risk of changes being made permanent(presumable PG
> would rollback at database level the changed buffers etc.,) unless the
> commit() method is invoked. Why then explicit rollback is needed? Is it
> not best if it is left to programmer to handle this in exception
> handling code?
There are arguments both ways. To some extent it depends on who you
trust more to get the code right: the DB developer (once) or the app
developer (once per query).
>>>>> Once a statement fails, to continue further, savepoints need to be used so that postgreSQL implicit rollback is not done. If implicit rollback by postgreSQL is done, I will get 25P02 next time I try some query so I have lost the transaction anyway unless there is a way to recover from 25P02.
Amaresh
-O
Indiatimes Email now powered by APIC Advantage. Help!
" " Help
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 00:44 Philip Yarra <philip@utiba.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 2 replies; 15+ messages in thread
From: Philip Yarra @ 2006-04-03 00:44 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Amaresh Wakkar <babu_moshay@indiatimes.com>; Oliver Jowett <oliver@opencloud.com>; pgsql-jdbc
I always assumed what Dave just said, but porting from Oracle & Sybase
to PostgreSQL, we ran into exactly the same issue - we also solved it
with savepoints. However, I threw together the attached sample app to
test *precisely* what ends up in the database when auto-commit is off.
For the impatient, it sets auto-commit off, and tries to insert 3 rows.
The first succeeds, the second violates a unique index, so fails, and
the third is issued after the second, so should also fail. We ignore the
exceptions, then commit. The results puzzle me somewhat:
Oracle 10g: first and third inserts are in the DB
Sybase ASE 12.5: first and third inserts are in the DB
PostgreSQL 8.1.1: first insert is in the DB
Now I agree that Oracle and Sybase have this kind of wrong - the third
insert should not succeed. However, reading Dave's statement "The
concept of an atomic transaction means that it must either succeed
completely or fail completely. PostgreSQL does this." makes me wonder if
the first insert should be in the DB either? Or am I making some sort of
mistake here? From my results, it looks more like PostgreSQL's behaviour
is "Everything up the first failure can be committed" which isn't quite
the same thing as an indivisible unit of work that succeeds or fails
completely.
Anyway, I'd be curious about people's feedback on this, as it has sort
of nagged at me since I tested it.
Regards, Philip.
Dave Cramer wrote:
> Well,
>
> The concept of an atomic transaction means that it must either succeed
> completely or fail completely. PostgreSQL does this.
>
> Dave
> On 2-Apr-06, at 8:08 AM, Amaresh Wakkar wrote:
>
>> Thanks!!
>>
>> The code works fine after I added savepoints around "Okay,even if
>> fails" statement.
>>
>> What is the idea behind taking this route(i.e all statements ignored
>> till end of block) though? Is there any archive thread discussing
>> this? In this particular case, the autocommit is off and the statement
>> has failed so there is no risk of changes being made
>> permanent(presumable PG would rollback at database level the changed
>> buffers etc.,) unless the commit() method is invoked. Why then
>> explicit rollback is needed? Is it not best if it is left to
>> programmer to handle this in exception handling code?
>>
>> I just had to add two lines of savepoints but I added them for making
>> my code work rather than using them for some application logic purpose.
>>
>> Cheers!!
>>
>> Amaresh Wakkar
>>
>>
>>
>> */"Oliver Jowett"/*// wrote:
>>
>>
>> babu_moshay wrote:
>>
>> > In my opinion, if there are reasons to throw 25P02 and abort
>> transaction unilaterally, then there are also good reasons not to
>> abort it and let programmer take the decision. A switching
>> mechanism would have been ideal.
>>
>> Create a savepoint before the possibly-failing query. If the query
>> fails
>> in the way you were expecting, roll back to the savepoint and
>> continue.
>>
>> -O
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 3: Have you checked our extensive FAQ?
>>
>> http://www.postgresql.org/docs/faq
>>
>>
>> ------------------------------------------------------------------------
>> Indiatimes Email now powered by *APIC Advantage*. Help!
>> <http://infinite.indiatimes.com/apic/;
>> My Presence
>> <http://imaround.indiatimes.com/IMaround/presencefr.mss?userid=<!--User
>> //-->>Help <http://infinite.indiatimes.com/apic/userpage.html;
>> ------------------------------------------------------------------------
>>
>> <http://www.indiatimes.chikka.com;
>
>
>
> ----------------
> This message has been scanned for viruses and
> dangerous content by *the Utiba Mail Server* <http://www.utiba.com/;,
> and is
> believed to be clean.
Attachments:
main.java (text/x-java, 3.7K) download
import java.sql.*;
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;
class main
{
static Connection conn = null;
static Properties prop = null;
public static void main(String [] args)
{
try
{
if(args.length > 0) prop = loadProp(args[0]);
else usage();
String url = prop.getProperty("url");
String user = prop.getProperty("user");
String pass = prop.getProperty("pass");
String driver = prop.getProperty("driver");
Class.forName(driver);
conn = DriverManager.getConnection(url,user,pass);
conn.setAutoCommit(false);
createTable();
executeInsert(1,"expected to succeed");
executeInsert(1,"expected to fail");
executeInsert(2,"expected to fail");
conn.commit();
dumpTable("tempextest");
conn.commit();
dropTable();
conn.commit();
conn.close();
log("all done");
}
catch(Exception ex)
{
log(ex);
System.exit(1);
}
}
static void executeInsert(int id, String msg)
{
log("executeInsert, id[" + id + "] msg[" + msg + "]");
PreparedStatement stmt = null;
try{
stmt = conn.prepareStatement("INSERT INTO tempextest(id,msg) VALUES(?,?)");
stmt.setInt(1,id);
stmt.setString(2,msg);
stmt.executeUpdate();
conn.commit();
} catch (SQLException sqlex) {
log(sqlex);
closeStatement(stmt);
}
}
static void createTable()
{
log("Creating table tempextest");
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("CREATE TABLE tempextest(id INT PRIMARY KEY, msg VARCHAR(20))");
stmt.executeUpdate();
} catch (SQLException sqlex) {
log(sqlex);
log("error creating table tempextest, can't proceed");
closeStatement(stmt);
System.exit(1);
}
log("Table tempextest created");
}
static void dropTable()
{
log("Dropping table tempextest");
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("DROP TABLE tempextest");
stmt.executeUpdate();
} catch (SQLException sqlex) {
log(sqlex);
closeStatement(stmt);
}
log("Table tempextest dropped");
}
static Properties loadProp(String fileName)
{
try{
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(fileName);
prop.load(fis);
return prop;
} catch (Exception ex) {
log("exception loading properties: " + ex);
usage();
}
return null;
}
static void usage()
{
System.err.println("Usage: java main propfile");
System.exit(1);
}
static void log(String msg)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
System.out.println(sdf.format(new java.util.Date()) + ":" + msg);
}
static void log(Exception ex)
{
log(ex.toString());
ex.printStackTrace();
}
static void log(Object o)
{
log(o.toString());
}
static void closeStatement(Statement st)
{
try{
st.close();
}catch(SQLException sqlex) {
log(sqlex);
}
}
static void dumpTable(String tableName)
{
log("dumping contents of table " + tableName);
try{
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM " + tableName);
ResultSetMetaData rsmd = rs.getMetaData();
for(int i = 1; i <= rsmd.getColumnCount(); i++)
{
System.out.print(rsmd.getColumnName(i) + "\t");
if(i != rsmd.getColumnCount())
System.out.print("|");
}
System.out.println("\n---------------------------------------------------------------------");
while(rs.next())
{
for(int i = 1; i <= rsmd.getColumnCount(); i++)
{
System.out.print(rs.getString(i) + "\t");
if(i != rsmd.getColumnCount())
System.out.print("|");
}
System.out.println();
}
rs.close();
s.close();
}catch(SQLException sqlex) {
System.err.println(sqlex);
}
}
}
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 00:56 Oliver Jowett <oliver@opencloud.com>
parent: Philip Yarra <philip@utiba.com>
1 sibling, 1 reply; 15+ messages in thread
From: Oliver Jowett @ 2006-04-03 00:56 UTC (permalink / raw)
To: Philip Yarra <philip@utiba.com>; +Cc: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; pgsql-jdbc
Philip Yarra wrote:
> I always assumed what Dave just said, but porting from Oracle & Sybase
> to PostgreSQL, we ran into exactly the same issue - we also solved it
> with savepoints. However, I threw together the attached sample app to
> test *precisely* what ends up in the database when auto-commit is off.
> For the impatient, it sets auto-commit off, and tries to insert 3 rows.
> The first succeeds, the second violates a unique index, so fails, and
> the third is issued after the second, so should also fail. We ignore the
> exceptions, then commit. The results puzzle me somewhat:
>
> Oracle 10g: first and third inserts are in the DB
> Sybase ASE 12.5: first and third inserts are in the DB
> PostgreSQL 8.1.1: first insert is in the DB
>
> Now I agree that Oracle and Sybase have this kind of wrong - the third
> insert should not succeed. However, reading Dave's statement "The
> concept of an atomic transaction means that it must either succeed
> completely or fail completely. PostgreSQL does this." makes me wonder if
> the first insert should be in the DB either? Or am I making some sort of
> mistake here? From my results, it looks more like PostgreSQL's behaviour
> is "Everything up the first failure can be committed" which isn't quite
> the same thing as an indivisible unit of work that succeeds or fails
> completely.
Can we see your testcase? The behaviour you describe is not what I'd expect.
-O
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 00:57 Oliver Jowett <oliver@opencloud.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 1 reply; 15+ messages in thread
From: Oliver Jowett @ 2006-04-03 00:57 UTC (permalink / raw)
To: Philip Yarra <philip@utiba.com>; +Cc: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; pgsql-jdbc
Oliver Jowett wrote:
> Can we see your testcase? The behaviour you describe is not what I'd
> expect.
And 2 seconds after hitting send I see it's attached to your mail .. sorry!
-O
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 01:03 Philip Yarra <philip@utiba.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 15+ messages in thread
From: Philip Yarra @ 2006-04-03 01:03 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; pgsql-jdbc
Oliver Jowett wrote:
> And 2 seconds after hitting send I see it's attached to your mail .. sorry!
Been there, done that before :-)
I have access to Sybase and Oracle DBs here. If you want, I can also
send output from running this test case against all 3 DB flavours I
mentioned originally. From your comments, though, I'm betting I've
goofed my test case somehow, and I just can't see it.
Regards, Philip.
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 01:03 Oliver Jowett <oliver@opencloud.com>
parent: Philip Yarra <philip@utiba.com>
1 sibling, 1 reply; 15+ messages in thread
From: Oliver Jowett @ 2006-04-03 01:03 UTC (permalink / raw)
To: Philip Yarra <philip@utiba.com>; +Cc: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; pgsql-jdbc
Philip Yarra wrote:
> I always assumed what Dave just said, but porting from Oracle & Sybase
> to PostgreSQL, we ran into exactly the same issue - we also solved it
> with savepoints. However, I threw together the attached sample app to
> test *precisely* what ends up in the database when auto-commit is off.
> For the impatient, it sets auto-commit off, and tries to insert 3 rows.
> The first succeeds, the second violates a unique index, so fails, and
> the third is issued after the second, so should also fail. We ignore the
> exceptions, then commit. The results puzzle me somewhat:
> static void executeInsert(int id, String msg)
> {
> log("executeInsert, id[" + id + "] msg[" + msg + "]");
> PreparedStatement stmt = null;
> try{
> stmt = conn.prepareStatement("INSERT INTO tempextest(id,msg) VALUES(?,?)");
> stmt.setInt(1,id);
> stmt.setString(2,msg);
> stmt.executeUpdate();
> conn.commit();
> } catch (SQLException sqlex) {
> log(sqlex);
> closeStatement(stmt);
> }
> }
Um, your testcase is committing after every insert, not once at the end.
So the behaviour you see sounds correct.
-O
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: 25P02, current transaction is aborted, commands ignored
@ 2006-04-03 01:16 Philip Yarra <philip@utiba.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 15+ messages in thread
From: Philip Yarra @ 2006-04-03 01:16 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Dave Cramer <pg@fastcrypt.com>; Amaresh Wakkar <babu_moshay@indiatimes.com>; pgsql-jdbc
Oliver Jowett wrote:
> Um, your testcase is committing after every insert, not once at the end.
> So the behaviour you see sounds correct.
*sigh* so it is. Sorry about that, Oliver.
With the bogus commit removed, yes, PostgreSQL does exactly what it is
supposed to.
For the record: Sybase and Oracle still happily end up with inserts one
and three in the DB.
Regards, Philip.
^ permalink raw reply [nested|flat] 15+ messages in thread
end of thread, other threads:[~2006-04-03 01:16 UTC | newest]
Thread overview: 15+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-02 05:01 25P02, current transaction is aborted, commands ignored until end of transaction block babu_moshay <babu_moshay@indiatimes.com>
2006-04-02 06:41 ` Re: 25P02, current transaction is aborted, commands ignored Oliver Jowett <oliver@opencloud.com>
2006-04-02 08:58 ` Regász Imre <linimi@gmail.com>
2006-04-02 12:08 Re: 25P02, current transaction is aborted, commands ignored Amaresh Wakkar <babu_moshay@indiatimes.com>
2006-04-02 12:36 ` Re: 25P02, current transaction is aborted, commands ignored Dave Cramer <pg@fastcrypt.com>
2006-04-03 00:44 ` Re: 25P02, current transaction is aborted, commands ignored Philip Yarra <philip@utiba.com>
2006-04-03 00:56 ` Re: 25P02, current transaction is aborted, commands ignored Oliver Jowett <oliver@opencloud.com>
2006-04-03 00:57 ` Re: 25P02, current transaction is aborted, commands ignored Oliver Jowett <oliver@opencloud.com>
2006-04-03 01:03 ` Re: 25P02, current transaction is aborted, commands ignored Philip Yarra <philip@utiba.com>
2006-04-03 01:03 ` Re: 25P02, current transaction is aborted, commands ignored Oliver Jowett <oliver@opencloud.com>
2006-04-03 01:16 ` Re: 25P02, current transaction is aborted, commands ignored Philip Yarra <philip@utiba.com>
2006-04-02 12:55 ` Re: 25P02, current transaction is aborted, commands ignored Oliver Jowett <oliver@opencloud.com>
2006-04-02 12:10 Re: 25P02, current transaction is aborted, commands ignored until end of transaction block Amaresh Wakkar <babu_moshay@indiatimes.com>
2006-04-02 14:54 Re: 25P02, current transaction is aborted, commands ignored Amaresh Wakkar <babu_moshay@indiatimes.com>
2006-04-02 15:03 Re: 25P02, current transaction is aborted, commands ignored Amaresh Wakkar <babu_moshay@indiatimes.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox