phppgadmin :它如何将用户踢出 postgres,以便可以 db_drop?
我有一个 Posgresql 数据库(我是所有者),我想删除它并从转储中重新创建它。
问题是,有几个应用程序(两个网站,rails 和 perl)定期访问数据库。所以我收到“数据库正在被其他用户访问”错误。
我读到一种可能性是获取所涉及进程的 pid 并单独杀死它们。如果可能的话,我想做一些更干净的事情。
Phppgadmin 似乎做了我想做的事:即使网站打开,我也可以使用其 Web 界面删除架构,而不会出现错误。所以我正在研究它的代码是如何工作的。但是,我不是 PHP 专家。
我试图理解 phppgadmin 代码,以便了解它是如何工作的。我发现一行 ( 257 in Schemas.php)其中显示:
$data->dropSchema(...)
$data
是一个全局变量,我找不到它的定义位置。
任何指示将不胜感激。
I've got one Posgresql database (I'm the owner) and I'd like to drop it and re-create it from a dump.
Problem is, there're a couple applications (two websites, rails and perl) that access the db regularly. So I get a "database is being accessed by other users" error.
I've read that one possibility is getting the pids of the processes involved and killing them individually. I'd like to do something cleaner, if possible.
Phppgadmin seems to do what I want: I am able to drop schemas using its web interface, even when the websites are on, without getting errors. So I'm investigating how its code works. However, I'm no PHP expert.
I'm trying to understand the phppgadmin code in order to see how it does it. I found out a line (257 in Schemas.php) where it says:
$data->dropSchema(...)
$data
is a global variable and I could not find where it is defined.
Any pointers would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,找到所有当前使用数据库的进程:
其次,终止您不需要的进程:
这在 8.4 版本中有效,否则 pg_terminate_backend() 是未知的,您必须在操作系统级别终止该进程。
要快速删除连接到给定数据库的所有连接,此快捷方式效果很好。必须以超级用户身份运行:
在较新的 Postgres 版本(至少 9.2+,可能更早)上,列名称已更改,查询为:
First, find all current procesid's using your database:
Second, kill the processes you don't want:
This works as of version 8.4, otherwise pg_terminate_backend() is unknown and you have to kill the process at OS level.
To quickly drop all connections connected to a given database, this shortcut works nicely. Must run as superuser:
On more recent Postgres versions (at least 9.2+, likely earlier), the column names have changed and the query is:
不确定 PostgreSQL,但我认为可能的解决方案是锁定表,这样其他进程在尝试访问它时就会失败。
看:
http://www.postgresql.org/docs/current/static/ sql-lock.html
Not sure about PostgreSQL but i think a possible solution would be to lock the table so other processes will fail when they try to access it.
See:
http://www.postgresql.org/docs/current/static/sql-lock.html