如何杀死我所有的postgresql连接?

我试着耙db:下降,但我得到:

ERROR:  database "database_name" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

我尝试过关闭我从ps -ef | grep postgres中看到的进程,但这也不起作用:

kill: kill 2358 failed: operation not permitted

当前回答

退出postgres并重新启动。很简单,但每次对我都有效,而其他cli命令有时不能。

其他回答

我是这样解决的:

在我的Windows8 64位,只是重新启动服务:postgresql-x64-9.5

远程场景。但如果你试图在rails应用程序中运行测试,你会得到

"ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:数据库"myapp_test"正在被其他用户访问 还有另外一个会话在使用数据库。

确保在运行测试之前关闭pgAdmin或任何其他postgres GUI工具。

也许只是重启postgres => sudo服务postgresql重启

我的工作如下:

sudo gitlab-ctl stop
sudo gitlab-ctl start gitaly
sudo gitlab-rake gitlab:setup [type yes and let it finish]
sudo gitlab-ctl start

我正在使用: gitlab_edition:“gitlab-ce” gitlab_version:“12.4.0-ce.0.el7”

我有这个问题,问题是Navicat连接到我本地的Postgres数据库。一旦我断开Navicat,问题就消失了。

编辑:

此外,作为最后的手段,你可以备份你的数据,然后运行这个命令:

sudo kill -15 `ps -u postgres -o pid`

... 这将杀死postgres用户正在访问的所有内容。避免在生产机器上这样做,但在开发环境中应该不会有问题。在尝试重启PostgreSQL之前,确保每个postgres进程都已经真正终止是至关重要的。

编辑2:

由于这个unix。SE post我从击杀-9改为击杀-15。