PostgreSQL: Temporarily disable connections

后端 未结 5 1797
我在风中等你
我在风中等你 2020-12-14 00:50

I have a script in PostgreSQL which restores test database from dump every night. The database is accessed by app servers and processes with connection pool which keeps a fe

5条回答
  •  囚心锁ツ
    2020-12-14 01:28

    If you are connected in session with the DB that you want to dissallow connecting to, and to stay connected in the same session after you disallow connections, then use this :

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

    ... which allows you to do stuff without any other connection happening until you re-enable

    But if you use this, it must be from in a session in another DB :

    ALTER DATABASE _db_name_ WITH ALLOW_CONNECTIONS false ;
    

    (( i realise this is almost a summary of the answers above ))

提交回复
热议问题