Thread: BUG #8307: can reproduce: pg_dump: schema with OID xxxxxx does not exist

BUG #8307: can reproduce: pg_dump: schema with OID xxxxxx does not exist

From
michael.enke@wincor-nixdorf.com
Date:
The following bug has been logged on the website:

Bug reference:      8307
Logged by:          Michael Enke
Email address:      michael.enke@wincor-nixdorf.com
PostgreSQL version: 9.1.8
Operating system:   Linux/CentOS 6.2
Description:

Hi,
after hitting the above error and found that this is a long lasting one
which nobody knows how to reproduce, I found a way to reproduce it:
In one session create tables in a schema,
in another session drop that schema.


Here comes my test script:


#!/bin/sh


DB=testdb # change if you need
NUM=2000 # adjust so that creation takes enough time to issue drop schema


CREATE=/tmp/$DB.sql
START=/tmp/testdb.start
END=/tmp/testdb.end


LANG=C
rm -f $START $END
>$CREATE
for I in $(seq $NUM); do
  echo "create table t$I(at text, bt text, ct text, dt text);" >> $CREATE
  echo "create table tt$I as select g1.*, t$I.* from g1, t$I where 1=2;" >>
$CREATE
  echo "drop table t$I;" >> $CREATE
done


(
  psql -U postgres -d template1 <<!
    \set ON_ERROR_STOP
    drop database $DB;
    create database $DB;
    \connect $DB
    create schema testschema;
    set search_path = testschema,"\$user",public;
    create table g1(ag text, bg text, cg text, dg text);
    \echo now create $NUM tables
    \o $START
    \o /dev/null
    \i $CREATE
    \o $END
!
  rm -f $CREATE
  sleep 2
  pg_dump -U postgres $DB > testdb.dump
)&


while [ ! -f $START ]; do usleep 100000; done
sleep 1
psql -U postgres -d $DB -c "drop schema testschema cascade" 2>&1 | grep
"^NOTICE"
if [ -f $END ]; then
  echo "too late"
fi
wait
rm -f $START $END


# end script


There are 3 possible errors reported (I executed 10x):
1: Deadlock detected: 1x
2: Could not open relation for Create: 4x
3: cache lookup failed: 5x


In case of 2 or 3 pg_dump reports above error.


If I modify the creation to only one line:
echo "create table tt$I as select g1.* from g1 where 1=2;" >> $CREATE
then in 100% I get the case number 2.


Hope it helps tracking down the reason.