-
Notifications
You must be signed in to change notification settings - Fork 832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defaultRowFetchSize and no known snapshots error #2227
Comments
I can confirm the bug. Could you guys please tell is it a Driver problem or a PostgreSQL server itself? |
What version of PostgreSQL is this. I am searching the source code for 'no known snapshots' and can't find it ? |
Here is a better formated steps to reproduce the bug Create test table and fill it with data-- create table
create table test_blob(content bytea);
-- generate 101 rows with 4096 bytes:
insert into test_blob
select (select decode(string_agg(lpad(to_hex(width_bucket(random(), 0, 1, 256) - 1), 2, '0'), ''), 'hex') FROM generate_series(1, 4096))
from generate_series(1, 101);
-- create function to read data
CREATE OR REPLACE FUNCTION test_blob(p_cur OUT REFCURSOR) AS $body$
BEGIN
OPEN p_cur FOR SELECT content FROM test_blob;
END;
$body$ LANGUAGE plpgsql STABLE; Create test classCreate file named Main.java: (change the URL and credentials) import java.sql.*;
public class Main {
public static void main(String[] args) throws SQLException {
String url = "jdbc:postgresql:https://localhost/postgres?defaultRowFetchSize=50";
Connection conn = DriverManager.getConnection(url, "user", "pwd");
conn.setAutoCommit(false);
int cnt = 0;
try (CallableStatement stmt = conn.prepareCall("{? = call test_blob()}")) {
stmt.registerOutParameter(1, Types.REF_CURSOR);
stmt.setFetchSize(0); // has no effect
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(1);
rs.setFetchSize(0); // has no effect
while (rs.next()) {
cnt++;
}
} finally {
System.out.println("records read: " + cnt);
}
conn.close();
}
} Compile and run
Expected output is But instead I got Environment
|
I got the "ERROR: cannot fetch toast data without an active snapshot" on PostgreSQL 14.0 |
@afel thanks for the test case. |
Here's the comment from the backend code that is relevant. Still working on it, but notarizing as I go
|
OK, found the issue, apparently we close the refcursor right away and only read 50 rows because of fetch size. |
@davecramer |
… on defaultRowFetchSize See pgjdbc#2227 See pgjdbc#2371
From the mailing list...
Klika David reported the following
I messed with this exception: PSQLException: ERROR: no known snapshots
I found that it arise when:
When the record no 101 is to be fetched, the exception is trown.
Note that CallableStatement.setFetchSize and ResultSet.setFetchSize works as expected.
I suggest at least adding a note about this limitation in the defaultRowFetchSize connection parameter description.
Thank you.
Best regards
David
Simple test case:
SQL:
create table test_blob(content bytea);
-- generate 101 rows with 4096 bytes:
insert into test_blob
select (select decode(string_agg(lpad(to_hex(width_bucket(random(), 0, 1, 256) - 1), 2, '0'), ''), 'hex') FROM generate_series(1, 4096))
from generate_series(1, 101);
CREATE OR REPLACE FUNCTION test_blob(p_cur OUT REFCURSOR) AS$body$
$body$ LANGUAGE plpgsql STABLE;
BEGIN
OPEN p_cur FOR SELECT content FROM test_blob;
END;
Java:
public static void main(String[] args) throws SQLException {
String url = "jdbc:postgresql:https://localhost/postgres?defaultRowFetchSize=100";
Connection conn = DriverManager.getConnection(url, "user", "password");
conn.setAutoCommit(false);
}
Output:
records read: 100
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: no known snapshots
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2284)
at org.postgresql.core.v3.QueryExecutorImpl.fetch(QueryExecutorImpl.java:2480)
at org.postgresql.jdbc.PgResultSet.next(PgResultSet.java:1958)
at TestBlob.main(TestBlob.java:19)
The text was updated successfully, but these errors were encountered: