一、安装
centos6.4服务器IP:192.168.220.131
window7客户端IP:192.168.199.218
在centos官网http://www.postgresql.org/download/linux/redhat/,通过如下指令安装postgresql
yum install postgresql-server
service postgresql initdb
chkconfig postgresql on
貌似已经安装过了,版本是8.4,因为看到update字样。不管。
二、本地建立数据库用户和DB,测试连接
su postgres //切换到默认建立的postgres用户 psql //进入postgresql命令控制台 CREATE USER root WITH PASSWORD 'root'; CREATE DATABASE rootdb WITH OWNER = root TEMPLATE = template0 ENCODING = 'UNICODE'; \q //退出postgresql命令控制台 exit //退出postgres用户到root用户 /usr/bin/psql -Uroot rootdb //测试本地环境用户登录
三、windows7客户端连接测试
1)关闭防火墙 service iptables stop
2)修改/var/lib/pgsql/data/postgresql.conf(修改内容listen_addresses = '*')后,提示错误
FATAL: no pg_hba.conf entry for host "192.168.220.1", user "root", database "rootdb", SSL off
2.1)重启命令 service iptables restart
2.2)可能会提示失败,查看log
2.2.1)确定log文件位置,通过查看postgresql.conf文件
# This is used when logging to stderr: logging_collector = on # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart) # These are only used if logging_collector is on: log_directory = 'pg_log' # directory where log files are written, # can be absolute or relative to PGDATA log_filename = 'postgresql-%a.log' # log file name pattern, # can include strftime() escapes
2.2.2)查看log(tail -f /var/lib/pgsql/data/pg_log/postgresql-Sat.log )
LOG: database system was shut down at 2014-09-06 10:09:32 CST
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
3)修改/var/lib/pgsql/data/pg_hba.conf ,如下
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 192.168.0.0/32 md5 host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 ident
最后添加了host all all 0.0.0.0/0 md5这么一段,成功连接。