Обсуждение: JDBC connection refused
I have Postgresql set up on RedHat 6.1, and I can access it with jdbc or pgaccess locally, and with pgaccess from another linux box on the same local net. However, I can't get a connection with jdbc across the net. The relevant code is public static void main (String[] args) { try { Class.forName("postgresql.Driver"); Connection con = DriverManager.getConnection("jdbc:postgresql://birch/auction", "collins", ""); // Do something useful here Statement stmt = con.createStatement(); .... and the error message is Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking.at postgresql.Connection.openConnection(Connection.java, Compiled Code) at postgresql.Driver.connect(Driver.java, Compiled Code)at java.sql.DriverManager.getConnection(DriverManager.java, Compiled Code).... Here's what I've checked:- postmaster is indeed being run with the -i flag. I think neither the local jdbc or the remote pgaccess would work otherwise. Here's the line from rc.d/init.d/postgres: su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql'- I've used every name I canthink of, including the ip address, in the URL above. I've used the port and I've not used the port.- I've used netstat to check that postmaster is indeed listeningon 5432 I'm stumped. Thanks in advance for any assistance. John Collins University of Minnesota
John Collins wrote: > - postmaster is indeed being run with the -i flag. I think neither the > local jdbc or the remote pgaccess would work otherwise. Here's the line > from rc.d/init.d/postgres: > su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql' > - I've used every name I can think of, including the ip address, in the > URL above. I've used the port and I've not used the port. > - I've used netstat to check that postmaster is indeed listening on > 5432 > > I'm stumped. Thanks in advance for any assistance. Is there a line in PGDATA/pg_hba.conf allowing access to the remote client? PGDATA on the RPM installation that shipped with RedHat 6.1 is /var/lib/pgsql, BTW. -- Lamar Owen WGCR Internet Radio 1 Peter 4:11
Lamar Owen wrote: > John Collins wrote: > > - postmaster is indeed being run with the -i flag. I think neither the > > local jdbc or the remote pgaccess would work otherwise. Here's the line > > from rc.d/init.d/postgres: > > su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql' > > - I've used every name I can think of, including the ip address, in the > > URL above. I've used the port and I've not used the port. > > - I've used netstat to check that postmaster is indeed listening on > > 5432 > > > > I'm stumped. Thanks in advance for any assistance. > > Is there a line in PGDATA/pg_hba.conf allowing access to the remote > client? > > PGDATA on the RPM installation that shipped with RedHat 6.1 is > /var/lib/pgsql, BTW. Here's the tail end of the file /var/lib/pgsql/pg_hba.conf. I've restarted twice since setting this info, using /etc/rc.d/init.d/postgresql restart. Then I tried a stop and a start just for good measure. The machines I'm trying to connect from are both 192.168.2.x. Did I get this right? ------------------ # By default, allow anything over UNIX domain sockets and localhost. local all trust host all 127.0.0.1 255.255.255.255 trust host all 192.168.2.0 255.255.255.0 trust ------------------ Thanks for your help. John Collins University of Minnesota
Unsure if it will help, but try: > telnet localhost 5432 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. rubbish text I typed. ^^ EInvalid packet lengthConnection closed by foreign host. --- But instead try 'birch' or the IP address and see what you get. But the pg_hba file looks fine as you've got it I think. Maybe a red herring but check whether there's any firewalling set up on the server that stops you from connecting. Joe -----Original Message----- From: owner-pgsql-interfaces@postgreSQL.org [mailto:owner-pgsql-interfaces@postgreSQL.org]On Behalf Of John Collins Sent: Friday, 3 March 2000 9:41 AM To: pgsql-interfaces@postgreSQL.org Cc: Lamar Owen Subject: Re: [INTERFACES] JDBC connection refused Lamar Owen wrote: > John Collins wrote: > > - postmaster is indeed being run with the -i flag. I think neither the > > local jdbc or the remote pgaccess would work otherwise. Here's the line > > from rc.d/init.d/postgres: > > su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql' > > - I've used every name I can think of, including the ip address, in the > > URL above. I've used the port and I've not used the port. > > - I've used netstat to check that postmaster is indeed listening on > > 5432 > > > > I'm stumped. Thanks in advance for any assistance. > > Is there a line in PGDATA/pg_hba.conf allowing access to the remote > client? > > PGDATA on the RPM installation that shipped with RedHat 6.1 is > /var/lib/pgsql, BTW. Here's the tail end of the file /var/lib/pgsql/pg_hba.conf. I've restarted twice since setting this info, using /etc/rc.d/init.d/postgresql restart. Then I tried a stop and a start just for good measure. The machines I'm trying to connect from are both 192.168.2.x. Did I get this right? ------------------ # By default, allow anything over UNIX domain sockets and localhost. local all trust host all 127.0.0.1 255.255.255.255 trust host all 192.168.2.0 255.255.255.0 trust ------------------ Thanks for your help. John Collins University of Minnesota ************
I tried your suggestion, and I can connect to localhost at port 5432 as you show below, and I can log in to the other machine and telnet to birch, port 5432, over the network. In both cases it connects, and then disconnects as soon as I type something and send it; I don't get an error message as you show below, just the Connection closed by foreign host message. So, I tried my simple jdbc example, and I'm still getting the Connection refused error. Just for grins, I went back to birch and tried running the same code, in which the URL looks like "jdbc:postgresql://birch/coffeebreak". That works, even with the hostname rather than "localhost". I can't imagine there's anything out of the ordinary with these two machines. They're both vanilla RedHat systems, plugged into the same ethernet hub, static addresses, etc. It seemed like a good idea. Thanks. I'm still stumped. John Collins University of Minnesota Joe Shevland wrote: > Unsure if it will help, but try: > > > telnet localhost 5432 > Trying 127.0.0.1... > Connected to localhost. > Escape character is '^]'. > > rubbish text I typed. > ^^ > > EInvalid packet lengthConnection closed by foreign host. > --- > > But instead try 'birch' or the IP address and see what > you get. But the pg_hba file looks fine as you've got it > I think. Maybe a red herring but check whether there's any > firewalling set up on the server that stops you from connecting. > > Joe > > -----Original Message----- > From: owner-pgsql-interfaces@postgreSQL.org > [mailto:owner-pgsql-interfaces@postgreSQL.org]On Behalf Of John Collins > Sent: Friday, 3 March 2000 9:41 AM > To: pgsql-interfaces@postgreSQL.org > Cc: Lamar Owen > Subject: Re: [INTERFACES] JDBC connection refused > > Lamar Owen wrote: > > > John Collins wrote: > > > - postmaster is indeed being run with the -i flag. I think neither the > > > local jdbc or the remote pgaccess would work otherwise. Here's the line > > > from rc.d/init.d/postgres: > > > su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql' > > > - I've used every name I can think of, including the ip address, in the > > > URL above. I've used the port and I've not used the port. > > > - I've used netstat to check that postmaster is indeed listening on > > > 5432 > > > > > > I'm stumped. Thanks in advance for any assistance. > > > > Is there a line in PGDATA/pg_hba.conf allowing access to the remote > > client? > > > > PGDATA on the RPM installation that shipped with RedHat 6.1 is > > /var/lib/pgsql, BTW. > > Here's the tail end of the file /var/lib/pgsql/pg_hba.conf. I've restarted > twice since setting this info, using /etc/rc.d/init.d/postgresql restart. > Then I tried a stop and a start just for good measure. The machines I'm > trying to connect from are both 192.168.2.x. Did I get this right? > > ------------------ > # By default, allow anything over UNIX domain sockets and localhost. > > local all trust > host all 127.0.0.1 255.255.255.255 trust > host all 192.168.2.0 255.255.255.0 trust > ------------------ > > Thanks for your help. > > John Collins > University of Minnesota > > ************
On Fri, 03 Mar 2000, John Collins wrote: > 5432, over the network. In both cases it connects, and then disconnects as > soon as I type something and send it; I don't get an error message as you show > below, just the Connection closed by foreign host message. So, I tried my > simple jdbc example, and I'm still getting the Connection refused error. Just Can you use psql from the client machine? psql -h server-name database ? Can the two machines communicate otherwise -- ping, telnet, etc? Are you using the same version of the JDBC client as you are of the server? (I know, obvious, and I'm not trying to insult your intelligence, just trying to cover all the bases) -- Lamar Owen WGCR Internet Radio 1 Peter 4:11
Lamar Owen wrote: > On Fri, 03 Mar 2000, John Collins wrote: > > 5432, over the network. In both cases it connects, and then disconnects as > > soon as I type something and send it; I don't get an error message as you show > > below, just the Connection closed by foreign host message. So, I tried my > > simple jdbc example, and I'm still getting the Connection refused error. Just > > Can you use psql from the client machine? psql -h server-name database ? Yes. Works fine from both machines, results seem identical. > > > Can the two machines communicate otherwise -- ping, telnet, etc? Yes. I don't get up from my chair to run from the other machine, I just rsh to it. > > > Are you using the same version of the JDBC client as you are of the server? (I > know, obvious, and I'm not trying to insult your intelligence, just trying to > cover all the bases) I'm actually running exactly the same code for the jdbc stuff. From both machines I'm running from the same nfs-mounted volume. For psql, pgaccess, and jdbc, I'm using the package that comes on the RedHat 6.1 CDROM. I'm using the same version of Java on both machines, the new Sun-released version of the Blackdown jdk1.2.2. I only have the one CDROM. The only difference between the two - that I'm aware of - is that birch is the only machine that has the postgresql server installed (and running). The rest of postgresql is installed on both machines. Thanks for the ideas. John Collins