The line in your netstat report shows that the database is only listening on localhost:5432 (127.0.0.1) for incoming tcp connections.
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 3561/postgres
So it can only accept local tcp connections regardless of what permissions you've specified in pg_hba.conf. pg_hba.conf only specifies allowed connections, but does not specify what interfaces your service will listen to.
The addresses the server listens on is specified with the listen_addresses GUC in postgresql.conf. If you want the server to listen for remote connections you should specify the ip(s) you want it to listen on or *
to listen on all available interfaces on the host.
To have your postgresql server listen on all interfaces on the host, you should have the following line in postgresql.conf:
listen_addresses = '*'
This is probably not the best way to do what you want to do. The "proper" way would probably be to execute the SQL commands in your file via jdbc.
That said, that's a long way from where you are now, and we can probably make what you are trying to do work.
The likely problem is that there is a space in the path to psql.exe.
When you use that particular format of exec, java uses a vanilla string tokenizer to split your string into an array, each entry being separated by a space. So it's going to be trying to execute a command "c:/Program
" and pass it parameters, the first of which is "Files/PostgreSQL/9.2/bin/psql.exe
" and, um, that isn't going to go so well.
Use exec (String[])
instead:
http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
This method doesn't apply the tokenizer, because it's accepting an array, so it doesn't think it needs to.
Try this:
String path = "H:/Data/samplescript_postgres.sql";
final String [] cmd = { "C:/Program Files/PostgreSQL/9.2/bin/psql.exe",
"-U", "postgres",
"-d", "sampledb",
"-f", path
};
try {
reloadProcess = Runtime.getRuntime().exec(cmd);
if(null!=reloadProcess){
if(reloadProcess.waitFor()==0){
System.out.println("Reloaded");
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
You can see that I've created the array manually. For readability, I've put the option "-U"
and the value "postgres"
on the same line, but they're separated by a comma.
Best Answer
I can connect to my postgres instance from pgAdmin III without a password for any user including superusers such as
postgres
.Because you are connecting ok from another client, there is no reason you should not be able to connect from pgAdmin if they are on the same workstation - unless some firewall rule on the client itself is allowing one program but not another.
If the problem is specific to this client, you may need to change one or more of:
But I recommend you don't do any of this. The manual says the following with good reason:
Instead, consider either: