案例说明:

本案例参考《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. Python列表解析式的正确使用方式

    先来逼逼两句: Python 是一种极其多样化和强大的编程语言!当需要解决一个问题时,它有着不同的方法.在本文中,将会展示列表解析式 (List Comprehension).我们将讨论如何使用它?什 ...

  2. (数据库提权——Redis)Redis未授权访问漏洞总结

    一.介绍 1.Redis数据库 Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key- ...

  3. Cf #782 (Div. 2)

    A. Red Versus Blue 题意 共有 n 个连续字符 ,其中有 a 个  R ,b 个 B (a+b=n),问怎么排列使 R 的最大连续个数最小,输出一种可能排列 思路 b 个B可以把a个 ...

  4. Oracle数据库常用查询语句

    1.[oracle@dbserver ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 15:1 ...

  5. 广义径向基网络(RBF网络)

  6. ArrayList集合存储基本数据类型

    如何存储基本数据类型 ArrayList对象不能存储基本类型,只能存储引用类型的数据.类似 <int> 不能写,但是存储基本数据类型对应的 包装类型是可以的.所以,想要存储基本类型数据, ...

  7. 编程技巧│超实用 nginx 中常见的配置合集

    目录 封禁 IP 仅开放内网 负载均衡 列出文件列表 路由转发 开启 gzip 压缩 解决跨域 资源防盗链 Keepalived 提高吞吐量 HTTP 强制跳转 HTTPS 封禁 IP 通过 deny ...

  8. 在.NET 6.0中配置WebHostBuilder

    大家好,我是张飞洪,感谢您的阅读,我会不定期和你分享学习心得,希望我的文章能成为你成长路上的垫脚石,让我们一起精进. 在阅读第4章"使用Kestrel配置和定制HTTPS"时,您可 ...

  9. MySQL 常见索引类型介绍

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. MySQL 主要索引类型有如下几种: 1.主键索引 2.唯一索引 3.普通索引 4.空间索引 5.全文索引 假设有如下一张 ...

  10. 结束语句之 continue

    C 语言自学之 continue Dome1:计算1到20之间不能被3整除的数字之和.               运算结果为: sum=147 1 #include<stdio.h> 2 ...