Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Started by Kristofer Munnalmost 27 years ago8 messageshackers
Jump to latest
#1Kristofer Munn
kmunn@munn.com

Is anyone else having any problems with the Perl Interface wrt Large
Objects under 6.5?

I compiled and installed 6.5 on an Intel/Linux/RedHat 6.0 machine that had
previously had 6.4.2 and imported existing data from the old database.
Perl scripts which were working under the previous version are now failing
when trying to open a newly created large object. A line appears in the
error log:

Jun 23 17:40:47 www logger: ERROR: lo_lseek: invalid large obj descriptor (0)

While the code being executed is a function call write_blob below. The
scaffolding internally tells me it is unable to open oid XXXXXX for
writing where XXXXXX is the newly "created" oid #.

sub write_blob {
my($oid, $blob) = @_;

print "write_blob($oid, '$blob');\n" if $debug;
if ($blob eq "") {
if ($oid > 0) {
$conn->lo_unlink($oid);
}
print "No blob to write\n" if $debug;
return "NULL";
}
if ($oid == 0) {
$oid = $conn->lo_creat(PGRES_INV_WRITE | PGRES_INV_READ);
if ($oid == PGRES_InvalidOid) {
print "Unable to get new oid.\n" if $debug;
return "NULL";
}
}
my($lobj_fd) = $conn->lo_open($oid, PGRES_INV_WRITE);
if ($lobj_fd == -1) {
print "Unable to open oid $oid for writing.\n" if $debug;
return "NULL";
}

if ($conn->lo_write($lobj_fd, $blob, length($blob)) == -1) {
$conn->lo_close($lobj_fd);
$conn->lo_unlink($oid);
print "Unable to write blob into open oid $oid.\n" if $debug;
return "NULL";
}
$conn->lo_close($lobj_fd);

print "write_blob successful\n" if $debug;

return $oid;
}

I reverted to 6.4.2 and the scripts worked again. Back to 6.5 - no dice.

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kristofer Munn (#1)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Kristofer Munn <kmunn@munn.com> writes:

Is anyone else having any problems with the Perl Interface wrt Large
Objects under 6.5?

I compiled and installed 6.5 on an Intel/Linux/RedHat 6.0 machine that had
previously had 6.4.2 and imported existing data from the old database.
Perl scripts which were working under the previous version are now failing
when trying to open a newly created large object. A line appears in the
error log:

Jun 23 17:40:47 www logger: ERROR: lo_lseek: invalid large obj descriptor (0)

6.5 enforces the requirement that LO objects be used inside a
transaction. Prior versions did not enforce this ... they just didn't
work very reliably if the lifetime of an LO FD wasn't encased in
begin/commit :-(. I suppose you had managed to get away with it,
but you'd be much better off adding the begin/commit even for 6.4.

regards, tom lane

#3Kristofer Munn
kmunn@munn.com
In reply to: Tom Lane (#2)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

On Wed, 23 Jun 1999, Tom Lane wrote:

6.5 enforces the requirement that LO objects be used inside a
transaction. . . . [remainder clipped]

Aha. And the implication is then that all large object operations
(creation, deletion and modification) are affected by rollbacks and
commits. As they should be.

I will add the transaction code. Thanks...

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn

#4Kristofer Munn
kmunn@munn.com
In reply to: Tom Lane (#2)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

I wrapped the large object functions in a transaction and they worked. A
side note (for the archives) is that even the reads need to be wrapped in
a transaction.

Thanks again...

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn

#5Edmund Mergl
E.Mergl@bawue.de
In reply to: Kristofer Munn (#1)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Kristofer Munn wrote:

Is anyone else having any problems with the Perl Interface wrt Large
Objects under 6.5?

yes, me too.

Wait for the next version of DDB-Pg.

Edmund

--
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl

#6Edmund Mergl
E.Mergl@bawue.de
In reply to: Kristofer Munn (#4)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Kristofer Munn wrote:

I wrapped the large object functions in a transaction and they worked. A
side note (for the archives) is that even the reads need to be wrapped in
a transaction.

Thanks again...

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn

Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c)
it works without transactions.

Edmund

--
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Edmund Mergl (#6)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Edmund Mergl <E.Mergl@bawue.de> writes:

Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c)
it works without transactions.

With 6.5? I don't think so ... I made sure that LO FDs would be
cancelled at transaction commit --- which is end of statement, if
you are not within a transaction ...

regards, tom lane

#8Edmund Mergl
E.Mergl@bawue.de
In reply to: Tom Lane (#7)
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Tom Lane wrote:

Edmund Mergl <E.Mergl@bawue.de> writes:

Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c)
it works without transactions.

With 6.5? I don't think so ... I made sure that LO FDs would be
cancelled at transaction commit --- which is end of statement, if
you are not within a transaction ...

regards, tom lane

yes, you're right, Accidentally I used the files from 6.4.

Edmund

--
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl