Blog Post

Connecting to PostgreSQL from Azure Data Studio

,

I’ve been doing a bit of work with PostgreSQL as part of my work with Redgate. PostgreSQL is a relational platform that is open source, free to use, available as a supported commercial product from various companies, and has been in active development for over 35 years.

More and more organizations are looking at PostgreSQL for relational data stores as both SQL Server and Oracle are very expensive, and this is a viable alternative.

This post looks at the basics of getting started with PostgreSQL by connecting to the platform with Azure Data Studio.

If you haven’t installed PostgreSQL, or want to work with a container, check out my previous post: Creating a PostgreSQL Docker Container with a Volume on Windows

Azure Data Studio

Azure Data Studio (ADS) is a fork of Visual Studio Code, but specialized for databases. I don’t use it a lot, but I find it useful for some coding. They also have added an extension that allows connections to PostgreSQL.

If you click the Extensions blade and then search for postgresql, you’ll find it. You can see it installed on my system below. Before you do this, the button that says uninstall would say install.

2022-12-27 10_26_31-Extension_ PostgreSQL - DBAScripts - Azure Data Studio

Once installed, the connection is like any connection in ADS.

First, make sure you have PostgreSQL installed. If you want to do this in a container, see my link above.

Connecting

To connect, first open a new Query window.

2022-12-27 10_28_43-SQLQuery_2 - disconnected - DBAScripts - Azure Data Studio

At the top there is a “Connect” button. Click this.

2022-12-27 10_28_47-SQLQuery_2 - disconnected - DBAScripts - Azure Data Studio

Now the connection blade opens. As you can see below, there are now two choices for the connection type: SQL Server and PostgreSQL. Choose PostgreSQL.

2022-12-27 10_29_34-Window

I choose localhost, as that’s where my instance is running. I also change the authentication type to Login and enter “postgres” as the default user. If you haven’t set up a user, use this. Then enter the password.

One last thing, as I often run databases in containers, I’ll change the port. To do that for PostgreSQL, click the “Advanced” button. I often use 54320, 54321, 54322 for my ports, so you can see I’ve entered that below:

2022-12-27 10_32_04-SQLQuery_2 - disconnected - DBAScripts - Azure Data Studio

Click Ok if you’re added a port, and you should see these details:

2022-12-27 10_31_49-SQLQuery_2 - disconnected - DBAScripts - Azure Data Studio

Click Connect, and you should connect immediately. Then you can verify your connection with a query or two. As you can see, the database is defaulted to postgres and my queries have returned the version and tables in this database.

2022-12-27 10_35_20-● SQLQuery_2 - localhost.postgres (postgres) - DBAScripts - Azure Data Studio

That’s it. Now time to work on some pgsql.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating