Postgresql:Centos7安装Postgresql


安装

官方安装文档: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

image-20220307162426043

配置

1.使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)

su - postgres

image-20220307162501950

2.登录postgresql数据库

psql

image-20220307162531302

3.修改默认密码

ALTER USER postgres with encrypted password 'postgres';

image-20220307162643922

4.推出数据库

\q

5.配置远程访问,取消 listen_addresses 的注释,将参数值改为“*”

vi /var/lib/pgsql/14/data/postgresql.conf

image-20220307162813906

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

image-20220307163008268

7.切换到root用户重启pg服务:

systemctl restart postgresql-14.service

8.测试pg数据的连接

image-20220307163129360