Ⅰ. 安装与初始账户密码修改
1. 安装
sudo apt-get install postgresql-9.4
2. 管理员身份打开pg
sudo -u postgres psql
sudo -u postgres 表示以postgres 用户身份登录
PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码随机;
3. 修改密码
ALTER USER postgres WITH PASSWORD '123456';
Ⅱ. 修改指定用户指定权限
alter user postgres superuser createrole createdb replication;
注意:如果出现 FATAL: role '...' is not permitted to log in. 的错误
alter user postgres superuser createrole createdb replication login;
在授权后面加入login 即可;
Ⅲ. 数据库更改属于postgres用户
postgres=# alter database database_name OWNER TO new_user;
IV. 修改PostgresSQL数据库配置实现远程访问
vi /etc/postgresql/9.4/main/postgresql.conf
1.监听任何地址访问,修改连接权限
#listen_addresses = 'localhost' 改为 listen_addresses = '*'
2.启用密码验证
#password_encryption = on 改为 password_encryption = on
vi /etc/postgresql/9.4/main/pg_hba.conf
在文档末尾加上以下内容
host all all 0.0.0.0 0.0.0.0 md5
6、重启服务
/etc/init.d/postgresql restart
7、5432端口的防火墙设置 ( Iptable版)
5432为postgreSQL默认的端口
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT