How to serve a Postgresql server through a public domain name?

I am currently developing a website using Flask and SQLAlchemy, and I am having issues connecting to the database. It is hosted on a separate network than the one I am typically on, so I wanted to host my own server for development.

To do this, I bought a domain name from Cloudflare and looked into how to make a postgres server public. I have edited the /etc/postgresql/15/main/postgresql.conf file to include listen_addresses = "*" and the /etc/postgresql/15/main/pg_hba.conf file to include host all all md5. Then, I created a tunnel through Cloudflare, pointing to tcp://localhost:5432 on my machine, and attached it to a subdomain.

Now, I am trying to connect to the server with some issues. When I try to connect to the server, I get errors saying Connection to server at "" (, port 5432 failed: Connection timed out and Is the server running on that host and accepting TCP/IP connections?. I am creating the URI to connect with this format f"postgresql://{username}:{pass}@{url}/{database}", without a port.

Does anybody know what I may be doing wrong?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.