Re: [ADMIN] Reg:lo_open error..pls help me

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-hackers(at)postgreSQL(dot)org, sandhya <sandhyar(at)amiindia(dot)co(dot)in>
Subject: Re: [ADMIN] Reg:lo_open error..pls help me
Date: 2006-03-01 16:30:10
Message-ID: 11346.1141230610@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

Michael Fuhr <mike(at)fuhr(dot)org> 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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jason Minion 2006-03-01 17:23:22 Re: problem in sequence
Previous Message Michael Fuhr 2006-03-01 16:10:59 Re: Reg:lo_open error..pls help me

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-03-01 16:32:12 Re: Automatic free space map filling
Previous Message Andrew Dunstan 2006-03-01 16:26:21 Re: Initdb on Windows 2003