From sandhyar@amiindia.co.in Wed Mar 1 12:13:11 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DC11E9DCC39 for ; Wed, 1 Mar 2006 08:13:11 -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 67247-06 for ; Wed, 1 Mar 2006 08:13:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from venus.amiindia.co.in (unknown [203.199.198.234]) by postgresql.org (Postfix) with ESMTP id CB5EB9DCADC for ; Wed, 1 Mar 2006 08:13:08 -0400 (AST) Received: from venus.amiindia.co.in (localhost.localdomain [127.0.0.1]) by venus.amiindia.co.in (8.12.11/8.12.11) with ESMTP id k21C7mTn006372 for ; Wed, 1 Mar 2006 17:37:49 +0530 Received: from sandhyar (unknown [10.0.0.205])by venus.amiindia.co.in (Postfix) with ESMTP id AD6AE332665for ; Wed, 1 Mar 2006 17:37:48 +0530 (IST) Message-ID: <01b701c63d2a$4d640880$cd00000a@sandhyar> From: "sandhya" To: "Postgres" References: <018201c63d27$34f26ec0$cd00000a@sandhyar> Subject: Reg:lo_open error..pls help me Date: Wed, 1 Mar 2006 17:48:51 +0530 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_01B4_01C63D58.66E7EE10" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-imss-version: 2.5 X-imss-result: Passed X-imss-scores: Clean:18.93184 C:21 M:1 S:5 R:5 X-imss-settings: Baseline:5 C:3 M:3 S:4 R:3 (0.2500 0.7500) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.081, HTML_MESSAGE=0.001, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200603/6 X-Sequence-Number: 20763 This is a multi-part message in MIME format. ------=_NextPart_000_01B4_01C63D58.66E7EE10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Is it possible to use lo_open after creating the object while the = application is running? Hi, In my application i need to create a file dynamically and load it into = DB. So.....I have created one object at run time .....and trying to open = it inorder to write the content into it..... But lo_open is returning -1(-ve value). where i am doing mistake pls tell me. lobjId =3D lo_creat(conn, INV_READ | INV_WRITE); if (lobjId =3D=3D 0) fprintf(stderr, "can't create large object\n"); lobj_fd =3D lo_open(conn, lobjId, INV_WRITE); //My application failed at this point..what i am missing here ? if (lobj_fd < 0) { fprintf(stderr, "can't open large object %d\n",lobjId); } lo_lseek(conn, lobj_fd, 0, SEEK_SET); nwritten =3D 0; len =3D strlen(szContent); while (len - nwritten > 0) { nbytes =3D lo_write(conn, lobj_fd, szContent, len - nwritten); nwritten +=3D nbytes; } ------=_NextPart_000_01B4_01C63D58.66E7EE10 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Is it possible to use lo_open after creating the = object while=20 the application is running?
Hi,

In my application i need to create a file dynamically and load it = into=20 DB.

So.....I have created one object at run time .....and trying = to open=20 it inorder to write the content into it.....
But lo_open is returning -1(-ve=20 value).

where i am doing mistake pls tell me.

lobjId =3D lo_creat(conn, INV_READ | INV_WRITE);
if = (lobjId =3D=3D=20 0)
fprintf(stderr, "can't create large object\n");
 
lobj_fd =3D lo_open(conn, lobjId, INV_WRITE);
//My application failed at this point..what = i am=20 missing here ?
if = (lobj_fd <=20 0)
{
fprintf(stderr, "can't open large object %d\n",lobjId);
}
lo_lseek(conn, lobj_fd, 0, SEEK_SET);
nwritten =3D 0;
len =3D strlen(szContent);
while = (len -=20 nwritten > 0)
{
nbytes =3D lo_write(conn, lobj_fd, szContent, len - = nwritten);
nwritten +=3D nbytes;
}
------=_NextPart_000_01B4_01C63D58.66E7EE10-- From mike@fuhr.org Wed Mar 1 15:26:35 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 354239DC828 for ; Wed, 1 Mar 2006 11:26:35 -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 09819-04 for ; Wed, 1 Mar 2006 11:26:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 391899DC821 for ; Wed, 1 Mar 2006 11:26:32 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k21FQOfY077964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Mar 2006 08:26:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k21FQNKH047373; Wed, 1 Mar 2006 08:26:23 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k21FQKIg047372; Wed, 1 Mar 2006 08:26:20 -0700 (MST) (envelope-from mfuhr) Date: Wed, 1 Mar 2006 08:26:20 -0700 From: Michael Fuhr To: sandhya Cc: Postgres Subject: Re: Reg:lo_open error..pls help me Message-ID: <20060301152619.GA42224@winnie.fuhr.org> References: <018201c63d27$34f26ec0$cd00000a@sandhyar> <01b701c63d2a$4d640880$cd00000a@sandhyar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01b701c63d2a$4d640880$cd00000a@sandhyar> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.122 required=5 tests=[AWL=0.122] X-Spam-Score: 0.122 X-Spam-Level: X-Archive-Number: 200603/8 X-Sequence-Number: 20765 On Wed, Mar 01, 2006 at 05:48:51PM +0530, sandhya wrote: > Is it possible to use lo_open after creating the object while > the application is running? Yes, but that's off-topic for pgsql-admin. Try pgsql-interfaces or pgsql-general. -- Michael Fuhr From tgl@sss.pgh.pa.us Wed Mar 1 16:03:20 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 695C69DC97A for ; Wed, 1 Mar 2006 12:03:20 -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 17469-07 for ; Wed, 1 Mar 2006 12:03:18 -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 203549DC821 for ; Wed, 1 Mar 2006 12:03:17 -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 k21G3CsS011080; Wed, 1 Mar 2006 11:03:12 -0500 (EST) To: "sandhya" cc: "Postgres" Subject: Re: Reg:lo_open error..pls help me In-reply-to: <01b701c63d2a$4d640880$cd00000a@sandhyar> References: <018201c63d27$34f26ec0$cd00000a@sandhyar> <01b701c63d2a$4d640880$cd00000a@sandhyar> Comments: In-reply-to "sandhya" message dated "Wed, 01 Mar 2006 17:48:51 +0530" Date: Wed, 01 Mar 2006 11:03:12 -0500 Message-ID: <11079.1141228992@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/9 X-Sequence-Number: 20766 "sandhya" writes: > But lo_open is returning -1(-ve value). 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. You might want to look at src/test/examples/testlo.c in the PG distribution. regards, tom lane From mike@fuhr.org Wed Mar 1 16:11:11 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4F3089DCA3E for ; Wed, 1 Mar 2006 12:11:11 -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 18608-05 for ; Wed, 1 Mar 2006 12:11:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 2D5B09DC840 for ; Wed, 1 Mar 2006 12:11:07 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k21GB0Xp078016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Mar 2006 09:11:02 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k21GAxiQ080217; Wed, 1 Mar 2006 09:10:59 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k21GAx5q080216; Wed, 1 Mar 2006 09:10:59 -0700 (MST) (envelope-from mfuhr) Date: Wed, 1 Mar 2006 09:10:59 -0700 From: Michael Fuhr To: Tom Lane Cc: sandhya , Postgres Subject: Re: Reg:lo_open error..pls help me Message-ID: <20060301161059.GA80123@winnie.fuhr.org> References: <018201c63d27$34f26ec0$cd00000a@sandhyar> <01b701c63d2a$4d640880$cd00000a@sandhyar> <11079.1141228992@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11079.1141228992@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.122 required=5 tests=[AWL=0.122] X-Spam-Score: 0.122 X-Spam-Level: X-Archive-Number: 200603/10 X-Sequence-Number: 20767 On Wed, Mar 01, 2006 at 11:03:12AM -0500, Tom Lane wrote: > "sandhya" writes: > > But lo_open is returning -1(-ve value). > > 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 -- Michael Fuhr From tgl@sss.pgh.pa.us Wed Mar 1 16:30:40 2006 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