Friday, January 27, 2012

PostgreSQL - Forbid access to a database temporarily.

I found out about this feature, thanks to someone who asked how to do this in the postgresql-es-ayuda list.

Disable connections to a PostgreSQL database temporarily

Today I had to disable access to some PostgreSQL databases temporarily. This can be easily done using pgAdmin. Under database properties, set "Connection Limit " to 0 from the default of -1. The corresponding SQL statement is
 ALTER DATABASE "dbname" WITH CONNECTION LIMIT = 0;

When you are ready to allow connections, change this back to -1.

Reference:
http://vimalkumar.in/2011/01/27/disable-connections-to-a-postgresql-database-temporarily/

1 comment:

  1. Didn't work for me with PostgreSQL 8.3. But this did:

    UPDATE pg_database SET datallowconn = false WHERE datname = 'my_db_name';


    ReplyDelete