Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007

    Question Unanswered: Accessing PostgreSQL connection refused.


    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) "".
    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:

    host all postgres md5
    host samegroup all md5
    local all postgres md5
    local samegroup all md5
    However, the postgresql 8.2.5 has the following format:
    # local
    local all postgres trust
    local samegroup all trust
    # IPv4 local connections:
    host all postgres trust
    host samegroup all 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:

    # - 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.

  2. #2
    Join Date
    May 2005
    San Antonio, Texas
    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

  3. #3
    Join Date
    Nov 2006
    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 '*'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts