Linux CentOS 7 安装 PostgreSQL v14
1、安装 PostgreSQL 的 RPM 资源库
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2、安装 PostgreSQL Server
sudo yum install -y postgresql14-server
3、初始化 PostgreSQL
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
4、配置 PostgreSQL
设置监听所有网络地址:
vim /var/lib/pgsql/14/data/postgresql.conf
设置允许接入来源IP:
vim /var/lib/pgsql/14/data/pg_hba.conf
5、设置 PostgreSQL 开机自启
sudo systemctl enable postgresql-14
6、启动 PostgreSQL 并查看运行状态
sudo systemctl start postgresql-14
sudo systemctl status postgresql-14
7、修改 PostgreSQL 数据库默认用户密码
PostgreSQL 数据库会创建一个 postgres 用户作为数据库管理员,因为该用户密码自动生成无从得知,所以需要修改密码。
例如修改密码为:pg123
sudo -u postgres psql
ALTER USER postgres WITH PASSWORD 'pg123';
8、DBMS 连接验证
PostgreSQL 相关目录位置
- 安装目录默认在 /usr/pgsql-*/ 下
- 数据文件和配置文件目录默认在 /var/lib/pgsql/ 下
(完毕)
参考资料
[ 1 ] [ PostgreSQL 官网 ] https://www.postgresql.org/download/linux/redhat/