CentOS安装PostgreSQL

https://yum.postgresql.org/repopackages.php

挑选一个版本,比如11,CentOS 7 – x86_64,复制链接

安装yum源
yum install https://download.postgresql.org/pub/repos/yum/testing/11/redhat/rhel-7-x86_64/pgdg-centos11-11-1.noarch.rpm
安装PostgreSQL
yum install -y postgresql11-server postgresql11-contrib
初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb

启动数据库
systemctl start postgresql-11
开机自启
systemctl enable postgresql-11

配置远程访问
vi /var/lib/pgsql/11/data/postgresql.conf
将listen_addresses = 'localhost'
改为listen_addresses = '*'

设置允许访问ip
vi /var/lib/pgsql/11/data/pg_hba.conf
在IPv4 local connections下方添加允许连接的IP
如果想允许所有IPv4地址,则加入一行host all all 0.0.0.0/0 md5
(此处用户不应all,应单个用户单个用户添加,postgres用户不应外网也可访问)
重启数据库
systemctl restart postgresql-11.service

修改默认用户密码

PostgreSQL安装后会创建一个用户,名为postgres。

su - postgres 切换至用户。
psql -U postgres 登录数据库。 
ALTER USER postgres with encrypted password 'xxx'; 设置默认用户postgre的密码,此处密码为xxx,可自行修改。 
\q 退出数据库。 
exit 退出用户。

创建新用户

su - postgres
psql
创建新用户
CREATE USER zhuqiaochu WITH PASSWORD '*****';
创建数据库
CREATE DATABASE exampledb OWNER zhuqiaochu;
将exampledb数据库的所有权限都赋予dbuser
GRANT ALL PRIVILEGES ON DATABASE exampledb TO dbuser;

 

参考:

https://blog.csdn.net/DaSo_CSDN/article/details/75330009

https://blog.csdn.net/zhangzeyuaaa/article/details/77941039

发表评论

电子邮件地址不会被公开。 必填项已用*标注