Postgres database refusing connection from Airflow: Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections port 5432?

I have an existing database (Postgres) that i want to connect to apache-Airflow on my host machine(Windows 10), I installed the apache-airflow on the WSL running ubuntu. The installation was smooth and working fine since i was able to get the airflow webserver running on my localhost(port:8081).

I tried connecting airflow to my existing database (carPrices) passing all the necessary parameters which were all correct. I also confirmed my database is up and running on port(5432). Whenever i click the connect button it will report this error..."could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?"

I dont know what exactly is the problem as i am new to airflow.

I tried setting the connection parameter of airflow by setting it through the airflow.cfg file and through the Airflow UI home. In the first case i cant even "airflow db init" as it report the same problem of connection refusal. the second case will setup a default sqlite db for the airflow UI to run. then i tried connecting using the UI but same error message was given.enter image description here

I check using if the postgres is up and running using netstat -ab and posgres is up and listening.enter image description here

I was expecting the connection to report succesful since i am sure of all the database parameters passed but instead i got this.enter image description here

Upvotes: 1

Views: 1894

Answers (1)

Found out the problem is with WSL 2, you cant connect to localhost from WSL2 without some complicated tweaks... The simplest thing to do is downgrade to WSL 1 running this command in powershell: wsl.exe --set-version Ubuntu-20.04 1

Upvotes: 1

Related Questions