赞
踩
进入官方文档下载页,选择linux --> Red Hat/Rocky/CentO, 然后进入安装教程
安装 postgresql-server
dnf install postgresql-server
用以下三条命令分别执行初始化数据库开启、开机自启动、启动数据库
postgresql-setup --initdb
systemctl enable postgresql.service
systemctl start postgresql.service
安装postgres数据后,会给操作系统创建一个postgres的用户,切换到postgres用户,进行登录操作
[root@ky10-xxj-20230412-1 test]# su - postgres
Last login: Thu Apr 13 14:23:08 CST 2023 on pts/1
[postgres@ky10-xxj-20230412-1 ~]$
默认用户
[postgres@ky10-xxj-20230412-1 ~]$ psql
psql (10.5)
Type "help" for help.
postgres=#
其他用户
psql -U my_user
本地登录时,postgres用户不需要密码,但是远程登录时需要密码,而该用户默认密码我们不知道,所以需要修改为我们能记住的密码
CREATE USER postgres WITH PASSWORD 'my_password';
由于文件的操作权限原因,一下操作可能需要操作系统切换到root用户下
先查找一下文件pg_hba.conf的位置
[root@ky10-xxj-20230412-1 pgsql]# find / -name pg_hba.conf
/var/lib/pgsql/data/pg_hba.conf
进入文件pg_hba.conf,并增加红框这一行,然后保存退出
接着查找文件postgresql.conf 的位置,找到关键字 listen_addresses=’localhost’, 并改为listen_addresses = ‘*’,然后保存退出
[root@ky10-xxj-20230412-1 pgsql]# find / -name postgresql.conf
/var/lib/pgsql/data/postgresql.conf
/usr/lib/tmpfiles.d/postgresql.conf
[root@ky10-xxj-20230412-1 pgsql]#
systemctl restart postgresql.service
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。