title: Postgres revoke database access from user
body: <p>When I tried </p>
  
  <pre><code>REVOKE ALL PRIVILEGES ON DATABASE postgres from admin; 
  </code></pre>
  
  <p>but the user <code>admin</code> is still able to connect to <code>postgres</code> remotely via <code>pgadmin</code> after that. </p>
  
  <p>How do I completely revoke an user's access to a database?</p>
  
  <pre><code>/root$ psql -U postgres
  psql (9.2.24)
  Type "help" for help.
  
  postgres=# \du
                               List of roles
   Role name |                   Attributes                   | Member of 
  -----------+------------------------------------------------+-----------
   admin     | No inheritance                                 | {}
   postgres  | Superuser, Create role, Create DB, Replication | {}
  
  postgres=# REVOKE ALL PRIVILEGES ON DATABASE postgres from admin; 
  REVOKE
  postgres=# SELECT * FROM pg_stat_activity;
   datid | datname  |  pid   | usesysid | usename  | application_name | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |
            query_start          |         state_change          | waiting | state  |              query              
  -------+----------+--------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+
  -------------------------------+-------------------------------+---------+--------+---------------------------------
   12924 | postgres | 121487 |       10 | postgres | psql             |             |                 |          -1 | 2018-03-10 20:20:42.458031+08 | 2018-03-10 20:21:27.367078+08 |
   2018-03-10 20:21:27.367078+08 | 2018-03-10 20:21:27.367082+08 | f       | active | SELECT * FROM pg_stat_activity;
  (1 row)
  
  postgres=# \q
  /root$ psql -U admin postgres
  psql (9.2.24)
  Type "help" for help.
  
  postgres=&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fdmP7.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/fdmP7.gif" alt="enter image description here"></a></p>