"Error could not open relation with OID ..." when selecting from pg_views

From: Marcin Gozdalik <gozdal(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: "Error could not open relation with OID ..." when selecting from pg_views
Date: 2017-09-06 12:33:55
Message-ID: CADu1mRMg3Z85wALRcCCMTsPqAFNWpH5GppfcLjh9n+PApGrYsw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Querying pg_views sometimes returns "Error could not open relation with OID
...".

Example program to exhibit the problem:

import sys
from threading import Thread

import psycopg2

class TempViewsCreator(Thread):
def run(self):
self.conn = psycopg2.connect("dbname=starfish user=starfish")
while True:
self.create_temp_tables()

def create_temp_tables(self):
cur = self.conn.cursor()
cur.execute("CREATE OR REPLACE VIEW foo AS SELECT 1;")
# COMMENT the following commit to make the problem go away
self.conn.commit()
cur.execute("DROP VIEW foo;")
self.conn.commit()
cur.close()

def main():
creator = TempViewsCreator()
creator.daemon = True
creator.start()

while True:
cur = None
conn = None
try:
conn = psycopg2.connect("dbname=starfish user=starfish")
cur = conn.cursor()
cur.execute("SELECT definition FROM pg_views;")
print('success')
except psycopg2.Error as e:
print('Error {e}'.format(e=e))
finally:
if cur:
cur.close()
if conn:
conn.close()

if __name__ == '__main__':
sys.exit(main())

I'd expect selecting from pg_views not to raise this error.

PostgreSQL 9.6.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609, 64-bit running on Ubuntu Xenial.
--

Marcin Gozdalik

Browse pgsql-bugs by date

  From Date Subject
Next Message kostin.artem 2017-09-06 13:21:56 BUG #14800: substring produces different results with similar types
Previous Message phb07 2017-09-06 12:00:05 BUG #14799: SELECT * FROM transition_table in a statement-level trigger