1
>>> import subprocess, sqlalchemy
>>> engine = sqlalchemy.create_engine("postgresql+psycopg://myuser:[email protected]/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.
我检查了哪个用户正在使用数据库,并且它是试图放弃它的用户。为什么我需要配置一个postgresql sqlalchemy引擎?
我可以通过拨打engine.dispose()
来解决这个问题,但我不知道为什么。首先不应该有任何开放的连接到数据库。
尝试与mysql
一样的事情作为后端工作,没有dispose()
调用工作就可以放弃数据库。
但是我没有连接到任何数据库。我没有做engine.connect()。 sqlalchemy在初始化引擎时是否创建了连接? – Oin