1.检查PostgreSQL 是否已经安装
rpm -qa|grep postgres
若已经安装,则使用rpm -e 命令卸载。
2.下载RPM包,下载其中3个RPM安装包就可以了:
https://yum.postgresql.org/rpmchart.php
- postgresql15 PostgreSQL client programs and libraries
- postgresql15-libs The shared libraries required for any PostgreSQL clients
- postgresql15-server The programs needed to create and run a PostgreSQL server
3.安装
注意安装顺序
rpm -ivh postgresql15-libs-15.4-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql15-15.4-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql15-server-15.4-1PGDG.rhel7.x86_64.rpm
如果提示缺少libicu、libzstd包,那么先去下载安装
下载地址:http://www.rpmfind.net/linux/rpm2html/search.php
安装:
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
rpm -ivh libzstd-1.5.5-1.el7.x86_64.rpm
4.服务
查看服务
systemctl status postgresql-15
查看服务文件
cat /usr/lib/systemd/system/postgresql-15.service
Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/
#程序目录
ExecStart=/usr/pgsql-13/bin/postmaster -D KaTeX parse error: Expected 'EOF', got '#' at position 42: …alhost postgre]#̲ su postgres ba… cd /usr/pgsql-15/bin/
bash-4.2$ ./initdb -D /var/lib/pgsql/15/data/
bash-4.2$ exit
exit
启动服务
[root@localhost postgre]# systemctl enable postgresql-15 && systemctl restart postgresql-15
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-15.service to /usr/lib/systemd/system/postgresql-15.service.
修改密码
[root@localhost postgre]# su postgres
bash-4.2$ psql -U postgres
postgres=# ALTER USER postgres with encrypted password ‘Aa@123456’;
配置远程连接
##想对所有IP开放,则将localhost改为*即可
vi /var/lib/pgsql/15/data/postgresql.conf
systemctl restart postgresql-15.service