I run this command:

psql --username=openerp --dbname=sf_template_20150608111121 --no-password \
     --command="update pg_database set datallowconn = false \
                where datname = 'sf_template_20150608111121'"

I use the openerp user to create all my databases. However, I get this error message:

ERROR: permission denied for relation pg_database

Why can't I access such table in my database? (again: the user is the actual creator of the database). My aim is to fully disable connections to this database.


Although openerp owns the database, the catalog tables are still owned by user postgres. In order to update pg_database, you need to be logged in as postgres, or another superuser role.

This makes sense, given that pg_database contains entries not just for your database, but for every database on the server.

If you want to disable connections to a database without superuser privileges, try:

ALTER DATABASE sf_template_20150608111121 CONNECTION LIMIT 0;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.