Backend problem with large objects - Mailing list pgsql-hackers

From Ian Grant
Subject Backend problem with large objects
Date
Msg-id Pine.LNX.3.96.990202105901.2017E-100000@wimp.amtp.cam.ac.uk
Whole thread Raw
Responses Re: [HACKERS] Backend problem with large objects
List pgsql-hackers
I am writing a Postgres interface for Guile. (I know, I am the other one
of the two people doing this!)

I sent a message at the weekend, but I used mime encoding of the files
which I understand some people have difficulty decoding, so here is my
report again, in the clear this time. 

I am having problems with my large object interface. In particular I get
the error
   ERROR: heap_fetch: xinv19073 relation: ReadBuffer(81aeefe) failed

from the backend.

I have written a small C program to reproduce the problem, and it follows 
below, along with the output of PQtrace.

In summary, the problem is: 

/* Pseudo-C */

conn = PQconnectdb()
PQexec (conn, BEGIN TRANSACTION)
oid = lo_creat (conn, INV_READ | WRITE)
fd = lo_open(conn oid, INV_READ | INV_WRITE)
for (i = 0; i < 5; i++)  lo_write(fd, 'X')
lo_lseek(fd, 1, 0)
lo_write(fd, 'y')
lo_lseek(fd, 3, 0)
lo_write(fd, 'y') /**** error happens here ****/
lo_close(fd)
PQexec (conn, END TRANSACTION)

The real C is:

#include <stdio.h>
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"

void exec_cmd(PGconn *conn, char *str);

main (int argc, char *argv[])
{  PGconn *conn;  int lobj_fd;  char buf[256];  int ret, i;  Oid lobj_id;
  conn = PQconnectdb("dbname=test");  if (PQstatus(conn) != CONNECTION_OK) {     fprintf(stderr, "Can't connect to
backend.\n");    fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));     exit(1);  }  exec_cmd(conn, "BEGIN
TRANSACTION"); PQtrace (conn, stdout);  if ((lobj_id = lo_creat(conn, INV_READ | INV_WRITE)) < 0) {     fprintf(stderr,
"Can'tcreate lobj.\n");     fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));     exit(1);  }  if ((lobj_fd =
lo_open(conn,lobj_id, INV_READ | INV_WRITE)) < 0) {     fprintf(stderr, "Can't open lobj.\n");     fprintf(stderr,
"ERROR:%s\n", PQerrorMessage(conn));     exit(1);  }  fprintf(stderr, "lo_open returned fd = %d.\n", lobj_fd);  for (i
=0; i < 5; i++) {     if ((ret = lo_write(conn, lobj_fd, "X", 1)) != 1) {        fprintf(stderr, "Can't write
lobj.\n");       fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));        exit(1);     }  }  if ((ret =
lo_lseek(conn,lobj_fd, 1, 0)) != 1) {     fprintf(stderr, "error (%d) lseeking in large object.\n", ret);
fprintf(stderr,"ERROR: %s\n", PQerrorMessage(conn));     exit(1);  }  if ((ret = lo_write(conn, lobj_fd, "y", 1)) != 1)
{    fprintf(stderr, "Can't write lobj.\n");     fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));     exit(1);  }
if((ret = lo_lseek(conn, lobj_fd, 3, 0)) != 3) {     fprintf(stderr, "error (%d) lseeking in large object.\n", ret);
fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));     exit(1);  }  if ((ret = lo_write(conn, lobj_fd, "y", 1)) !=
1){     fprintf(stderr, "Can't write lobj.\n");     fprintf(stderr, "ERROR: %s\n", PQerrorMessage(conn));     exit(1);
} ret = lo_close(conn, lobj_fd);  printf("lo_close returned %d.\n", ret);  if (ret)     fprintf(stderr, "Error message:
%s\n",PQerrorMessage(conn));  PQuntrace(conn);  exec_cmd(conn, "END TRANSACTION");  exit(0);
 
}

void exec_cmd(PGconn *conn, char *str)
{  PGresult *res;
  if ((res = PQexec(conn, str)) == NULL) {     fprintf(stderr, "Error executing %s.\n", str);     fprintf(stderr,
"Errormessage: %s\n", PQerrorMessage(conn));     exit(1);  }  if (PQresultStatus(res) != PGRES_COMMAND_OK) {
fprintf(stderr,"Error executing %s.\n", str);     fprintf(stderr, "Error message: %s\n", PQerrorMessage(conn));
PQclear(res);    exit(1);  }  PQclear(res);
 
}

Here is a trace-log of the whole affair:

To backend> Q
To backend> select proname, oid from pg_proc                where proname = 'lo_open'               or proname =
'lo_close'              or proname = 'lo_creat'               or proname = 'lo_unlink'               or proname =
'lo_lseek'              or proname = 'lo_tell'               or proname = 'loread'               o
 
r proname = 'lowrite'
>From backend> P
>From backend> "blank"
>From backend> T
>From backend (#2)> 2
>From backend> "proname"
>From backend (#4)> 19
>From backend (#2)> 32
>From backend (#4)> -1
>From backend> "oid"
>From backend (#4)> 26
>From backend (#2)> 4
>From backend (#4)> -1
>From backend> D
>From backend (1)> À
>From backend (#4)> 11
>From backend (7)> lo_open
>From backend (#4)> 7
>From backend (3)> 952
>From backend> D
>From backend (1)> À
>From backend (#4)> 12
>From backend (8)> lo_close
>From backend (#4)> 7
>From backend (3)> 953
>From backend> D
>From backend (1)> À
>From backend (#4)> 12
>From backend (8)> lo_creat
>From backend (#4)> 7
>From backend (3)> 957
>From backend> D
>From backend (1)> À
>From backend (#4)> 13
>From backend (9)> lo_unlink
>From backend (#4)> 7
>From backend (3)> 964
>From backend> D
>From backend (1)> À
>From backend (#4)> 12
>From backend (8)> lo_lseek
>From backend (#4)> 7
>From backend (3)> 956
>From backend> D
>From backend (1)> À
>From backend (#4)> 11
>From backend (7)> lo_tell
>From backend (#4)> 7
>From backend (3)> 958
>From backend> D
>From backend (1)> À
>From backend (#4)> 10
>From backend (6)> loread
>From backend (#4)> 7
>From backend (3)> 954
>From backend> D
>From backend (1)> À
>From backend (#4)> 11
>From backend (7)> lowrite
>From backend (#4)> 7
>From backend (3)> 955
>From backend> C
>From backend> "SELECT"
>From backend> Z
>From backend> Z
To backend> F 
To backend (4#)> 957
To backend (4#)> 1
To backend (4#)> 4
To backend (4#)> 393216
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 19201
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 952
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 19201
To backend (4#)> 4
To backend (4#)> 393216
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 0
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 956
To backend (4#)> 3
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 4
To backend (4#)> 0
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 0
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> X
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> X
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> X
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> X
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> X
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 956
To backend (4#)> 3
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 4
To backend (4#)> 1
To backend (4#)> 4
To backend (4#)> 0
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> y
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 1
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 956
To backend (4#)> 3
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 4
To backend (4#)> 3
To backend (4#)> 4
To backend (4#)> 0
>From backend> V
>From backend> G
>From backend (#4)> 4
>From backend (#4)> 3
>From backend> 0
>From backend> Z
To backend> F 
To backend (4#)> 955
To backend (4#)> 2
To backend (4#)> 4
To backend (4#)> 0
To backend (4#)> 1
To backend> y
>From backend> E
>From backend> "ERROR:  heap_fetch: xinv19201 relation: ReadBuffer(81aeefe) failed
"
>From backend> Z





pgsql-hackers by date:

Previous
From: Goran Thyni
Date:
Subject: Re: [HACKERS] Patch (was: tough locale bug)
Next
From: Àíäðåé Íîâèêîâ
Date:
Subject: VACUUM problem