On Tue, 12 Apr 2005, [UTF-8] Poul Møller Hansen wrote:
> I have rewritten the application so every client thread is opening a new
> database connection, and yesterday it happened again.
> ---
> 2005-04-11 12:27:54 ERROR: invalid string enlargement request size
> 1358954492
> 2005-04-11 12:27:54 WARNING: AbortTransaction and not in in-progress
> state
> 2005-04-11 12:27:54 FATAL: invalid frontend message type
> 78
> ---
> The application is opening a socket listener, and every client
> connection opens a new connection to the database.
> The clients sends a status message every 2nd minute that are written to
> the database.
> I'm using Postgresql version 7.4.7 and jdbc driver version
> pg74.215.jdbc3.jar.
>
> Do you have a clue on what's going on ?
>
No, I don't. Do you have any more information? What is your code doing
when it fails? Just issuing a regular query? Are you using any of the
less common driver features: Large objects, fastpath api, a COPY patch?
If the driver had a protocol problem I would expect it to be rather
repeatable. If the driver had a synchronization problem it should have
disappeared when you moved to a single thread model. I've attached the
test script I've used to try and beat on the driver.
Kris Jurka
import java.sql.*;
import org.postgresql.*;
import org.postgresql.largeobject.*;
public class Threads {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
conn.setAutoCommit(false);
Runner runners[] = new Runner[10];
setupBlob(conn, runners.length);
for (int i=0; i<runners.length; i++) {
runners[i] = new Runner(conn, i);
runners[i].start();
}
}
private static void setupBlob(Connection conn, int len) throws Exception {
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE tblob (a int, b oid)");
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tblob VALUES (?, lo_creat(-1))");
for (int i=0; i<len; i++) {
pstmt.setInt(1,i);
pstmt.executeUpdate();
}
pstmt.close();
byte buf[] = new byte[2048];
for (int i=0; i<buf.length; i++) {
buf[i] = (byte)i;
}
LargeObjectManager lom = ((PGConnection)conn).getLargeObjectAPI();
ResultSet rs = stmt.executeQuery("SELECT b FROM tblob");
while (rs.next()) {
LargeObject obj = lom.open(rs.getInt(1), LargeObjectManager.WRITE);
obj.write(buf, 0, buf.length);
obj.close();
}
}
}
class Runner extends Thread {
private Connection conn;
private int version;
public Runner(Connection conn, int version) {
this.conn = conn;
this.version = version;
}
public void run() {
while(true) {
try {
if (version % 4 == 0) {
// Normal query execution.
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pg_class");
while (rs.next()) { }
rs.close();
rs = stmt.executeQuery("SELECT * FROM pg_class");
while (rs.next()) { }
rs.close();
stmt.close();
} else if (version % 4 == 1) {
// Use a cursor
Statement stmt = conn.createStatement();
stmt.setFetchSize(20);
ResultSet rs = stmt.executeQuery("SELECT * FROM pg_class");
while (rs.next()) { }
rs.close();
rs = stmt.executeQuery("SELECT * FROM pg_class");
while (rs.next()) { }
rs.close();
stmt.close();
} else if (version % 4 == 2) {
// Use a prepared statement
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM pg_proc where proname = ?");
((PGStatement)pstmt).setUseServerPrepare(true);
pstmt.setString(1, "textin");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) { }
rs.close();
rs = pstmt.executeQuery();
while (rs.next()) { }
rs.close();
pstmt.setString(1, "version");
rs = pstmt.executeQuery();
while (rs.next()) { }
rs.close();
pstmt.close();
} else if (version % 4 == 3) {
// Use a blob
PreparedStatement pstmt = conn.prepareStatement("SELECT b FROM tblob WHERE a = ?");
pstmt.setInt(1, version);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Blob b = rs.getBlob(1);
for (int i=0; i<b.length(); i++) {
byte dat[] = b.getBytes(i,1);
}
}
rs.close();
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend