W
Wasp3mo ago
WWWillems

Issue externally connecting to Fly.io database

Hello Waspeteers, Not perse a Wasp issue, but figured I would try asking as I've been struggling to connect to my Fly.io database from trigger.dev. I followed this guide, without any luck: https://fly.io/docs/postgres/connecting/connecting-external/ I have set up a shared ipv4 address, but am not sure if this is sufficient. Do i need a dedicated ipv4 address? I would like my trigger.dev jobs to be able to directly write to my database. It works when developing locally but fails to establish a connection when i deploy it to production. When i run fly services list -a my_app_name I am seeing:
Services
PROTOCOL PORTS HANDLERS FORCE HTTPS PROCESS GROUP REGIONS MACHINES
TCP 5432 => 5432 [PG_TLS] False app lax 1
TCP 5433 => 5433 [PG_TLS] False app lax 1
Services
PROTOCOL PORTS HANDLERS FORCE HTTPS PROCESS GROUP REGIONS MACHINES
TCP 5432 => 5432 [PG_TLS] False app lax 1
TCP 5433 => 5433 [PG_TLS] False app lax 1
To test the Postgres connection I am using psql without any luck too: psql "host=my-app-production-db.fly.dev dbname=my_app_db_name user=postgres sslmode=require" When running this psql command I am getting the error:
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Does anyone have experience setting this up and willing to help me? Bit stuck here atm. Thanks! (I have replaced host/appname with paceholders)
Fly
External Connections
Documentation and guides from the team at Fly.io.
6 Replies
kapa.ai
kapa.ai3mo ago
Hi @WWWillems. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but the knowledge sources provided do not contain specific information about connecting to a Fly.io Postgres database from external services like trigger.dev, or about the requirements for a dedicated vs. shared IPv4 address for such connections. However, there are related discussions about connecting to Fly.io Postgres databases for development and seeding purposes, which typically involve opening a secure tunnel using the Fly CLI (e.g., fly proxy 5432 -a <db-app-name>) and connecting via localhost. This approach is mainly for local development or administrative tasks, not for persistent external service connections in production environments. The sources do not mention configuring public access or dedicated IPs for direct external connections from third-party services like trigger.dev. If you need to allow external services to connect directly to your Fly.io Postgres instance, you may need to consult the official Fly.io documentation or support for guidance on network configuration, firewall rules, and whether a dedicated IPv4 address is required for your use case. Be cautious with exposing your database to the public internet and ensure proper security measures are in place. If you have questions about connecting your Wasp app to a database, seeding, or tunneling for local access, I can provide detailed guidance based on the sources above. For your specific scenario with trigger.dev and external access, the knowledge sources do not provide enough information to give a confident answer. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @WWWillems, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
WWWillems
WWWillemsOP3mo ago
@kapa.ai ChatGPT is advising me to edit the Postgres config and enable
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
but i am a bit afraid of straying too far from the default Wasp setup. Also the official documentation doesn't mention this.
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The official Wasp documentation and community discussions do not mention the need to manually edit the Postgres configuration files (such as enabling ssl = on or specifying certificate files) when using Fly.io-managed Postgres databases. In fact, when you provision a database through Fly.io as part of the Wasp deployment process, Fly.io handles the database setup, including SSL configuration, for you. You are not expected to manually modify the Postgres server configuration in this scenario. If you are following the standard Wasp + Fly.io deployment flow, you should rely on the connection details and environment variables provided by Fly.io. For example, Fly.io typically provides a DATABASE_URL that already includes SSL requirements, and Wasp will use this for connecting to the database. There is no mention in the Wasp docs of needing to change Postgres config files for SSL support when using Fly.io's managed databases Connecting to a Database. If you are having trouble connecting externally, the issue is more likely related to network access, firewall rules, or Fly.io's service configuration, rather than missing SSL settings in the Postgres config. Editing the Postgres config is not part of the recommended or documented Wasp workflow for Fly.io deployments. If you need further customization or are running your own Postgres instance (not managed by Fly.io), then editing the config might be necessary, but this is outside the scope of the standard Wasp setup. In summary:
You do not need to manually edit the Postgres config for SSL when using the default Wasp + Fly.io setup. Stick to the official documentation and the connection details provided by Fly.io and Wasp. If you encounter connection issues, focus on network and access settings rather than Postgres server configuration. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @WWWillems, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
WWWillems
WWWillemsOP3mo ago
Ok I managed to resolve it by creating a dedicated ipv4 address on fly.io (docs didnt mention this)
Vinny (@Wasp)
Vinny (@Wasp)3mo ago
Interesting. Is this something we should document or take into account somehow -- what do you think @Carlos ?
Carlos
Carlos3mo ago
I see this is not related to Wasp, but two external services (Fly and Trigger). Specifically to how Fly configures its Postgres instances. I wouldn't add this to our documentation tbh. Wasp is not spinning the DB or configuring it so it's not in there at any point really. I found that Fly's documentation do mention this as peculiarity of their shared IPv4 addresses, even though it's not in the section you'd look in: https://fly.io/docs/networking/services/#dedicated-ipv4

Did you find this page helpful?