丶Terminator

导航

step by step设置postgresql用户密码并配置远程连接

设置pgsql默认用户posgres的密码

1、确认pgsql是开启的 /etc/init.d/postgresql status
2、使用默认用户登录 sudo su postgres
3、进入psql客户端 命令为 sudo -u postgres psql 进入之后就可以写sql了
4、执行第三步如果出现“postgres is not in the sudoers file.  This incident will be reported.”提示则需要在sudoers里面加上postgres,步骤如下:
        1) 输入命令 su - 进入超级用户模式(如果当前不是root用户,则进行root身份验证);
        2) chmod u+w /etc/sudoers 为sudoers文件添加写的权限(默认是只读)
        3) vim /etc/sudoers 编辑sudoers文件,在root ALL=(ALL) ALL这一行下面加上 postgres  ALL=(ALL) ALL
        4)撤销sudoers文件可写 chmod u-w /etc/sudoers
5、继续执行第三步,进入psql客户端之后执行 postgres=# ALTER USER postgres with password '123456';(将默认的postgres用户密码设置为123456,注意语句后面一定要加分号),postgres=# \q 退出psql客户端
 

设置pgsql远程连接

1、修改pgsql配置文件postgresql.conf(默认位于安装目录的data子文件夹下)。找到 listen_addresses = 'localhost' 这一行,将localhost修改为 * 所有ip都允许连接,并取消注释
2、port = 5432 取消注释
3、修改pg_hda.conf(和postgresql.conf同一个目录),在末尾加一行  host    all         all         0.0.0.0/0      md5
4、开启5432端口:
iptables -I INPUT -p tcp --dport 5432 -j ACCEPT 
/etc/init.d/iptables save
/etc/init.d/iptables restart

posted on 2013-09-06 18:02  夜蹲寡妇门  阅读(2168)  评论(0编辑  收藏  举报