title: Postgres connection refused from Openshift Tomcat 7 cartridge
body: <p>I'm trying to deploy an app on an Openshift Tomcat 7 (JBoss EWS 2.0) cartridge, but I'm getting:</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.
  </code></pre>
  
  <p>Here's my datasource config:</p>
  
  <pre><code>public class OpenshiftDataConfig {
      @Inject private Environment environment;
      @Bean
      public DataSource dataSource() {
          HikariDataSource dataSource = new HikariDataSource();
          dataSource.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
          dataSource.setJdbcUrl(String.format("jdbc:%s/%s",
                  environment.getProperty("OPENSHIFT_POSTGRESQL_DB_URL"), 
                  "dev"));
          dataSource.setUsername(environment.getProperty("OPENSHIFT_POSTGRESQL_DB_USERNAME"));
          dataSource.setPassword(environment.getProperty("OPENSHIFT_POSTGRESQL_DB_PASSWORD"));
          return dataSource;
      }
  }
  </code></pre>
  
  <p>I'm logging the JDBC URL during testing, and I've tried it with username/password embedded:</p>
  
  <pre><code>jdbc:postgresql://&lt;value of OPENSHIFT_POSTGRESQL_DB_USERNAME&gt;:&lt;value of OPENSHIFT_POSTGRESQL_DB_PASSWORD&gt;@&lt;value of OPENSHIFT_POSTGRESQL_DB_HOST&gt;:&lt;value of OPENSHIFT_POSTGRESQL_DB_PORT&gt;/dev
  </code></pre>
  
  <p>and without (built with slightly different code):</p>
  
  <pre><code>jdbc:postgresql://&lt;value of OPENSHIFT_POSTGRESQL_DB_HOST&gt;:&lt;value of OPENSHIFT_POSTGRESQL_DB_PORT&gt;/dev
  </code></pre>
  
  <p>I've tested connectivity using psql while logged into the app:</p>
  
  <pre><code>psql -h $OPENSHIFT_POSTGRESQL_DB_HOST -p $OPENSHIFT_POSTGRESQL_DB_PORT -U $OPENSHIFT_POSTGRESQL_DB_USERNAME
  </code></pre>
  
  <p>And I can see my data is there. I've also verified that the admin user is a login role. The pg_hba.conf file should allow the connection:</p>
  
  <pre><code># Allow all users to connect over the network with valid credentials
  host    all         all           0.0.0.0/0             md5
  host    all         all           ::/0                  md5
  </code></pre>
  
  <p>This seems like an issue with Openshift's firewall configuration between the two cartridges, so I'm contacting their official support as well.</p>