Private IPs for DigitalOcean PostgreSQL

DigitalOcean Postgres Private IPs

DigitalOcean Postgres customers can save some money on bandwith. Database Labs' Postgres as a Service now comes with private IP addresses enabled. DigitalOcean apps in the same region can connect to the private IP to avoid bandwidth charges for their database usage.

DigitalOcean Private IPs

DigitalOcean nodes come with a public IP address by default. You are allocated a certain amount of public IP bandwidth every month, and charged for overages.

You can also enable an optional private IP address that is only accessible from other DigitalOcean hosts in the same region. Traffic over the private IP address is free and unmetered.

Database traffic is often between an app server and a database in the same DigitalOcean region. In this case, it makes sense to use the private IP address instead of the public IP, as you can use as much bandwidth as you like for free.

Your Postgres's IP in DigitalOcean

All of our DigitalOcean databases come with private IPs enabled by default. The public IP hostname is formatted like foo-bar-123.db.databaselabs.io. To get the private IP, replace the .db. with .lan. in the hostname. In this example, you can reach foo-bar-123's private IP by pointing your app at foo-bar-123.lan.databaselabs.io.

Bear in mind that the private IP hostname will only work from machines in the same DigitalOcean region as your database.

Adding a private IP to an existing DigitalOcean node

Our databases always come with DigitalOcean private IPs enabled. Your app server also has to have its Private IP enabled for them to communicate over the private network.

If you enabled the private IP feature at the time you built your DigitalOcean app server node, it will come with the private network interface already configured.

If you add the private IP feature to an existing node in the DigitalOcean management console, you will also have to configure the operating system to know about the new IP address.

On Linux, for example, add the following to /etc/network/interfaces, substituting in your actual private IP addres:

auto eth1
iface eth1 inet static
        address 10.x.x.x
        netmask 255.255.0.0
September 28, 2015