X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CB3199DC840 for ; Wed, 1 Mar 2006 12:30:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25507-02 for ; Wed, 1 Mar 2006 12:30:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 955E29DC854 for ; Wed, 1 Mar 2006 12:30:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k21GUArl011347; Wed, 1 Mar 2006 11:30:10 -0500 (EST) To: Michael Fuhr cc: pgsql-hackers@postgreSQL.org, sandhya Subject: Re: [ADMIN] Reg:lo_open error..pls help me In-reply-to: <20060301161059.GA80123@winnie.fuhr.org> References: <018201c63d27$34f26ec0$cd00000a@sandhyar> <01b701c63d2a$4d640880$cd00000a@sandhyar> <11079.1141228992@sss.pgh.pa.us> <20060301161059.GA80123@winnie.fuhr.org> Comments: In-reply-to Michael Fuhr message dated "Wed, 01 Mar 2006 09:10:59 -0700" Date: Wed, 01 Mar 2006 11:30:10 -0500 Message-ID: <11346.1141230610@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200603/14 X-Sequence-Number: 80412 Michael Fuhr writes: > On Wed, Mar 01, 2006 at 11:03:12AM -0500, Tom Lane wrote: >> Are you sure that's where it's failing? The fragment you showed looks >> fine as far as it goes. The most likely bet is you forgot to wrap it in >> a transaction (BEGIN/COMMIT commands), but that would result in a >> failure at the seek/write commands because the object wouldn't be open >> anymore. > lo_open() fails if it's not in a transaction. The error from > PQerrorMessage is: > ERROR: invalid large-object descriptor: 0 Hmm, I wonder why that is [ looks at code ... ] The culprit seems to be this little bit in libpq's lo_open() function: /* have to do this to reset offset in shared fd cache */ /* but only if fd is valid */ if (fd >= 0 && lo_lseek(conn, fd, 0L, SEEK_SET) < 0) return -1; return fd; Outside a transaction block, this fails since the LO FD is already closed by the time the lo_lseek request is run. This hack goes all the way back --- it's in our original CVS version, and there is equivalent code in Postgres v4r2 --- but it sure looks to me like a workaround for a long-forgotten bug. It's forcing an extra network round trip for every lo_open, so I'm very strongly tempted to remove it. Comments? regards, tom lane