本教程将详细介绍如何在CentOS7操作系统中安装PostgreSQL9.3数据库。PostgreSQL是一个功能强大的开源关系型数据库,在企业应用和Web应用中被广泛使用。
yum -y install https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-3.noarch.rpm
yum makecache
yum install -y postgresql93-server postgresql93-contrib postgresql93-devel
/usr/pgsql-9.3/bin/postgresql93-setup initdb
systemctl start postgresql-9.3.service
systemctl enable postgresql-9.3.service
firewall-cmd --addClass=postgresql
firewall-cmd --zone=public --add-service=postgresql --permanent
firewall-cmd --reload
su - postgres
psql -U postgres -c "alter user postgres with password 'yourpassword'"
将/etc/postgresql93/pg_hba.conf文件的所有内容替换为以下内容:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
# 修改为
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 0.0.0.0/0 md5
psql -h youripaddress -U postgres -d postgres
SELECT version();
示例一:
如果查到的版本信息为:
PostgreSQL 9.3.24 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
说明PostgreSQL9.3已经成功安装。
示例二:
如果连接到PostgreSQL的过程中遇到下列错误信息:
psql: FATAL: Peer authentication failed for user "postgres"
说明可能在步骤四中没有正确配置访问控制,需要重新检查。
在本教程中,我们介绍了如何在CentOS 7中安装PostgreSQL 9.3。安装过程分为5个步骤,涵盖了PGDG源的安装、依赖项的安装、数据库的初始化、PostgreSQL服务的启动和配置、密码和访问控制的设置以及测试SQL查询。
本文链接:http://task.lmcjl.com/news/13825.html