Thread: ERROR: heap_fetch: xinv19073 relation: ReadBuffer(81aeefe) failed

ERROR: heap_fetch: xinv19073 relation: ReadBuffer(81aeefe) failed

From
Ian Grant
Date:
Hello PostgreSQL Hackers,

I get this error with the attached program. Is this a bug or is it that
I'm doing something totally stupid?

The program opens a connection, starts a transaction, creates a large
object with mode INV_READ | INV_WRITE, opens it with the same mode, calls
lo_write five times with a single 'X', calls lo_lseek to seek to position
1, calls lo_write to write a single 'y', then calls lo_lseek to seek to
position 3 and writes another 'y', then calls lo_close and finally ends
the transaction. The error happens when I write the second 'y'.

I have attached a trace to this message too.

Thanks in advance for your time.

Ian
#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);
 
}
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'               or 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