How to connect on-prem postgres to Azure function app which is in NodeJS

Abhishek Patil 0 Reputation points

Hi , I wanted to connect my azure function to the postgres database which is hosted on prem on my personal laptop . How can I connect this ? I have tried inserting the inbound ip address of my function app in pg_hba.conf and also provided my local machine ip address as server name while connecting to postgres in function code.Error in code


Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,476 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Dillon Silzer 54,926 Reputation points

    Hello Abhishek,

    You will need to provide the host as your Public IP address. Your home router must also allow port forwarding (port 5432) to communicate.

    It looks like you have provided a private IP address (

    To get your public IP you can go to the following link: You will then need to look at your router's manual to find out how to allow port forwarding for firewall rules to allow Azure Functions to communicate with your db.

    If this is helpful please accept answer.

    0 comments No comments

  2. MayankBargali-MSFT 69,841 Reputation points

    @Abhishek Patil Thanks for reaching out.

    You need to Ensure that your PostgreSQL database is accessible from the internet. You need to ensure that your PostgreSQL database is accessible from the internet by configuring your router to forward incoming traffic on the PostgreSQL port (default port is 5432) to your laptop's IP address. Make sure to have the static IP as if you have dynamic IP then the connection IP would be changed every time.

    Once you have verified the above step then you need to Configure your PostgreSQL database to allow incoming connections: You need to configure your PostgreSQL database to allow incoming connections from the internet. You can do this by modifying the pg_hba.conf file to allow incoming connections from your Azure Function's IP address

    If you need any assistance on the above then I will suggest you to reach out to the postgres database for the configuration help or someone from your networking team that can help you with the setup so your DB can be accessed over internet.

    If you need any assistance from the Azure function end then feel free to reach out to us in Microsoft QnA.

    0 comments No comments