postgres 增加用户及远程连接

来源:互联网 发布:强制win7 areo软件 编辑:程序博客网 时间:2024/05/21 10:44

   yum install postgres-*

 1 :  Add  user  and   create   database         

sudo -u postgres psql
could not change directory to "/root"
psql (8.4.9)
Type "help" for help.
postgres=# CREATE USER test WITH PASSWORD 'abc';          
CREATE ROLE
postgres=# CREATE DATABASE test;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE test to test;     
GRANT
postgres=# \q

2   配置postgres   远程连接

1.修改pg_hba.conf文件,配置用户的访问权限:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
host    all         all         192.168.1.0/24        md5   #   允许192.168.1.0上的所有主机使用所有合法的数据库用户名访问数据库,并提供加密的密码验 证
# IPv6 local connections:

host    all         all         ::1/128               trust  #  免认证。
host    all         all         ::1/128               trust   #

2.修改postgresql.conf文件,将数据库服务器的监听模式修改为监听所有主机发出的连接请求。

#listen_addresses='localhost'。PostgreSQL安装完成后,默认是只接受来在本机localhost的连接请 求,通过将改行内容修改为listen_addresses='*'来允许数据库服务器监听来自任何主机的连接请求:

listen_addresses = '*'             # what IP address(es) to listen on;

3  /etc/init.d/postgresql restart