pgagent 作为postgresql的一个任务调度代理,在postgresql 9.0 以前 是附带在pgadmin 包下面 的,只是默认不安装,9.0之后作为了一个单独是的安装包。所以要使用pgagent定时任务调度的话还得单独安装。个人觉得还是挺方便的,
以下是我 安装使用的一些记录,分享给大家,
在安装pgagent之前还需要安装另外的2个依赖包,cmake 以及wxGTK,
这里我选择的软件版本分别是
postgresql 9.5.1
pgagent-3.4.0下载地址:https://www.pgadmin.org/download/pgagent.PHP
cmake-2.8.5 下载地址:http://cmake.org/download/
wxGTK-2.8.12 下载地址:http://www.wxwidgets.org/downloads/
一、postgresql 的安装
(略)
二、cmake的安装
将安装包上传至服务器并解压,解压后进入解压后生成的cmake-2.8.5目录,执行以下命令。
[root@lsrac97 ~]# tar zxvf pgagent-3.4.0.tar.gz
[root@lsrac97 ~]# cdcmake-2.8.5
[root@lsrac97 cmake-2.8.5]# ./bootstrap && make && make install
三、wxGTK-2.8.12 的安装。
首先配置.bash_profile参数文件
[root@lsrac97 ~]#vi.bash_profile
加入以下内容:
PATH=$PATH:$HOME/bin:/usr/local/wxGTK-2.8.12/bin
export LD_LIBRARY_PATH=/usr/local/wxGTK-2.8.12/lib:$LD_LIBRARY_PATH
注 若PATH 和export LD_LIBRARY_PATH 已存在的 直接在PATH和export LD_LIBRARY_PATH里面 加 : 符号然后后面进行添加即可。修改完后 按ESC 然后 输入:wq保存退出
并生效参数文件,命令如下:
[root@lsrac97 ~]#source .bash_profile
接着解压该安装包并进入其目录 (同 第二步)
进入目录后编译
[root@lsrac97 wxGTK-2.8.12]#./configure --enable-shared=no --enable-unicode=yes --prefix=/usr/local/wxGTK-2.8.12
四、pgagent的安装
[root@lsrac97 pgAgent-3.4.0-Source]# cmake ./
CMake Error at cmake/FindPG.cmake:131 (MESSAGE):No Postgresql installation could be found.
Call Stack (most recent call first):
CMakeLists.txt:107 (FIND_PACKAGE)
这里需要先指定postgresql环境变量
[root@lsrac97 pgAgent-3.4.0-Source]# source /home/postgres/.bash_profile
[root@lsrac97 pgAgent-3.4.0-Source]# cmake ./
--
-- ================================================================================
-- Configuration summary:
--
-- Project : pgagent
-- Description : pgAgent is a job scheduling engine for Postgresql
-- Version : 3.4.0
--
-- Postgresql version string : Postgresql 9.5.1
-- Postgresql version parts : 9.5.1
-- Postgresql path : /app/postgresql/pg951
-- Postgresql config binary : /app/postgresql/pg951/bin/pg_config
-- Postgresql include path : /app/postgresql/pg951/include
-- Postgresql library path : /app/postgresql/pg951/lib
-- Postgresql share path : /app/postgresql/pg951/share
--
-- wxWidgets version : 2.8.12
-- wxWidgets path : /usr/local/wxGTK-2.8.12
-- wxWidgets config binary : /usr/local/wxGTK-2.8.12/bin/wx-config
-- wxWidgets Static linking : YES
-- wxWidgets Debug? : NO
-- ================================================================================
--
-- Configuring done
-- Generating done
-- Build files have been written to: /app/pgAgent-3.4.0-Source
然后编译安装 make && make install 即可
[root@lsrac97 pgAgent-3.4.0-Source]# make
--
-- ================================================================================
-- Configuration summary:
--
-- Project : pgagent
-- Description : pgAgent is a job scheduling engine for Postgresql
-- Version : 3.4.0
--
-- Postgresql version string : Postgresql 9.5.1
-- Postgresql version parts : 9.5.1
-- Postgresql path : /app/postgresql/pg951
-- Postgresql config binary : /app/postgresql/pg951/bin/pg_config
-- Postgresql include path : /app/postgresql/pg951/include
-- Postgresql library path : /app/postgresql/pg951/lib
-- Postgresql share path : /app/postgresql/pg951/share
--
-- wxWidgets version : 2.8.12
-- wxWidgets path : /usr/local/wxGTK-2.8.12
-- wxWidgets config binary : /usr/local/wxGTK-2.8.12/bin/wx-config
-- wxWidgets Static linking : YES
-- wxWidgets Debug? : NO
-- ================================================================================
--
-- Configuring done
-- Generating done
-- Build files have been written to: /app/pgAgent-3.4.0-Source
Scanning dependencies of target pgagent
[ 12%] Building CXX object CMakeFiles/pgagent.dir/job.cpp.o
[ 25%] Building CXX object CMakeFiles/pgagent.dir/win32.cpp.o
[ 37%] Building CXX object CMakeFiles/pgagent.dir/precomp.cpp.o
[ 50%] Building CXX object CMakeFiles/pgagent.dir/misc.cpp.o
[ 62%] Building CXX object CMakeFiles/pgagent.dir/unix.cpp.o
[ 75%] Building CXX object CMakeFiles/pgagent.dir/pgAgent.cpp.o
[ 87%] Building CXX object CMakeFiles/pgagent.dir/connection.cpp.o
Linking CXX executable pgagent
[ 87%] Built target pgagent
Scanning dependencies of target run
[ 87%] Generating pgagent--3.4.sql,pgagent.control
[100%] Built target run
[root@lsrac97 pgAgent-3.4.0-Source]# make install
[ 87%] Built target pgagent
[100%] Built target run
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/pgagent
-- Removed runtime path from "/usr/local/bin/pgagent"
-- Installing: /usr/local/share/pgagent.sql
-- Installing: /usr/local/share/pgagent_upgrade.sql
-- Installing: /usr/local/./README
-- Installing: /usr/local/./LICENSE
-- Installing: /app/postgresql/pg951/share/extension/pgagent--3.4.sql
-- Installing: /app/postgresql/pg951/share/extension/pgagent.control
-- Installing: /app/postgresql/pg951/share/extension/pgagent--unpackaged--3.4.sql
编译安装完之后切换postgres用户(postgresl服务必须是起来的)
[root@lsrac97 pgAgent-3.4.0-Source]# su - postgres
[postgres@lsrac97 ~]$psql -h127.0.0.1 -p 5432 -U postgres -d postgres -f /usr/local/share/pgagent.sql
[postgres@lsrac97 ~]$psql -h127.0.0.1 -p 5432 -U postgres -d postgres -f /usr/local/share/pgagent_upgrade.sql
[postgres@lsrac97 ~]$ pgagent --help
Usage:
pgagent [options] <connect-string>
options:
-f run in the foreground (do not detach from the terminal)
-t <poll time interval in seconds (default 10)>
-r <retry period after connection abort in seconds (>=10,default 30)>
-s <log file (messages are logged to STDOUT if not specified>
-l <logging verbosity (ERROR=0,WARNING=1,DEBUG=2,default 0)>
到这一步 pgagent基本上就安装成功了,接着到pgadmin里面直接连接postgresql就可以看到有“”作业“”这个选项了
如图
接着配置作业就可以了。
配置作业后还需启动pgagent服务 方能启动任务调度功能命令如下(在postgres用户下执行):
[postgres@lsrac97 ~]$ pgagent hostaddr=172.19.188.197 dbname=postgres user=postgres password=postgres -s ./pgagent.log
如何使用pgagent任务调度?请看如下教学
右键点击新建作业
新建作业的属性如下。
新建作业定义,即要定时执行的sql
新建计划即定时调度的时间点
到此全部完成!