Skip site navigation (1) Skip section navigation (2)

cannot read pg_class without having selected a database / is this a bug?

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-hackers(at)postgresql(dot)org
Subject: cannot read pg_class without having selected a database / is this a bug?
Date: 2011-12-03 22:33:20
Message-ID: 4EDAA3B0.1010707@fuzzy.cz (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi,

I've written a simple extension that limits number of connection by
IP/db/user, and I do receive this exception:

psql: FATAL:  cannot read pg_class without having selected a database

I've found this happens because the extension defines a client auth hook
that reads pg_stat_activity. The really interesting thing is that this
happens only when I start several backends 'at the same time' right
after the cluster is started. From that time, everything works just fine.

So it seems like a race condition or something like that.

I've prepared a simple testcase to demonstrate this issue - see the
files attached. I've put there several 'sleep' to demonstrate the timing
error.

All you need to do is this:

1) compile the extension (make install)
2) add the extension to shared_preload_libraries
3) restart the cluster
4) start two backends at the same time (within a second or so)


Tomas

Attachment: Makefile
Description: text/plain (238 bytes)
Attachment: issue.control
Description: text/plain (103 bytes)
Attachment: issue.c
Description: text/x-c (3.0 KB)

Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2011-12-03 22:37:07
Subject: Re: cannot read pg_class without having selected a database / is this a bug?
Previous:From: Andres FreundDate: 2011-12-03 21:57:49
Subject: Re: Command Triggers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group