Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > Accessing PostgreSQL connection refused.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-07, 14:07
illbemissingu illbemissingu is offline
Registered User
 
Join Date: Nov 2007
Posts: 1
Question Accessing PostgreSQL connection refused.

Hi,

I am trying to access PostgreSQL 8.2.5 work using a simple java code on my MacBook. It's my first time using postgresql.

What I had been following is Apple Developer Center's (ADC) "developer.apple.com/internet/opensource/postgres.html".
Java compiled fine, but when I execute the file by typing:
java PgTest test <usrname> <password>
I got the error saying:
"org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."

So I'm thinking there might be something wrong with the pg_hba.conf file I modified. The reason is that on ADC's page, the postgresql is an older version 7.4.1, so the pg_hba.conf file suggested this format:
-----------
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD

host all postgres 127.0.0.1 255.255.255.255 md5
host samegroup all 127.0.0.1 255.255.255.255 md5
local all postgres md5
local samegroup all md5
----------
However, the postgresql 8.2.5 has the following format:
----------
# TYPE DATABASE USER CIDR-MASK METHOD
# local
local all postgres trust
local samegroup all trust
# IPv4 local connections:
host all postgres 127.0.0.1/32 trust
host samegroup all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
=====
I changed the method back to trust for now after several attempts to make the java code work with postgesql..

The other change I made was simply adding:
-------
tcpip_socket = true
-------
to /usr/local/pgsql/data/postgresql.conf file.

HOWEVER, it was suspecious that this line :
---
#tcpip_socket = false
------
did not exist in the original version, as it is said on ADC's page.
I'm not sure if it's the version issue again, but, I added it in the connection section of the file.
Mine now looks like this:
--------------------
#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------

# - Connection Settings -

tcpip_socket = true ####I ADDED THIS LINE###
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
#port = 5432 # (change requires restart)
max_connections = 30 # (change requires restart)
# Note: increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction). You
# might also need to raise shared_buffers to support more connections.
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = '' # (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # octal
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
----------------


I really don't know why is it not working. The other thing that might caused this is: I created .tcsh file under home directory of "postgres", the new user I created for db, as ADC suggested with the following content:
------
setenv PGDATA /usr/local/pgsql/data
setenv PATH ${PATH}:/usr/local/pgsql/bin
------

However, it seemed not work if I tried to type the postgresql commands directly.

Could anyone give me some help?
Thanks a lot.
Reply With Quote
  #2 (permalink)  
Old 11-26-07, 13:25
amthomas amthomas is offline
Registered User
 
Join Date: May 2005
Location: San Antonio, Texas
Posts: 134
I am not familiar with 7.4 but I will try to look into this more later.

first some simple things that you probably already did..

Did you actually reload/restart the server after you made the config and hba changes?

try connecting remotely using psql using the network settings and not the java application. you should be able to connect using '-h localhost' or '-h <ip address>' and get it to connect if it is configured correctly.
__________________
Vi veri veniversum vivus vici
By the power of truth, I, a living man, have conquered the universe
Reply With Quote
  #3 (permalink)  
Old 11-27-07, 13:17
rski rski is offline
Registered User
 
Join Date: Nov 2006
Posts: 12
The error you receive is not pg_hba error in my opinion, it looks like postres is not listening for network connections.
In postgres 8.2.X there is no option tcpip_socket, use option listen_addresses, uncomment it and set to '*'.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On