Answer the question
In order to leave comments, you need to log in
psycopg2.OperationalError: cannot drop the currently open database?
I do everything according to this tutorial .
I got to the point where I need to add conn.set_isolation_level(0)
.
Gives an error message
psycopg2.OperationalError: cannot drop the currently open database
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
try:
conn = psycopg2.connect("dbname='db1' user='egor0' host='localhost' password=''")
except:
print ("I am unable to connect to the database")
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
conn.autocommit = True
cur = conn.cursor()
cur.execute("""SELECT datname from pg_database""")
rows = cur.fetchall()
for row in rows:
print(row[0])
cur.execute("""DROP DATABASE db1""")
Answer the question
In order to leave comments, you need to log in
To drop a base, you must be connected to something other than it. You can, for example, hook into template1. And it is necessary that no one else use it at this moment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question