最近因为疫情的原因在家办公,工作量也不多,所以闲来无事学一下PGSQL
- 本次演示环境配置
系统:centos7
pgsql版本: 9.6
-
配置步骤
- 安装rpm源
'root@localhost> yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm'- 安装pgsql
'root@localhost> yum install -y postgresql96 postgresql96-server' # 可以使用 rpm -aq | grep postgres 来检查安装是否成功- 初始化数据库
'root@localhost> /usr/pgsql-9.6/bin/postgresql96-setup initdb ' # 初始化数据库 'root@localhost> systemctl enable postgresql-9.6' # 设置开机启动 'root@localhost> systemctl start postgresql-9.6' # 启动pgsql- 修改默认密码
'root@locahost> su - postgres' # 切换用户 '-bash-4.2$ psql -U postgres' # 进入数据库 'postgres=# alter user postgres with password 'root'' # 修改密码 'postgres=# create user root with password 'root';' # 创建用户 'postgres=# create database item owner root;' # 创建数据库并绑定root用户 'postgres=# grant all privileges on database item to root;' # 授权 '\q' # 退出 (突然遇到这样的命令一开始真的挺难适应的) 'exit' # 退出postgres用户- 开启远程访问
'root@localhost> sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /var/lib/pgsql/9.6/data/postgresql.conf' 'root@localhost> vi /var/lib/pgsql/9.6/data/pg_hba.conf' # 将host all all 127.0.0.1/32 ident 修改为 host all all 0.0.0.0/0 md5 'root@localhost> systemctl restart postgresql-9.6' # 重启pgsql然后就可以使用navicat来连接数据库了,连接失败的话通常是端口问题,关闭防火墙或者防火墙开放5432端口就行了