Operating system: windows xp
In my config file:
max_connections = 300
My test program just creates 200 threads to perform some simple query task. I find
server often restart when the 155th connection thread startup.
======================================================
console information:
.......
at 153
at 154
org.postgresql.util.PSQLException: An I/O error occured while reading from
backend - Exception: java.net.SocketException: Connection reset
Stack Trace:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:166)
at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1C
onnection.java:301)
at
org.postgresql.jdbc1 .AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
nection.java:214)
at org.postgresql.Driver.connect(Driver.java:139)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDBConnection.main(TestDBConnection.java:48)
End of Stack Trace
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:172)
at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1C
onnection.java:301)
at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
nection.java:214)
at org.postgresql.Driver.connect(Driver.java:139)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDBConnection.main(TestDBConnection.java:48)
===================================================
errors in log:
2005-06-29 01:49:42 LOG: unexpected EOF on client connection
2005-0 6-29 01:52:08 LOG: server process (PID 13764) exited with unexpected
status 128
2005-06-29 01:52:08 LOG: terminating any other active server processes
2005-06-29 01:52:08 WARNING: terminating connection because of crash of
another server process
2005-06-29 01:52:08 DETAIL: The postmaster has commanded this server
process to roll back the current transaction and exit, because another
server process exited abnormally and possibly corrupted shared memory.
2005-06-29 01:52:08 HINT: In a moment you should be able to reconnect to
the database and repeat your command.
2005-06-29 01:52:08 WARNING: terminating connection because of crash of
another server process
2005-06-29 01:52:08 DETAIL: The postmaster has commanded this server
process to roll back the current
========================================
My Java code :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class TestDBConnection extends Thread{
TestDBConnection(int i, Connection conn){
this.order = i;
this.conn =conn;
}
public void run(){
try {
System.out.println("at " + order);
conn.createStatement().executeQuery("select * from book_status");
synchronized ("finished_task"){
finished++;
}
synchronized(lock){
lock.wait();
}
System.out.println("fat "+ order);
} catch (Throwable e) {
e.printStackTrace();
}
}
int order = 0;
Connection conn;
static int finished = 0;
static Object lock = new Object();
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
int num = 200;
Thread[] ts = new Thread[num];
Connection[] cs = new Connection[num];
for (int i = 0; i < num; i++){
cs[i] = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "test", "test");
ts[i] = new TestDBConnection(i, cs[i]);
ts[i].start();
}
while (TestDBConnection.finished != num){
Thread.sleep(300);
}
synchronized(lock){
lock.notifyAll();
}
for (int j = 0; j < num; j++){
cs[j].close();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
=================================================================================
My table infomation:
test=# d book_status;
---------------+-----------------------+----------
bookid | character varying(64) | not null
length | integer |
lastupdate | character varying(16) |
curblock | integer |
downloadtimes | integer |
INDEX:
"book_status_pkey" PRIMARY KEY, btree (bookid)
test=#
Á¢¿ÌÓµÓÐ1GÍøÂçUÅÌ£¡ |
½ðÇú÷Ò÷Ñ£¬×îin×îÇ¿ |