重庆思庄Oracle、Redhat认证学习论坛

标题: 源码安装PG16.2 [打印本页]

作者: 郑全    时间: 2024-3-18 08:25
标题: 源码安装PG16.2
1.建立用户
   -- 创建用户
groupadd postgres
useradd -g postgres postgres
echo "postgres" | passwd --stdin postgres

2. 创建目录
mkdir -p /u01/postgresql/{pgdata,archive,scripts,backup,pg16,soft}
chown -R postgres:postgres /u01/postgresql
chmod -R 775 /u01/postgresql

3.依赖包安装
  yum install -y cmake make gcc zlib zlib-devel gcc-c++ perl readline readline-devel  \
python36 tcl openssl ncurses-devel openldap pam flex libicu-devel

4.下载软件源
  cd /u01/postgresql/soft
  wget https://ftp.postgresql.org/pub/s ... tgresql-16.2.tar.gz

5.配置环境变量
cat >>  ~/.bash_profile <<"EOF"
export PGPORT=5432
export PGDATA=/u01/postgresql/pgdata
export PGHOME=/u01/postgresql/pg16
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
export PGCLIENTENCODING=GBK
EOF


6.支持中文
   修改/etc/locale.conf配置

  原配置:    LANG="en_US.UTF-8"
  修改为:    LANG="zh_CN.UTF-8"
  输入:      source /etc/locale.conf

7.配置
  -- 配置
  su - postgres
  cd /u01/postgresql/soft
  tar zxvf postgresql-16.2.tar.gz
  cd postgresql-16.2
  ./configure --prefix=/u01/postgresql/pg16

8.编译安装
  $ make world -j 16 && make install-world

9.初始化
   su - postgres
   export LANG=zh_CN.gbk
   /u01/postgresql/pg16/bin/initdb -D /u01/postgresql/pgdata -E UTF8 --locale=zh_CN.UTF8 -U postgres


10.修改数据库参数
cat >> /u01/postgresql/pgdata/postgresql.conf << "EOF"
listen_addresses = '*'
port=5432
unix_socket_directories='/u01/postgresql/pgdata'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
max_connections = 500
shared_buffers = 16GB
EOF

11.允许客户端访问
   cat >> /u01/postgresql/pgdata/pg_hba.conf << "EOF"
# TYPE  DATABASE    USER    ADDRESS       METHOD
host      all       all    0.0.0.0/0        md5
EOF

12.设置系统服务
  -- 配置系统服务
  $ su -
cat > /etc/systemd/system/PG16.service <<"EOF"
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target

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

[Install]
WantedBy=multi-user.target
EOF

13.配置自动启动
   systemctl daemon-reload
   systemctl enable PG16
   systemctl start PG16
   systemctl status PG16


14.修改POSTGRES密码
   su - postgres
   psql
   \password postgres
   or:
   alter user postgres with password 'postgres';

到此,安装到此全部完成。








欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2