The most convenient way to set up a live connection between Power BI and a PostgreSQL database is to use the DirectQuery option, which allows Power BI to query the database directly without importing the data itself. The following is a guide to easy steps:
Install the PostgreSQL ODBC Driver: Download and install the PostgreSQL ODBC Driver from the PostgreSQL website. It's also known as the "psilotic" driver, and it is the first step in defining the connection between Power BI and your PostgreSQL database.
Permissions: Make sure that the PostgreSQL user account has sufficient access to the target database. The user should have at least read access to tables against which you run queries.
Connect it:
Start Power BI Desktop and choose Home > Get Data > PostgreSQL Database.
Enter the server name and database name. Select the authentication method (either Windows or database).
DirectQuery should be chosen under Data Connectivity mode. This option allows the data to be queried live and not imported.
Set up the Data Gateway (when applicable): An On-Premises Data Gateway must be installed to link your Power BI environment with your on-premises PostgreSQL server. You can download the gateway from the Power BI Service and configure it to your PostgreSQL server.
Testing the Connection: Once you have everything configured, you can test it to see if there are any issues with Power BI fetching data from PostgreSQL.
Possible Challenges:
Firewall and Network Configuration: Ensure your firewall makes provisions for Power BI (or the Data Gateway) to communicate with your PostgreSQL database.
Performance Considerations: Because DirectQuery executes a live direct request on the database, ensure query performance optimizations are made in the Postgresql server.
For a much clearer visual walkthrough, there is a YouTube video tutorial that shows the detailed setup and troubleshooting steps.
The whole process is quite simple; it involves getting the right permissions and setting the gateway configuration to refresh live.