title: postgresql not accepting tcp/ip on port 5432 for rails on linux
body: <p>I've tried installing psql on linux but ran into some issues. I downloaded from yaourt and the psql command is running without any issues. It all seems to work fine until I try to run <code>rails db:setup</code>, at which point I'm thrown the error:</p>
  
  <pre><code>could not connect to server: Connection timed out
      Is the server running on host "localhost" (92.242.132.16) and accepting
      TCP/IP connections on port 5432?
  Couldn't create database for {"adapter"=&gt;"postgresql", "encoding"=&gt;"unicode", "pool"=&gt;5, "username"=&gt;"revisionhubadmin", "password"=&gt;"password", "host"=&gt;"localhost", "database"=&gt;"revisionHub_development"}
  rails aborted!
  PG::ConnectionBad: could not connect to server: Connection timed out
      Is the server running on host "localhost" (92.242.132.16) and accepting
      TCP/IP connections on port 5432?
  Traceback (most recent call last):
  bin/rails: undefined method `reject' for nil:NilClass (NoMethodError)
  </code></pre>
  
  <p>This is despite the <code>psql</code> command running okay and the following response from <code>systemctl status postgresql.service</code></p>
  
  <pre><code>● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2018-02-13 16:05:40 GMT; 2h 31min ago
    Process: 1961 ExecStop=/usr/bin/pg_ctl -s -D ${PGROOT}/data stop -m fast (code=exited, status=1/FAILURE)
    Process: 2084 ExecStart=/usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120 (code=exited, status=0/SUCCESS)
    Process: 2082 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=0/SUCCESS)
   Main PID: 2086 (postgres)
      Tasks: 5 (limit: 4915)
     CGroup: /system.slice/postgresql.service
             ├─2086 /usr/bin/postgres -D /var/lib/postgres/data
             ├─2088 postgres: checkpointer process   
             ├─2089 postgres: writer process   
             ├─2090 postgres: wal writer process   
             └─2091 postgres: bgworker: logical replication launcher   
  
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.524 GMT [2086] LOG:  listening on IPv4 address "0.0.0.0", port 5432
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.524 GMT [2086] LOG:  listening on IPv6 address "::", port 5432
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.526 GMT [2086] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.554 GMT [2086] LOG:  could not bind socket for statistics collector: Cannot assign requested address
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.554 GMT [2086] LOG:  disabling statistics collector for lack of working socket
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.554 GMT [2086] WARNING:  autovacuum not started because of misconfiguration
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.554 GMT [2086] HINT:  Enable the "track_counts" option.
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.556 GMT [2087] LOG:  database system was shut down at 2018-02-13 16:05:17 GMT
  Feb 13 16:05:40 bens-xps postgres[2084]: 2018-02-13 16:05:40.561 GMT [2086] LOG:  database system is ready to accept connections
  Feb 13 16:05:40 bens-xps systemd[1]: Started PostgreSQL database server.
  </code></pre>
  
  <p>I've already tried changing my pg_hba.config to</p>
  
  <pre><code># TYPE  DATABASE        USER            ADDRESS                 METHOD
  
  # "local" is for Unix domain socket connections only
  local   all             all                                     trust
  # IPv4 local connections:
  host    all             all             0.0.0.0/0            trust
  # IPv6 local connections:
  host    all             all             ::0/0                 trust
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  local   replication     all                                     trust
  host    replication     all             127.0.0.1/32            trust
  host    replication     all             ::1/128                 trust
  </code></pre>
  
  <p>and changed local addresses to * with <code>listen_addresses = '*'</code> and uncommenting <code>port = 5432</code> in postgresql.conf.</p>
  
  <p>These files were from <code>/var/lib/postgres/data</code>, which I thought was odd because <code>which psql</code> returns <code>/usr/bin/psql</code> but systemctl confirms that I edited the right ones because the logs mention <code>0.0.0.0/0</code></p>
  
  <p>I downloaded postgres with yaourt on antergos, which is an arch based linux distro. PG is added to my gemfile on version 0.18.4 and postgres is installed as version 10.1.</p>
  
  <p>My heroku server which runs the app I'm trying to run db:setup on in production works fine without any issues and the app has also been fine running on a previous install of linux (Ubuntu) on the same laptop and on a mac, suggesting that the issue probably isn't with this specific rails app. Regardless, here's the default and dev part of my database.yml file:</p>
  
  <pre><code>default: &amp;default
    adapter: postgresql
    encoding: unicode
    pool: 5
    username: revisionhubadmin
    password: **********
    host: localhost
  
  development:
    &lt;&lt;: *default
    database: revisionHub_development
  </code></pre>
  
  <p>And yes, I have made a revisionhubadmin psql account. Running \du in psql gives:</p>
  
  <pre><code>ben              | Superuser, Create DB
  
  postgres         | Superuser, Create role, Create DB, Replication, Bypass RLS
  
  revisionhubadmin | Superuser, Create DB
  </code></pre>
  
  <p>So yeah, I'm a little bit confused. Does anyone know how to fix this?</p>