一、前言
官网地址:https://www.postgresql.org/download/linux/redhat/
二、安装
# Install the repository RPM: sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Disable the built-in PostgreSQL module: sudo dnf -qy module disable postgresql # Install PostgreSQL: sudo dnf install -y postgresql13-server # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable postgresql-13 sudo systemctl start postgresql-13
过程中如果出现错误,请执行:sudo dnf install wget
三、配置
# 切换成 postgres 用户 sudo -i -u postgres
password
四、远程访问
cd /var/lib/pgsql/13/data
vim pg_hba.conf
1、修改pg_hba.conf,添加一行到IPv4
host all all 0.0.0.0/0 scram-sha-256
2、修改postgresql.conf
取消#listen_addresses = 'localhost'注释
修改为listen_addresses = '*'
3、重启
systemctl restart postgresql-13.service
五、其他
1.查看当前连接数
select count(1) from pg_stat_activity;
2.查看最大连接数
show max_connections;
3.设置最大连接数
cd /var/lib/pgsql/13/data
vim postgresql.conf
max_connections = 1000