前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GreenPlum 6.27.0版本新特性及pg_cron模块配置定时任务说明

GreenPlum 6.27.0版本新特性及pg_cron模块配置定时任务说明

作者头像
小麦苗DBA宝典
发布2024-04-15 11:01:41
1010
发布2024-04-15 11:01:41
举报

简介

GreenPlum 6.27.0于2024-04-05已发布,GreenPlum的发布历史请参考:https://www.xmmup.com/greenplumbanbenfabulishi.html

GreenPlum 6.27.0 有以下几个新特性:

Greenplum Database 6.27.0 includes these new and changed features:

  • The gpfdist parallel file distribution utility now supports multi-threaded data compression and transmission.
  • The PgBouncer distributed with Greenplum Database has been updated to version 1.21.0.
  • The gpcheckcat utility now includes a new test -- mix_distribution_policy -- which checks for tables created with legacy and non-legacy hash operations.
  • This release updates the plcontainer version to 2.4.0 and the python3 image version to 2.4.0. Previous image releases cannot be used with the 2.4.0+ plcontainer.
  • The pg_config utility option --version now displays the version of the PostgreSQL backend server, and the new option --gp_version prints the version of Greenplum.
  • VMware Greenplum 6.27.0 introduces the pg_cron module, which provides a cron-based job scheduler that runs inside the database.
  • VMware Greenplum 6.27.0 supports Run-length encoding (RLE) compression with the Zstandard algorith, or zstd for column-oriented tables.
  • The log_checkpoints server configuration parameter is now set to on by default.
  • The gpsupport gp_log_collector tool now supports gathering logs for VMware Greenplum Disaster Recovery, via the new -with-gpdr-primary and -with-gpdr-recovery options.
  • The ip4r module distributed with VMware Greenplum has been updated to version 2.4.2.
  • With the 6.27.0 release, VMware Greenplum now supports the VMware Greenplum Virtual Appliance. The virtual machine appliance contains everything you may need for an easy deploying of VMware Greenplum on vSphere. See VMware Greenplum on vSphere for more details.
  • VMware Greenplum 6.27.0 enhances WAL archive recovery by preventing scanning of nonexistent WAL segment files.
  • You may now pass the -i and --differential in the same gprecoverseg command.

其中,最令我关注的还是pg_cron模块,这个模块可以配置定时任务,接下来着重介绍该特性。

6.27.0测试环境

代码语言:javascript
复制
docker rm -f gpdb6270
docker run -itd --name gpdb6270 -h gpdb6270 \
  -p 5627:5432 -p 26270:28080  \
  -v /sys/fs/cgroup:/sys/fs/cgroup \
  --privileged=true lhrbest/greenplum:6.27.0 \
  /usr/sbin/init

docker exec -it gpdb6270 bash

su - gpadmin


gpstart -a
gpcc start



gpcc status
gpstate 

pg_cron模块使用说明

参考:

https://docs.vmware.com/en/VMware-Greenplum/6/greenplum-database/ref_guide-modules-pg_cron.html

https://github.com/citusdata/pg_cron

在启用pg_cron模块后,后台会有一个进程:

代码语言:javascript
复制
[gpadmin@gpdb6270 ~]$ ps -ef|grep cron | grep post
gpadmin    16678   16660  0 14:02 ?        00:00:00 postgres:  5432, bgworker: pg_cron launcher   
[gpadmin@gpdb6270 ~]$ 

pg_cron的时间配置:

代码语言:javascript
复制
 ┌───────────── min (0 - 59)
 │ ┌────────────── hour (0 - 23)
 │ │ ┌─────────────── day of month (1 - 31) or last day of the month ($)
 │ │ │ ┌──────────────── month (1 - 12)
 │ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to
 │ │ │ │ │                  Saturday, or use names; 7 is also Sunday)
 │ │ │ │ │
 │ │ │ │ │
 * * * * *

安装pg_cron

代码语言:javascript
复制
-- 1、默认在postgres数据库中,可以通过如下命令修改成其它数据库(可选)
gpconfig -c cron.database_name -v 'db_name' --skipvalidation


-- 2、修改shared_preload_libraries参数,注意该参数之前的值
gpconfig -s shared_preload_libraries

gpconfig -c shared_preload_libraries -v 'metrics_collector,pg_cron'
gpstop -M fast -ar

gpconfig -s shared_preload_libraries


-- 3、只能在第1步中cron.database_name配置的数据库中创建扩展,否则会报错
CREATE EXTENSION pg_cron;
GRANT USAGE ON SCHEMA cron TO user1;

报错:

代码语言:javascript
复制
ERROR:  can only create extension in database postgres
DETAIL:  Jobs must be scheduled from the database configured in cron.database_name, since the pg_cron background worker reads job descriptions from this database.
HINT:  Add cron.database_name = 'lhrgpdb' in postgresql.conf to use the current database.

升级pg_cron

代码语言:javascript
复制
ALTER EXTENSION pg_cron UPDATE TO '1.6.2';

使用pg_cron

代码语言:javascript
复制
SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);

-- 更改JOB
UPDATE cron.job SET database = 'database1' WHERE jobid = 106;
SELECT cron.reload_job();


SELECT cron.schedule_in_database('weekly-vacuum', '0 4 * * 0', 'VACUUM', 'some_other_database');



-- Delete old cron.job_run_details records of the current user every day at noon
SELECT  cron.schedule('delete-job-run-details', '0 12 * * *', $$DELETE FROM cron.job_run_details WHERE end_time < now() - interval '7 days'$$);



-- 每2秒执行1次
SELECT  cron.schedule_in_database('run-select66', '2 seconds', $$SELECT 66$$,'db1');

-- 修改为10秒
UPDATE cron.job SET schedule = '10 seconds' WHERE jobid = 2;
-- 或:SELECT cron.alter_job(2,'20 seconds');
SELECT cron.reload_job();


-- 删除job
SELECT cron.unschedule(1);


-- 禁用或启用某个job
UPDATE cron.job SET active = 'f' WHERE jobid = 2;
SELECT cron.reload_job();



-- 查询
SELECT * from cron.job;
select * from cron.job_run_details order by runid desc limit 100;

参考

https://docs.vmware.com/en/VMware-Greenplum/6/greenplum-database/relnotes-release-notes.html

https://docs.vmware.com/en/VMware-Greenplum/6/greenplum-database/ref_guide-modules-pg_cron.html

本文参与?腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-04-08,如有侵权请联系?cloudcommunity@tencent.com 删除

本文分享自 DB宝 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
  • 6.27.0测试环境
  • pg_cron模块使用说明
    • 安装pg_cron
      • 升级pg_cron
        • 使用pg_cron
        • 参考
        相关产品与服务
        数据库
        云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
        http://www.vxiaotou.com