更新时间:2024-05-31 GMT+08:00
分享

SHOW EVENTS

功能描述

显示指定SCHEMA下所有定时任务的基本信息。

注意事项

定时任务相关操作只有sql_compatibility = 'B'时支持。

语法格式

SHOW EVENTS
    [{FROM | IN} schema_name]
    [LIKE 'pattern' | WHERE condition];

参数说明

  • {FROM | IN}

    指定要查询的schema,默认情况下为当前schema。

  • LIKE

    LIKE可以模式匹配定时任务名称,不指定则打印当前schema下所有定时任务。

  • WHERE

    WHERE子句构成一个行选择表达式,用来缩小SHOW EVENTS查询的范围。condition是返回值为布尔型的任意表达式,任何不满足该条件的行都不会被检索。

示例

--创建并切换至测试数据库。
gaussdb=# CREATE DATABASE test_event WITH DBCOMPATIBILITY = 'b';
test_event=# \c test_event

--创建SCHEMA。
test_event=# CREATE SCHEMA test;       

--创建表。
test_event=# CREATE TABLE t_ev(num int);

--创建一个默认当前SCHEMA的定时任务。
test_event=# CREATE EVENT IF NOT EXISTS event_e2 ON SCHEDULE EVERY 1 minute DO insert into t_ev values(1);

--创建一个SCHEMA为test的定时任务。
test_event=# CREATE EVENT IF NOT EXISTS test.event_e3 ON SCHEDULE EVERY 1 minute DO insert into t_ev values(2);

--查看所有定时任务。
test_event=# SHOW EVENTS;
job_name | schema_name | log_user | priv_user | job_status |         start_date         |       interval       |      end_date       | enable |                 failure_msg    
----------+-------------+----------+-----------+------------+----------------------------+----------------------+---------------------+--------+-------------------------------
event_e2  | public      | omm      | omm       | s          | 2023-11-28 10:13:48.675215 | interval '1'  minute | 3999-12-31 16:00:00 | t      | 
(1 rows)

--查看SCHEMA为test的定时任务。
test_event=# SHOW EVENTS FROM test;
job_name | schema_name | log_user | priv_user | job_status |         start_date         |       interval       |      end_date       | enable |                 failure_msg                 
----------+-------------+----------+-----------+------------+----------------------------+----------------------+---------------------+--------+--------------------------------event_e3 | test        | omm      | omm       | s          | 2023-11-28 10:29:42.327827 | interval '1'  minute | 3999-12-31 16:00:00 | t      | 
(1 row)

--删除定时任务。
test_event=# DROP EVENT event_e2;
test_event=# DROP EVENT test.event_e3;

--删除表。
test_event=# DROP TABLE t_ev;

--删除SCHEMA。
test_event=# DROP SCHEMA test;

--切换回初始数据库,并删除测试数据库。请用真实的数据库名替换postgres。
test_event=# \c postgres
gaussdb=# DROP DATABASE test_event;
分享:

    相关文档

    相关产品