>>> import subprocess, sqlalchemy
>>> engine = sqlalchemy.create_engine("postgresql+psycopg://myuser:secret@localhost/mydb")
>>> subprocess.Popen(['/usr/bin/dropdb', '-U', 'myuser', 'mydb'])
dropdb: database removal failed: ERROR:  database "openstack_citest" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

我检查了哪个用户正在使用数据库,正是那个用户试图删除它。
我可以通过发出engine.dispose()呼叫来解决这个问题,但我不知道为什么。首先不应该有任何到数据库的开放连接。
在没有mysql调用的情况下尝试使用dispose()作为后端工作,这样可以很好地删除数据库。

最佳答案

那是通过design
删除数据库删除数据库。[...]. 而且,它不能执行
当您或任何其他人连接到目标数据库时

关于python - 为什么我需要配置一个PostgreSQL sqlalchemy引擎?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14258680/

10-12 17:19
查看更多