Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BB4DF2E01F6 for ; Fri, 14 Dec 2007 17:50:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36173-01 for ; Fri, 14 Dec 2007 17:50:54 -0400 (AST) Received: from web39108.mail.mud.yahoo.com (web39108.mail.mud.yahoo.com [209.191.87.227]) by postgresql.org (Postfix) with SMTP id 47FF02E2D8E for ; Fri, 14 Dec 2007 17:50:54 -0400 (AST) Received: (qmail 98170 invoked by uid 60001); 14 Dec 2007 21:50:53 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=I+OWzjDjCV6ZX4/gdM1dCtMZiYJMAobwDS1Z0FqKiaoXQL80Ku/KN1l8hLL0PzpNh4WjCwZdc7AOSJdcv7ejRGeionhoySzLKN6qWcu9FKCk3MDO7ogFk4ve54YP32YDCH8oDmf+eys3OSG98Fn5sSeT9U1B55wE0PHZXYrUwTE=; X-YMail-OSG: P4LVXKIVM1nQsXL5oN1RaZjELT1IY2hr9si6vLmj7xeWDN4gT.yOgUUIxxcE2uAI6mWdsaEil28T7P01OXyyhNi..KDJ3wwtpUjTvopin3kO_wg- Received: from [210.2.161.149] by web39108.mail.mud.yahoo.com via HTTP; Fri, 14 Dec 2007 13:50:52 PST Date: Fri, 14 Dec 2007 13:50:52 -0800 (PST) From: Altaf Malik Subject: Re: JDBC causing the connection to close after executing a COPY command To: Kris Jurka Cc: Dave Cramer , pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1730698753-1197669052=:97215" Content-Transfer-Encoding: 8bit Message-ID: <70448.97215.qm@web39108.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/124 X-Sequence-Number: 17979 --0-1730698753-1197669052=:97215 Content-Type: multipart/alternative; boundary="0-300522718-1197669052=:97215" --0-300522718-1197669052=:97215 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I am attaching the new patch. For CopyInResponse, client will send a CopyFail message and server won't wait for the client input. For CopyOutResponse, exception is generated for only CopyOutResponse and not for every CopyData message. Also slightly changed the 'ignoring' mechanism from reading the message to ignore it to skipping the message. I hope this will also improve the performance. Altaf Malik EnterpriseDB http://www.enterprisedb.com/ Kris Jurka wrote: In the case of copying data from the server, if you do have a large table, you'll generate a SQLException for every row of the copy result which isn't great, but I guess it's better than failing completely. Trying to copy out a single column table of 100k integers took about seven minutes and 150 MB of memory here. Also, it doesn't work for copying data to the server. In that case the server is sitting waiting for data and the driver is waiting for the server and nothing happens. That was the case before, so this is no worse. Do you have plans to work on this further or shall I apply just this minor improvement? Kris Jurka Best Regards Muhammad Altaf Malik Sr. Software Engineer, EnterpriseDB (SMC) (pvt) Ltd. 3rd floor, Software Technology Park, Islamabad. Ph: +92 (051) 2873815 Cell: 0321-5177961 --------------------------------- Never miss a thing. Make Yahoo your homepage. --0-300522718-1197669052=:97215 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I am attaching the new patch.

For CopyInResponse, client will send a CopyFail message and server won't wait for the client input. For CopyOutResponse, exception is generated for only CopyOutResponse and not for every CopyData message. Also slightly changed the 'ignoring' mechanism from reading the message to ignore it to skipping the message. I hope this
 will also improve the performance.

Altaf Malik
EnterpriseDB
http://www.enterprisedb.com/

Kris Jurka <books@ejurka.com> wrote:

In the case of copying data from the server, if you do have a
large table, you'll generate a SQLException for every row of the copy
result which isn't great, but I guess it's better than failing completely.

Trying to copy out a single column table of 100k integers took about seven
minutes and 150 MB of memory here.

Also, it doesn't work for copying data to the server. In that case the
server is sitting waiting for data and the driver is waiting for the
server and nothing happens. That was the case before, so this is no
worse.

Do you have plans to work on this further or shall I apply just this minor
improvement?

Kris Jurka



Best Regards
Muhammad Altaf Malik
Sr. Software Engineer,
EnterpriseDB (SMC) (pvt) Ltd.
3rd floor, Software Technology Park,
Islamabad. Ph: +92 (051) 2873815
Cell: 0321-5177961


Never miss a thing. Make Yahoo your homepage. --0-300522718-1197669052=:97215-- --0-1730698753-1197669052=:97215 Content-Type: text/x-patch; name="pg_copy.diff" Content-Description: 2290331491-pg_copy.diff Content-Disposition: inline; filename="pg_copy.diff" *** org/postgresql/core/v3/QueryExecutorImpl.java 2007-10-15 13:06:24.000000000 +0500 --- org/postgresql/core/v3/QueryExecutorImpl.java 2007-12-15 02:40:49.000000000 +0500 *************** *** 1425,1447 **** break; case 'G': // CopyInResponse case 'H': // CopyOutResponse case 'c': // CopyDone ! case 'd': // CopyData ! { ! // COPY FROM STDIN / COPY TO STDOUT, neither of which are currently ! // supported. ! ! // CopyInResponse can only occur in response to an Execute we sent. ! // Every Execute we send is followed by either a Bind or a ClosePortal, ! // so we don't need to send a CopyFail; the server will fail the copy ! // automatically when it sees the next message. ! ! int l_len = pgStream.ReceiveInteger4(); ! /* discard */ ! pgStream.Receive(l_len); ! handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); } break; --- 1425,1469 ---- break; case 'G': // CopyInResponse + if (logger.logDebug()) { + logger.debug(" <=BE CopyInResponse"); + logger.debug(" FE=> CopyFail"); + } + + //COPY sub-protocol is not implemented yet + // We'll send a CopyFail message for COPY FROM STDIN so that server does not wait for the data + // For COPY TO STDOUT we cannot abort the data transfer ... we'll just ignore the messages + + byte[] buf = GT.tr("The driver currently does not support COPY operations.").getBytes(); + pgStream.SendChar('f'); + pgStream.SendInteger4(buf.length + 4 + 1); + pgStream.Send(buf); + pgStream.SendChar(0); + pgStream.flush(); + sendSync(); // send sync message + skipCopyResponse(); // skip the response message + break; + case 'H': // CopyOutResponse + if (logger.logDebug()) + logger.debug(" <=BE CopyOutResponse"); + + skipCopyResponse(); + //In case of CopyOutResponse we cannot abort data transfer - we will just throw error and ignore CopyData messages + handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); + break; + case 'c': // CopyDone ! skipCopyResponse(); // skip the response message ! if (logger.logDebug()) { ! logger.debug("<=BE CopyDone"); ! } ! break; ! case 'd': // CopyData ! skipCopyResponse(); // skip the response message ! if (logger.logDebug()) { ! logger.debug("<=BE CopyData"); } break; *************** *** 1452,1457 **** --- 1474,1487 ---- } } + // skipCopyResponse + // ignore the response message by just skipping the next n bytes where n is the message length in bytes + private void skipCopyResponse() throws IOException { + int l_len = pgStream.ReceiveInteger4(); + // skip l_len-4 (length includes the 4 bytes for message length itself + pgStream.Skip(l_len - 4); + } + public synchronized void fetch(ResultCursor cursor, ResultHandler handler, int fetchSize) throws SQLException { final Portal portal = (Portal)cursor; --0-1730698753-1197669052=:97215--