Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id BFECF2E003E for ; Tue, 10 Jun 2008 18:46:55 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57359-08 for ; Tue, 10 Jun 2008 18:46:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailrelay.embarq.synacor.com (mailrelay.embarq.synacor.com [208.47.184.3]) by developer.postgresql.org (Postfix) with ESMTP id 817EF2E0033 for ; Tue, 10 Jun 2008 18:46:52 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha1; d=embarqmail.com; s=s012408; c=relaxed/simple; q=dns/txt; i=@embarqmail.com; t=1213134410; h=From:Subject:Date:To:Mime-Version:Content-Type; bh=P4N+SEUkP6EkMq5OC33gyu7agWA=; b=MghhLDcli3XK6dlbGapWZ2VCbwzAoEPGrmDRkOb0R8Ge4JzqdQ8asDBk7rct339E TQoBMoLM5yMbSothf4O9U5G5Y8VM7r2YsVPgD5TDsxu/ARjpcjoYMjSVlYcc/X18; X_CMAE_Category: 0,0 Undefined,Undefined X-CNFS-Analysis: v=1.0 c=1 a=yojgaC0HzEAA:10 a=gra_WR_tcWEA:10 a=OEPRTt4cA10nCcNXdYkA:9 a=7sUZi-kPBt9bxPrsbo0A:7 a=jh1JZPHBhjblphsymTBIURAmlX0A:4 a=cvn8laQl214A:10 a=LY0hPdMaydYA:10 X-CM-Score: 0 X-Scanned-by: Cloudmark Authority Engine Authentication-Results: smtp07.embarq.synacor.com smtp.user=amsden_linux@embarqmail.com; auth=pass (LOGIN) Received: from [71.2.202.190] ([71.2.202.190:36452] helo=[192.168.0.30]) by mailrelay.embarq.synacor.com (envelope-from ) (ecelerity 2.2.1.28 r(22594)) with ESMTPA id 02/56-06326-A46FE484; Tue, 10 Jun 2008 17:46:50 -0400 Subject: Re: pqlib large object error From: Edward Amsden To: pgsql-interfaces@postgresql.org In-Reply-To: <24396.1213130996@sss.pgh.pa.us> References: <1213118594.9123.11.camel@dad-desktop2> <21991.1213122593@sss.pgh.pa.us> <1213130242.15557.3.camel@dad-desktop2> <24396.1213130996@sss.pgh.pa.us> Content-Type: text/plain Date: Tue, 10 Jun 2008 17:46:41 -0400 Message-Id: <1213134401.17568.0.camel@dad-desktop2> Mime-Version: 1.0 X-Mailer: Evolution 2.22.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/8 X-Sequence-Number: 6751 On Tue, 2008-06-10 at 16:49 -0400, Tom Lane wrote: > Edward Amsden writes: > > On Tue, 2008-06-10 at 14:29 -0400, Tom Lane wrote: > >> Edward Amsden writes: > >>> I cannot seem to figure this error message out: > >>> > >>> ERROR: duplicate key value violates unique constraint "pg_largeobject_loid_pn_index" > >> > >> Huh, that shouldn't happen. Is it repeatable? > > > Yes. It happens every time the program runs, no matter what db or user, > > tried unix socket and tcp connect > > >> What PG version > >> is your server? > > > 8.3.1, running on Ubuntu Linux > > Hmph. The only thing I can think of is that that index is corrupt, > but it seems unlikely that it would be so in all databases. What > happens if you REINDEX pg_largeobject? The error has disappeared. Now it can't write to the object. lo_open seems to be successful, but lo_write is failing with: > ERROR: invalid large-object descriptor: 0 0 is a valid value (I checked) but it appears it cannot write to the object. lo_open should return a negative value if it cannot create the handle Here is my code: if (PQstatus(connect1) == CONNECTION_OK) { lo_1 = lo_creat(connect1, INV_READ|INV_WRITE); if (lo_1 > 0) { lo_1_fd = lo_open(connect1, lo_1, INV_READ|INV_WRITE); written = lo_write(connect1, lo_1_fd, filedata, (size_t) filelen); if (written == filelen) { printf ("Write successful, %d bytes written.\n", written); } else if (written < 0) { printf ("Write unsuccessful: %s\n", PQerrorMessage(connect1)); } else { printf ("Write partially successful. %d of %d bytes written.\n", written, filelen); } } else { fprintf (stderr, "Unable to create large object: %s\n", PQerrorMessage(connect1)); } } else { fprintf (stderr, "Unable to open connection: %s\n", PQerrorMessage(connect1)); } Let me know if it's unreadable, my mail client can do funny things with indents. > regards, tom lane