【问题详细描述】
在连接时,出现尝试连线已失败,报如下错误
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Unable to open a test connection to the given database. JDBC url = jdbc:postgresql://192.168.0.155:11810/foo, username = root. Terminating connection pool. Original Exception: ------
org.postgresql.util.PSQLException: 尝试连线已失败。
at org.postgresql.core.v3.ConnectionFactoryI
【解决办法】
1、建议参考http://doc.sequoiadb.com/cn/index-cat_id-1432190716-edition_id-0文档进行安装
2、修改 PostgreSQL 的连接配置
修改 PostgreSQL 的监听地址
$ sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '0.0.0.0'/g" pg_data/postgresql.conf
修改信任的机器列表
$ linenum=$(cat -n pg_data/pg_hba.conf | grep "# IPv4 local connections:" | awk '{print $1}');
$ let "linenum=linenum+1";varStr="host all all 0.0.0.0/0 trust";
$ sed -i "${linenum} a${varStr}" pg_data/pg_hba.conf;
重启 PostgreSQL
$ bin/pg_ctl stop -s -D pg_data/ -m fast; bin/postgres -D pg_data/ >> logfile 2>&1 &
用户需要对postgresql 的配置文件进行修改,让pgsql 支持其他服务器进行连接
连接失败,可能是在安装的过程中并未对文件进行配置,建议参考http://doc.sequoiadb.com/cn/index-cat_id-1432190716-edition_id-0,并按照步骤在安装过程中配置文件
【参考链接】
错误码
常见错误处理指南