#计划管理

YashanDB计划管理是指通过yasboot工具定时执行SQL任务,具体的命令参数介绍请查阅yasboot job命令

通过yasboot调用DBMS_STATS高级包可定时管理优化器的统计信息。

  1. 生成job配置文件。

    $ ./bin/yasboot job config gen -c yashandb --job-name test --user username --password password --sql "exec DBMS_STATS.GATHER_DATABASE_STATS('GATHER AUTO', 1, 2,  'FOR ALL COLUMNS SIZE AUTO', 'AUTO', TRUE, FALSE);" -ce "30 0 * * *"
    |key                    |value
    |-----------------------+------
    |cluster                |yashandb
    |job_name               |test
    |sql                    |exec DBMS_STATS.GATHER_DATABASE_STATS('GATHER AUTO', 1, 2,  'FOR ALL COLUMNS SIZE AUTO', 'AUTO', TRUE, FALSE);
    |---------------------- |--------
    |cron_expression        |30 0 * * *
    
    Generate config completed
    

    成功执行上述命令后,系统会生成job_集群名_job名.toml配置文件(根据上述示例命令,文件名为job_yashandb_test.toml),允许手动修改该配置文件。

    cluster = "yashandb"
    job_name = "test"
    username = "username"
    password = "password"
    sql = "exec DBMS_STATS.GATHER_DATABASE_STATS('GATHER AUTO', 1, 2,  'FOR ALL COLUMNS SIZE AUTO', 'AUTO', TRUE, FALSE);"
    
    [time_config]
    cron_expression = "30 0 * * *"
    
  2. 添加job。

    $ ./bin/yasboot job add -t job_yashandb_test.toml
    
  3. 将job应用到数据库节点,本文以1-1节点为例。

    $ ./bin/yasboot job apply -c yashandb --job-name test -n 1-1
    
  4. 查看计划执行状态。

    达到设定的计划时间时会自动触发job,自动执行配置的SQL命令或SQL文件。job执行完成后,可以通过job show命令查看执行情况。

    $ ./bin/yasboot job show -c yashandb -n 1-1 --job-name test
    id | job_id                           | job_name | node_id | status  | start_time          | completion_time     | hostid   | failed_reason                                                           
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    2  | 65a8a0d8954d05c0fef16ef3021bf34a | test     | 1-1     | failed  | 2024-01-18 11:58:28 | 2024-01-18 11:58:28 | host0001 | node 1-1 exec job sql failed, stdout:
    [1:1]YAS-04231 keyword expected  
    ----+----------------------------------+----------+---------+---------+---------------------+---------------------+----------+-------------------------------------------------------------------------
    1  | 65a8a0d8954d05c0fef16ef3021bf34a | test     | 1-1     | success | 2024-01-18 11:55:00 | 2024-01-18 11:55:00 | host0001 | -                                                                       
    ----+----------------------------------+----------+---------+---------+---------------------+---------------------+----------+-------------------------------------------------------------------------
    
pdf-btn 下载文档
copy-btn 复制链接