Access database from Retool

Another thing you can do is open a public port to make the database accessible:

1. Assign a Public IP

$ fly ips allocate-v4    # you can also allocate ipv6

2. Configure External Port

Start by saving the database’s fly config to disk in an empty dir:

$ fly config save --app $YOUR_DB

This will create a new fly.toml file with the database config. You can also save it as something like fly.db.toml in your existing app’s directory. Add the following services section to the config (remember to remove the empty services section at the top first):

  internal_port = 5432 # Postgres instance
  protocol = "tcp"

# Example of opening port 12500 for insecure connections.
  handlers = []
  port = 12500

3. Deploy changes

First, you’d need to confirm the database version:

$ fly pg connect $YOUR_DB
PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) ....

Then redeploy your database with the correct image:

$ fly deploy . --config fly.db.toml --image flyio/postgres:14.2

4. Create a new user for Retool

This is optional but you should create a separate role for retool and any other services that use your DB:

$ fly pg connect $YOUR_DB
psql>  CREATE USER retool WITH PASSWORD 'password';
psql>  \du;  -- assign databases and more...

5. Connect externally

You can now connect to the database instance from retool at: