文章目录
How to Install PostgreSQL on CentOS 7
安装 Postgres
1 2 |
sudo yum install postgresql-server postgresql-contrib |
初始化db
1 2 |
sudo postgresql-setup initdb |
启动 postgresql
1 2 3 |
sudo systemctl start postgresql sudo systemctl enable postgresql |
检查启动状态

PostgreSQL 基础设置
新增用户
1 2 3 |
sudo passwd postgres su - postgres |
设置数据库账号密码
1 2 3 4 5 6 7 8 9 10 11 12 |
➜ su - postgres Last login: Wed Oct 23 11:00:48 CST 2019 on pts/4 -bash-4.2$ psql psql (9.2.24) Type "help" for help. postgres=# create user root with password 'xxx'; CREATE ROLE postgres=# create database data_lyric with encoding='utf8' owner=root; CREATE DATABASE postgres=# |

设置远程连接
打开配置文件 /var/lib/pgsql/data/pg_hba.conf

修改为:
1 2 3 4 5 6 7 |
# "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 ident |
修改 /var/lib/pgsql/data/postgresql.conf
listen_addresses = 'localhost' 为
1 2 3 4 5 6 |
listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) #port = 5432 # (change requires restart) |
重启 PostgreSQL
1 2 |
systemctl restart postgresql.service |
查看网络

远程连接

