从 php 删除 PostgreSql 数据库
Drop PostgreSql DB from php
有什么方法可以从 php 脚本编写 DROP DATABASE [ IF EXISTS ] name
吗?似乎我需要类似于 mysql_drop_db
的东西,只是为了 Postrge。
我在 $conn = pg_connect($connStr)
中的 $connStr
如何才能拥有执行此命令的权限?我必须连接什么数据库?
- 您必须以超级用户角色或数据库所有者身份连接到同一集群上的不同数据库
https://www.postgresql.org/docs/current/static/sql-dropdatabase.html
It can only be executed by the database owner. Also, it cannot be
executed while you or anyone else are connected to the target
database. (Connect to postgres or any other database to issue this
command.)
在删除之前必须 pg_terminate_backend(pid)
要删除的数据库上的其他连接:
select pg_terminate_backend(pid)
from pg_stat_activity
where pid <> pg_backend_pid() and datname = 'db_to_drop';
有什么方法可以从 php 脚本编写 DROP DATABASE [ IF EXISTS ] name
吗?似乎我需要类似于 mysql_drop_db
的东西,只是为了 Postrge。
我在 $conn = pg_connect($connStr)
中的 $connStr
如何才能拥有执行此命令的权限?我必须连接什么数据库?
- 您必须以超级用户角色或数据库所有者身份连接到同一集群上的不同数据库
https://www.postgresql.org/docs/current/static/sql-dropdatabase.html
It can only be executed by the database owner. Also, it cannot be executed while you or anyone else are connected to the target database. (Connect to postgres or any other database to issue this command.)
在删除之前必须
pg_terminate_backend(pid)
要删除的数据库上的其他连接:select pg_terminate_backend(pid) from pg_stat_activity where pid <> pg_backend_pid() and datname = 'db_to_drop';