public inbox for pgsql-jdbc@postgresql.org
help / color / mirror / Atom feedDon't see CLOSE packet been sent
3+ messages / 2 participants
[nested] [flat]
* Don't see CLOSE packet been sent
@ 2025-12-04 13:37 Manav Kumar <mkumar@yugabyte.com>
2025-12-06 11:35 ` Re: Don't see CLOSE packet been sent Manav Kumar <mkumar@yugabyte.com>
0 siblings, 1 reply; 3+ messages in thread
From: Manav Kumar @ 2025-12-04 13:37 UTC (permalink / raw)
To: pgsql-jdbc@lists.postgresql.org
Hi Team,
Wrote a simple below application to understand nature of CLOSE packet.
But i don't see the JDBC sending CLOSE packet. Any ideas what i can do see
CLOSE packet.
I'm compiling with:
javac -classpath /home/manavkumar/postgresql-42.7.1.jar sendClose.java && \
java -cp .:/home/manavkumar/postgresql-42.7.1.jar sendClose
```import java.sql.*;
public class sendClose {
public static void main(String[] args) {
Connection connection = null;
PreparedStatement pstmt1 = null, pstmt2 = null;
try {
// prepareThreshold=1 is crucial here
connection = DriverManager.getConnection("jdbc:postgresql://
10.150.3.175:5433/yugabyte?prepareThreshold=1", "yugabyte","yugabyte");
// ---------------------------------------------------------
// CHANGE 1: Use placeholders (?)
// This forces the driver to use Extended Query Protocol (Parse/Bind)
// and create a named statement (e.g., "S_1") on the server.
// ---------------------------------------------------------
pstmt1 = connection.prepareStatement("insert into t_ values (?, ?)");
pstmt1.setInt(1, 1);
pstmt1.setInt(2, 2);
// Execute twice to ensure the driver switches to server-prepare mode
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
// ---------------------------------------------------------
// CHANGE 2: Close the statement
// The driver now marks "S_1" as closed internally and queues the packet.
// ---------------------------------------------------------
pstmt1.close();
System.out.println("Statement 1 closed. Sending Statement 2 to flush the
buffer...");
// ---------------------------------------------------------
// CHANGE 3: Send ANY other traffic
// The driver will attach the buffered "CLOSE S_1" packet
// to the front of this new request.
// ---------------------------------------------------------
pstmt2 = connection.prepareStatement("SELECT 1");
pstmt2.execute();
pstmt2.close();
connection.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
```
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Don't see CLOSE packet been sent
2025-12-04 13:37 Don't see CLOSE packet been sent Manav Kumar <mkumar@yugabyte.com>
@ 2025-12-06 11:35 ` Manav Kumar <mkumar@yugabyte.com>
2025-12-07 13:50 ` Re: Don't see CLOSE packet been sent Dave Cramer <davecramer@postgres.rocks>
0 siblings, 1 reply; 3+ messages in thread
From: Manav Kumar @ 2025-12-06 11:35 UTC (permalink / raw)
To: pgsql-jdbc@lists.postgresql.org
Hi Team,
Writing to ask for a follow up. Can someone please clarify. I only see
CLOSE been sent by driver when server returns an error message 'prepared
statement does not exist".
Thanks
Manav
On Thu, Dec 4, 2025 at 7:07 PM Manav Kumar <mkumar@yugabyte.com> wrote:
> Hi Team,
> Wrote a simple below application to understand nature of CLOSE packet.
> But i don't see the JDBC sending CLOSE packet. Any ideas what i can do see
> CLOSE packet.
> I'm compiling with:
> javac -classpath /home/manavkumar/postgresql-42.7.1.jar sendClose.java && \
> java -cp .:/home/manavkumar/postgresql-42.7.1.jar sendClose
>
> ```import java.sql.*;
>
> public class sendClose {
>
> public static void main(String[] args) {
> Connection connection = null;
> PreparedStatement pstmt1 = null, pstmt2 = null;
>
> try {
> // prepareThreshold=1 is crucial here
> connection = DriverManager.getConnection("jdbc:postgresql://
> 10.150.3.175:5433/yugabyte?prepareThreshold=1", "yugabyte","yugabyte");
>
> // ---------------------------------------------------------
> // CHANGE 1: Use placeholders (?)
> // This forces the driver to use Extended Query Protocol (Parse/Bind)
> // and create a named statement (e.g., "S_1") on the server.
> // ---------------------------------------------------------
> pstmt1 = connection.prepareStatement("insert into t_ values (?, ?)");
> pstmt1.setInt(1, 1);
> pstmt1.setInt(2, 2);
> // Execute twice to ensure the driver switches to server-prepare mode
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> pstmt1.execute();
> // ---------------------------------------------------------
> // CHANGE 2: Close the statement
> // The driver now marks "S_1" as closed internally and queues the packet.
> // ---------------------------------------------------------
> pstmt1.close();
>
> System.out.println("Statement 1 closed. Sending Statement 2 to flush the
> buffer...");
>
> // ---------------------------------------------------------
> // CHANGE 3: Send ANY other traffic
> // The driver will attach the buffered "CLOSE S_1" packet
> // to the front of this new request.
> // ---------------------------------------------------------
> pstmt2 = connection.prepareStatement("SELECT 1");
> pstmt2.execute();
> pstmt2.close();
>
> connection.close();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> ```
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Don't see CLOSE packet been sent
2025-12-04 13:37 Don't see CLOSE packet been sent Manav Kumar <mkumar@yugabyte.com>
2025-12-06 11:35 ` Re: Don't see CLOSE packet been sent Manav Kumar <mkumar@yugabyte.com>
@ 2025-12-07 13:50 ` Dave Cramer <davecramer@postgres.rocks>
0 siblings, 0 replies; 3+ messages in thread
From: Dave Cramer @ 2025-12-07 13:50 UTC (permalink / raw)
To: Manav Kumar <mkumar@yugabyte.com>; +Cc: pgsql-jdbc@lists.postgresql.org
Please post this on github as you will get more traction
https://github.com/pgjdbc/pgjdbc/issues
Does seem like a bug though.
Dave Cramer
www.postgres.rocks
On Sat, 6 Dec 2025 at 06:35, Manav Kumar <mkumar@yugabyte.com> wrote:
> Hi Team,
> Writing to ask for a follow up. Can someone please clarify. I only see
> CLOSE been sent by driver when server returns an error message 'prepared
> statement does not exist".
>
> Thanks
> Manav
>
> On Thu, Dec 4, 2025 at 7:07 PM Manav Kumar <mkumar@yugabyte.com> wrote:
>
>> Hi Team,
>> Wrote a simple below application to understand nature of CLOSE packet.
>> But i don't see the JDBC sending CLOSE packet. Any ideas what i can do
>> see CLOSE packet.
>> I'm compiling with:
>> javac -classpath /home/manavkumar/postgresql-42.7.1.jar sendClose.java &&
>> \
>> java -cp .:/home/manavkumar/postgresql-42.7.1.jar sendClose
>>
>> ```import java.sql.*;
>>
>> public class sendClose {
>>
>> public static void main(String[] args) {
>> Connection connection = null;
>> PreparedStatement pstmt1 = null, pstmt2 = null;
>>
>> try {
>> // prepareThreshold=1 is crucial here
>> connection = DriverManager.getConnection("jdbc:postgresql://
>> 10.150.3.175:5433/yugabyte?prepareThreshold=1", "yugabyte","yugabyte");
>>
>> // ---------------------------------------------------------
>> // CHANGE 1: Use placeholders (?)
>> // This forces the driver to use Extended Query Protocol (Parse/Bind)
>> // and create a named statement (e.g., "S_1") on the server.
>> // ---------------------------------------------------------
>> pstmt1 = connection.prepareStatement("insert into t_ values (?, ?)");
>> pstmt1.setInt(1, 1);
>> pstmt1.setInt(2, 2);
>> // Execute twice to ensure the driver switches to server-prepare mode
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> pstmt1.execute();
>> // ---------------------------------------------------------
>> // CHANGE 2: Close the statement
>> // The driver now marks "S_1" as closed internally and queues the packet.
>> // ---------------------------------------------------------
>> pstmt1.close();
>>
>> System.out.println("Statement 1 closed. Sending Statement 2 to flush the
>> buffer...");
>>
>> // ---------------------------------------------------------
>> // CHANGE 3: Send ANY other traffic
>> // The driver will attach the buffered "CLOSE S_1" packet
>> // to the front of this new request.
>> // ---------------------------------------------------------
>> pstmt2 = connection.prepareStatement("SELECT 1");
>> pstmt2.execute();
>> pstmt2.close();
>>
>> connection.close();
>> }
>> catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>> }
>>
>> ```
>>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2025-12-07 13:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-04 13:37 Don't see CLOSE packet been sent Manav Kumar <mkumar@yugabyte.com>
2025-12-06 11:35 ` Manav Kumar <mkumar@yugabyte.com>
2025-12-07 13:50 ` Dave Cramer <davecramer@postgres.rocks>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox