安装
官方安装文档:https://www.postgresql.org/download/linux/redhat/
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql14-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
配置
1.使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
su - postgres
2.登录postgresql数据库
psql
3.修改默认密码
ALTER USER postgres with encrypted password 'postgres';
4.推出数据库
\q
5.配置远程访问,取消 listen_addresses 的注释,将参数值改为“*”
vi /var/lib/pgsql/14/data/postgresql.conf
6.修改/var/lib/pgsql/14/data/pg_hba.conf
文件,最后一行增加 host all all 0.0.0.0/0 md5
vi /var/lib/pgsql/14/data/pg_hba.conf
7.切换到root用户重启pg服务:
systemctl restart postgresql-14.service
8.测试pg数据的连接