Upload/insert data into fly.io postgres database, can't connect

Hey :slight_smile:
probably a trivial question, but I haven’t found an answer jet. I created a postgres DB on fly.io and now I want to be able to connect to it, create tables and upload/insert data from my local machine, preferebly via a python script (I use the psycopg2 package). Infortunately I am not able to connect and via python I always receive the error:

“could not translate host name “” to address: nodename nor servname provided, or not known”

doesnt matter if I use the url: ```
postgres://{username}:{password}@{hostname}:{port}/{database}?options

with 
conn = psycopg2.connect(postgres_url, sslmode='require')

or the postgres syntax

conn = psycopg2.connect(
    host=pg_hostname,
    database=pg_username,
    user=pg_username,
    password=pg_password,
    port=pg_port)

Thanks in advance

I think a previous answer of mine could be helpful in this case:

Thanks so I opened a new terminal entered:
flyctl proxy 15432:5432 -a <app name (no .internal)>, let that terminal open, then I could connect via, setting the port to 15432 and the host to localhost
conn = psycopg2.connect(
host=f"localhost",
database=database,
user=username,
password=password,
port=15432)

1 Like