Postgresql 9.6 scheduled tasks

1. Preparations

The Postgresql environment demonstrated in this article is Postgresql 9.6

Installation method reference URL: https://my.oschina.net/corleone/blog/1575150

After installing postgresql9.6, remember to configure environment variables:

$: vi /etc/profile
// 由于postgresql9.6是默认安装,故在文件末尾添加如下内容
PATH=$PATH:/usr/pgsql-9.6/bin

$: source /etc/profile

Download the package:

﹒pgAgent-3.4.0-Source.tar.gz

pg_agent download address: https://www.pgadmin.org/download/pgagent-source-code/

Macmake-3.9.6.tar.gz

cmake download address: https://cmake.org/download/

﹒wxGTK-2.8.12.tar.gz

wxWidgets download address: http://www.wxwidgets.org/downloads/

Unzip the installation package:

$: cd /usr/local
$: mkdir pgagent
$: tar zxvf pgAgent-3.4.0-Source.tar.gz 
$: tar zxvf cmake-3.9.6.tar.gz
$: tar xvf wxGTK-2.8.12.tar.gz

2. Install cmake

$: cd /usr/local/cmake-3.9.6
$: ./configure --prefix=/usr/local/cmake-3.9.6
$: make
$: make install

$: vi /etc/profile
// 添加如下内容
export PATH=/usr/local/cmake-3.9.6/bin:$PATH

$: source /etc/profile

3. Install wxWidgets

Install gtk2-devel and binutils first

$: yum -y install gtk2-devel binutils-devel

Install wxWidgets (wxWidgets takes longer to compile)

$: cd /usr/local/wxGTK-2.8.12
// enable-shared=yes 表示设置为公共库
$: ./configure --enable-shared=no --enable-unicode=yes 
$: make
$: sudo make install

Seeing the following display indicates that the installation was successful:

Enter image description

Configure environment variables:

$: vi /etc/profile
// 添加以下内容
export PATH=/usr/local/wxGTK-2.8.12/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/wxGTK-2.8.12/lib:$LD_LIBRARY_PATH
$: source /etc/profile

Set its dynamic library directory:

$: cd /etc/ld.so.conf.d/
$: sudo touch wxWidgets.conf
$: sudo vi wxWidgets.conf
// 添加以下内容
/usr/local/lib

$: source /etc/profile
$: sudo ldconfig  # 重新加载动态库配置信息

Restart the server:

$: reboot

4. Install pgAgent

$: cd /usr/local/pgAgent-3.4.0-Source
$: cmake ./
$: make && make install

(Reference picture) After cmake ./ is completed, as shown in the figure:

Enter image description

(Reference picture) After make && make install is completed, as shown in the figure:

Enter image description

Create the pgAgent database in postgresql:

$; psql -h 192.168.1.189 -d postgres -U postgres -p 5432
// 在postgresql中输入sql如下
create extension pgagent;
CREATE EXTENSION

5. Start pgAgent First create the log directory of pgAgent:

$: mkdir -p /data/pgdata/log

Start the pgAgent daemon:

# hostaddr输入postgresql的主机地址
# dbname输入postgresql的数据库名称
# port输入postgresql的端口号
# user输入postgresql的用户账号
# password输入postgresql的用户密码
$: pgagent -t 60 -l 2 hostaddr=192.168.1.189 dbname=postgres port=5432 user=postgres password=1234 -s /data/pgdata/log/pgagent.log

// 检查pgagent进程
$: ps -ef | grep pgagent
// 显示如下
root      15216      1  0 Nov30 ?        00:00:02 pgagent -t 60 -l 2 hostaddr=192.168.1.189 dbname=postgres port=5432 user=postgres password=1234 -s /data/pgdata/log/pgagent.log

6. Install pgAdmin4

Official website download address: https://www.pgadmin.org/download/

Download the corresponding version according to the computer operating system, this article downloads the Windows version of pgAdmin4;

After downloading, install it;

Connect to postgresql after opening:

1) Add a server

Enter image description

2) Configure server information

Enter image description Enter image description

7.pgAdmin timed task configuration

After logging in, you will see the task of pgAgent

Enter image description

1) Create a scheduled task

Right-click on the pgAgent job and create pgAgentJob

Enter image description Enter image description

2) Configure the schedule

Right click on the schedule and create a Schedule

Enter image description

Configure time task name, start time, end time

Enter image description

Set task repeat execution time

Enter image description

3) Configuration steps

Right click on the step and create a Job Step

Enter image description

Add step name

Enter image description

Add a task to execute SQL

Enter image description

At this point, the entire timing task configuration is completed;

8. Error solution

报错1:/usr/bin/ld: cannot find -lldap

solution:

$: locate  libldap

Find the relevant path such as:

/lib64/libldap-2.4.so.2

/lib64/libldap-2.4.so.2.10.3

/lib64/libldap_r-2.4.so.2

/lib64/libldap_r-2.4.so.2.10.3

/usr/lib64/libldap-2.3.so.0

/usr/lib64/libldap-2.3.so.0.2.31

/usr/lib64/libldap_r-2.3.so.0

/usr/lib64/libldap_r-2.3.so.0.2.31

Edit the file manually

$: sudo ln -s /usr/lib64/libldap-2.3.so.0 /usr/lib/libldap.so

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325445828&siteId=291194637