Connecting to a Postgres database with Azure Data Studio

Connecting to a Postgres database with Azure Data Studio

Table of Contents

Introduction

I have been working with a Postgres database in a docker container recently to get to grips with dbt. I typically work in the world of SQL Server and so I have Azure Data Studio installed on my Mac. I was delighted to discover that Azure Data Studio is capable of connecting to a Postgres database. Here’s how to do it…

Install Azure Data Studio

Firstly, you need to install Azure Data Studio. You can download it from Microsoft.

Install the Postgres extension

Once you have installed Azure Data Studio, you need to install the Postgres extension. You can do this by clicking on the Extensions icon on the left-hand side of the screen and searching for Postgres or from the marketplace.

Create a new connection

Once you have installed the extension, you can create a new connection by clicking on the New Connection icon on the left-hand side of the screen. You will need to enter the following details:

  1. Switch Connection type to PostgreSQL.
  2. Enter the Server name.
  3. Enter the user name and password.
  4. Enter the database name.

If you set up the Postgres container on a non-default port, you can set that port in the advanced settings.

screenshot shows the azure data studio app with a new connection pane open, the connection details have been entered as described above

Connect to the database

Once you have entered the details, you can click on the Connect button. If you have entered the details correctly, you should see the database in the Object Explorer on the left-hand side of the screen. You can also create databases, tables, and run queries from here.

screenshot shows the azure data studio app connected to the postgres server, a query window is open with the output from a SELECT statement against information_schemas.tables

Unresponsive

The extension is still in preview and so it is a bit buggy. I have found that sometimes I need to close and reopen Azure Data Studio to get it to connect to the database as it will just hang whilst refreshing the connection in the object explorer. I’m sure there are better tools out there for connecting to Postgres databases, but as a way to just get started quickly to evaluate dbt with the tools that I’m already comfortable with, it’s ideal.

Conclusion

I have shown you how to connect Azure Data Studio to a Postgres database. vscode / Azure Data Studio are such flexibile tools it’s great to be able to work with a multitude of different languages, databases, and extensions all in once place.

References

#mtfbwy



Recent Posts