Whenever I try to drop database I get:
ERROR: database \"pilot\" is being accessed by other users
DETAIL: There is 1 other session using the database.
In terminal try this command:
ps -ef | grep postgres
you will see like:
501 1445 3645 0 12:05AM 0:00.03 postgres: sasha dbname [local] idle
The third number (3645) is PID.
You can delete this
sudo kill -9 3645
And after that start your PostgreSQL connection.
Start manually:
pg_ctl -D /usr/local/var/postgres start
Simple as that
sudo service postgresql restart
REVOKE CONNECT
will not prevent the connections from the db owner or superuser. So if you don't want anyone to connect the db, follow command may be useful.
alter database pilot allow_connections = off;
Then use:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'pilot';
In my opinion there are some idle queries running in the backgroud.
SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' ORDER BY query_start desc;
SELECT pg_terminate_backend(procpid);
Note: Killing a select query doesnt make any bad impact
It means another user is accessing the database. Simply restart PostgreSQL. This command will do the trick
root@kalilinux:~#sudo service postgresql restart
Then try dropping the database:
postgres=# drop database test_database;
This will do the trick.