PostgreSQL详细安装步骤
1.准备环境
postgresql官网:https://www.postgresql.org/
1.1.选择安装环境
1.2.选择要安装的版本以及安装平台
安装版本:postgresql14
安装平台:centos7
2.安装
1.安装RPM存储库,执行以下命令:
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安装PostgreSQL,使用以下命令:
yum install -y postgresql14-server
3.初始化数据库
1.初始化数据库并启用自动启动,使用以下命令:
/usr/pgsql-14/bin/postgresql-14-setup initdb
2.设置成centos7开机启动PostgreSQL服务
systemctl enable postgresql-14
3.启动PostgreSQL服务
systemctl start postgresql-14
注意:PostgreSQL初始化数据库之后,默认的数据目录是在/var/lib/pgsql,但是该目录在根分区下,一般建议放到独立的数据目录下。
所以这里进行如下操作:
3.1.验证安装是否成功
切换到postgres用户(yum安装时自动生成)
然后直接输入psql回车,输出psql(14.6)就代表安装成功。
4.修改账户密码
5.PostgreSQL的简单配置(远程连接)
PostgreSQL14配置文件位置在:/usr/local/tools/pgsql/14/data/postgresql.conf
5.1.修改ip绑定
若要远程连接数据库,则需要修改数据目录下的配置文件。
修改配置文件postgresql.conf:
vim /usr/local/tools/pgsql/14/data/postgresql.conf
注解:
listen_addresses = * *代表监听所有IP,也可以指定特定的IP列表
5.2.允许所有ip访问
vi /usr/local/tools/pgsql/14/data/pg_hba.conf
6.检查数据库状态
systemctl restart postgresql-14