Static IP guide

Connecting to Postgres with a static IP from a Java app on Heroku

JDBC has an underused option for this: the Postgres driver honors the socksProxyHost and socksProxyPort system properties, so a Java service on Heroku can reach an allowlisted Postgres server through Fixie Socks without any tunnel process. Alternatively, Fixie-Wrench gives you a localhost port and the JDBC URL just points there.

RuntimeJava
PlatformHeroku
DestinationPostgres
Fixie productFixie Socks Heroku add-on

Recommended setup

Use Fixie Socks Heroku add-on for Postgres connections to a database that only accepts traffic from approved IP addresses. Store the proxy value in FIXIE_SOCKS_HOST, then configure Java to route outbound traffic through Fixie before connecting to Postgres.

Set up Fixie on Heroku

Heroku is a native Fixie marketplace flow. Install the Fixie Socks Heroku add-on or attach it from the Heroku CLI. Heroku will create FIXIE_SOCKS_HOST as a config var for the app.

Attach fixie-socks to your Heroku app

heroku addons:create fixie-socks
heroku config:get FIXIE_SOCKS_HOST

Implementation

The example below shows the core application-side change. Keep credentials in environment variables and avoid committing proxy, database, or API secrets.

Forward a local port to Postgres through Fixie Socks

# Install Fixie-Wrench in your app build or deploy process.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/usefixie/fixie-wrench/HEAD/install.sh)"

# Start a tunnel from localhost:5432 to postgres.example.com:5432.
# Your Java app connects to localhost:5432; Fixie handles the outbound static IP.
./bin/fixie-wrench 5432:postgres.example.com:5432

Good to know

  • For the system-property route, also register a java.net.Authenticator with the SOCKS credentials, as shown in the Java docs.
  • With the tunnel approach, the JDBC URL becomes jdbc:postgresql://localhost:5432/yourdb and connection pools like HikariCP need no special handling.

Allowlist and test the static IPs

  1. Open the Fixie dashboard and copy the outbound IP addresses for this proxy.
  2. Add both IPs to the Postgres firewall or security group.
  3. Deploy the updated Java app on Heroku.
  4. Run a small connection test before sending production traffic.

Related guides

Related docs