Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 037BA632DBC for ; Mon, 13 Sep 2010 09:52:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 43471-07 for ; Mon, 13 Sep 2010 12:51:54 +0000 (UTC) X-Greylist: delayed 00:38:21.484444 by SQLgrey-1.7.6 Received: from cicero-fbr1.cybercity.dk (cicero-fbr1.cybercity.dk [212.242.40.5]) by mail.postgresql.org (Postfix) with ESMTP id 793FF632CA5 for ; Mon, 13 Sep 2010 09:51:55 -0300 (ADT) Received: from cicero3.cybercity.dk (cicero3.cybercity.dk [212.242.43.248]) by cicero-fbr1.cybercity.dk (Postfix) with ESMTP id 483803D2B49 for ; Mon, 13 Sep 2010 14:13:31 +0200 (CEST) Received: from jukebox.alleroedderne.adsl.dk (port161.ds1-aroe.adsl.cybercity.dk [217.157.138.230]) by cicero3.cybercity.dk (Postfix) with ESMTP id 9D0CE261865; Mon, 13 Sep 2010 14:13:27 +0200 (CEST) Received: from localhost (jukebox.alleroedderne.adsl.dk [127.0.0.1]) by jukebox.alleroedderne.adsl.dk (Postfix) with ESMTP id 6553C3E462; Mon, 13 Sep 2010 14:13:27 +0200 (CEST) X-Virus-Scanned: amavisd-new at alleroedderne.adsl.dk Received: from jukebox.alleroedderne.adsl.dk ([127.0.0.1]) by localhost (jukebox.alleroedderne.adsl.dk [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Oe6TrwkGSMWW; Mon, 13 Sep 2010 14:13:25 +0200 (CEST) Received: from [127.0.0.1] (jukebox.alleroedderne.adsl.dk [127.0.0.1]) by jukebox.alleroedderne.adsl.dk (Postfix) with ESMTP id 049783E3DA; Mon, 13 Sep 2010 14:13:24 +0200 (CEST) Message-ID: <4C8E1564.80405@alleroedderne.adsl.dk> Date: Mon, 13 Sep 2010 14:13:24 +0200 From: Kim Bisgaard User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Synchronisation problems in COPY IN Content-Type: multipart/mixed; boundary="------------040908050009080702010105" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201009/20 X-Sequence-Number: 20890 This is a multi-part message in MIME format. --------------040908050009080702010105 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, We are occasionally experiencing problems with our JDBC implementation of COPY IN. We have cut our program down to the attached example. Guessing from the error messages it looks like jdbc is overwriting the buffer sent to the server before it is done. We are writing the data in CSV format, with integer(serial),date(now),float format, so it is easy to see if the buffer is garbled. Here is an example: INFO: ERROR: extra data after last expected column Where: COPY temporary_wind_speed_50_m_3, line 175: "60000179,2010-09-07 00:00:00,60001043,2010-09-07 00:00:00,10.032084733490484" org.postgresql.util.PSQLException: ERROR: extra data after last expected column Where: COPY temporary_wind_speed_50_m_3, line 175: "60000179,2010-09-07 00:00:00,60001043,2010-09-07 00:00:00,10.032084733490484" at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062) at org.postgresql.core.v3.QueryExecutorImpl.processCopyResults(QueryExecutorImpl.java:929) at org.postgresql.core.v3.QueryExecutorImpl.writeToCopy(QueryExecutorImpl.java:838) at org.postgresql.core.v3.CopyInImpl.writeToCopy(CopyInImpl.java:53) at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:179) at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:161) at dk.dmi.appl.evejrfeeder.EvejrDBCopy.run(Unknown Source) at java.lang.Thread.run(Thread.java:595) It thus looks like a synchronisation problem (locking problem), but we are using Piped(Input/Output)Stream, which must be properly synchronised, and CopyManager.CopyIn, where there is nowhere to add synchronisation. To us it looks like a problem in CopyManager.CopyIn, or alternatively we are not doing something we where expected to do? We use PostgreSQL 8.4, and JDBC 8.4-702. Thanks in advance! Kim --------------040908050009080702010105 Content-Type: text/x-java; name="EvejrDBCopy.java" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="EvejrDBCopy.java" import java.io.*; import java.sql.*; import java.util.ArrayList; import org.postgresql.Driver; import org.postgresql.PGConnection; import org.postgresql.copy.*; import org.postgresql.core.*; public class EvejrDBCopy implements Runnable { private PipedOutputStream pipe; private PGConnection connection; private String tableNameAndContents; // e.g. "TABLE(index, value)" public EvejrDBCopy(Connection conn, String tableNameAndContents) throws SQLException { this.connection = (PGConnection)conn; this.tableNameAndContents = tableNameAndContents; pipe = new PipedOutputStream(); } public void run() { try { //InputStream from = new PipedInputStream(pipe); PipedInputStream from = new PipedInputStream(pipe); CopyManager cm = new CopyManager((BaseConnection) connection); String copyString = "copy "+tableNameAndContents+" from STDIN with csv"; System.out.println(copyString); cm.copyIn(copyString, from); } catch (IOException e) { System.err.println(e.getMessage()); System.err.println(e.getLocalizedMessage()); e.printStackTrace(); } catch (SQLException e) { System.err.println(e.getMessage()); System.err.println(e.getLocalizedMessage()); e.printStackTrace(); } } public PipedOutputStream pipe() { return pipe; } public static void main(String[] args) { ArrayList tableNames = new ArrayList(); for (int i=1; i<11; i++) { tableNames.add("nkptest"+i); } long ROWCOUNT = 100000; double VALUE = 3.14; Date validTime = new Date(System.currentTimeMillis()); String validTimeString = validTime.toString(); try { String url = "jdbc:postgresql://griddb3:5432/grid"; String user = "gridadm"; String pass = "XXXXXX"; Driver driver = new Driver(); DriverManager.registerDriver(driver); Connection connection = DriverManager.getConnection(url, user, pass); for (String tableName : tableNames) { tableName = "temporary_"+tableName; String fullContentDefinition = "( gridpoint_id integer NOT NULL, valid_at timestamp without time zone NOT NULL, parameter_value real NOT NULL )"; String contentDefinition = "( gridpoint_id, valid_at, parameter_value )"; Statement tableStm = connection.createStatement(); tableStm.execute("DROP TABLE IF EXISTS "+tableName); tableStm.execute("CREATE TABLE "+tableName+" "+fullContentDefinition); EvejrDBCopy evCopy = new EvejrDBCopy(connection, tableName + contentDefinition); Thread t = new Thread(evCopy); t.start(); PrintWriter dataStream = new PrintWriter(evCopy.pipe(), true); try { for (int i = 0; i