title: How do I make Rails use SSL to connect to PostgreSQL?
body: <p>When I try to connect to the remote PostgreSQL database with a Rails 3.2 project I get this error:</p>
  
  <pre><code>FATAL:  no pg_hba.conf entry for host "10.0.0.3", user "projectx", database "projectx", SSL off
  </code></pre>
  
  <p>My configuration on Rails looks like this:</p>
  
  <pre><code>staging:
    adapter: postgresql
    database: projectx
    username: projectx
    password: 123456
    host: 10.0.0.3
    encoding: utf8
    template: template0
    min_messages: warning
  </code></pre>
  
  <p>and on PostgreSQL looks like this:</p>
  
  <pre><code>hostssl    all             all             0.0.0.0/0            md5
  hostssl    all             all             ::/0                 md5
  </code></pre>
  
  <p>Both machines are running on an Ubuntu 12.04.</p>
  
  <p>I found posts saying that it should work automatically, which clearly doesn't happen. I found some saying that libpq didn't have SSL enabled and enabling it solved the problem, but no explanation on how to enable it. I can see when I look at the dependencies of libpq that it depends on the some SSL packages, so I would assume SSL support is compiled.</p>
  
  <p>Some posts recommended adding this:</p>
  
  <pre><code>sslmode: require
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>sslmode: enabled
  </code></pre>
  
  <p>to enable ssl mode, but it had no effect for me. I read that it's silently ignored.</p>
  
  <p>I also tried the database string approach, ending up with:</p>
  
  <pre><code>staging:
    adapter: postgresql
    database: "host=10.0.0.3 dbname=projectx user=projectx password=123456 sslmode=require"
  </code></pre>
  
  <p>and then I got the error:</p>
  
  <pre><code>could not connect to server: No such file or directory
  Is the server running locally and accepting
  connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  </code></pre>
  
  <p>which seems to indicate that Rails was trying to connect to localhost or rather, the local PostgreSQL (there's none) instead of 10.0.0.3.</p>
  
  <p>Any ideas?</p>