Does dropping a database have to be done not in any transaction?

后端 未结 1 1641
眼角桃花
眼角桃花 2020-12-21 19:04

From https://wiki.postgresql.org/wiki/Psycopg2_Tutorial

PostgreSQL can not drop databases within a transaction, it is an all or nothing command. If

相关标签:
1条回答
  • 2020-12-21 19:31

    I'm unfamiliar with psycopg2 so I can only provide steps to be performed.

    Steps to be taken to perform DROP DATABASE from Python:

    1. Connect to a different database, which you don't want to drop
    2. Store current isolation level in a variable
    3. Set isolation level to 0
    4. Execute DROP DATABASE query
    5. Set isolation level back to original (from #2)

    Steps to be taken to perform DROP DATABASE from PSQL:

    1. Connect to a different database, which you don't want to drop
    2. Execute DROP DATABASE query

    Code in psql

    \c second_db
    DROP DATABASE first_db;
    

    Remember, that there can be no live connections to the database you are trying to drop.

    0 讨论(0)
提交回复
热议问题