Blog Post

Microsoft Developer Community Blog
9 MIN READ

Talk to your data: PostgreSQL gets a voice in VS Code

TELAWRENCE's avatar
TELAWRENCE
Icon for Microsoft rankMicrosoft
Sep 25, 2025

As product roadmaps accelerate to meet new business needs, developer teams are struggling to maintain productivity, some even reporting that they need to use six or more tools to do their job. To address this, Microsoft has released an improved PostgreSQL extension to aid developers working with PostgreSQL in Visual Studio (VS) Code streamline their workflows and increase productivity. 

PostgreSQL and VS Code are top choices among developers, but, until now, using PostgreSQL and VS Code together meant constantly Alt-Tabbing or copying queries between windows. The new extension, now in public preview, brings full database management and query capabilities into VS Code, right alongside your code. You can connect to PostgreSQL databases, run queries, explore schemas, and even get AI assistance to talk to your data. The extension integrates with Azure Database for PostgreSQL and supports local databases, so it works whether you’re working with a cloud database or a container on your machine. Plus, features like context-aware IntelliSense and a built-in AI Copilot agent help you write and optimize SQL queries, so you can focus on building your application instead of wrestling with disconnected tools. 

Install it from the VS Code marketplace to start working with PostgreSQL right inside the code editor. 

Step 1: Installing the PostgreSQL Extension in VS Code 

First, let’s get the extension set up. 

  1. Open VS Code and go to the Extensions view (the square icon on the left toolbar or use Ctrl+Shift+X in Windows/Linux or ⌘+Shift+X on Mac). 
  1. Search for "PostgreSQL" in the Extensions Marketplace. Look for the official extension for PostgreSQL (Preview) authored by Microsoft (it has a blue elephant icon). 
  1. Click “Install” to add it to VS Code. Once installed, you’ll see an elephant icon in the Activity Bar – this represents the PostgreSQL extension.  

That’s it! The extension is now ready to use. It’s in public preview, which means you might see the word “Preview” in its name. Despite that, it’s already quite powerful. After installation, you might also want to ensure you have GitHub Copilot (and the Copilot Chat extension) installed and logged in, because the extension for PostgreSQL can hook into Copilot for AI features. We’ll get to that later. 

Step 2: Connect to (or provision) a PostgreSQL Database from VS Code 

With the extension installed, the next step is to connect it to a PostgreSQL database. This could be an existing database you have, or you can provision a new database directly from VS Code. There are options for both an Azure cloud database and a local Docker container option, which is super convenient. 

To add a database connection: 

  • Click the elephant icon on the left bar (the PostgreSQL extension panel). You should see a section for Connections. Click on “Add Connection” (usually a plus + button or a link). 
  • A dialog will prompt for connection details. You have a few options here: 
  • Connect to an Azure PostgreSQL server: If you have an Azure Database for PostgreSQL, you can use the “Browse Azure” option in the connection dialog. This lets you sign in with your Microsoft Entra ID (formerly Azure AD) and pick your database from a list. The extension natively supports Azure authentication, meaning there’s no need to remember passwords if you’re already signed in. It’ll use your Azure credentials securely. This is great for enterprise scenarios with centralized identity management (one less password to juggle!).  
  • Connect with a connection string or parameters: You can always paste in a traditional Postgres connection string or manually enter your host, port, user, and password. The extension will parse it and save a profile for you. It also supports SSL and other advanced settings you might need. Under the hood, it stores credentials encrypted on your machine, so your passwords/tokens aren’t exposed in plain text. 
  • Create a local database (Docker): Don’t have a Postgres server running? No problem. The extension can help you spin up a local PostgreSQL instance via Docker. In the “Add Connection” menu, look for an option like “Create new PostgreSQL (Docker)”. If Docker Desktop is running, the extension will pull a PostgreSQL container image and set it up for you automatically. You simply provide a name or accept defaults, and within seconds you have a local database running. This is perfect for a quick dev/test database.  

After providing the details, hit Connect. You should then see your new connection listed in the Connections tree, with the server name or connection nickname you gave. Expanding it will show databases and within those your schemas, tables, etc. 

Security tip: The extension uses encrypted storage for sensitive data like passwords. And if you connected to Azure using Entra ID, it’s effectively password-less and uses tokens behind the scenes, refreshing them as needed to keep you logged in. 

Step 3: Explore your database with the VS Code Extension 

Once connected, you can browse and manage your database right from VS Code’s sidebar. This is where the extension really starts to feel like a full GUI client but embedded in your IDE. 

In the PostgreSQL Explorer (the sidebar tree under your connection), try expanding the nodes: 

  • Databases and Schemas: Under your server connection, you’ll see one or more databases. Expand one to see schemas, then tables, views, functions, etc. It’s a structured view of all your database objects.  
  • Tables: You can expand a table to see its columns and indexes. If you right-click on a table, you’ll get options like “Select Top 100 Rows” (to quickly view data), “Script as Create” (to get the CREATE TABLE script), or even “Delete” or “New Table” if you want to modify schema. Yes, you can create and alter tables from here; It’s not just read-only browsing. 
  • Functions/Stored Procedures: You can similarly drill into stored routines or triggers and script them out or create new ones. 

This Object Explorer makes it easy to navigate your database structure. No more typing \\d commands or remembering system tables. If you have a large schema, there’s even a filter box to quickly find a specific table or view by name. 

Let’s say our goal is to build an intelligent application that uses data from this database. A common task might be to verify the data or adjust the schema. With this extension, you could, for example, quickly check a table’s schema or content before writing code that uses it. The integration means less guesswork since you can double-check your database while coding the app logic. 

Step 4: Run queries without leaving VS Code with IntelliSense magic 

Browsing is nice, but as developers you often need to run queries or update data as part of development. The PostgreSQL extension provides a rich query editor inside VS Code. 

Here’s how you can run a SQL query in this environment: 

  • Open a new SQL query: There are multiple ways. One easy method is to right-click on a database or schema in the sidebar and choose “New Query”, which opens a SQL query editor tab associated with that connection. You could also use the command palette and search “PostgreSQL: New Query”. 
  • Write your SQL: The query editor has full syntax highlighting for SQL, so your keywords, strings, and comments are color-coded. But even better, it has context-aware IntelliSense. This means as you type, it auto-completes table names, column names, functions, etc., based on the schema of your currently connected database. For example, start typing SELECT * FROM <your_table>... and you’ll get suggestions for table names. After selecting a table, typing a dot (your_table.) will suggest column names. If you have a JOIN, it can suggest join conditions, and so on. It feels like the kind of IntelliSense you get in programming languages, now for SQL. 
  • Execute the query: You can run the query by clicking the “Run” button in the top right of the editor or press a keyboard shortcut. The results will appear below the query in a dedicated Results pane. 

What’s cool about the results is that they’re interactive too: 

  • You’ll see the rows returned in a grid format. You can sort by clicking column headers, and there’s a filter box to quickly search within the result set if needed. 
  • If the data is large or you need to share it, you can export the results to CSV, JSON, or Excel with one click. This is super handy for grabbing data samples. 
  • The results pane stays open as a tab, so you can open multiple query results at once or refer to a previous result while you continue coding. 
  • The extension also keeps a history of queries you’ve run in each session. In the sidebar, underneath the Object Explorer, you’ll find a “Query History” section listing recent queries. If you accidentally close a tab, you can get your query back or quickly re-execute a previous command. 

All these features mean you can treat VS Code as your SQL playground. For instance, if you’re debugging why your app’s query isn’t returning the expected results, you can tweak and run that query right here, see the data, then adjust your application code accordingly within VS Code. 

Step 5: Leverage AI features to build smarter applications 

One of the most exciting aspects of this new extension is how it integrates AI assistance via GitHub Copilot to make writing and optimizing SQL easier. These features can help you build intelligent applications by injecting AI power into your database development workflow: 

  • AI-Powered IntelliSense and Suggestions: Behind the scenes, part of the context-aware IntelliSense is powered by an AI understanding of PostgreSQL syntax and your schema. It’s like having a smart SQL assistant that knows your database. This reduces the PostgreSQL learning curve and helps prevent errors. 
  • Copilot Chat (@pgsql): If you have GitHub Copilot Chat enabled in VS Code, the PostgreSQL extension adds a specialized database assistant. You can open the Copilot Chat pane and ask database-related questions or give commands, prefixing with @pgsql to focus on Postgres. For example, you could ask: “@pgsql how do I create a new table with a JSONB column indexed for search?” and it will understand the context is PostgreSQL and provide an appropriate answer or even code snippet. Copilot Chat Agent Mode can even handle multi-step tasks. This is next-level automation; you can literally tell the AI “set up my database” in plain English and it does it (safely, with confirmations). Now imagine using this to speed up your app development: you could prototype parts of your database or queries by just describing what you need. 
  • “Explain” and “Optimize” Queries: Writing a complex SQL query? You can highlight it, right-click, and you’ll see AI-driven options like Explain Query or Rewrite Query in the context menu. Explain Query will use Copilot to give you a natural language explanation of what the query does (useful for understanding or code reviews), and Rewrite Query can suggest a potentially more efficient or clean version of your query. There’s also Analyze Query Performance, which might suggest indexes or changes that could help your query run faster. These are like having a database expert pair-programming with you, ensuring your SQL and data access are top-notch for your application’s needs. 
  • AI for Data Insights: Although not explicitly a part of the extension’s UI, having your database accessible in VS Code means you can easily feed data into other AI tools or libraries. For example, if you’re building an AI-powered app, like doing ML or semantic search with your Postgres data, you can quickly query and export data for model training or connect to Python notebooks, etc. The extension itself focuses on database operations, but it’s an enabler for those bigger scenarios. Microsoft is even building features like new vector search indexing (DiskANN) and integrations with AI frameworks (Semantic Kernel, etc.) for Postgres, which you can manage through VS Code now.  

These AI features help you not only write correct SQL, but also optimize it and use your database effectively when developing intelligent applications. They lower the barrier to working with Postgres for newcomers and speed up tasks for veterans. Thomas Flock, Principle AI Architect at 3 Cloud, an Azure partner that develops AI applications shared: “I was able to ask questions on my data using the GitHub Copilot chat and create a database based on example data. Creating with the PostgreSQL extension for VS Code made it possible to develop POC applications much quicker for my clients. As an architect I always need to be one step ahead, and the extension allowed me to test my ideas before handing them off to the team.” 

Getting started 

By bringing these capabilities into VS Code, you can drastically reduce context-switching and development friction. Early feedback from the developer community has been enthusiastic. “As an early adopter of the PostgreSQL extension for VS Code, we knew immediately that it would greatly simplify the work we do with PostgreSQL every day,” said Rand Morimoto, President of Convergent Computing. The extension simplifies workflows that used to involve multiple tools and windows. Now, whether you’re building a simple web app or an AI-driven application with Postgres as a backbone, you can do it all in one place. 

Ready to try it out? The extension is available in the VS Code Marketplace (just search “PostgreSQL”). Since it’s a preview, you might see updates coming in frequently. Be sure to update regularly to get the latest features. Also, check out the official documentation and quickstart guides on Microsoft Learn for more examples and advanced usage (like using the VS Code Azure portal integration, or configuring Copilot agent mode). Install the extension, connect to a database, and use these step-by-step tips to boost your Postgres development productivity.  

Happy coding and may your context switches be few! 

Updated Sep 24, 2025
Version 1.0
No CommentsBe the first to comment