案例说明:

本案例参考《Job And Schedule (V8R6C4)》(https://www.cnblogs.com/kingbase/p/15194227.html)单实例环境下的job管理案例。

本案例重点是在测试集群切换后在新的主库下,job任务是否能正常被执行。

测试数据库版本:

prod=# select version();
version ----------------------------------------------------------------------------------------------------------
KingbaseES V008R006C005B0023 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

集群架构:

[kingbase@node3 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+-------------------
1 | node243 | primary | * running | | default | 100 | 1 | host=192.168.7.243 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node248 | standby | running | node243 | default | 100 | 1 | host=192.168.7.248 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

一、配置job

1、配置kb_schedule extension (所有节点)

[kingbase@node3 data]$ cat kingbase.conf |grep schedule
shared_preload_libraries = 'repmgr,liboracle_parser, synonym, plsql, force_view, kdb_flashback,plugin_debugger, plsql_plugin_debugger, plsql_plprofiler, ora_commands,kdb_ora_expr, sepapower, dblink, sys_kwr, sys_ksh, sys_spacequota, sys_stat_statements, backtrace, kdb_utils_function,kdb_schedule' prod=# select name from sys_available_extensions where name like '%schedule%';
name
--------------
kdb_schedule
(1 row)

2、所有节点配置job_queue_processes

prod=# show job_queue_processes;
job_queue_processes
---------------------
0
(1 row) prod=# alter system set job_queue_processes=5;
ALTER SYSTEM
prod=# select sys_reload_conf();
sys_reload_conf
-----------------
t
(1 row) 注意: 配置完成后,重启集群。 # 主备库:
test=# show job_queue_processes;
job_queue_processes
---------------------
5
(1 row)

3、测试job管理

主库执行:

1)创建测试表

prod=# create table d_test(tid varchar2(64), insdate date);
CREATE TABLE

2)创建测试procedure

prod=# \set SQLTERM /
prod=#
prod=# create or replace procedure p_test() as
prod-# begin
prod-# insert into d_test values(to_char(sysdate, 'yyyymmddhh24miss'), sysdate);
prod-# commit;
prod-# end;
prod-# / CREATE PROCEDURE
\set SQLTERM ;

3)创建job

prod=# \set SQLTERM ;
prod=#
prod=# \set SQLTERM /
prod=# DECLARE
prod-# v_jobid NUMBER;
prod-# BEGIN
prod-# dbms_job.submit(v_jobid, 'call p_test()', now(), 'Freq=Minutely;Interval=1');
prod-# COMMIT;
prod-# END;
prod-# /
\set SQLTERM ;ANONYMOUS BLOCK
prod=# \set SQLTERM ; prod=# call dbms_job.instance(1, 'user=system dbname=prod port=54321 password=123456ab');
CALL

4)主备库查询

prod=# select jobid,jobname,jobenabled,joblastrun,jobnextrun,jobrepeattimes from kdb_job;
jobid | jobname | jobenabled | joblastrun | jobnextrun | jobrepeattimes
-------+---------------------------------------------+------------+------------+---------------------------
1 | internal_job1:2021-03-01 16:52:12.416076+08 | f | | 2021-03-01 16:52:12.416076+08 | 0
(1 row)

主库执行:

5)启用job

prod=# call dbms_job.broken(1,false);
CALL

主备库查询:

prod=# select jobid,jobname,jobenabled,joblastrun,jobnextrun,jobrepeattimes from kdb_job;
jobid | jobname | jobenabled | joblastrun | jobnextrun | jobrepeattimes
-------+---------------------------------------------+------------+------------+--------------------------
1 | internal_job1:2021-03-01 16:52:12.416076+08 | t | | 2021-03-01 16:52:12.416076+08 | 0
(1 row) prod=# select * from kdb_schedule.kdb_schedule;
scid | scname | scdesc | scenabled | scstart | scend | screpeat_interval
------+--------+--------+-----------+----------------------------+-------+--------------------------
1 | | | t | 2021-03-01 16:52:12.416076 | | Freq=Minutely;Interval=1
(1 row) prod=# select * from kdb_schedule.kdb_schedule_job;
sjid | sjscid | sjjobid | sjstatus | sjlasttime | sjnexttime
------+--------+---------+----------+------------+-------------------------------
1 | 1 | 1 | s | | 2021-03-01 16:52:12.416076+08
(1 row)

6)查看job执行情况

# 主备库查询:
prod=# select * from d_test;
tid | insdate
----------------+---------------------
20210301170529 | 2021-03-01 17:05:29
20210301171623 | 2021-03-01 17:16:23
20210301172126 | 2021-03-01 17:21:26
20210301172216 | 2021-03-01 17:22:16
20210301172316 | 2021-03-01 17:23:16
20210301172416 | 2021-03-01 17:24:16
(6 rows)

二、主备切换测试

1、switchover切换

# 执行switchover

[kingbase@node1 bin]$ ./repmgr standby switchover -h 192.168.7.243 -U esrep -d esrep --dry-run
WARNING: following problems with command line parameters detected:
database connection parameters not required when executing UNKNOWN ACTION
NOTICE: checking switchover on node "node248" (ID: 2) in --dry-run mode
INFO: ES connection to host "192.168.7.243" succeeded
INFO: able to execute "repmgr" on remote host "localhost"
INFO: 1 walsenders required, 32 available
INFO: demotion candidate is able to make replication connection to promotion candidate
INFO: 0 pending archive files
INFO: replication lag on this standby is 0 seconds
INFO: 1 replication slots required, 32 available
INFO: would pause repmgrd on node "node243" (ID 1)
INFO: would pause repmgrd on node "node248" (ID 2)
NOTICE: local node "node248" (ID: 2) would be promoted to primary; current primary "node243" (ID: 1) would be demoted to standby
INFO: following shutdown command would be run on node "node243":
"/home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/sys_ctl -D '/home/kingbase/cluster/R6C5/R6C5R/kingbase/data' -l /home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/logfile -W -m fast stop"
INFO: prerequisites for executing STANDBY SWITCHOVER are met [kingbase@node1 bin]$ ./repmgr standby switchover -h 192.168.7.243 -U esrep -d esrep
WARNING: following problems with command line parameters detected:
database connection parameters not required when executing UNKNOWN ACTION
NOTICE: executing switchover on node "node248" (ID: 2)
INFO: pausing repmgrd on node "node243" (ID 1)
INFO: pausing repmgrd on node "node248" (ID 2)
NOTICE: local node "node248" (ID: 2) will be promoted to primary; current primary "node243" (ID: 1) will be demoted to standby
NOTICE: stopping current primary node "node243" (ID: 1)
NOTICE: issuing CHECKPOINT
NOTICE: node (ID: 1) release the virtual ip 192.168.7.241/24 success
DETAIL: executing server command "/home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/sys_ctl -D '/home/kingbase/cluster/R6C5/R6C5R/kingbase/data' -l /home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/logfile -W -m fast stop"
INFO: checking for primary shutdown; 1 of 60 attempts ("shutdown_check_timeout")
INFO: checking for primary shutdown; 2 of 60 attempts ("shutdown_check_timeout")
INFO: checking for primary shutdown; 3 of 60 attempts ("shutdown_check_timeout")
INFO: checking for primary shutdown; 4 of 60 attempts ("shutdown_check_timeout")
INFO: checking for primary shutdown; 5 of 60 attempts ("shutdown_check_timeout")
NOTICE: current primary has been cleanly shut down at location 0/8000028
NOTICE: PING 192.168.7.241 (192.168.7.241) 56(84) bytes of data. --- 192.168.7.241 ping statistics ---
2 packets transmitted, 0 received, +1 errors, 100% packet loss, time 1003ms WARNING: ping host"192.168.7.241" failed
DETAIL: average RTT value is not greater than zero
INFO: loadvip result: 1, arping result: 1
NOTICE: new primary node (ID: 2) acquire the virtual ip 192.168.7.241/24 success
NOTICE: promoting standby to primary
DETAIL: promoting server "node248" (ID: 2) using sys_promote()
NOTICE: waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
NOTICE: STANDBY PROMOTE successful
DETAIL: server "node248" (ID: 2) was successfully promoted to primary
NOTICE: issuing CHECKPOINT
INFO: local node 1 can attach to rejoin target node 2
DETAIL: local node's recovery point: 0/8000028; rejoin target node's fork point: 0/80000A0
NOTICE: setting node 1's upstream to node 2
WARNING: unable to ping "host=192.168.7.243 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3"
DETAIL: PQping() returned "PQPING_NO_RESPONSE"
NOTICE: begin to start server at 2021-03-01 17:26:43.843581
NOTICE: starting server using "/home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/sys_ctl -w -t 90 -D '/home/kingbase/cluster/R6C5/R6C5R/kingbase/data' -l /home/kingbase/cluster/R6C5/R6C5R/kingbase/bin/logfile start"
NOTICE: start server finish at 2021-03-01 17:26:44.055041
NOTICE: replication slot "repmgr_slot_2" deleted on node 1
NOTICE: NODE REJOIN successful
DETAIL: node 1 is now attached to node 2
NOTICE: switchover was successful
DETAIL: node "node248" is now primary and node "node243" is attached as standby
INFO: unpausing repmgrd on node "node243" (ID 1)
INFO: unpause node "node243" (ID 1) successfully
INFO: unpausing repmgrd on node "node248" (ID 2)
INFO: unpause node "node248" (ID 2) successfully
NOTICE: STANDBY SWITCHOVER has completed successfully # 切换后集群状态: [kingbase@node1 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------
1 | node243 | standby | running | node248 | default | 100 | 1 | host=192.168.7.243 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node248 | primary | * running | | default | 100 | 2 | host=192.168.7.248 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
INFO: 1 replication slots required, 32 available # job正常被执行: prod=# select * from d_test;
tid | insdate
----------------+---------------------
20210301170529 | 2021-03-01 17:05:29
20210301171623 | 2021-03-01 17:16:23
20210301172126 | 2021-03-01 17:21:26
20210301172216 | 2021-03-01 17:22:16
20210301172316 | 2021-03-01 17:23:16
20210301172416 | 2021-03-01 17:24:16
20210301172516 | 2021-03-01 17:25:16
20210301172616 | 2021-03-01 17:26:16
20210301172908 | 2021-03-01 17:29:08
20210301172918 | 2021-03-01 17:29:18

2、failover 切换测试

# 执行failover切换
# 停止主库数据库服务
[kingbase@node1 bin]$ ./sys_ctl stop -D ../data
waiting for server to shut down........ done
server stopped # failover切换完成:
[kingbase@node1 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+------------------
1 | node243 | primary | * running | | default | 100 | 3 | host=192.168.7.243 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node248 | standby | running | node243 | default | 100 | 2 | host=192.168.7.248 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3 #查看job执行: prod=# select * from d_test;
tid | insdate
----------------+---------------------
20210301170529 | 2021-03-01 17:05:29
20210301171623 | 2021-03-01 17:16:23
20210301172126 | 2021-03-01 17:21:26
20210301172216 | 2021-03-01 17:22:16
20210301172316 | 2021-03-01 17:23:16
20210301172416 | 2021-03-01 17:24:16
20210301172516 | 2021-03-01 17:25:16
20210301172616 | 2021-03-01 17:26:16
20210301172908 | 2021-03-01 17:29:08
20210301172918 | 2021-03-01 17:29:18
20210301173018 | 2021-03-01 17:30:18
20210301173118 | 2021-03-01 17:31:18
20210301173218 | 2021-03-01 17:32:18
20210301173318 | 2021-03-01 17:33:18
20210301173418 | 2021-03-01 17:34:18
20210301173518 | 2021-03-01 17:35:18
20210301173820 | 2021-03-01 17:38:20
20210301173920 | 2021-03-01 17:39:20
20210301174017 | 2021-03-01 17:40:17
20210301174117 | 2021-03-01 17:41:17
(20 rows)

删除job:

prod=# call dbms_job.remove(1);
CALL prod=# select * from kdb_schedule.kdb_schedule_job;
sjid | sjscid | sjjobid | sjstatus | sjlasttime | sjnexttime
------+--------+---------+----------+------------+------------
(0 rows)

三、总结

通过以上案例说明,在集群环境下job的管理和单实例环境下配置基本一致,集群主备切换后,主库上的job任务亦可以正常被执行。

KingbaseES R6 集群测试job管理测试的更多相关文章

  1. KingbaseES R6 集群主库网卡down测试案例

    数据库版本: test=# select version(); version ------------------------------------------------------------ ...

  2. KingbaseES R6 集群repmgr.conf参数'recovery'测试案例(一)

    KingbaseES R6集群repmgr.conf参数'recovery'测试案例(一) 案例说明: 在KingbaseES R6集群中,主库节点出现宕机(如重启或关机),会产生主备切换,但是当主库 ...

  3. KingbaseES R6 集群 recovery 参数对切换的影响

    案例说明:在KingbaseES R6集群中,主库节点出现宕机(如重启或关机),会产生主备切换,但是当主库节点系统恢复正常后,如何对原主库节点进行处理,保证集群数据的一致性和安全,可以通过对repmg ...

  4. KingbaseES R6 集群修改物理IP和VIP案例

    在用户的实际环境里,可能有时需要修改主机的IP,这就涉及到集群的配置修改.以下以例子的方式,介绍下KingbaseES R6集群如何修改IP. 一.案例测试环境 操作系统: [KINGBASE@nod ...

  5. KingbaseES R6 集群修改data目录

    案例说明: 本案例是在部署完成KingbaseES R6集群后,由于业务的需求,集群需要修改data(数据存储)目录的测试.本案例分两种修改方式,第一种是离线修改data目录,即关闭整个集群后,修改数 ...

  6. KingbaseES R6 集群sys_monitor.sh change_password一键修改集群用户密码

    案例说明: kingbaseES R6集群用户密码修改,需要修改两处: 1)修改数据库用户密码(alter user): 2)修改.encpwd文件中用户密码: 可以通过sys_monitor.sh ...

  7. KingbaseES R6 集群创建流复制只读副本库案例

    一.环境概述 [kingbase@node2 bin]$ ./ksql -U system test ksql (V8.0) Type "help" for help. test= ...

  8. KingbaseES R6 集群通过备库clone在线添加新节点

    案例说明: KingbaseES R6集群可以通过图形化方式在线添加新节点,但是在添加新节点clone环节时,是从主库copy数据到新的节点,这样在生产环境,如果数据量大,将会对主库的网络I/O造成压 ...

  9. KingbaseES R6 集群启动‘incorrect command permissions for the virtual ip’故障案例

    案例说明: KingbaseES R6集群启动时,出现"incorrect command permissions for the virtual ip"故障,本案例介绍了如何分析 ...

  10. kingbaseES R3 集群修改data路径测试案例

    案例说明: 默认KingbaseES R3集群部署后,数据存储目录(data)在/home/kingbase下,部署时不能更改:本案例是在部署完成后,迁移data目录到其他指定的存储位置. 数据库版本 ...

随机推荐

  1. vue在Docker上运行

    Dockerfile # 设置基础镜像 FROM nginx:latest # 定义作者 MAINTAINER test # 将dist文件中的内容复制到 /etc/nginx/html/ 这个目录下 ...

  2. NC14583 糖糖别胡说,我真的不是签到题目

    NC14583 糖糖别胡说,我真的不是签到题目 题目 题目描述 从前,有 \(n\) 只萌萌的糖糖,他们分成了两组一起玩游戏.他们会排成一排,第 \(i\) 只糖糖会随机得到一个能力值 \(b_i\) ...

  3. Ubuntu14.04.6配置阿里源

    Ubuntu14.04.6配置阿里源 这两天上手 Ubuntu 系统,因为公司用的是 14.04.6 版本,所以有了一些踩坑记录. 起因是安装完系统我需要安装一个搜狗输入法,过程得安装 fcitx,需 ...

  4. 2022-7-9 html 第七组 刘昀航

    ​ 一.基础认知 1.1 认识网页 网页的组成: 文字.图片.音频.视频.超链接 网页背后的本质:前端程序员写的代码 前端的代码通过什么软件转换成用户眼中的页面:浏览器转化(解析和渲染) 1.2 5大 ...

  5. 7 什么是dubbo

    什么是dubbo 快速入门dubbo 了解什么是dubbo之前,我们得先了解什么是分布式系统? <分布式系统原理与范型>定义: 分布式系统是若干独立计算机的集合,这些计算机对于用户来说就像 ...

  6. 一文搞懂│php 中的 DI 依赖注入

    目录 什么是 DI / 依赖注入 依赖注入出现的原因 简单的依赖注入 高阶的依赖注入 依赖注入的应用 依赖注入高阶优化 什么是 DI / 依赖注入 依赖注入DI 其实本质上是指对类的依赖通过构造器完成 ...

  7. Javaweb-文件上传和邮件发送

    1.文件上传 新建空项目 准备工作 在maven仓库里下载commons io 和 commons fileupload两个jar包 实用类介绍 文件上传注意事项 为保证服务器安全,上传文件应该放在外 ...

  8. vue-cli 启动项目时空白页面

    vue-cli 启动项目时空白页面 在启动项目时 npm run serve / npm run dev 启动 vue 项目空白页:且终端及控制台都未报错 通过各种查阅发现在项目根目录中 vue-co ...

  9. 【活动专辑】Gitee X DolphinScheduler 邀你一起参与 issue 解决赢好礼!

    在你参与 DolphinScheduler 项目开发时,是否曾因为这些问题困惑: 对项目感兴趣,但不清楚自己可以为项目做什么 在众多 issue 中,找不到合适自己参与的 issue 任务 认为参与开 ...

  10. Apache DolphinScheduler 使用文档(7/8):系统参数及自定义参数

    本文章经授权转载,原文链接: https://blog.csdn.net/MiaoSO/article/details/104770720 目录 7. 参数 7.1 系统参数 7.2 时间自定义参数 ...