↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / psql 命令 / 查询执行

\watch

重复执行当前查询缓冲区(如同 \g 一样),直到被中断、查询失败、达到执行次数上限(如果给定)或查询返回的行数低于最小要求。两次执行之间等待指定的秒数(默认 2 秒)。默认等待时间可通过变量 WATCH_INTERVAL 修改。为保持向后兼容, seconds 可以带或不带 interval= 前缀。每次查询结果都会带有一个头部,其中包含 \pset title 字符串(如果有)、查询开始时的时间以及延迟间隔。

当前查看 PostgreSQL 18.6。

说明

重复执行当前查询缓冲区(如同 \g 一样),直到被中断、查询失败、达到执行次数上限(如果给定)或查询返回的行数低于最小要求。两次执行之间等待指定的秒数(默认 2 秒)。默认等待时间可通过变量 WATCH_INTERVAL 修改。为保持向后兼容, seconds 可以带或不带 interval= 前缀。每次查询结果都会带有一个头部,其中包含 \pset title 字符串(如果有)、查询开始时的时间以及延迟间隔。

客户端
psql 18.6
区分大小写的写法
\watch

用法

\watch [ i[nterval]= seconds ] [ c[ount]= times ] [ m[in_rows]= rows ] [ seconds ]

本版手册中的写法

命令手册中的后缀修饰符
\watch此语法签名未列出

手册定义

\watch [ i[nterval]=seconds ] [ c[ount]=times ] [ m[in_rows]=rows ] [ seconds ]

重复执行当前查询缓冲区(如同 \g 一样),直到被中断、查询失败、达到执行次数上限(如果给定)或查询返回的行数低于最小要求。两次执行之间等待指定的秒数(默认 2 秒)。默认等待时间可通过变量WATCH_INTERVAL修改。为保持向后兼容,seconds 可以带或不带 interval= 前缀。每次查询结果都会带有一个头部,其中包含 \pset title 字符串(如果有)、查询开始时的时间以及延迟间隔。

若当前查询缓冲区为空,则重新执行最近发送的查询。

相关条目

文档与源码

来源构建
版本
18.6
构建
https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8

版本比较

PostgreSQL 15 → 16: 属性变化。

以下差异保留原始字段名与英文源描述。

--- PostgreSQL 15
+++ PostgreSQL 16
@@ -1,7 +1,7 @@
 {
-  "definition": "Repeatedly execute the current query buffer (as \\g does) until interrupted or the query fails. Wait the specified number of seconds (default 2) between executions. Each query result is displayed with a header that includes the \\pset title string (if any), the time as of query start, and the delay interval. If the current query buffer is empty, the most recently sent query is re-executed instead.",
+  "definition": "Repeatedly execute the current query buffer (as \\g does) until interrupted, or the query fails, or the execution count limit (if given) is reached. Wait the specified number of seconds (default 2) between executions. For backwards compatibility, seconds can be specified with or without an interval= prefix. Each query result is displayed with a header that includes the \\pset title string (if any), the time as of query start, and the delay interval. If the current query buffer is empty, the most recently sent query is re-executed instead.",
   "modifiers": [],
-  "signature": "\\watch [ seconds ]",
+  "signature": "\\watch [ i[nterval]= seconds ] [ c[ount]= times ] [ seconds ]",
   "spellings": [
     "\\watch"
   ]

比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。

相关条目

导出 JSON · 返回psql 命令 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。