# Cannot connect to a Digital Ocean hosted database after deploying

**URL:** <https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904>\
**Category:** Questions / Help\
**Created:** [October 22, 2021, 3:47am UTC](https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904 "2021-10-22T03:47:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uncvrd](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/uncvrd/32/18514_2.png) [@uncvrd](https://community.fly.io/u/uncvrd)\
**Post date:** [October 22, 2021, 3:47am UTC](https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904/1 "2021-10-22T03:47:29Z")

</div>

Hi! I’ve just deployed a NodeJS application using [Fly.io](http://Fly.io). However my Digital Ocean database requires that I add the IP of the app as a “trusted source” in order to connect to it properly. I tried adding the IPv4 address that’s displayed in my dashboard with no luck. Is there a specific IP I should be adding instead?

This is similar to this question, except they disabled trusted sources and I don’t set socket\_options 🤔

> [@Can't connect to a database hosted on DigitalOcean from Phoenix](https://community.fly.io/t/cant-connect-to-a-database-hosted-on-digitalocean-from-phoenix/1245):
>
> Hey, I am trying to get my Phoenix app running on [fly.io](http://fly.io)! But it seems like I can’t connect to the database hosted on DigitalOcean (DbaaS). I set the environment variable DATABASE\_URL to the one I copy from DigitalOcean and it seems like [fly.io](http://fly.io) servers can’t resolve the DNS entry for it? This is what I get in the logs: [error] Postgrex.Protocol (#PID\<0.3781.0\>) failed to connect: \*\* (DBConnection.ConnectionError) tcp connect (xxxxxxxxxx.db.ondigitalocean.com:25060): non-existing domain - :nx…

For reference, this is from the fly error logs:

```auto
UnhandledPromiseRejectionWarning: Error: {"is_panic":false,"message":"Can't reach database server at `xxxx-3203921-0.b.db.ondigitalocean.com`:`25060`\n\nPlease make sure your database server is running at `xxxx-3203921-0.b.db.ondigitalocean.com`:`25060`.","meta":{"database_host":"xxxx-3203921-0.b.db.ondigitalocean.com","database_port":25060},"error_code":"P1001"}
2021-10-22T02:42:27.185 app[dc16e717] lax [info] (Use `node --trace-warnings ...` to show where the warning was created)

```

Any insight would be really helpful, thank you!

EDIT: Ok I bit the bullet and removed the requirement to connect from a trusted IP source…and it connected just fine. Clearly it’s an IP issue. So my question now is, what IP should my database be allowing connections from if not the IPv4 that’s listed in my Fly dashboard 🤯

```auto
# fly.toml file generated for graphql-staging on 2021-10-21T18:39:37-07:00

app = "graphql-staging"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 4001
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

```

---

<div class="post-metadata">

**Author:** ![greg](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/greg/32/2119_2.png) [@greg](https://community.fly.io/u/greg)\
**Post date:** [October 22, 2021, 1:36pm UTC](https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904/2 "2021-10-22T13:36:47Z")

</div>

Yes, you’re right it’s the IP that’s the issue.

Unfortunately the IP that Fly shows you is the one for _incoming_ requests to the app. They don’t reveal the outgoing IP. Which is what you need when using an external database that needs an IP.

Fly can provide an IP range for a particular region _but_ those IPs are subject to change. So that is half-way there but not ideal. I’m not aware of a solution to getting a fixed IP.

See e.g

> [@Allow traffic only from whitelisted IP addresses](https://community.fly.io/t/allow-traffic-only-from-whitelisted-ip-addresses/2782):
>
> Is there a way to allow traffic only from whitelisted IP addresses for an app? For example, in AWS we can use security groups to block all traffic except from a certain IP range (e.g. allow traffic only from Cloudflare IPs). This prevents a ton of traffic from bots.

> [@Best way to allow access to my app to only certain IPs](https://community.fly.io/t/best-way-to-allow-access-to-my-app-to-only-certain-ips/1137):
>
> Hello, I have been looking into running a UDP syslog server but would like to limit access to it to only certain IPs, naturally. Is there a best approach to doing this on fly? Since fly does not have the equivalent of an AWS security group (at the platform level) would it mean installing something like iptables in my Dockerfile? I have read bits about it which apparently gets complicated when running inside docker with the host having its own rules. For people that have IP-limited access bef…

---

<div class="post-metadata">

**Author:** ![loldedmded](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/loldedmded/32/37241_2.png) [@loldedmded](https://community.fly.io/u/loldedmded)\
**Post date:** [January 4, 2023, 1:08pm UTC](https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904/3 "2023-01-04T13:08:55Z")

</div>

Did you manage to find a solution for this? I’m running through this right now.

---

<div class="post-metadata">

**Author:** ![uncvrd](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/uncvrd/32/18514_2.png) [@uncvrd](https://community.fly.io/u/uncvrd)\
**Post date:** [January 4, 2023, 7:57pm UTC](https://community.fly.io/t/cannot-connect-to-a-digital-ocean-hosted-database-after-deploying/2904/4 "2023-01-04T19:57:32Z")

</div>

> [@uncvrd](#):
>
> Ok I bit the bullet and removed the requirement to connect from a trusted IP source

Yea, had to remove the requirement from a trusted IP source.
