PG12中新增:VACUUM命令的SKIP_LOCKED選項
PG12的VACUUM命令相對於之前版本,新增了SKIP_LOCKED選項。在擁有SKIP_LOCKED選項時,vacuum命令會跳過被lock住的table,並且vacuum命令會被看做是成功執行。之前的版本,vacuum命令遇到了lock住的table時,vacuum命令會一直處於等待狀態。
PostgreSQL 12.1
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 12.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
在第一個session中執行lock table操作:
postgres=# begin;
BEGIN
postgres=# lock table ysla in exclusive mode;
LOCK TABLE
然後在第二個session中進行vacuum測試:
postgres=# vacuum ysla;
^CCancel request sent
ERROR: canceling statement due to user request
postgres=# vacuum (skip_locked) ysla;
WARNING: skipping vacuum of "ysla" --- lock not available
VACUUM
可以透過 自PostgreSQL 11 版本增加的特性捕獲SQL的執行結果
postgres=# \echo :SQLSTATE
00000
//返回00000代表執行成功
Release 說明
Add psql variables to report query activity and errors (Fabien Coelho)
Specifically, the new variables are ERROR, SQLSTATE, ROW_COUNT, LAST_ERROR_MESSAGE, and LAST_ERROR_SQLSTATE.
變數解釋
關於這幾個變數的說明如下:
**ERROR**
true if the last SQL query failed, false if it succeeded. See also SQLSTATE.
**SQLSTATE**
The error code (see Appendix A) associated with the last SQL query is failure, or 00000 if it succeeded.
**ROW_COUNT**
The number of rows returned or affected by the last SQL query, or 0 if the query failed or did not report a row count.
**LAST_ERROR_MESSAGE**
**LAST_ERROR_SQLSTATE**
The primary error message and associated SQLSTATE code for the most recent failed query in the current psql session, or an empty string and 00000 if no error has occurred in the current session.
附帶pg10、pg11對比
PostgreSQL 10.14
postgres=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 10.14 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
在第一個session中執行lock table操作:
postgres=# begin;
BEGIN
postgres=# lock table test_user in exclusive mode;
LOCK TABLE
然後在第二個session中進行vacuum測試:
postgres=# vacuum test_user;
^CCancel request sent
ERROR: canceling statement due to user request
postgres=# VACUUM (skip_locked) test_user;
ERROR: unrecognized VACUUM option "skip_locked"
LINE 1: VACUUM (skip_locked) test_user;
^
PostgreSQL 11.5
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 11.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
在第一個session中執行lock table操作:
postgres=# begin;
BEGIN
postgres=# lock table qq in exclusive mode;
LOCK TABLE
然後在第二個session中進行vacuum測試:
postgres=# vacuum qq;
^CCancel request sent
ERROR: canceling statement due to user request
postgres=# vacuum (skip_locked) qq;
ERROR: unrecognized VACUUM option "skip_locked"
LINE 1: vacuum (skip_locked) qq;
^
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69990629/viewspace-2779508/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- pg12中oid2name新增選項介紹
- pg12中pg_dump/pg_dumpall新增選項介紹
- Linux 中grep命令中 -P選項的作用Linux
- 在Linux中,ls命令有哪些常用的選項?Linux
- tcpdump 命令的常用選項:一TCP
- tcpdump 命令的常用選項:二TCP
- tcpdump 命令的常用選項:三TCP
- QListWidget項新增勾選框
- Linux 中 sed命令 h和H選項的應用Linux
- 很有用的 GCC 命令列選項GC命令列
- tcpdump 命令的個常用選項:一TCP
- tcpdump 命令的個常用選項:三TCP
- tcpdump 命令的個常用選項:二TCP
- Linux中sed命令b選項遮蔽指定的處理區域Linux
- cmake中新增 -g編譯選項編譯
- Win10系統如何新增或刪除右鍵選單中的“傳送到”選項Win10
- golang中的選項模式Golang模式
- pflag - 更好的PHP命令列選項解析庫PHP命令列
- Js/JQuery下拉框新增新選項JSjQuery
- 使用Vue實現下拉選單框批量新增選項Vue
- win10系統中怎麼給右鍵選單選項新增圖示Win10
- CSP201403-3:命令列選項命令列
- 10個 ssh 簡單命令選項
- 完全解析Rsync命令的17個備份選項
- Linux 中 ss 命令的使用例項Linux
- Linux 中的 JQ 命令使用例項Linux
- Linux中ip命令的使用例項Linux
- Linux中的basename命令使用例項Linux
- .Net Core 中的選項Options
- excel下拉選擇項怎麼設定 excel怎麼新增下拉選項內容Excel
- 選項中選擇現在
- 啟用命令選項板工具:Paletro for MacMac
- Linux中head命令例項Linux
- Qtum如何新增執行選項(或配置檔案)QT
- C# ClosedXML 匯出 Excel 新增下拉選項 CellDropdownC#XMLExcel
- Node.js 構建命令列工具:實現 ls 命令的 -a 和 -l 選項Node.js命令列
- PostgreSQL的vacuum流程SQL
- Linux中printf命令使用例項Linux