这篇文章主要讲解了“PG 13提供的force选项有什么作用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PG 13提供的force选项有什么作用”吧!

在PG 12或以下版本,删除数据库时如存在连接则无法删除,PG 13提供了force选项,可终止相关连接直接删除数据库。

PG 12
创建数据库并连接

[pg12@localhost~]$createdbdropdb[pg12@localhost~]$[pg12@localhost~]$psql-ddropdbExpandeddisplayisusedautomatically.psql(12.1)Type"help"forhelp.[local:/run/pg12]:5120pg12@dropdb=#

删除数据库,一直在等待,超时后提示

[pg12@localhost~]$psqlExpandeddisplayisusedautomatically.psql(12.1)Type"help"forhelp.[local:/run/pg12]:5120pg12@testdb=#dropdatabasedropdb;ERROR:database"dropdb"isbeingaccessedbyotherusersDETAIL:Thereis1othersessionusingthedatabase.

PG 13
创建数据库并连接

[pg13@localhost~]$createdbdropdb[pg13@localhost~]$psql-ddropdbExpandeddisplayisusedautomatically.psql(13devel)Type"help"forhelp.[local:/run/pg13]:5130pg13@dropdb=#

删除数据库,提示无法删除数据库

[pg13@localhost~]$psqlExpandeddisplayisusedautomatically.psql(13devel)Type"help"forhelp.[local:/run/pg13]:5130pg13@masterdb=#dropdatabasedropdb;ERROR:database"dropdb"isbeingaccessedbyotherusersDETAIL:Thereis1othersessionusingthedatabase.[local:/run/pg13]:5130pg13@masterdb=#

使用force选项删除

[local:/run/pg13]:5130pg13@masterdb=#dropdatabasedropdbwith(force);DROPDATABASE[local:/run/pg13]:5130pg13@masterdb=#

回到连接dropdb数据库的session,该session已被drop

[local:/run/pg13]:5130pg13@dropdb=#select1;FATAL:terminatingconnectionduetoadministratorcommandserverclosedtheconnectionunexpectedlyThisprobablymeanstheserverterminatedabnormallybeforeorwhileprocessingtherequest.Theconnectiontotheserverwaslost.Attemptingreset:Failed.:@!>?

感谢各位的阅读,以上就是“PG 13提供的force选项有什么作用”的内容了,经过本文的学习后,相信大家对PG 13提供的force选项有什么作用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!