pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feed[pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
8+ messages / 2 participants
[nested] [flat]
* [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:19 "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
0 siblings, 0 replies; 8+ messages in thread
From: qinarmy-zoro (@qinarmy-zoro) @ 2026-03-23 10:19 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Please read https://stackoverflow.com/help/minimal-reproducible-example
**Describe the issue**
A clear and concise description of what the issue is.
**Driver Version?**
42.7.10
**Java Version?**
all
**OS Version?**
all
**PostgreSQL Version?**
18.3
**To Reproduce**
Steps to reproduce the behaviour:
I reproduce , see https://github.com/PillArmy/army/blob/master/army-example/src/test/java/io/army/temp/PostgreBugRepro...
**Expected behaviour**
A clear and concise description of what you expected to happen.
And what actually happens
// org.postgresql.jdbc.PgStatement.executeInternal()
// no -> flags |= QueryExecutor.QUERY_FORWARD_CURSOR;
**Logs**
If possible PostgreSQL logs surrounding the occurrence of the issue
Additionally logs from the driver can be obtained adding
Using the following template code make sure the bug can be replicated in the driver alone.
```
package io.army.temp;
import com.alibaba.druid.pool.DruidDataSource;
import org.testng.annotations.Test;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class PostgreBugReproduce {
@Test
public void reproduce() throws Exception {
try (DruidDataSource db = createDataSource()) {
try (Connection conn = db.getConnection()) {
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate(ddl());
stmt.executeUpdate("START TRANSACTION READ ONLY");
System.out.printf("autoCommit is %s after start transaction%n", conn.getAutoCommit());
stmt.setFetchSize(1);
// org.postgresql.jdbc.PgStatement.executeInternal()
// no -> flags |= QueryExecutor.QUERY_FORWARD_CURSOR;
try (ResultSet rs = stmt.executeQuery("SELECT u.id,u.name FROM u_user as u ORDER BY u.id")) {
while (rs.next()) {
System.out.printf("id:%s ; name : %s%n", rs.getLong(1), rs.getString(2));
}
}
}
}
}
}
private static String ddl() {
return """
create table IF NOT EXISTS u_user
(
id BIGSERIAL not null primary key,
name varchar(15) not null
);
""";
}
private static DruidDataSource createDataSource() {
final String url;
url = "jdbc:postgresql://localhost:5432/postgres";
final Properties properties = new Properties();
properties.put("user", "army_w");
properties.put("password", "army123");
final DruidDataSource ds;
ds = new DruidDataSource();
ds.setUrl(url);
ds.setDriverClassName(org.postgresql.Driver.class.getName());
ds.setConnectProperties(properties);
ds.setInitialSize(10);
ds.setMaxActive(200);
ds.setMaxWait(27L * 1000L);
ds.setValidationQuery("SELECT 1 ");
ds.setTestOnBorrow(Boolean.FALSE);
ds.setTestWhileIdle(Boolean.TRUE);
ds.setTestOnReturn(Boolean.TRUE);
ds.setTimeBetweenEvictionRunsMillis(5L * 1000L);
ds.setRemoveAbandoned(Boolean.FALSE);
ds.setMinEvictableIdleTimeMillis(30000L);
return ds;
}
}
```
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:19 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: qinarmy-zoro (@qinarmy-zoro) @ 2026-03-23 10:19 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
more see https://github.com/pgjdbc/pgjdbc/pull/3980
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:22 ` "davecramer (@davecramer)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: davecramer (@davecramer) @ 2026-03-23 10:22 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Does this problem exist if you use setAutoCommit(false) and setReadonly(true)
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:26 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: qinarmy-zoro (@qinarmy-zoro) @ 2026-03-23 10:26 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
> Does this problem exist if you use setAutoCommit(false) and setReadonly(true)
not exists, but you should not restrict how developers use it, as long as their usage is legal, reasonable, and supported by the database. Do you agree with me?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:35 ` "davecramer (@davecramer)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: davecramer (@davecramer) @ 2026-03-23 10:35 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
I suppose not, but if you aren't going to use the API, why would you expect the rest of the API to work ?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:48 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: qinarmy-zoro (@qinarmy-zoro) @ 2026-03-23 10:48 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
> I suppose not, but if you aren't going to use the API, why would you expect the rest of the API to work ?
Why can't I use the START TRANSACTION command while using a cursor? Does PostgreSQL prohibit me from using it?
Is it unreasonable to add a single line of code just to check if the current connection is inside a database transaction block?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 10:54 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: qinarmy-zoro (@qinarmy-zoro) @ 2026-03-23 10:54 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
> > I suppose not, but if you aren't going to use the API, why would you expect the rest of the API to work ?
>
> Why can't I use the START TRANSACTION command while using a cursor? Does PostgreSQL prohibit me from using it?
>
> Is it unreasonable to add a single line of code just to check if the current connection is inside a database transaction block?
It is incorrect to judge the transactional state of a connection using only getAutoCommit(), as it is unreliable. The accurate approach is to verify if connection.getQueryExecutor().getTransactionState() == TransactionState.OPEN
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC'
@ 2026-03-23 11:17 ` "davecramer (@davecramer)" <[email protected]>
6 siblings, 0 replies; 8+ messages in thread
From: davecramer (@davecramer) @ 2026-03-23 11:17 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
No, it's fine. Just add tests for it before and after any operations on the connection
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2026-03-23 11:17 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-23 10:19 [pgjdbc/pgjdbc] issue #3993: fix Enable cursor-based bug, when start transaction by 'START TRANSAC' "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
2026-03-23 10:19 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
2026-03-23 10:22 ` "davecramer (@davecramer)" <[email protected]>
2026-03-23 10:26 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
2026-03-23 10:35 ` "davecramer (@davecramer)" <[email protected]>
2026-03-23 10:48 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
2026-03-23 10:54 ` "qinarmy-zoro (@qinarmy-zoro)" <[email protected]>
2026-03-23 11:17 ` "davecramer (@davecramer)" <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox