pgsql安装

#Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

sudo yum install -y postgresql12-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
systemctl start postgresql-12
systemctl status postgresql-12
image.png

安装postgresql-server会附带安装上postgres客户端,因此不必重复安装。安装完成,postgresql操作相关的命令都会添加到/usr/bin目录下,可以在命令行下直接使用。


检查安装是否完成.png

检查数据存储路径


image.png

登录测试

默认情况下,我们使用psql postgres命令登录,使用的是root用户,会提示没有这个角色,我们按照提示使用psql -U postgres命令登录,发现提示Peer authentication failed for user "postgres",我们只能切换到postgres用户,然后直接登录:

image.png

修改配置文件,root用户下可以直接登录pgsql

vim pg_hba.conf
host    all             all             0.0.0.0/0               md5  #增加一行以MD5加密方式所有主机都可以访问
local   all             all                                     trust  #将local   all             all                                     peer的peer 修改为trust

修改监听地址
vim postgresql.conf
listen_addresses = '*'
image.png

image.png

重启pgsql

systemctl restart postgresql-12

测试本地可以在root用户下使用psql -U postgres直接登录了,不会报错。

data]# psql -U postgres
image.png
远程测试

安装postgresql就是为了让外部能够连接的,这里安装之前,需要修改postgres用户的密码,在本机,修改密码有两种方式:直接\password 的方式和通过alter user postgres with password 'postgres'语句:

image.png

navicat连接测试

image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容