Posted By: Anonymous
I’m trying to drop my database and create a new one through the command line.
I log in using
psql -U username and then do a
connect template1, followed by a
DROP DATABASE databasename;.
I get the error
database databasename is being accessed by other users
I shut down Apache and tried this again but I’m still getting this error. Am I doing something wrong?
You can run the dropdb command from the command line:
dropdb 'database name'
Note that you have to be a superuser or the database owner to be able to drop it.
You can also check the
pg_stat_activity view to see what type of activity is currently taking place against your database, including all idle processes.
SELECT * FROM pg_stat_activity WHERE datname='database name';
Note that from PostgreSQL v13 on, you can disconnect the users automatically with
DROP DATABASE dbname FORCE;
dropdb -f dbname