概述

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

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

需要下载

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

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

安装步骤

postgresql的安装

(略)

cmake安装

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

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

wxWidgets的安装

先配置.bash_profile文件

  1. [root@lsrac97 ~]#vi .bash_profile
  2. #加入以下内容:
  3. PATH=$PATH:$HOME/bin:/usr/local/wxWidgets-3.1.1/bin
  4. export LD_LIBRARY_PATH=/usr/local/wxWidgets-3.1.1/lib:$LD_LIBRARY_PATH
  5. #并生效参数文件,命令如下:
  6. [root@lsrac97 ~]#source .bash_profile

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

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

可能会报错

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

解决方法

  1. yum install gtk*

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

  1. /usr/bin/install -c -m 644 ./include/$f /usr/local/wxWidgets-3.1.1/include/wx-3.1/$f; \
  2. done
  3. ------------------------------------------------------
  4. The installation of wxWidgets is finished. On certain
  5. platforms (e.g. Linux) you'll now have to run ldconfig
  6. if you installed a shared library and also modify the
  7. LD_LIBRARY_PATH (or equivalent) environment variable.
  8. wxWidgets comes with no guarantees and doesn't claim
  9. to be suitable for any purpose.
  10. Read the wxWindows Licence on licencing conditions.
  11. ------------------------------------------------------
  12. [root@stephen wxWidgets-3.1.1]#

pgagent的安装

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

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

可能会报错:

  1. -- Found Threads: TRUE
  2. CMake Error at cmake/FindBoost.cmake:2044 (message):
  3. Unable to find the requested Boost libraries.
  4. Unable to find the Boost header files. Please set BOOST_ROOT to the root
  5. directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  6. Boost's headers.
  7. Call Stack (most recent call first):
  8. CMakeLists.txt:112 (FIND_PACKAGE)
  9. CMake Error at CMakeLists.txt:118 (MESSAGE):
  10. Boost library not found.
  11. -- Configuring incomplete, errors occurred!
  12. See also "/tmp/pgAgent-4.0.0-Source/CMakeFiles/CMakeOutput.log".
  13. See also "/tmp/pgAgent-4.0.0-Source/CMakeFiles/CMakeError.log".

解决方法

  1. yum install boost*

再次执行cmake ./

  1. [root@stephen pgAgent-4.0.0-Source]# cmake ./
  2. -- Boost version: 1.53.0
  3. -- Found the following Boost libraries:
  4. -- filesystem
  5. -- regex
  6. -- date_time
  7. -- thread
  8. -- system
  9. -- chrono
  10. -- atomic
  11. --
  12. -- ================================================================================
  13. -- Configuration summary:
  14. --
  15. -- Project : pgagent
  16. -- Description : pgAgent is a job scheduling engine for PostgreSQL
  17. -- Version : 4.0.0
  18. --
  19. -- PostgreSQL version string : PostgreSQL 9.6.0
  20. -- PostgreSQL version parts : 9.6
  21. -- PostgreSQL path : /usr/local/pgsql-9
  22. -- PostgreSQL config binary : /usr/local/pgsql-9/bin/pg_config
  23. -- PostgreSQL include path : /usr/local/pgsql-9.6/include
  24. -- PostgreSQL library path : /usr/local/pgsql-9.6/lib
  25. -- PostgreSQL share path : /usr/local/pgsql-9.6/share
  26. --
  27. -- Boost version : 1.53.0
  28. -- Boost path : /usr/include
  29. -- Boost include directory : /usr/include
  30. -- Boost library directory : /usr/lib64
  31. -- Boost Static linking : NO
  32. -- ================================================================================
  33. --
  34. -- Configuring done
  35. -- Generating done
  36. -- Build files have been written to: /tmp/pgAgent-4.0.0-Source

编译完成

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

  1. [root@stephen pgAgent-4.0.0-Source]# make
  2. Scanning dependencies of target run
  3. [ 11%] Generating pgagent--4.0.sql, pgagent.control
  4. [ 11%] Built target run
  5. Scanning dependencies of target pgagent
  6. [ 22%] Building CXX object CMakeFiles/pgagent.dir/connection.cpp.o
  7. [ 33%] Building CXX object CMakeFiles/pgagent.dir/job.cpp.o
  8. [ 44%] Building CXX object CMakeFiles/pgagent.dir/misc.cpp.o
  9. [ 55%] Building CXX object CMakeFiles/pgagent.dir/pgAgent.cpp.o
  10. [ 66%] Building CXX object CMakeFiles/pgagent.dir/precomp.cpp.o
  11. [ 77%] Building CXX object CMakeFiles/pgagent.dir/unix.cpp.o
  12. [ 88%] Building CXX object CMakeFiles/pgagent.dir/win32.cpp.o
  13. [100%] Linking CXX executable pgagent
  14. [100%] Built target pgagent
  15. [root@stephen pgAgent-4.0.0-Source]# make install
  16. [ 11%] Built target run
  17. [100%] Built target pgagent
  18. Install the project...
  19. -- Install configuration: ""
  20. -- Installing: /usr/local/bin/pgagent
  21. -- Set runtime path of "/usr/local/bin/pgagent" to ""
  22. -- Installing: /usr/local/share/pgagent.sql
  23. -- Installing: /usr/local/./README
  24. -- Installing: /usr/local/./LICENSE
  25. -- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--4.0.sql
  26. -- Installing: /usr/local/pgsql-9.6/share/extension/pgagent.control
  27. -- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--3.4--4.0.sql
  28. -- Installing: /usr/local/pgsql-9.6/share/extension/pgagent--unpackaged--4.0.sql

配置pgagent

创建拓展

  1. postgres=# create extension pgagent ;
  2. CREATE EXTENSION

启动pgagent进程

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

配置定时任务

连接pgadmin

用你的账号信息连接

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

创建任务

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

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

2 评论  
lxcos · 2L · 2018-10-19 19:28:47

评论加一

lxcos · 1L · 2018-10-19 19:23:26

评论

添加一条新评论