通过命令行删除postgresql数据库 [英] Drop postgresql database through command line
问题描述
我试图删除我的数据库,并通过命令行创建一个新的。我使用psql -U用户名登录,然后做一个\connect template1,后面是一个DROP DATABASE databasename;
I'm trying to drop my database and create a new one through the command line. I login using psql -U username and then do a \connect template1, followed by a DROP DATABASE databasename;
我得到错误'database databasename正在被其他用户。我关闭apache和尝试这,并仍然得到这个错误。
I get the error 'database databasename is being accessed by other users'. I shutdown apache and tried this and am still getting this error. Am I doing something wrong?
感谢
推荐答案
从命令行执行 dropdb 命令:
dropdb 'database name'
请注意,您必须是超级用户或数据库所有者才能删除它。
Note that you have to be a superuser or the database owner to be able to drop it.
您还可以检查pg_stat_activity视图以查看什么类型的活动正在对您的数据库执行,包括所有空闲进程。
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';
这篇关于通过命令行删除postgresql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!