共計 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 小編將為大家推送更多相關知識點的文章,歡迎關注!
正文完