ryan
ryan

Reputation: 333

Connection refused while creating connection pool for postgresql vendor in glassfish server admin console

I am trying to create a connection pool to a PostgreSQL database in Glassfish server. What I have done the steps as:

  1. I copied the jar of postgresql jdbc jar in full path C:\Program Files\glassfish-3.1.1\glassfish\domains\domain1\lib\ext

  2. I have specified full path to the jar in the glassfish server admin console:

    Pool Name: post-gre-sql_CommonPush_postgresPool

    Resource Type: javax.sql.XADataSource

    Datasource Classname: org.postgresql.ds.PGSimpleDataSource

In case of additional properties I have specified as:

driverClass:org.postgresql.Driver

URL: jdbc:postgresql://10.137.243.1:5432/CommonPush
portNumber: 5432
databaseName: CommonPush
serverName: 10.137.243.1(My system's IP)
user: postgres
password: 

When I ping the above settings I get the error as:

An error has occurred

Ping Connection Pool for post-gre-sql_CommonPush_postgresPool is Failed. Ping failed Exception - Connection could not be allocated because: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Please check the server.log for more details.

Ping failed Exception - Connection could not be allocated because: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Please check the server.log for more details.

I am not able to figure out this problem, can anyone help?

Upvotes: 1

Views: 3631

Answers (2)

AVA
AVA

Reputation: 2568

Cause could be that the user may not be having enough privileges on the db objects.
Grant the required privileges to the user, like:

###GRANT USAGE ON service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT USAGE ON SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON TABLES OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON TABLES IN SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON SEQUENCES OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON SEQUENCES IN SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON FUNCTIONS OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON FUNCTIONS IN SCHEMA "service_schema" TO "admin";"

Upvotes: 0

unwichtich
unwichtich

Reputation: 13857

You should use the Resource Type javax.sql.DataSource. I'm not sure if this is causing the error, you may also try to change the hostname to localhost.

Can you access the PostgreSQL DB via pgAdmin or psql commands?

Upvotes: 2

Related Questions