PostgreSQL Like a Pro · VS Code Edition: Watch on YouTube (opens in a new tab)

Install the free PostgreSQL
extension for VS Code

Connect a database and run every move from the series in under 20 minutes. Works with Azure HorizonDB, Azure Database for PostgreSQL, or any other PostgreSQL database.

What the extension does

  • Connect and explore

    Add a connection and browse databases, schemas, and tables.

  • AI-assisted query writing

    Schema-aware IntelliSense with connected database context.

  • Ask @pgsql

    Get Copilot answers grounded in your connected database.

  • Agent mode, with approval

    Let Copilot work through an unfamiliar schema.

Why the editor

Your whole PostgreSQL workflow, in the editor you already use

  • Stay in flow

    Connect, query, and manage PostgreSQL where you already write code.

  • Write SQL that matches your schema

    IntelliSense knows your connected database, so names and completions are right the first time.

  • Bring AI in on your terms

    Ask @pgsql about your data. Agent mode can act, but only with your approval.

  • Diagnose and resolve issues

    Open the Metrics Dashboard and Azure Advisor recommendations without switching tools.

Hands-on

Build a research agent
backed by PostgreSQL on Azure

Turn what you learned into a working agent: PostgreSQL as the vector store, a Microsoft Foundry agent as the brain, and real Washington State case law as the data.

  1. Step 1: Set up your environment

    Clone the repo, create a Python virtual environment, and add your keys to .env.

    git clone https://github.com/Azure-Samples/postgres-agentscd postgres-agentspip install -r requirements.txt
  2. Step 2: Enable the extensions

    Allow-list azure_ai and vector on your Azure Database for PostgreSQL server, then create them.

    CREATE EXTENSION IF NOT EXISTS azure_ai;CREATE EXTENSION IF NOT EXISTS vector;
  3. Step 3: Load data and generate embeddings

    Create the cases table and embed the case opinions with Azure OpenAI. About 3–5 minutes.

    cd load_datapython main.pycd ..
  4. Step 4: Give your agent a Postgres tool

    vector_search_cases in legal_agent_tools.py runs a pgvector similarity search the agent can call.

  5. Step 5: Create and run the agent

    Initialize the agent in your Microsoft Foundry project with gpt-4o-mini, and answer a real legal question end to end.

    python src/simple_postgres_and_ai_agent.py
  6. Step 6: Test and iterate

    Ask follow-up questions in the Microsoft Foundry playground and trace each step.

You watched the workflow.
Now it can live in your editor.

Free extension. Install it, connect a database, and ask @pgsql about your data.