pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
problem with transactions
12+ messages / 6 participants
[nested] [flat]

* problem with transactions
@ 2004-05-10 12:00  pginfo <pginfo@t1.unisoftbg.com>
  0 siblings, 3 replies; 12+ messages in thread

From: pginfo @ 2004-05-10 12:00 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

We are using pg 7.4.2 + jdbc to connect to jboss.

It looks that pg have problems with transactions and jdbc.

My example:

Connection con = ... I get connection to my db.

con.setAutoCommit(false);    // begin transaction

// do some inserts

con.rollback(); // rollback

After this code all is working very well.
All inserts are rollbacked and so on.

And now the second example:

Connection con = ... I get connection to my db.

con.setAutoCommit(false);    // begin transaction

// do some inserts

con.rollback(); // rollback
con.setAutoCommit(true);    // set autocommit. We are using connection 
pool and will to have clear connection.

For my supprice the last example do not rollback any inserts !
I do not see nothink bad in this code, and also it is working perfect on 
oracle + jdbc and also MSSQL + jdbc.

Pls., can some one check the situation and post the result.

I tryed to insert sole sllep for 5 sec. before the last 
con.setAutoCommit(true); , but it do not help.

Is it bug into the jdbc or pg ?

I tested it also with pg 7.4.1 and 7.4. and I have the same problem.

regards,
ivan.




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 14:08  Oliver Jowett <oliver@opencloud.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  2 siblings, 0 replies; 12+ messages in thread

From: Oliver Jowett @ 2004-05-10 14:08 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: pgsql-jdbc

pginfo wrote:
> Hi,
> 
> We are using pg 7.4.2 + jdbc to connect to jboss.
> 
> It looks that pg have problems with transactions and jdbc.
> 
> My example:
> 
> Connection con = ... I get connection to my db.
> 
> con.setAutoCommit(false);    // begin transaction
> 
> // do some inserts
> 
> con.rollback(); // rollback
> 
> After this code all is working very well.
> All inserts are rollbacked and so on.
> 
> And now the second example:
> 
> Connection con = ... I get connection to my db.
> 
> con.setAutoCommit(false);    // begin transaction
> 
> // do some inserts
> 
> con.rollback(); // rollback
> con.setAutoCommit(true);    // set autocommit. We are using connection 
> pool and will to have clear connection.
> 
> For my supprice the last example do not rollback any inserts !
> I do not see nothink bad in this code, and also it is working perfect on 
> oracle + jdbc and also MSSQL + jdbc.
> 
> Pls., can some one check the situation and post the result.

All I can guess from the above is that there is a bug in your connection 
pool implementation, in jboss itself, or in the way you're using 
transactions within jboss. Does jboss want you to hook into its 
transaction manager rather than manage your own transactions? Needing to 
reset autocommit when handing the connection back to the pool seems 
suspicious, shouldn't the pool deal with that itself?

One possibility is that if something (jboss? connection pool?) is 
intercepting the rollback() call before it reaches the JDBC driver, then 
the subsequent setAutoCommit() will cause the inserts to be committed 
(setAutoCommit() does an implicit commit() -- see the JDBC javadoc).

Either way it seems unlikely that rollback() is broken in the current 
JDBC driver -- it's working just fine here.

Can you provide a selfcontained testcase that demonstrates the problem? 
You may want to turn on statement logging on the server (log_statement = 
true) to see exactly what statements the JDBC driver is sending.

Also, exactly which version of the JDBC driver are you using -- the one 
supplied with 7.4.2? Does using a more recent driver from 
jdbc.postgresql.org change the behaviour?

-O



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 14:13  Kris Jurka <books@ejurka.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  2 siblings, 0 replies; 12+ messages in thread

From: Kris Jurka @ 2004-05-10 14:13 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: pgsql-jdbc



On Mon, 10 May 2004, pginfo wrote:

> Hi,
> 
> We are using pg 7.4.2 + jdbc to connect to jboss.
> 
> Connection con = ... I get connection to my db.
> con.setAutoCommit(false);    // begin transaction
> // do some inserts
> con.rollback(); // rollback
> con.setAutoCommit(true);    // set autocommit. We are using connection 
> pool and will to have clear connection.
> 
> For my supprice the last example do not rollback any inserts !

I find that very hard to believe.  The attached file shows the expected 
behavior for me.  If it fails for you or you can modify it to fail, I 
would be very interested.

Kris Jurka

Attachments:

TransactionTest2.java (text/plain, 1.2K) download import java.sql.*; public class TransactionTest2 { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5750/jurka","jurka",""); Statement stmt = conn.createStatement(); stmt.executeUpdate("CREATE TEMP TABLE tt (a int)"); stmt.executeUpdate("INSERT INTO tt VALUES (3)"); stmt.close(); printRowCount(conn, "Initial"); conn.setAutoCommit(false); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tt VALUES (?)"); for (int i=0; i<10; i++) { pstmt.setInt(1,i); pstmt.executeUpdate(); } pstmt.close(); printRowCount(conn, "After Inserts"); conn.rollback(); printRowCount(conn, "After Rollback"); conn.setAutoCommit(true); printRowCount(conn, "After AutoCommit"); conn.close(); } private static void printRowCount(Connection conn, String label) throws SQLException { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM tt"); rs.next(); System.err.println(label + " Row Count: " + rs.getInt(1)); rs.close(); stmt.close(); } }
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 15:14  pginfo <pginfo@t1.unisoftbg.com>
  parent: Barry Lind <blind@xythos.com>
  0 siblings, 2 replies; 12+ messages in thread

From: pginfo @ 2004-05-10 15:14 UTC (permalink / raw)
  To: Barry Lind <blind@xythos.com>; +Cc: pgsql-jdbc

Barry Lind wrote:

> I would suggest that you turn on sql statement logging on your 
> database server and see exactly what the jdbc driver is sending to the 
> server.  I suspect this information will help you track down the problem.
>
> thanks,
> --Barry
>
>
> pginfo wrote:
>
>> Hi,
>>
>> We are using pg 7.4.2 + jdbc to connect to jboss.
>>
>> It looks that pg have problems with transactions and jdbc.
>>
>> My example:
>>
>> Connection con = ... I get connection to my db.
>>
>> con.setAutoCommit(false);    // begin transaction
>>
>> // do some inserts
>>
>> con.rollback(); // rollback
>>
>> After this code all is working very well.
>> All inserts are rollbacked and so on.
>>
>> And now the second example:
>>
>> Connection con = ... I get connection to my db.
>>
>> con.setAutoCommit(false);    // begin transaction
>>
>> // do some inserts
>>
>> con.rollback(); // rollback
>> con.setAutoCommit(true);    // set autocommit. We are using 
>> connection pool and will to have clear connection.
>>
>> For my supprice the last example do not rollback any inserts !
>> I do not see nothink bad in this code, and also it is working perfect 
>> on oracle + jdbc and also MSSQL + jdbc.
>>
>> Pls., can some one check the situation and post the result.
>>
>> I tryed to insert sole sllep for 5 sec. before the last 
>> con.setAutoCommit(true); , but it do not help.
>>
>> Is it bug into the jdbc or pg ?
>>
>> I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
>>
>> regards,
>> ivan.
>>
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 8: explain analyze is your friend
>
>
>
>
>
How to do it?
Will I need to recompile pg or I can set it up into conf-file?




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 15:50  Barry Lind <blind@xythos.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  2 siblings, 1 reply; 12+ messages in thread

From: Barry Lind @ 2004-05-10 15:50 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: pgsql-jdbc

I would suggest that you turn on sql statement logging on your database 
server and see exactly what the jdbc driver is sending to the server.  I 
suspect this information will help you track down the problem.

thanks,
--Barry


pginfo wrote:
> Hi,
> 
> We are using pg 7.4.2 + jdbc to connect to jboss.
> 
> It looks that pg have problems with transactions and jdbc.
> 
> My example:
> 
> Connection con = ... I get connection to my db.
> 
> con.setAutoCommit(false);    // begin transaction
> 
> // do some inserts
> 
> con.rollback(); // rollback
> 
> After this code all is working very well.
> All inserts are rollbacked and so on.
> 
> And now the second example:
> 
> Connection con = ... I get connection to my db.
> 
> con.setAutoCommit(false);    // begin transaction
> 
> // do some inserts
> 
> con.rollback(); // rollback
> con.setAutoCommit(true);    // set autocommit. We are using connection 
> pool and will to have clear connection.
> 
> For my supprice the last example do not rollback any inserts !
> I do not see nothink bad in this code, and also it is working perfect on 
> oracle + jdbc and also MSSQL + jdbc.
> 
> Pls., can some one check the situation and post the result.
> 
> I tryed to insert sole sllep for 5 sec. before the last 
> con.setAutoCommit(true); , but it do not help.
> 
> Is it bug into the jdbc or pg ?
> 
> I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
> 
> regards,
> ivan.
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 16:33  pginfo <pginfo@t1.unisoftbg.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 12+ messages in thread

From: pginfo @ 2004-05-10 16:33 UTC (permalink / raw)
  To: pg@fastcrypt.com; +Cc: Barry Lind <blind@xythos.com>; pgsql-jdbc

Dave Cramer wrote:

>It is in the conf file, and then you need to restart postgres
>
>DAve
>On Mon, 2004-05-10 at 11:14, pginfo wrote:
>  
>
>>Barry Lind wrote:
>>
>>    
>>
>>>I would suggest that you turn on sql statement logging on your 
>>>database server and see exactly what the jdbc driver is sending to the 
>>>server.  I suspect this information will help you track down the problem.
>>>
>>>thanks,
>>>--Barry
>>>
>>>
>>>pginfo wrote:
>>>
>>>      
>>>
>>>>Hi,
>>>>
>>>>We are using pg 7.4.2 + jdbc to connect to jboss.
>>>>
>>>>It looks that pg have problems with transactions and jdbc.
>>>>
>>>>My example:
>>>>
>>>>Connection con = ... I get connection to my db.
>>>>
>>>>con.setAutoCommit(false);    // begin transaction
>>>>
>>>>// do some inserts
>>>>
>>>>con.rollback(); // rollback
>>>>
>>>>After this code all is working very well.
>>>>All inserts are rollbacked and so on.
>>>>
>>>>And now the second example:
>>>>
>>>>Connection con = ... I get connection to my db.
>>>>
>>>>con.setAutoCommit(false);    // begin transaction
>>>>
>>>>// do some inserts
>>>>
>>>>con.rollback(); // rollback
>>>>con.setAutoCommit(true);    // set autocommit. We are using 
>>>>connection pool and will to have clear connection.
>>>>
>>>>For my supprice the last example do not rollback any inserts !
>>>>I do not see nothink bad in this code, and also it is working perfect 
>>>>on oracle + jdbc and also MSSQL + jdbc.
>>>>
>>>>Pls., can some one check the situation and post the result.
>>>>
>>>>I tryed to insert sole sllep for 5 sec. before the last 
>>>>con.setAutoCommit(true); , but it do not help.
>>>>
>>>>Is it bug into the jdbc or pg ?
>>>>
>>>>I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
>>>>
>>>>regards,
>>>>ivan.
>>>>
>>>>
>>>>---------------------------(end of broadcast)---------------------------
>>>>TIP 8: explain analyze is your friend
>>>>        
>>>>
>>>
>>>
>>>
>>>      
>>>
>>How to do it?
>>Will I need to recompile pg or I can set it up into conf-file?
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 4: Don't 'kill -9' the postmaster
>>
>>
>>
>>!DSPAM:409fb0d2240831803312480!
>>
>>
>>    
>>
Hi,

I am ready with first results from my test.
I send a part of my pg log with comments:

I make getConnection();
LOG:  statement: rollback; begin;

I only check the count to be sure that the command is executed in place.
LOG:  statement: select count(*) from  tt

conn.setAutoCommit(false);
LOG:  statement: begin;

Test the value from my table. It is as expected.
LOG:  statement: select count(*) from  tt

Insert new row.
LOG:  statement: insert into tt values (1)

Check the new  count. It is ok.
LOG:  statement: select count(*) from  tt

!!! I make conn.rollbac(), but do not find any command in my pg LOG ! It 
is big mistake. I think by jboss, but I am not sure for now.

I check the value after rollback and it is wrong.
LOG:  statement: select count(*) from  tt

I close the connection. Jboss sends rollback now! I do not know why for now.
LOG:  statement: rollback; begin;


Any idea how to search the problem?
Of course I can  close connection instead rollback, but it is not the 
best solution.

regards,
ivan.



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 16:43  Barry Lind <blind@xythos.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  1 sibling, 0 replies; 12+ messages in thread

From: Barry Lind @ 2004-05-10 16:43 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: pgsql-jdbc

It is a setting in the postgresql.conf file.  I believe Oliver in his 
response to your original question mentioned the specific parameter.

--Barry

pginfo wrote:
> Barry Lind wrote:
> 
>> I would suggest that you turn on sql statement logging on your 
>> database server and see exactly what the jdbc driver is sending to the 
>> server.  I suspect this information will help you track down the problem.
>>
>> thanks,
>> --Barry
>>
>>
>> pginfo wrote:
>>
>>> Hi,
>>>
>>> We are using pg 7.4.2 + jdbc to connect to jboss.
>>>
>>> It looks that pg have problems with transactions and jdbc.
>>>
>>> My example:
>>>
>>> Connection con = ... I get connection to my db.
>>>
>>> con.setAutoCommit(false);    // begin transaction
>>>
>>> // do some inserts
>>>
>>> con.rollback(); // rollback
>>>
>>> After this code all is working very well.
>>> All inserts are rollbacked and so on.
>>>
>>> And now the second example:
>>>
>>> Connection con = ... I get connection to my db.
>>>
>>> con.setAutoCommit(false);    // begin transaction
>>>
>>> // do some inserts
>>>
>>> con.rollback(); // rollback
>>> con.setAutoCommit(true);    // set autocommit. We are using 
>>> connection pool and will to have clear connection.
>>>
>>> For my supprice the last example do not rollback any inserts !
>>> I do not see nothink bad in this code, and also it is working perfect 
>>> on oracle + jdbc and also MSSQL + jdbc.
>>>
>>> Pls., can some one check the situation and post the result.
>>>
>>> I tryed to insert sole sllep for 5 sec. before the last 
>>> con.setAutoCommit(true); , but it do not help.
>>>
>>> Is it bug into the jdbc or pg ?
>>>
>>> I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
>>>
>>> regards,
>>> ivan.
>>>
>>>
>>> ---------------------------(end of broadcast)---------------------------
>>> TIP 8: explain analyze is your friend
>>
>>
>>
>>
>>
>>
> How to do it?
> Will I need to recompile pg or I can set it up into conf-file?
> 




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 16:49  Dave Cramer <pg@fastcrypt.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  1 sibling, 1 reply; 12+ messages in thread

From: Dave Cramer @ 2004-05-10 16:49 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: Barry Lind <blind@xythos.com>; pgsql-jdbc

It is in the conf file, and then you need to restart postgres

DAve
On Mon, 2004-05-10 at 11:14, pginfo wrote:
> Barry Lind wrote:
> 
> > I would suggest that you turn on sql statement logging on your 
> > database server and see exactly what the jdbc driver is sending to the 
> > server.  I suspect this information will help you track down the problem.
> >
> > thanks,
> > --Barry
> >
> >
> > pginfo wrote:
> >
> >> Hi,
> >>
> >> We are using pg 7.4.2 + jdbc to connect to jboss.
> >>
> >> It looks that pg have problems with transactions and jdbc.
> >>
> >> My example:
> >>
> >> Connection con = ... I get connection to my db.
> >>
> >> con.setAutoCommit(false);    // begin transaction
> >>
> >> // do some inserts
> >>
> >> con.rollback(); // rollback
> >>
> >> After this code all is working very well.
> >> All inserts are rollbacked and so on.
> >>
> >> And now the second example:
> >>
> >> Connection con = ... I get connection to my db.
> >>
> >> con.setAutoCommit(false);    // begin transaction
> >>
> >> // do some inserts
> >>
> >> con.rollback(); // rollback
> >> con.setAutoCommit(true);    // set autocommit. We are using 
> >> connection pool and will to have clear connection.
> >>
> >> For my supprice the last example do not rollback any inserts !
> >> I do not see nothink bad in this code, and also it is working perfect 
> >> on oracle + jdbc and also MSSQL + jdbc.
> >>
> >> Pls., can some one check the situation and post the result.
> >>
> >> I tryed to insert sole sllep for 5 sec. before the last 
> >> con.setAutoCommit(true); , but it do not help.
> >>
> >> Is it bug into the jdbc or pg ?
> >>
> >> I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
> >>
> >> regards,
> >> ivan.
> >>
> >>
> >> ---------------------------(end of broadcast)---------------------------
> >> TIP 8: explain analyze is your friend
> >
> >
> >
> >
> >
> How to do it?
> Will I need to recompile pg or I can set it up into conf-file?
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 
> 
> 
> !DSPAM:409fb0d2240831803312480!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 17:00  pginfo <pginfo@t1.unisoftbg.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 12+ messages in thread

From: pginfo @ 2004-05-10 17:00 UTC (permalink / raw)
  To: pg@fastcrypt.com; +Cc: Barry Lind <blind@xythos.com>; pgsql-jdbc

Dave Cramer wrote:
Hi Dave.

>Ivan,
>
>First I would try to find out if the connection is being wrapped by
>another class. Probably is, then hunt around in that class to see why
>the rollback is not being issued right away.
>
>  
>
I will check the jboss code tomorow (it is too late by me).

>Why are you doing select count(*) exactly. They are very expensive
>operations.
>  
>
I know, but I have only one record in this table and I use it only for 
this test.

>Dave
>On Mon, 2004-05-10 at 12:33, pginfo wrote:
>  
>
>>Dave Cramer wrote:
>>
>>    
>>
>>>It is in the conf file, and then you need to restart postgres
>>>
>>>DAve
>>>On Mon, 2004-05-10 at 11:14, pginfo wrote:
>>> 
>>>
>>>      
>>>
>>>>Barry Lind wrote:
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>>>I would suggest that you turn on sql statement logging on your 
>>>>>database server and see exactly what the jdbc driver is sending to the 
>>>>>server.  I suspect this information will help you track down the problem.
>>>>>
>>>>>thanks,
>>>>>--Barry
>>>>>
>>>>>
>>>>>pginfo wrote:
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>We are using pg 7.4.2 + jdbc to connect to jboss.
>>>>>>
>>>>>>It looks that pg have problems with transactions and jdbc.
>>>>>>
>>>>>>My example:
>>>>>>
>>>>>>Connection con = ... I get connection to my db.
>>>>>>
>>>>>>con.setAutoCommit(false);    // begin transaction
>>>>>>
>>>>>>// do some inserts
>>>>>>
>>>>>>con.rollback(); // rollback
>>>>>>
>>>>>>After this code all is working very well.
>>>>>>All inserts are rollbacked and so on.
>>>>>>
>>>>>>And now the second example:
>>>>>>
>>>>>>Connection con = ... I get connection to my db.
>>>>>>
>>>>>>con.setAutoCommit(false);    // begin transaction
>>>>>>
>>>>>>// do some inserts
>>>>>>
>>>>>>con.rollback(); // rollback
>>>>>>con.setAutoCommit(true);    // set autocommit. We are using 
>>>>>>connection pool and will to have clear connection.
>>>>>>
>>>>>>For my supprice the last example do not rollback any inserts !
>>>>>>I do not see nothink bad in this code, and also it is working perfect 
>>>>>>on oracle + jdbc and also MSSQL + jdbc.
>>>>>>
>>>>>>Pls., can some one check the situation and post the result.
>>>>>>
>>>>>>I tryed to insert sole sllep for 5 sec. before the last 
>>>>>>con.setAutoCommit(true); , but it do not help.
>>>>>>
>>>>>>Is it bug into the jdbc or pg ?
>>>>>>
>>>>>>I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
>>>>>>
>>>>>>regards,
>>>>>>ivan.
>>>>>>
>>>>>>
>>>>>>---------------------------(end of broadcast)---------------------------
>>>>>>TIP 8: explain analyze is your friend
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>How to do it?
>>>>Will I need to recompile pg or I can set it up into conf-file?
>>>>
>>>>
>>>>---------------------------(end of broadcast)---------------------------
>>>>TIP 4: Don't 'kill -9' the postmaster
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>Hi,
>>
>>I am ready with first results from my test.
>>I send a part of my pg log with comments:
>>
>>I make getConnection();
>>LOG:  statement: rollback; begin;
>>
>>I only check the count to be sure that the command is executed in place.
>>LOG:  statement: select count(*) from  tt
>>
>>conn.setAutoCommit(false);
>>LOG:  statement: begin;
>>
>>Test the value from my table. It is as expected.
>>LOG:  statement: select count(*) from  tt
>>
>>Insert new row.
>>LOG:  statement: insert into tt values (1)
>>
>>Check the new  count. It is ok.
>>LOG:  statement: select count(*) from  tt
>>
>>!!! I make conn.rollbac(), but do not find any command in my pg LOG ! It 
>>is big mistake. I think by jboss, but I am not sure for now.
>>
>>I check the value after rollback and it is wrong.
>>LOG:  statement: select count(*) from  tt
>>
>>I close the connection. Jboss sends rollback now! I do not know why for now.
>>LOG:  statement: rollback; begin;
>>
>>
>>Any idea how to search the problem?
>>Of course I can  close connection instead rollback, but it is not the 
>>best solution.
>>
>>regards,
>>ivan.
>>
>>
>>
>>!DSPAM:409fc09161237423516082!
>>
>>
>>    
>>




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: problem with transactions
@ 2004-05-10 18:04  Dave Cramer <pg@fastcrypt.com>
  parent: pginfo <pginfo@t1.unisoftbg.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Dave Cramer @ 2004-05-10 18:04 UTC (permalink / raw)
  To: pginfo <pginfo@t1.unisoftbg.com>; +Cc: Barry Lind <blind@xythos.com>; pgsql-jdbc

Ivan,

First I would try to find out if the connection is being wrapped by
another class. Probably is, then hunt around in that class to see why
the rollback is not being issued right away.

Why are you doing select count(*) exactly. They are very expensive
operations.

Dave
On Mon, 2004-05-10 at 12:33, pginfo wrote:
> Dave Cramer wrote:
> 
> >It is in the conf file, and then you need to restart postgres
> >
> >DAve
> >On Mon, 2004-05-10 at 11:14, pginfo wrote:
> >  
> >
> >>Barry Lind wrote:
> >>
> >>    
> >>
> >>>I would suggest that you turn on sql statement logging on your 
> >>>database server and see exactly what the jdbc driver is sending to the 
> >>>server.  I suspect this information will help you track down the problem.
> >>>
> >>>thanks,
> >>>--Barry
> >>>
> >>>
> >>>pginfo wrote:
> >>>
> >>>      
> >>>
> >>>>Hi,
> >>>>
> >>>>We are using pg 7.4.2 + jdbc to connect to jboss.
> >>>>
> >>>>It looks that pg have problems with transactions and jdbc.
> >>>>
> >>>>My example:
> >>>>
> >>>>Connection con = ... I get connection to my db.
> >>>>
> >>>>con.setAutoCommit(false);    // begin transaction
> >>>>
> >>>>// do some inserts
> >>>>
> >>>>con.rollback(); // rollback
> >>>>
> >>>>After this code all is working very well.
> >>>>All inserts are rollbacked and so on.
> >>>>
> >>>>And now the second example:
> >>>>
> >>>>Connection con = ... I get connection to my db.
> >>>>
> >>>>con.setAutoCommit(false);    // begin transaction
> >>>>
> >>>>// do some inserts
> >>>>
> >>>>con.rollback(); // rollback
> >>>>con.setAutoCommit(true);    // set autocommit. We are using 
> >>>>connection pool and will to have clear connection.
> >>>>
> >>>>For my supprice the last example do not rollback any inserts !
> >>>>I do not see nothink bad in this code, and also it is working perfect 
> >>>>on oracle + jdbc and also MSSQL + jdbc.
> >>>>
> >>>>Pls., can some one check the situation and post the result.
> >>>>
> >>>>I tryed to insert sole sllep for 5 sec. before the last 
> >>>>con.setAutoCommit(true); , but it do not help.
> >>>>
> >>>>Is it bug into the jdbc or pg ?
> >>>>
> >>>>I tested it also with pg 7.4.1 and 7.4. and I have the same problem.
> >>>>
> >>>>regards,
> >>>>ivan.
> >>>>
> >>>>
> >>>>---------------------------(end of broadcast)---------------------------
> >>>>TIP 8: explain analyze is your friend
> >>>>        
> >>>>
> >>>
> >>>
> >>>
> >>>      
> >>>
> >>How to do it?
> >>Will I need to recompile pg or I can set it up into conf-file?
> >>
> >>
> >>---------------------------(end of broadcast)---------------------------
> >>TIP 4: Don't 'kill -9' the postmaster
> >>
> >>
> >>
> >>
> >>
> >>
> >>    
> >>
> Hi,
> 
> I am ready with first results from my test.
> I send a part of my pg log with comments:
> 
> I make getConnection();
> LOG:  statement: rollback; begin;
> 
> I only check the count to be sure that the command is executed in place.
> LOG:  statement: select count(*) from  tt
> 
> conn.setAutoCommit(false);
> LOG:  statement: begin;
> 
> Test the value from my table. It is as expected.
> LOG:  statement: select count(*) from  tt
> 
> Insert new row.
> LOG:  statement: insert into tt values (1)
> 
> Check the new  count. It is ok.
> LOG:  statement: select count(*) from  tt
> 
> !!! I make conn.rollbac(), but do not find any command in my pg LOG ! It 
> is big mistake. I think by jboss, but I am not sure for now.
> 
> I check the value after rollback and it is wrong.
> LOG:  statement: select count(*) from  tt
> 
> I close the connection. Jboss sends rollback now! I do not know why for now.
> LOG:  statement: rollback; begin;
> 
> 
> Any idea how to search the problem?
> Of course I can  close connection instead rollback, but it is not the 
> best solution.
> 
> regards,
> ivan.
> 
> 
> 
> !DSPAM:409fc09161237423516082!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Problem with transactions
@ 2004-05-12 19:22  Marcos Truchado <mtruchado@telefonica.net>
  0 siblings, 1 reply; 12+ messages in thread

From: Marcos Truchado @ 2004-05-12 19:22 UTC (permalink / raw)
  To: pgsql-jdbc

Hi:

this is normal or it's a bug?

please, rewrite the line 98 to fit your database:

DriverManager.getConnection("jdbc:postgresql://yourIp:yourPort/yourDataBaseName?charSet=yourCharSet", 
"yourUser", "yourPassword");

Attachments:

Problem.java (text/x-java, 3.4K) download import java.sql.*; import java.io.IOException; import javax.swing.JOptionPane; class Problem { public static void main(String [] arguments) { Connection conn = null; try { conn = getConn(); Statement stat = conn.createStatement(); String sequenceTest = "CREATE SEQUENCE sequence_test"; String table1 = "CREATE TABLE test (id INTEGER DEFAULT NEXTVAL('sequence_test') NOT NULL, value VARCHAR(100))"; //create sequence and table for testing purposes stat.executeUpdate(sequenceTest); stat.executeUpdate(table1); //let's go with the problem boolean autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); String insert1 = "INSERT INTO test(value) VALUES('this will have id1')"; String insert2 = "INSERT INTO test(value) VALUES('this will have id2')"; String insert3 = "INSERT INTO test(value, other) VALUES('this will have id3', 'this will cause an error')"; //<= error stat.executeUpdate(insert1); stat.executeUpdate(insert2); stat.executeUpdate(insert3); conn.setAutoCommit(autoCommit); } catch(SQLException e) { try { conn.rollback(); conn.close(); System.out.println("rollback done"); } catch(SQLException SQLe) { e.printStackTrace(); SQLe.printStackTrace(); System.out.println("rollback isn't done :'("); } System.out.println("Error code: " + e.getErrorCode()); System.out.println("Error messague: " + e.getMessage()); System.out.println("Localized messague: " + e.getLocalizedMessage()); System.out.println("Description: " + e); System.out.println(); System.out.println("<- ->"); System.out.println(); e.printStackTrace(); System.out.println(); System.out.println("<- ->"); System.out.println(); } catch(IOException ioe) { ioe.printStackTrace(); System.out.println("Imput/output error"); } try { conn = getConn(); Statement stat = conn.createStatement(); String insert1 = "INSERT INTO test(value) VALUES('this will have id1')"; stat.executeUpdate(insert1); stat.close(); PreparedStatement pstmt = conn.prepareStatement("SELECT CURRVAL('sequence_test') AS CURRVAL"); ResultSet rs = pstmt.executeQuery(); if (rs.first()) { System.out.println("Current sequence value is: " + rs.getInt("CURRVAL")); System.out.println("According with the code, rollback was called, so this new row should have 1"); } else { System.out.println("FATAL"); System.out.println("FATAL"); System.out.println("FATAL"); System.out.println("cannot reach the sequence"); return; } rs.close(); pstmt.close(); conn.close(); } catch(SQLException e) { e.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } } public static Connection getConn() throws SQLException, IOException { try { Class.forName("org.postgresql.Driver").newInstance(); //return DriverManager.getConnection("jdbc:postgresql://yourIp:yourPort/yourDataBaseName?charSet=yourCharSet", "yourUser", "yourPassword"); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(IllegalAccessException ee) { ee.printStackTrace(); } catch(InstantiationException eee) { eee.printStackTrace(); } catch(SQLException e) { JOptionPane.showMessageDialog(null, "can't connect with database"); } return null; } }
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Problem with transactions
@ 2004-05-12 20:02  Dave Cramer <pg@fastcrypt.com>
  parent: Marcos Truchado <mtruchado@telefonica.net>
  0 siblings, 0 replies; 12+ messages in thread

From: Dave Cramer @ 2004-05-12 20:02 UTC (permalink / raw)
  To: Marcos Truchado <mtruchado@telefonica.net>; +Cc: pgsql-jdbc

Sequences do not rollback, so it is not a bug


Dave
On Wed, 2004-05-12 at 15:22, Marcos Truchado wrote:
> Hi:
> 
> this is normal or it's a bug?
> 
> please, rewrite the line 98 to fit your database:
> 
> DriverManager.getConnection("jdbc:postgresql://yourIp:yourPort/yourDataBaseName?charSet=yourCharSet", 
> "yourUser", "yourPassword");
> 
> 
> !DSPAM:40a27f82120464098919018!
> 
> ______________________________________________________________________
> import java.sql.*;
> import java.io.IOException;
> import javax.swing.JOptionPane;
> 
> class Problem {
> 
>     public static void main(String [] arguments) {
> 	Connection conn = null;
> 	try {
> 	    conn = getConn();
> 	    
> 	    Statement stat = conn.createStatement();
> 	    
> 	    String sequenceTest = "CREATE SEQUENCE sequence_test";
> 	    String table1 = "CREATE TABLE test (id INTEGER DEFAULT NEXTVAL('sequence_test') NOT NULL, value VARCHAR(100))";
> 	    
> 	    //create sequence and table for testing purposes
> 	    stat.executeUpdate(sequenceTest);
> 	    stat.executeUpdate(table1);
> 
> 	    //let's go with the problem
> 	    
> 	    boolean autoCommit = conn.getAutoCommit();
> 	    conn.setAutoCommit(false);
> 	    
> 	    String insert1 = "INSERT INTO test(value) VALUES('this will have id1')";
> 	    String insert2 = "INSERT INTO test(value) VALUES('this will have id2')";
> 	    String insert3 = "INSERT INTO test(value, other) VALUES('this will have id3', 'this will cause an error')"; //<= error
> 
> 	    stat.executeUpdate(insert1);
> 	    stat.executeUpdate(insert2);
> 	    stat.executeUpdate(insert3);
> 	    
> 	    conn.setAutoCommit(autoCommit);
> 	    
> 	} catch(SQLException e) {
> 	    try {
> 		conn.rollback();		
> 		conn.close();
> 		System.out.println("rollback done");
> 	    } catch(SQLException SQLe) {
> 		e.printStackTrace();
> 		SQLe.printStackTrace();
> 		System.out.println("rollback isn't done :'(");
> 	    }
> 	    System.out.println("Error code: " + e.getErrorCode());
> 	    System.out.println("Error messague: " + e.getMessage());
> 	    System.out.println("Localized messague: " + e.getLocalizedMessage());
> 	    System.out.println("Description: " + e);
> 	    System.out.println();
> 	    System.out.println("<-  ->");
> 	    System.out.println();	 
> 	    e.printStackTrace();
> 	    System.out.println();
> 	    System.out.println("<-  ->");
> 	    System.out.println();
> 	} catch(IOException ioe) {
> 	    ioe.printStackTrace();
> 	    System.out.println("Imput/output error");
> 	}
> 
> 
> 	try {
> 	    conn = getConn();
> 	    Statement stat = conn.createStatement();
> 	    String insert1 = "INSERT INTO test(value) VALUES('this will have id1')";
> 	    stat.executeUpdate(insert1);
> 	    stat.close();
> 	    
> 	    PreparedStatement pstmt = conn.prepareStatement("SELECT CURRVAL('sequence_test') AS CURRVAL");
> 	    ResultSet rs = pstmt.executeQuery();
> 	    if (rs.first()) {
> 		System.out.println("Current sequence value is: " + rs.getInt("CURRVAL"));
> 		System.out.println("According with the code, rollback was called, so this new row should have 1");
> 	    } else {
> 		System.out.println("FATAL");
> 		System.out.println("FATAL");
> 		System.out.println("FATAL");
> 		System.out.println("cannot reach the sequence");
> 		return;
> 	    }
> 	    rs.close();
> 	    pstmt.close();
> 	    conn.close();
> 	} catch(SQLException e) {
> 	    e.printStackTrace();
> 	} catch(IOException ioe) {
> 	    ioe.printStackTrace();
> 	}
>     }
> 
>     public static Connection getConn() throws SQLException, IOException {	   	 
> 	
> 	try {
> 	    
> 	    Class.forName("org.postgresql.Driver").newInstance();
>             
> 	    //return DriverManager.getConnection("jdbc:postgresql://yourIp:yourPort/yourDataBaseName?charSet=yourCharSet", "yourUser", "yourPassword");
> 	    
> 	} catch(ClassNotFoundException e) {
> 	    e.printStackTrace();    	 
> 	} catch(IllegalAccessException ee) {
> 	    ee.printStackTrace();
> 	} catch(InstantiationException eee) {
> 	    eee.printStackTrace();
> 	}    	 
> 	
> 	catch(SQLException e) {
> 	    JOptionPane.showMessageDialog(null,
> 					  "can't connect with database");
> 	    
> 	}
> 	
> 	return null;   
>     }
> 
> }
> 
> 
> !DSPAM:40a27f82120464098919018!
> 
> ______________________________________________________________________
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
> 
> 
> !DSPAM:40a27f82120464098919018!
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2004-05-12 20:02 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-10 12:00 problem with transactions pginfo <pginfo@t1.unisoftbg.com>
2004-05-10 14:08 ` Oliver Jowett <oliver@opencloud.com>
2004-05-10 14:13 ` Kris Jurka <books@ejurka.com>
2004-05-10 15:50 ` Barry Lind <blind@xythos.com>
2004-05-10 15:14   ` pginfo <pginfo@t1.unisoftbg.com>
2004-05-10 16:43     ` Barry Lind <blind@xythos.com>
2004-05-10 16:49     ` Dave Cramer <pg@fastcrypt.com>
2004-05-10 16:33       ` pginfo <pginfo@t1.unisoftbg.com>
2004-05-10 18:04         ` Dave Cramer <pg@fastcrypt.com>
2004-05-10 17:00           ` pginfo <pginfo@t1.unisoftbg.com>
2004-05-12 19:22 Problem with transactions Marcos Truchado <mtruchado@telefonica.net>
2004-05-12 20:02 ` Re: Problem with transactions Dave Cramer <pg@fastcrypt.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