This tutorial explains how to connect to PostgreSQL database in Azure Data Studio. Microsoft Azure Studio is an open source database tool using which, you can connect to a running MSSQL instance and carry out simple and complex database operations. But now Microsoft has added supports for PostgreSQL database in this tool through an official plugin. Now, you can connect to a local and remote PostgreSQL instance, retrieve databases, and run SQL to edit tables and data inside. The plugin adds support for database explorer and PostgreSQL editor in Data Studio and you can export data from tables to other formats as well.
Since PostgreSQL comes has some great advantages over other DBMS, so I think this is one of the reasons that Microsoft has added support for this in Azure Data Studio. For complex SQL queries PostgreSQL is a very good option and if you often use this then you need a client for it as well. And Azure Data Studio is one of those database management tools that provide a handy database explorer with some powerful features such as Microsoft Intellisense. You can use all this while manipulating PostgreSQL database via simple and complex queries.
How to Connect to PostgreSQL Database in Azure Data Studio?
You can download latest version of Azure Data Studio from here for your platform. Or, if you are already using this then simply open it up and in the marketplace, search “postgre”. When it appears in the results, click on that to install it. After installation of this plugin, you will have to restart Data Studio.
Now, you are simply ready to connect to a PostgreSQL instance. On the database connection window, a new entry “PostgreSQL” will appear in the drop down. Specify the connection parameters and specify the username and password for the database to connect to it. After it connects to the database, you can see all available schemas and other database objects.
Now, you can either use the database explorer from he left panel. Or, you can open the SQL editor to run SQL commands to manipulate data. The SQL editor is intuitive and supports syntax highlighting with Intellisense like suggestions. You run the SQL queries in the editor and see the corresponding response in the console at the bottom side.
You can open the data objects tables either through SQL or using explorer and then analyze the data. The table view that it show can be exported as a CSV or XML file. For that, you just have to click on the export icon from the right side in the viewer section.
If you want to connect to multiple PostgreSQL instances then you can do that. And if you want to switch to different database in the current session then just select that from the main interface. For this article, I tested this on a local PostgreSQL instance but it should work for the remote PostgreSQL instance too without any problem. In the SQL editor, you can import an SQL script and save the output in various formats.
Closing thoughts
PostgreSQL is preferred database to be used in production and I am glad that Microsoft has added support for this in Azure Data Studio. Now, you just connect to any PostgreSQL database and start doing database operations you want to do. Explore data objects, run SQL scripts, and see the log in the terminal like window. So, if you’ve been using some other database clients to connect and manage PostgreSQL databases then I will suggest you to give Azure Data Studio a try.