E
E
Egorian2018-06-09 15:43:00
Python
Egorian, 2018-06-09 15:43:00

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

The code looks like this:
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""")

This is what my database looks like.
5b1bcb2151e8e751008703.png
What's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elmo Sputterspark, 2018-06-09
@Egorian

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 question

Ask a Question

731 491 924 answers to any question