出现此错误:postgreSQLPool的Ping连接池失败。无法分配连接,因为:致命:数据库“/ localhost:5432 / mydatabase”不存在
池配置如下:
Pool Name: postgreSQLPool Resource Type: javax.sql.ConnectionPoolDataSource Datasource Classname: org.postgresql.ds.PGConnectionPoolDataSource portNumber: 5432 databaseName: myDatabase datasourceName: myDatabaseDS roleName: myRole networkProtocol: jdbc:postgresql: serverName: //localhost user: myUser password: myPassword
postgresql服务器正在运行,因为我可以使用与上面相同的连接值连接到数据库。
postgresql-9.3-1100.jdbc4.jar位于$glassfish_home/domains/domain1/lib directory
任何帮助将不胜感激,
戴夫
答案 0 :(得分:1)
您的池配置看起来像废话。 serverName
中不应包含//
,而networkProtocol
不适用于JDBC URL。
您的配置应该更像这样:
Pool Name: postgreSQLPool
portNumber: 5432
databaseName: myDatabase
datasourceName: myDatabaseDS
roleName: myRole
serverName: localhost
user: myUser
password: myPassword
(我完全不确定roleName
或datasourceName
是否需要或更正,但没有时间进一步审核要检查的文档。
如果仍有问题,请尝试回退到基本数据源:
Resource Type: javax.sql.DataSource
Datasource Classname: org.postgresql.ds.PGSimpleDataSource
有关资源类型的信息,请参阅PGConnectionPoolDataSource,ConnectionPoolDataSource。
请参阅:
答案 1 :(得分:0)
下面:
< DB_NAME&GT = MYDATABASE
< DB_PORT> = 5432
< DB_USER&GT = MYUSER
< DB_USER_PWD&GT = MYPASSWORD
< SCHEMA_NAME&GT = MYSCHEMA
< DB_CONN_POOL&GT = postgreSQLPool
< DATA_SRC&GT = myDatabaseDS
步骤:
a)允许防火墙glassfish服务器,postgres端口,例如centos7
#systemctl enable firewalld
#firewall --add-port=<DB_PORT>/tcp --permanent
##systemctl reload firewalld (<---doesn't work)
#firewall-cmd --reload
b)为用户配置pg_hba.conf以进行SSL登录:
hostnossl all all 0.0.0.0/0 reject
hostssl all postgres 0.0.0.0/0 reject
hostssl <DB_NAME> <USER_NAME> <IR_ADDR> md5
c)在必需的对象上创建用户,数据库,模式并向用户授予优先权,例如:
###CREATE USER
sudo -u postgres psql -p <DB_PORT> -d postgres -c "CREATE USER <USER_NAME> ENCRYPTED PASSWORD 'myUser_pwd';"
###CREATE DB
sudo -u postgres psql -p <DB_PORT> -d postgres -c "CREATE DATABASE <DB_NAME> OWNER <USER_NAME> ENCODING 'UTF-8' TABLESPACE service_ts LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8' LIMIT -1;"
###CREATE SCHEMA
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "CREATE SCHEMA "<SCHEMA_NAME>";"
###REVOKE PREVILEGES ON <SCHEMA_NAME> from public
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "REVOKE ALL ON SCHEMA "<SCHEMA_NAME>" FROM "public";"
###GRANT USAGE ON <SCHEMA_NAME> TO <DB_USER>
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "GRANT USAGE ON SCHEMA "<SCHEMA_NAME>" TO <USER_NAME>;"
###GRANT PREVILEGES ON TABLES OF <SCHEMA_NAME> TO <DB_USER>
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "GRANT ALL ON TABLES IN SCHEMA "<SCHEMA_NAME>" TO <USER_NAME>;"
###GRANT PREVILEGES ON SEQUENCES OF <SCHEMA_NAME> TO <DB_USER>
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "GRANT ALL ON SEQUENCES IN SCHEMA "<SCHEMA_NAME>" TO <USER_NAME>;"
###GRANT PREVILEGES ON FUNCTIONS OF <SCHEMA_NAME> TO <DB_USER>
sudo -u postgres psql -p <DB_PORT> -d <DB_NAME> -c "GRANT ALL ON FUNCTIONS IN SCHEMA "<SCHEMA_NAME>" TO <USER_NAME>;"
d)重新启动Postgresql以进行配置更改
e)将正确的postgresql jdbc4 jar(对应于所使用的服务器版本,例如9.3 / 9.4 / 10.1 )放在域的lib文件夹中((即)... / glassfish / domains / &LT; DOMAIN_NAME&GT; / IIb)的
f)重新启动Glassfish以配置发生更改
使用命令:
asadmin create-jdbc-connection-pool --datasourceClassName "org.postgresql.ds.PGConnectionPoolDataSource" --restype "javax.sql.ConnectionPoolDataSource" --property "ServerName=localhost:PortNumber=<DB_PORT>:DatabaseName=<DB_NAME>:User=<DB_USER>:Password=<DB_USER_PWD>" "<DB_CONN_POOL>"
和
asadmin create-jdbc-resource --connectionpoolid "<DB_CONN_POOL>" "jdbc/<DATA_SRC>"