源码编译安装PostgreSQL12.9

源码编译安装PostgreSQL12.9

PG版本:12.9

OS:CentOS 7.6

[root@pgcm ~]# docker rm -f wcbpgcm1
wcbpgcm1
[root@pgcm ~]# docker run -d --name wcbpgcm1 -h wcbpgcm1 \
  -p 65432-65439:5432-5439 -p 63389:3389 \
  -v /sys/fs/cgroup:/sys/fs/cgroup \
  --privileged=true lhrbest/lhrcentos76:8.8 \
  /usr/sbin/init
2ea437de727b412a8c3b46ae354b7784115a67f2321f5f6001addeaba0491746
[root@pgcm ~]# docker exec -it wcbpgcm1 bash
[root@wcbpgcm1 /]# wget https://ftp.postgresql.org/pub/source/v12.9/postgresql-12.9.tar.gz  --no-check-certificate

其他版本的源码包

wget https://ftp.postgresql.org/pub/source/v13.2/postgresql-13.2.tar.gz

wget https://ftp.postgresql.org/pub/source/v12.9/postgresql-12.9.tar.gz --no-check-certificate

wget https://ftp.postgresql.org/pub/source/v11.11/postgresql-11.11.tar.gz

wget https://ftp.postgresql.org/pub/source/v10.16/postgresql-10.16.tar.gz

wget https://ftp.postgresql.org/pub/source/v9.6.21/postgresql-9.6.21.tar.gz

wget https://ftp.postgresql.org/pub/source/v9.4.26/postgresql-9.4.26.tar.gz

# 创建用户
[root@wcbpgcm1 /]# useradd pg12
[root@wcbpgcm1 /]# echo "pg12:wcb" | chpasswd
# 编译
[root@wcbpgcm1 /]# su - pg12
[pg12@wcbpgcm1 ~]$ cp /postgresql-12.9.tar.gz ./
[pg12@wcbpgcm1 ~]$ ls -lth
total 27M
-rw-r--r-- 1 pg12 pg12 27M Apr  7 18:34 postgresql-12.9.tar.gz
[pg12@wcbpgcm1 ~]$ tar -zxvf postgresql-12.9.tar.gz
[pg12@wcbpgcm1 ~]$ cd postgresql-12.9/
[pg12@wcbpgcm1 postgresql-12.9]$./configure --prefix=/home/pg12/soft/ --with-openssl
[pg12@wcbpgcm1 postgresql-12.9]$ make -j 16 && make install
[pg12@wcbpgcm1 postgresql-12.9]$ make world -j 16 && make install-world

# 配置环境变量
[pg12@wcbpgcm1 postgresql-12.9]$ cat >>  ~/.bash_profile <<"EOF"
export PGHOME=/home/pg12/soft
export PGDATA=/home/pg12/data
export PGUSER=postgres
export PGPORT=5432
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PGHOME/bin:$PATH

EOF

[pg12@wcbpgcm1 postgresql-12.9]$ source  ~/.bash_profile

# 初始化
[pg12@wcbpgcm1 postgresql-12.9]$ initdb -D /home/pg12/data -U postgres -k
The files belonging to this database system will be owned by user "pg12".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are enabled.

creating directory /home/pg12/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /home/pg12/data -l logfile start


# 修改参数
[pg12@wcbpgcm1 postgresql-12.9]$ cat >> postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
EOF

[pg12@wcbpgcm1 postgresql-12.9]$ cat  >> pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
host all all all trust
EOF


# 启动
[pg12@wcbpgcm1 postgresql-12.9]$ pg_ctl start
waiting for server to start....2022-04-07 18:40:00.811 CST [12154] LOG:  starting PostgreSQL 12.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2022-04-07 18:40:00.811 CST [12154] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2022-04-07 18:40:00.811 CST [12154] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2022-04-07 18:40:00.811 CST [12154] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-04-07 18:40:00.814 CST [12154] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-04-07 18:40:00.823 CST [12155] LOG:  database system was shut down at 2022-04-07 18:39:07 CST
2022-04-07 18:40:00.825 CST [12154] LOG:  database system is ready to accept connections
 done
server started
[pg12@wcbpgcm1 postgresql-12.9]$ pg_ctl status
pg_ctl: server is running (PID: 12154)
/home/pg12/soft/bin/postgres
[pg12@wcbpgcm1 postgresql-12.9]$ pg_ctl stop
waiting for server to shut down....2022-04-07 18:40:09.758 CST [12154] LOG:  received fast shutdown request
2022-04-07 18:40:09.759 CST [12154] LOG:  aborting any active transactions
2022-04-07 18:40:09.760 CST [12154] LOG:  background worker "logical replication launcher" (PID 12161) exited with exit code 1
2022-04-07 18:40:09.760 CST [12156] LOG:  shutting down
2022-04-07 18:40:09.769 CST [12154] LOG:  database system is shut down
 done
server stopped

[pg12@wcbpgcm1 postgresql-12.9]$ exit
logout
# 配置系统服务
[root@wcbpgcm1 /]#cat > /etc/systemd/system/PG12.service <<"EOF"
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target

[Service]
Type=forking
User=pg12
Group=pg12
Environment=PGPORT=5432
Environment=PGDATA=/home/pg12/data
OOMScoreAdjust=-1000
ExecStart=/home/pg12/soft/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/home/pg12/soft/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/home/pg12/soft/bin/pg_ctl reload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EOF

[root@wcbpgcm1 /]# systemctl daemon-reload
[root@wcbpgcm1 /]# 
[root@wcbpgcm1 /]# systemctl enable PG12
Created symlink from /etc/systemd/system/multi-user.target.wants/PG12.service to /etc/systemd/system/PG12.service.
[root@wcbpgcm1 /]# systemctl start PG12
[root@wcbpgcm1 /]# systemctl status PG12
● PG12.service - PostgreSQL database server
   Loaded: loaded (/etc/systemd/system/PG12.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-04-07 18:42:07 CST; 3s ago
     Docs: man:postgres(1)
  Process: 12351 ExecStart=/home/pg12/soft/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
 Main PID: 12353 (postgres)
   CGroup: /system.slice/docker-2ea437de727b412a8c3b46ae354b7784115a67f2321f5f6001addeaba0491746.scope/system.slice/PG12.service
           ├─12353 /home/pg12/soft/bin/postgres -D /home/pg12/data -p 5432
           ├─12355 postgres: checkpointer   
           ├─12356 postgres: background writer   
           ├─12357 postgres: walwriter   
           ├─12358 postgres: autovacuum launcher   
           ├─12359 postgres: stats collector   
           └─12360 postgres: logical replication launcher   

Apr 07 18:42:07 wcbpgcm1 systemd[1]: Starting PostgreSQL database server...
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.079 CST [12353] LOG:  starting PostgreSQL 12.9 on x86_64-pc-linux-gnu, compiled...), 64-bit
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.079 CST [12353] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.079 CST [12353] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.079 CST [12353] HINT:  Is another postmaster already running on port 5432? If n...nd retry.
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.081 CST [12353] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.092 CST [12354] LOG:  database system was shut down at 2022-04-07 18:40:09 CST
Apr 07 18:42:07 wcbpgcm1 pg_ctl[12351]: 2022-04-07 18:42:07.094 CST [12353] LOG:  database system is ready to accept connections
Apr 07 18:42:07 wcbpgcm1 systemd[1]: Started PostgreSQL database server.
Hint: Some lines were ellipsized, use -l to show in full.

# 修改postgres密码
[root@wcbpgcm1 /]# su - pg12
Last login: Thu Apr  7 18:33:49 CST 2022 on pts/0
Last failed login: Thu Apr  7 18:39:57 CST 2022 on pts/0
There was 1 failed login attempt since the last successful login.
[pg12@wcbpgcm1 ~]$ psql
psql (12.9)
Type "help" for help.

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# \q

你可能感兴趣的:(pg,源码编译)