title: connection refused in centOS with postgresql
body: <p>I know that many people ask this question but I try many path solution but any one was correct.</p>
  
  <p>So, I have problem with connect to my postgresql server(on CentOS 6.4 minimal version - I have there only postgresql server, ftp and ssh service) from remote client(in LAN). I have ssh connection so I think that problem can by with permission tcp/ip.
  Java throw exception:</p>
  
  <pre><code>    org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:207)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:136)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:29)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:21)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:31)
      at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24)
      at org.postgresql.Driver.makeConnection(Driver.java:393)
      at org.postgresql.Driver.connect(Driver.java:267)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at Main.main(Main.java:19)
  Caused by: java.net.ConnectException: Connection timed out: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:60)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:101)
      ... 11 more
  </code></pre>
  
  <p>ifconfig:</p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr 08:00:27:F0:3A:F4
        inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
        inet6 addr: fe80::a00:27ff:fef0:3af4/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:2677 errors:0 dropped:0 overruns:0 frame:0
        TX packets:1437 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:251266 (245.3 KiB)  TX bytes:214910 (209.8 KiB)
  </code></pre>
  
  <p>/var/lib/pgsql/9.2/data/pg_hba.conf - only main part of file</p>
  
  <pre><code> # "local" is for Unix domain socket connections only
  local   all             all                                     peer
  # IPv4 local connections:
  host    all             all             127.0.0.1/32            ident
  host    all             all             192.168.1.18 255.255.255.0      password
  #hostssl all            all             192.168.1.18 255.255.255.0      trust
  #hostnossl      all     all             192.168.1.18 255.255.255.0      trust
  # IPv6 local connections:
  host    all             all             ::1/128                 ident
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  #local   replication     postgres                                peer
  #host    replication     postgres        127.0.0.1/32            ident
  #host    replication     postgres        ::1/128                 ident
  
  host all all 192.168.1.18 255.255.255.255 password
  host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff password
  </code></pre>
  
  <p>var/lib/pgsql/9.2/data/poistgresql.conf - only main part</p>
  
  <pre><code># - Connection Settings -
  
  listen_addresses = '*'
  #'localhost,192.168.1.18'
                                          # what IP address(es) to listen on;
                                          # comma-separated list of addresses;
                                          # defaults to 'localhost'; use '*' for all
                                          # (change requires restart)
  #port = 5432                            # (change requires restart)
  max_connections = 100                   # (change requires restart)
  # Note:  Increasing max_connections costs ~400 bytes of shared memory per
  # connection slot, plus lock space (see max_locks_per_transaction).
  #superuser_reserved_connections = 3     # (change requires restart)
  #unix_socket_directory = ''             # (change requires restart)
  #unix_socket_group = ''                 # (change requires restart)
  #unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                          # (change requires restart)
  #bonjour = off                          # advertise server via Bonjour
                                          # (change requires restart)
  </code></pre>
  
  <p>and last debug info is comment netstat -ta</p>
  
  <pre><code>Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address               Foreign Address             State
  tcp        0      0 *:ssh                       *:*                         LISTEN
  tcp        0      0 *:postgres                  *:*                         LISTEN
  tcp        0      0 localhost:smtp              *:*                         LISTEN
  tcp        0     52 PC2.home:ssh                Michal-laptop.home:26146    ESTABLISHED
  tcp        0      0 PC2.home:ssh                Michal-laptop.home:25917    ESTABLISHED
  tcp        0      0 *:ssh                       *:*                         LISTEN
  tcp        0      0 *:postgres                  *:*                         LISTEN
  tcp        0      0 localhost:smtp              *:*                         LISTEN
  </code></pre>
  
  <p>Can you help my? what I should do to allow connection?
  Thank you for your time.</p>