一、安装PostgreSQL13
以root身份运行如下命令
rpm -ivh postgresql13-libs-13.1-3PGDG.rhel7.x86_64 rpm -ivh postgresql13-13.1-3PGDG.rhel7.x86_64 rpm -ivh postgresql13-server-13.1-3PGDG.rhel7.x86_64 rpm -ivh postgresql13-contrib-13.1-3PGDG.rhel7.x86_64 rpm -ivh postgresql13-pltcl-13.1-3PGDG.rhel7.x86_64 rpm -ivh postgresql13-devel-13.1-3PGDG.rhel7.x86_64.rpm
二、 数据库配置
2.1 修改环境变量
$ sudo su - postgres $ vi ~/.bashrc export PGHOME=/usr/pgsql-13 export PGDATA=/data/pgsql/13/data export PGUSER=postgres export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH export PATH=$PGHOME/bin:$PATH
2.2 修改数据库配置
- 初始化数据库
initdb
- 修改postgresql.conf
$ cd $PGDATA $ vi postgresql.conf # 修改listen_addresses listen_addresses = '*'
- 修改pg_hba.conf
$ cd $PGDATA $ vi pg_hba.conf # 新增一行 host all all 0.0.0.0/0 md5
三、配置自启动
修改数据存储目录在自启动脚本中的值
$ vi /usr/lib/systemd/system/postgresql-13.service # Location of database directory # Environment=PGDATA=/var/lib/pgsql/13/data/ #-- 注释掉这一句 Environment=PGDATA=/data/pgsql/13/data/ #-- 修正为实际值
使用系统命令控制数据库启停
systemctl enable postgresql-13 systemctl status postgresql-13 systemctl start postgresql-13