Configure connections

/etc/postgresql/9.1/main/postgresql.conf:
-----------------------------------------
...
listen_addresses = '*'                  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
...
/etc/postgresql/9.1/main/pg_hba.conf:
-------------------------------------
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5 (o trust)   <---
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.0.0/16          md5             <---

List of active connections

(postgres@host)_$: psql database-devel
database-devel=# SELECT * FROM pg_stat_activity
WHERE datname = 'database-devel';

Close connections

Close all connections from a host

# PostgreSQL <= 9.1
(postgres@host)_$: psql database-devel
database-devel=# SELECT pg_terminate_backend(procpid)     <===
FROM pg_stat_activity
WHERE procpid <> pg_backend_pid()
  AND client_addr = '192.168.1.16'
  AND datname = 'database-devel';
# PostgreSQL >= 9.2
(postgres@host)_$: psql database-devel
database-devel=# SELECT pg_terminate_backend(pid)         <===
FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
  AND client_addr = '192.168.1.16'
  AND datname = 'database-devel';

Close all connectios to a database

# PostgreSQL <= 9.1
(postgres@host)_$: psql -c "SELECT pg_terminate_backend(procpid)
FROM pg_stat_activity
WHERE datname='database-devel';"
# PostgreSQL >= 9.2
(postgres@host)_$: psql -c "SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname='database-devel';"