Re: Connecting Postgres using other network

From: Mohammad Tanvir Huda <shayer009(at)yahoo(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Connecting Postgres using other network
Date: 2004-08-12 01:45:14
Message-ID: 20040812014514.42134.qmail@web60304.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hello All
Thanks for your reply.
i want to use the port 6432 because some other instance of Postgresql is running on default port 5432,. And the psql command in this port works fine.

/scratch/huda/bin/psql -p 6432 test

If i want to allow any ip to get access to database what should i do.
is the following this legal

host template1 all 192.*.*.* 255.255.255.0 ident sameuser

Because when i hooked my PC to network it is assigned a dynamic IP .

thirdly, as mentioned in previous email where can i find the psql client tool.

Regards

Tanvir

"Bender, Cheryl" <cbender(at)mriresearch(dot)org> wrote:
A few things I would do;

1. As other replies have mentioned check the port. If you want to use 6432 I believe you have to put that in your conf file
2. You need another line in your pg_hba.conf that provides access to the network or specific IP and netmask of the computer you are connecting from. Lots of examples are found in the manual but I've put one below

# Allow any user from any host with IP address 192.168.93.x to connect

# to database "template1" as the same user name that ident reports for

# the connection (typically the Unix user name).

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD

host template1 all 192.168.93.0 255.255.255.0 ident sameuser

3. Verify you can connect locally with the settings (especially if you changed the port).
4. If local connection works but your code still doesn't work, then verify you can connect from the client if possible using something other than jdbc (psql client tool or odbc).
5. Check the log on the server.

Hope this helps some.
Cheryl

Cheryl Bender
-----Original Message-----
From: pgsql-admin-owner(at)postgresql(dot)org [mailto:pgsql-admin-owner(at)postgresql(dot)org] On Behalf Of Mohammad Tanvir Huda
Sent: Wednesday, August 11, 2004 2:40 PM
To: pgsql-admin(at)postgresql(dot)org
Subject: [ADMIN] Connecting Postgres using other network

Hello Everyone

I have installed Postgres server in a network and i am trying to use the database using
Java code from other network.

I have set the tcp_ip=true in postgresql.conf file.
I have also add the follwing line in the pg_hba.conf

host all all 127.0.0.0 255.255.255.255 trust

Then i start the server in port 6432.

After that i want to access the application using the following javacode.

import java.sql.*; // All we need for JDBC
import java.text.*;
import java.io.*;
public class HelloPost
{
Connection db; // A connection to the database
Statement sql; // Our statement to run queries with
DatabaseMetaData dbmd; // This is basically info the driver delivers
// about the DB it just connected to. I use
// it to get the DB version to confirm the
// connection in this example.
public HelloPost()
throws ClassNotFoundException, SQLException
{
String database = "test";
String username = "abc";
String password = "xyz";
try{
Class.forName("org.postgresql.Driver"); file://load the driver
db = DriverManager.getConnection("jdbc:postgresql://abc.csse.uts.edu:6432:test",
username,
password); file://connect to the db
dbmd = db.getMetaData(); file://get MetaData to confirm connection
System.out.println("Connection to "+dbmd.getDatabaseProductName()+" "+
dbmd.getDatabaseProductVersion()+" successful.\n");
sql = db.createStatement(); file://create a statement that we can use later
}catch (ClassNotFoundException e) {
System.err.println( "Driver not found: " + e + "\n" + e.getMessage() );
}
db.close();
}
public static void main (String args[])
{
try
{
HelloPost demo = new HelloPost();
}
catch (Exception ex)
{
System.out.println("***Exception:\n"+ex);
ex.printStackTrace();
}
}
}

But this give me the following error

Exception: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the post
accepting TCP/IP connections.
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Can anyone please tell me where is the error. what should i doo ..

regards

Shayer

---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!


---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Devi Munandar 2004-08-12 01:56:37 distibuted database for postgresql
Previous Message Bruno Wolff III 2004-08-11 23:28:59 Re: Minimal required to run psql on remote machine