aspose file tools*
The moose likes Tomcat and the fly likes Postgresql connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Postgresql connection problem" Watch "Postgresql connection problem" New topic
Author

Postgresql connection problem

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510


i installed Postgresql in a ssh Linux server with default settings. i have a web application that i use postgresql as db backend accessing postgresql with (localhost:5432 defaults of Ubuntu ). i run my web app remotely using the ssh host of server <ssh-host>/webapp however it seems the Postgresql from web app can't be established. i edited both postgresql.conf ( listen-addresses='*') pg_hba.conf ( host all all 127.0.0.1/32 trust) i setup an apache2 sever proxy and use the following file : /etc/apache2/sites-available/jbilling


but when i run the web app i get this error:

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /billing/

how can i enable connections to postgresql at host localhost and port 5432?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

PostgreSQL doesn't care whether or not you're fronting Tomcat with some other server such as Tomcat.

And if you're trying to proxy PostgreSQL itself via Apache httpd that won't work either. PostgreSQL client/server communications are done in a proprietary protocol, and Apache only understands web protocols such as http and https.

In the common architecture, you'd use Apache as your public front-end, have Apache pipe requests to a Tomcat server via mod_proxy or mod_jk, and Tomcat would communicate to the backend PostgreSQL server via JDBC connections obtained from a configured Tomcat connection pool.

In that scenario, you'd set up access to your PostgreSQL database(s) by providing an entry in the pg_hba.conf file that permitted the Tomcat server process to connect and use the database. No other users, servers, or other players would be involved.


Customer surveys are for companies who didn't pay proper attention to begin with.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Tim Holloway wrote:

In that scenario, you'd set up access to your PostgreSQL database(s) by providing an entry in the pg_hba.conf file that permitted the Tomcat server process to connect and use the database. No other users, servers, or other players would be involved.

what the entry in pg_hba.conf file should look like?

thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Yahya Elyasse wrote:
Tim Holloway wrote:

In that scenario, you'd set up access to your PostgreSQL database(s) by providing an entry in the pg_hba.conf file that permitted the Tomcat server process to connect and use the database. No other users, servers, or other players would be involved.

what the entry in pg_hba.conf file should look like?

thanks


That depends a lot on you, since there are several different ways to authenticate clients to PostgreSQL. Most often you'd add a line that indicates the database for which access is authorized and the IP address(es) from which requests are allowed. After that, you'd either provide the directives to authorize using either an OS user ID (the Tomcat process userid), or a PostgreSQL-defined userid/password. Or, you can just tell it to trust you, which is good for testing the basic config, but not recommended for production.

For specifics on how to code authorization definitions I'll have to refer you to the PostgreSQL documentation. Tomcat, however, is no different in the eyes of PostgreSQL than any other program.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Tim Holloway wrote:
Yahya Elyasse wrote:
Tim Holloway wrote:

In that scenario, you'd set up access to your PostgreSQL database(s) by providing an entry in the pg_hba.conf file that permitted the Tomcat server process to connect and use the database. No other users, servers, or other players would be involved.

what the entry in pg_hba.conf file should look like?

thanks


That depends a lot on you, since there are several different ways to authenticate clients to PostgreSQL. Most often you'd add a line that indicates the database for which access is authorized and the IP address(es) from which requests are allowed. After that, you'd either provide the directives to authorize using either an OS user ID (the Tomcat process userid), or a PostgreSQL-defined userid/password. Or, you can just tell it to trust you, which is good for testing the basic config, but not recommended for production.

For specifics on how to code authorization definitions I'll have to refer you to the PostgreSQL documentation. Tomcat, however, is no different in the eyes of PostgreSQL than any other program.

I think i have done that but still doesn't work. i'll show you my pg_hba.conf file. i don't know why it won't allow connection . can you point some mistakes in the below pg_hba.con file?


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Without actually RTFM'ing, I can't see anything wrong with pg_hba.conf there.

But make sure that you actually have a network channel. You need to make sure that the Postmaster was started with the ability to accept connections from other machines AND you need to make sure that the PostgreSQL server has appropriate firewall permissions (allow connections for IP protocol with destination port 5432).

The Postmaster option is the one most likely to bite people, since it's disabled by default on most distros (do a "netstat -ln | grep 5432"). I haven't checked Ubuntu lately, but Red Hat has a config file to store that setting so that the installed startup script doesn't need to be modified to enable that feature.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thank you. i managed to get it work by adding a line to pg_hba.conf to point to the virtual Ubuntu server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Postgresql connection problem
 
Similar Threads
Filter Not Found in new deployment
secure web based mail
Resin with Apache
Tomcat 7 digest authentication problem
connecting Apache and Mongrel