centos安装postgresql并配置

安装postgresql
yum install -y postgresql-server
初始化数据库
postgresql-setup initdb
允许外部访问数据库
nano /var/lib/pgsql/data/postgresql.conf

替换listen_addresses = 'localhost'listen_addresses = '*'

允许通过密码登录
nano /var/lib/pgsql/data/pg_hba.conf

将ident替换为md5

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5	

如果需要外部访问添加

host    all             all             107.155.94.0/24         md5
启动服务器并开启自动启动
systemctl start postgresql.service
systemctl enable postgresql.service
打开防火墙5432端口
创建数据库和用户
su - postgres
createdb test
psql test
CREATE USER testusr WITH SUPERUSER LOGIN PASSWORD 'testusr';
测试
psql -h localhost -d test -U testusr
管理员远程访问密码
su - postgres
psql postgres

然后

\password postgres