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.