title: Painfully slow connection speed from local machine to AWS RDS PostgreSQL database
body: <p>I've looked everywhere for an answer to this problem. I found a <a href="https://stackoverflow.com/questions/33141467/aws-rds-painfully-slow-when-connecting-from-local-machine">similar (unanswered) question</a> on SO but not related to Java or SSL issues.</p>
  
  <p>Important Information:</p>
  
  <ul>
  <li>The database I connect to is PostgreSQL on RDS.</li>
  <li>I can actually connect to the DB (it takes about 3 minutes to establish the connection). After the connection is established, simple queries take between 15-120 seconds.</li>
  <li>The problem only happens when connecting from my code. </li>
  <li>Connecting from Postico (on the same machine) works perfectly.</li>
  <li>Deploying to AWS EC2 the exact same connection works perfectly.</li>
  <li>I have added the RDS certificates to the keystore. </li>
  <li>The RDS force_ssl parameter is set to true.</li>
  <li>Notice the  <code>+ "?ssl=true"</code> parameter at the end of the connection string.</li>
  <li>Tested replacing the domain by the direct IP (to rule out DNS problems). Same thing.</li>
  </ul>
  
  <p>I suspect it has something to do with SSL but can't confirm it. </p>
  
  <p>This is my connection (pretty standard):</p>
  
  <pre><code>    String dbUriString = ConfigUtils.getEnv("DATABASE_URL");
  
      URI dbUri = new URI(dbUriString);
  
      String username = dbUri.getUserInfo().split(":")[0];
      String password = dbUri.getUserInfo().split(":")[1];
      String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true";
  
      ComboPooledDataSource datasource = new ComboPooledDataSource();
  
      datasource.setUser(username);
      datasource.setPassword(password);
      datasource.setJdbcUrl(dbUrl);
      datasource.setDriverClass("org.postgresql.Driver");
  
      datasource.setMaxPoolSize(20);
      datasource.setMinPoolSize(5);
      datasource.setAcquireIncrement(1);
      datasource.setAcquireRetryAttempts(3);
      datasource.setInitialPoolSize(5);
      datasource.setTestConnectionOnCheckout(true);
  
      return datasource;
  </code></pre>
  
  <p>A little more information: </p>
  
  <ul>
  <li>It's a Play Framework application. </li>
  <li>Java 8.</li>
  <li>DataSource connector c3p0.</li>
  </ul>
  
  <p>Any help is deeply appreciated.</p>