簡體   English   中英

無法在 python 中的 psycopg2 連接中執行刪除索引

[英]Can't execute drop index in psycopg2 connect in python

我正在嘗試使用 python 中的 psycopg2 來刪除 postgresql 中的索引:

connection = psycopg2.connect(host=hostname, user=username, password=password, dbname=database)
cur = connection.cursor()
statement = "DROP INDEX IF EXISTS idx_my_id"
cur.execute(statement)
connection.commit()

在 pgAdmin4 中可以在一秒鍾內完成相同的語句。 但是在 python 中,執行從未完成。

“pg_stat_activity”顯示 wait_event_type 是 Lock,wait_event 是 relation。

什么地方出了錯?

不適合放在評論中。 也許是因為你不承諾你的聯系?

將此添加到您的代碼中,關閉所有連接並重試:

connection.set_session(autocommit=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM