PG数据库定时任务:PgAgent 编译安装使用

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: PG的定时任务插件

概述

pgagent 作为postgresql的一个任务调度代理,在postgresql 9.0 以前 是附带在pgadmin 包下面的,只是默认不安装,9.0之后作为了一个单独是的安装包。所以要使用pgagent定时任务调度的话还得单独安装。

因为某些系统的yum源中不含有pgaent包,或者版本不适配。可以进行编译安装

需要下载

这里我选择的软件版本分别是:

postgresql 10.3
pgagent-3.4.0下载地址:https://www.pgadmin.org/download/pgagent.php
cmake-3.12.2 下载地址:http://cmake.org/download/
wxWidgets-3.1.1 下载地址:http://www.wxwidgets.org/downloads/

安装步骤

postgresql的安装

(略)

cmake安装

将安装包上传至服务器并解压,解压后进入解压后生成的cmake-3.12.2目录,执行以下命令。

[root@lsrac97 ~]# tar zxvf cmake-3.12.2.tar.gz
[root@lsrac97 ~]# cd cmake-3.12.2
[root@lsrac97 cmake-2.8.5]# ./bootstrap && gmake && gmake install

wxWidgets的安装

先配置.bash_profile文件

[root@lsrac97 ~]#vi .bash_profile
#加入以下内容:

PATH=$PATH:$HOME/bin:/usr/local/wxWidgets-3.1.1/bin
export LD_LIBRARY_PATH=/usr/local/wxWidgets-3.1.1/lib:$LD_LIBRARY_PATH
#并生效参数文件,命令如下:
[root@lsrac97 ~]#source .bash_profile

接着解压该安装包并进入其目录,然后编译和安装

[root@lsrac97 wxGTK-2.8.12 ]# ./configure --enable-shared=no --enable-unicode=yes --prefix=/usr/local/wxWidgets-3.1.1
[root@lsrac97 wxGTK-2.8.12 ]# make && make install

可能会报错

configure: error: 
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.

解决方法

yum install gtk*

显示以下内容表示编译安装完成

/usr/bin/install -c -m 644 ./include/$f /usr/local/wxWidgets-3.1.1/include/wx-3.1/$f; \
done

 
 ------------------------------------------------------
 
 The installation of wxWidgets is finished.  On certain
 platforms (e.g. Linux) you'll now have to run ldconfig
 if you installed a shared library and also modify the
 LD_LIBRARY_PATH (or equivalent) environment variable.
 
 wxWidgets comes with no guarantees and doesn't claim
 to be suitable for any purpose.
 
 Read the wxWindows Licence on licencing conditions.
 
 ------------------------------------------------------
 
[root@stephen wxWidgets-3.1.1]# 

pgagent的安装

上传安装包至服务器并解压,进入目录执行如下命令:

[root@lsrac97 pgAgent-4.0.0-Source]# cmake ./

可能会报错:

-- Found Threads: TRUE  
CMake Error at cmake/FindBoost.cmake:2044 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMakeLists.txt:112 (FIND_PACKAGE)


CMake Error at CMakeLists.txt:118 (MESSAGE):
  Boost library not found.


-- Configuring incomplete, errors occurred!
See also "/tmp/pgAgent-4.0.0-Source/CMakeFiles/CMakeOutput.log".
See also "/tmp/pgAgent-4.0.0-Source/CMakeFiles/CMakeError.log".

解决方法

yum install boost*

再次执行cmake ./

[root@stephen pgAgent-4.0.0-Source]# cmake ./
-- Boost version: 1.53.0
-- Found the following Boost libraries:
--   filesystem
--   regex
--   date_time
--   thread
--   system
--   chrono
--   atomic
--  
-- ================================================================================
-- Configuration summary:
--  
--   Project                     : pgagent
--   Description                 : pgAgent is a job scheduling engine for PostgreSQL
--   Version                     : 4.0.0
--  
--   PostgreSQL version string   : PostgreSQL 9.6.0
--   PostgreSQL version parts    : 9.6
--   PostgreSQL path             : /usr/local/pgsql-9
--   PostgreSQL config binary    : /usr/local/pgsql-9/bin/pg_config
--   PostgreSQL include path     : /usr/local/pgsql-9.6/include
--   PostgreSQL library path     : /usr/local/pgsql-9.6/lib
--   PostgreSQL share path       : /usr/local/pgsql-9.6/share
--  
--   Boost version               : 1.53.0
--   Boost path                  : /usr/include
--   Boost include directory     : /usr/include
--   Boost library directory     : /usr/lib64
--   Boost Static linking        : NO
-- ================================================================================
--  
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/pgAgent-4.0.0-Source

编译完成

然后编译安装 make && make install即可

[root@stephen pgAgent-4.0.0-Source]# make
Scanning dependencies of target run
[ 11%] Generating pgagent--4.0.sql, pgagent.control
[ 11%] Built target run
Scanning dependencies of target pgagent
[ 22%] Building CXX object CMakeFiles/pgagent.dir/connection.cpp.o
[ 33%] Building CXX object CMakeFiles/pgagent.dir/job.cpp.o
[ 44%] Building CXX object CMakeFiles/pgagent.dir/misc.cpp.o
[ 55%] Building CXX object CMakeFiles/pgagent.dir/pgAgent.cpp.o
[ 66%] Building CXX object CMakeFiles/pgagent.dir/precomp.cpp.o
[ 77%] Building CXX object CMakeFiles/pgagent.dir/unix.cpp.o
[ 88%] Building CXX object CMakeFiles/pgagent.dir/win32.cpp.o
[100%] Linking CXX executable pgagent
[100%] Built target pgagent
[root@stephen pgAgent-4.0.0-Source]# make install
[ 11%] Built target run
[100%] Built target pgagent
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/pgagent
-- Set runtime path of "/usr/local/bin/pgagent" to ""
-- Installing: /usr/local/share/pgagent.sql
-- Installing: /usr/local/./README
-- Installing: /usr/local/./LICENSE
-- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--4.0.sql
-- Installing: /usr/local/pgsql-9.6/share/extension/pgagent.control
-- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--3.4--4.0.sql
-- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--unpackaged--4.0.sql

配置pgagent

创建拓展

postgres=# create extension pgagent ;
CREATE EXTENSION

启动pgagent进程

postgres@stephen ~]$ pgagent  hostaddr=127.0.0.1  dbname=postgres user=postgres password=postgres
[postgres@stephen ~]$ 

配置定时任务

连接pgadmin

用你的账号信息连接

如果正确安装了pgagent,就会有个pgagent任务

创建任务

步骤里主要写好基础设置,和需要执行的代码

时间表的信息就可以设置时间的重复。

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
9月前
|
SQL 关系型数据库 MySQL
OceanBase数据库社区版的MySQL模式支持定时任务
OceanBase数据库社区版的MySQL模式支持定时任务
328 1
|
28天前
|
SQL 监控 关系型数据库
PG数据库释放闲置连接
PG数据库释放闲置连接
36 0
|
1月前
|
数据库
使用Navicat Premium 12进行数据库定期自动备份(定时任务)--图文详解
使用Navicat Premium 12进行数据库定期自动备份(定时任务)--图文详解
24 0
|
4月前
|
关系型数据库 数据库 流计算
Flink CDC在处理Incremental Snapshot PG数据库时
Flink CDC在处理Incremental Snapshot PG数据库时
144 1
|
5月前
|
关系型数据库 MySQL Shell
MySQL【实践 01】Linux 环境 MySQL 数据库备份 shell 脚本(脚本源码及说明+定时任务配置+数据库恢复测试)粘贴可以
MySQL【实践 01】Linux 环境 MySQL 数据库备份 shell 脚本(脚本源码及说明+定时任务配置+数据库恢复测试)粘贴可以
52 0
|
5月前
|
SQL 关系型数据库 数据库
postgresql|数据库|pg数据库的文件系统详解---最全面的解析
postgresql|数据库|pg数据库的文件系统详解---最全面的解析
150 0
|
5月前
|
缓存 Linux Shell
Linux使用crontab定时任务定时备份数据库
Linux使用crontab定时任务定时备份数据库
66 0
|
10月前
|
SQL 缓存 Oracle
Linux中的HugePage对数据库服务来说为什么如此重要:以PG为例
Linux中的HugePage对数据库服务来说为什么如此重要:以PG为例
124 3
|
10月前
|
存储 固态存储 关系型数据库
基于PMEM的PG数据库Memhive白皮书
基于PMEM的PG数据库Memhive白皮书
78 0
|
12月前
|
SQL 缓存 负载均衡
PG数据库实现高可用方案(包括通用型方案Corosync+pacemaker协作)
PG数据库实现高可用方案(包括通用型方案Corosync+pacemaker协作)
794 0