Re: pqlib large object error

From: Edward Amsden <amsden_linux(at)embarqmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: pqlib large object error
Date: 2008-06-10 21:46:41
Message-ID: 1213134401.17568.0.camel@dad-desktop2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Tue, 2008-06-10 at 16:49 -0400, Tom Lane wrote:
> Edward Amsden <amsden_linux(at)embarqmail(dot)com> writes:
> > On Tue, 2008-06-10 at 14:29 -0400, Tom Lane wrote:
> >> Edward Amsden <amsden_linux(at)embarqmail(dot)com> 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

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2008-06-10 23:05:25 Re: pqlib large object error
Previous Message Tom Lane 2008-06-10 21:21:56 Re: pqlib large object error