Manage PostgreSQL Databases Directly in VS Code with Microsoft’s Extension

Running PostgreSQL, whether on local machines or in the cloud, has become significantly more streamlined with Microsoft’s PostgreSQL extension for VS Code. This powerful tool seamlessly integrates database management into your coding environment, allowing users to connect to databases, write and execute queries, visualize schemas, and even engage with GitHub Copilot—all without the need to switch between different applications. For those utilizing Azure, the extension also incorporates Entra authentication for Azure Database for PostgreSQL, enhancing security and ease of access.

GitHub Copilot Integration

One of the standout features of this extension is the inclusion of a @pgsql GitHub Copilot agent, designed specifically to assist with PostgreSQL tasks. Users can request Copilot to rewrite queries, clarify their functions, or analyze performance metrics directly from the context menu. This integration not only simplifies the coding process but also enhances productivity by providing intelligent suggestions at your fingertips.

The @pgsql Copilot agent can rewrite, explain, and analyze query performance. Image source: VS Code Marketplace

Taking it a step further, the Copilot Chat Agent Mode allows users to tackle multi-step tasks such as debugging, schema optimization, and performance tuning. Importantly, it ensures that users are informed and in control by seeking permission before executing any changes to the database.

Schema Visualization

Understanding the structure of a database is crucial for effective management. With the extension, users can simply right-click on any database entry in the Object Explorer and select “Visualize Schema” to generate a visual representation of their database architecture. This feature significantly aids in comprehending table relationships and navigating complex databases.

Visualize your database schema directly in VS Code. Image source: VS Code Marketplace

Connection Management

The extension is versatile, supporting both local PostgreSQL instances and cloud-hosted databases. Users can create multiple connection profiles, parse connection strings, and explore Azure Database for PostgreSQL deployments directly within the extension. For Azure users, the integration of Entra ID authentication facilitates passwordless login, complete with automatic token refresh for added convenience.

Query Tools

Writing SQL queries in VS Code is enhanced by context-aware IntelliSense, which suggests table names, columns, and SQL keywords as users type. The extension also features syntax highlighting, auto-formatting, and a query history panel, allowing for easy review of previously executed queries. Furthermore, users can export query results in various formats such as CSV, JSON, or Excel, simplifying data sharing and integration with other tools.

Docker Support

For developers in need of a local PostgreSQL instance, the extension offers the capability to spin up PostgreSQL containers with minimal setup. This feature enables users to establish a functional database environment without ever leaving the comfort of VS Code.

Additional Features

  • Server Dashboard: Monitor performance metrics for your PostgreSQL servers.
  • Schema Migration: Convert Oracle databases to an Azure Database for PostgreSQL with AI-assisted transformation.
  • Object Explorer: Browse tables, views, functions, and other database objects with ease.

To experience these features, users can install the PostgreSQL extension from the VS Code Marketplace or search for “PostgreSQL” in the Extensions sidebar.

Tech Optimizer