PG 13提供的force选项有什么作用

39次阅读
没有评论

共计 1760 个字符,预计需要花费 5 分钟才能阅读完成。

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

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

PG 12
创建数据库并连接

[pg12@localhost ~]$ createdb dropdb
[pg12@localhost ~]$ 
[pg12@localhost ~]$ psql -d dropdb
Expanded display is used automatically.
psql (12.1)
Type  help  for help.
[local:/run/pg12]:5120 pg12@dropdb=#

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

[pg12@localhost ~]$ psql
Expanded display is used automatically.
psql (12.1)
Type  help  for help.
[local:/run/pg12]:5120 pg12@testdb=# drop database dropdb;
ERROR: database  dropdb  is being accessed by other users
DETAIL: There is 1 other session using the database.

PG 13
创建数据库并连接

[pg13@localhost ~]$ createdb dropdb
[pg13@localhost ~]$ psql -d dropdb
Expanded display is used automatically.
psql (13devel)
Type  help  for help.
[local:/run/pg13]:5130 pg13@dropdb=#

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

[pg13@localhost ~]$ psql
Expanded display is used automatically.
psql (13devel)
Type  help  for help.
[local:/run/pg13]:5130 pg13@masterdb=# drop database dropdb;
ERROR: database  dropdb  is being accessed by other users
DETAIL: There is 1 other session using the database.
[local:/run/pg13]:5130 pg13@masterdb=#

使用 force 选项删除

[local:/run/pg13]:5130 pg13@masterdb=# drop database dropdb with(force);
DROP DATABASE
[local:/run/pg13]:5130 pg13@masterdb=#

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

[local:/run/pg13]:5130 pg13@dropdb=# select 1;
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
 This probably means the server terminated abnormally
 before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
: @! ?

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

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-26发表,共计1760字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)