Kylin v10 源码安装Postgres-13

背景

...

环境

  • OS: Kylin v10 SP2
  • PostgreSQL: 13.12
  • Platform: Arm64

安装步骤

1、下载二进制包

# cd /usr/local/src
# wget https://ftp.postgresql.org/pub/source/v13.12/postgresql-13.12.tar.bz2

2、解压

# tar axvf postgresql-13.12.tar.bz2

3、安装依赖组件

# yum install readline-devel zlib-devel

4、创建用户

# groupadd -g 8848 postgres
# useradd -u 8848 -g postgres postgres
# passwd postgres

5、软件编译安装

# cd postgresql-13.12
#  ./configure --prefix=/usr/local/postgresql-13.12 --with-pgport=5432
# make -j $(nproc --all)
# make install

//安装contrib 模块(可选)
# cd contrib && make && make install

# cd /usr/local/ && ln -svf postgresql-13.12 postgresql

6、创建数据目录

# mkdir -pv /data/pgsql/logs /data/pgsql/data
# chown -R postgres:postgres /data/pgsql/logs /data/pgsql/data /usr/local/postgresql

7、初始化数据

# su - postgres
$ /usr/local/postgresql/bin/initdb -D /data/pgsql/data/

8、添加环境变量

  • 单用户
$ vim .bashrc
...
# Postgresql
export LD_LIBRARY_PATH=/usr/local/postgresql/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/postgresql/bin/:$PATH
  • 全局
# cat > /etc/profile.d/postgresql.sh<<EOF
export LD_LIBRARY_PATH=/usr/local/postgresql/lib:\$LD_LIBRARY_PATH
export PATH=/usr/local/postgresql/bin/:\$PATH
EOF

9、创建systemd 服务文件

cat >/etc/systemd/system/postgresql.service<<EOF
[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
## Add a service section and set the max number of open files
LimitNOFILE=102400
User=postgres
Group=postgres
Environment=PGSTARTTIMEOUT=270
Environment=PGLOG=/data/pgsql/logs/startup.log
Environment=PGDATA=/data/pgsql/data
ExecStart=/usr/local/postgresql/bin/pg_ctl start -w -D \$PGDATA -l \$PGLOG
ExecStop=/usr/local/postgresql/bin/pg_ctl stop -m fast -w -D \$PGDATA
ExecReload=/usr/local/postgresql/bin/pg_ctl reload -D \$PGDATA
TimeoutSec=300

[Install]
WantedBy=multi-user.target
EOF

10、基本配置

# vim /data/pgsql/data/postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 8848
shared_buffers = 4096MB
effective_cache_size = 8GB

# vim pg_hba.conf
host    all             all             0.0.0.0/0               scram-sha-256
host    replication     all             10.120.164.234/32       trust

11、服务启动

# systemctl enable postgresql.service --now

12、使用psql 命令测试

$ psql
psql (13.12)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)