Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wxhev-0003t0-HW for pgsql-odbc@arkaria.postgresql.org; Thu, 19 Jun 2014 19:06:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wxheu-0008Mx-OS for pgsql-odbc@arkaria.postgresql.org; Thu, 19 Jun 2014 19:06:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Wxe2j-0004xu-4L for pgsql-odbc@postgresql.org; Thu, 19 Jun 2014 15:14:25 +0000 Received: from mail-bn1ln0183.outbound.protection.outlook.com ([2a01:111:f400:7c10::183] helo=na01-bn1-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wxe2d-0007eR-U5 for pgsql-odbc@postgresql.org; Thu, 19 Jun 2014 15:14:22 +0000 Received: from BY2PR08MB281.namprd08.prod.outlook.com (10.242.237.145) by BY2PR08MB282.namprd08.prod.outlook.com (10.242.237.148) with Microsoft SMTP Server (TLS) id 15.0.954.9; Thu, 19 Jun 2014 15:14:09 +0000 Received: from BY2PR08MB281.namprd08.prod.outlook.com ([169.254.7.113]) by BY2PR08MB281.namprd08.prod.outlook.com ([169.254.7.113]) with mapi id 15.00.0954.000; Thu, 19 Jun 2014 15:14:08 +0000 From: Barry Bell To: "Inoue, Hiroshi" CC: "pgsql-odbc@postgresql.org" Subject: Out of memory while reading tuples error Thread-Topic: [ODBC] Out of memory while reading tuples error Thread-Index: Ac+L0NdDky8ilGTGQcWoRMMLfhUocw== Date: Thu, 19 Jun 2014 15:14:08 +0000 Message-ID: <7de4876cf1284c7280461aaf5fb5bd41@BY2PR08MB281.namprd08.prod.outlook.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [63.95.64.254] x-microsoft-antispam: BL:0; ACTION:Default; RISK:Low; SCL:0; SPMLVL:NotSpam; PCL:0; RULEID: x-forefront-prvs: 02475B2A01 x-forefront-antispam-report: SFV:NSPM; SFS:(6009001)(428001)(479174003)(13464003)(199002)(189002)(24454002)(51704005)(377454003)(38414003)(15202345003)(50986999)(85306003)(95666004)(77096002)(21056001)(86362001)(87936001)(92566001)(4396001)(99286002)(2656002)(54356999)(85852003)(83072002)(105586002)(99396002)(101416001)(81542001)(79102001)(74316001)(76576001)(83322001)(31966008)(19580395003)(19580405001)(74502001)(74662001)(81342001)(77982001)(76482001)(80022001)(66066001)(33646001)(64706001)(46102001)(20776003)(15975445006)(24736002); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR08MB282; H:BY2PR08MB281.namprd08.prod.outlook.com; FPR:; MLV:sfv; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (: hartehanks.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Barry.Bell@hartehanks.com; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hartehanks.com X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org Hi: When executing a SQL statement with a large # of records (500,000 in t= his case), I am getting " Out of memory while reading tuples error" Communication error while getting a tuple; Error fetching next row I turned on USEDECLAREFETCH=3D1 (B6=3D1), which has no effect on this erro= r.=20 Any Ideas? Barry Bell Senior Developer/Analyst Logistics Harte Hanks 1525 NW 3rd ST Deerfield Beach FL, 33442 954-429-3771 Ext 267 office 954-281-1464 fax hartehanks.com / linkedin / twitter / facebook -----Original Message----- From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.o= rg] On Behalf Of Inoue, Hiroshi Sent: Thursday, June 19, 2014 12:25 AM To: Craig Ringer Cc: pgsql-odbc@postgresql.org Subject: Re: [ODBC] Protocol de-synchronisation bug, bogus query sent Hi Craig, The code seems for v0/v1 protocol. Though I don't remember well, the dance = was probably because v0/v1 didn't have clear sync mechanism. I wonder why the code reached there. The flag beforeV2 is broken? regards, Hiroshi Inoue (2014/06/19 12:44), Craig Ringer wrote: > Hi folks > > I've found a bug in psqlODBC, in CC_send_query_append, where psqlODBC=20 > gets out of sync with the server's idea of the connection state and=20 > both wait for each other indefinitely. > > So far I've only reproduced it as part of debugging a larger issue.=20 > I've only actually seen it when psqlODBC establishes an "isolated" XA=20 > connection after failing to acquire a lock on the DTC connection in=20 > IAsyncPG::getLockedXAConn(). If the client has specified a=20 > connect-time query string with a DSN like: > > DRIVER=3D{PostgreSQL=20 > ANSI};SERVER=3DLOCALHOST;DATABASE=3Dpostgres;A6=3Dset > search_path to someschema;UID=3D;PWD=3D;BI=3D-5;debug=3D1;commlog=3D1; > > ... but it's clearly a bug in its own right, so I'll write it up here=20 > and propose a fix. > > > Patch attached, or you can pull the branch: > > fix-febe-protocol-desync-emptyquery > > from https://github.com/ringerc/psqlODBC.git > > > > The whole code block around connection.c:3082 appears to be attempting=20 > to send an empty query in order to elicit an 'I' (EmptyQueryResponse)=20 > message. It sends a malformed protocol message: > > SOCK_put_string(self->sock, "Q "); > SOCK_flush_output(self->sock); > > so the server just waits for the rest of the message, never responding. > > When the connection is killed by program exit later, the server will log: > > LOG: unexpected EOF within message length word > LOG: disconnection: session time: 0:00:08.910 user=3DAdministrator=20 > database=3DXXXX host=3D127.0.0.1 port=3D53705 > LOG: could not receive data from client: No connection could be made=20 > because the target machine actively refused it. > > > That's because the V3 protocol specifies that the message format for=20 > Query is: > > 'Q' > [32 bit integer] > [query string] > > http://www.postgresql.org/docs/current/static/protocol-message-formats > .html > > ... but psqlODBC just sends: > > 'Q' > '\x20' > '\x00' > > If it is really necessary to go through this empty-query dance, then=20 > for the V3 protocol the correct message would be: > > /* Send an empty query to elicit an 'I' (EmptyQueryResponse) > * from the server */ > SOCK_put_char(self->sock, 'Q'); > SOCK_put_int(self->sock, 5, 4); > SOCK_put_char(self->sock, '\0'); > > > > Since no 'I' message is ever received the next message is 'Z' > (ReadyForQuery). psqlODBC consumes this and carries on waiting for the=20 > next message, as it has set emptyreqs=3D1 to expect 'I' messages. So it=20 > waits forever, since the server thinks it's waiting for psqlODBC to=20 > finish sending the prior protocol message. > > It isn't clear to me why psqlODBC does this weird dance with empty=20 > queries at all, but it's certainly doing it wrong. > > The attached patch fixes the immediate problem, but I'd like to see if=20 > this can be simplified out entirely in favour of, in ascending=20 > size-of-work order, (a) using a protocol sync message, then (b)=20 > deleting as much as possible of this custom protocol handling code=20 > entirely and using libpq. -- I am using the free version of SPAMfighter. SPAMfighter has removed 10973 of my spam emails to date. Get the free SPAMfighter here: http://www.spamfighter.com/len Do you have a slow PC? Try a Free scan http://www.spamfighter.com/SLOW-PCfighter?cid=3Dsigen --=20 Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --=20 Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc