# Postgres public access

**URL:** <https://community.fly.io/t/postgres-public-access/5325>\
**Category:** Questions / Help\
**Tags:** postgres\
**Created:** [May 25, 2022, 10:27am UTC](https://community.fly.io/t/postgres-public-access/5325 "2022-05-25T10:27:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![factorialhr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@factorialhr](https://community.fly.io/u/factorialhr)\
**Post date:** [May 25, 2022, 10:27am UTC](https://community.fly.io/t/postgres-public-access/5325/1 "2022-05-25T10:27:35Z")

</div>

Hi, I’ve created a nodeJS project and added a postgresDB during the setup

The problem that I have now is that I want to connect to the DB from outside the machine. I can do it by using the proxy command pointing to the app but the problem is that I need to do that without the proxy command (since I need to connect the DB to an analytics software that doesn’t allow that)

I’ve tried to change the fly.toml file and add another service (since in the documentation says it can be multi service) but it seems that it replaces the node service’s config with the last one it finds and thus makes the app not public

This is the config that I tried:

```nohighlight
app = "desky-api"

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

[build]
  builder = "heroku/buildpacks:20"

[env]
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

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

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

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

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

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"
    
[[services]]
  internal_port = 5432
  protocol = "tcp"
  
  # For secure connections
  [[services.ports]]
   handlers = ["tls"]
   port = 443

  # For insecure connections. 
  [[services.ports]]
   handlers = []
   port = 54320

```

Thanks a lot for the help

---

<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:** [May 25, 2022, 1:34pm UTC](https://community.fly.io/t/postgres-public-access/5325/2 "2022-05-25T13:34:46Z")

</div>

I wasn’t quite clear if you were using Fly’s Postgres, or your own.

If it’s Fly’s Postgres (generally better than doing it yourself, with HA etc, but up to you!), yes you can use a proxy but if can’t, you could attach an IP to it and then expose that to allow externals connections. Here’s how to do that: [Multi-region PostgreSQL · Fly Docs](https://fly.io/docs/getting-started/multi-region-databases/#connecting-external-services)

If it’s your _own_ Postgres _and_ can’t use the proxy, you could go about it _another_ way by installing Wireguard. Your machine could then resolve Fly’s private `pg-app-name.internal` hostnames which of course otherwise it couldn’t. It’s then as if your machine was another Fly app within your private network. Here’s a guide for _that_ approach depending on your OS: [Private Networking · Fly Docs](https://fly.io/docs/reference/private-networking/#step-by-step)

---

<div class="post-metadata">

**Author:** ![factorialhr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@factorialhr](https://community.fly.io/u/factorialhr)\
**Post date:** [May 25, 2022, 1:55pm UTC](https://community.fly.io/t/postgres-public-access/5325/3 "2022-05-25T13:55:31Z")

</div>

Hi Greg!

I’m using fly’s postgres. I have added already an IPv4 and also IPv6 with a domain certificate too but no luck on connecting to it

But I’ve followed the guide and the key was to export the configuration, remove the line where it says

```auto
services = []

```

and add the following:

```auto
[[services]]
  internal_port = 5432 # Postgres instance
  protocol = "tcp"

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

[[services.ports]]
  handlers = []
  port = 5432

```

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [September 1, 2022, 1:30pm UTC](https://community.fly.io/t/postgres-public-access/5325/5 "2022-09-01T13:30:34Z")

</div>

Postgres SSL is non standard and won’t work with our proxy. You’d need to install certificates and enable your own SSL in the app to make postgres + tls work.

---

<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:** [September 1, 2022, 6:41pm UTC](https://community.fly.io/t/postgres-public-access/5325/7 "2022-09-01T18:41:29Z")

</div>

@josephxanderson Hearing my name mentioned 🙂

I _think_ what Kurt means is the Fly proxy that sits in front of all their apps. So by assigning an IP and exposing a port, you _are_ using the proxy. As the connection to your app would go through it, to get to your database app. In which case you couldn’t use their tls handler (in their proxy) for the reason Kurt says.
