Welcome to PostgreSQL for Visual Studio Code! An extension for developing PostgreSQL with functionalities including:
- Visual Studio Code Postgresql Connection
- Postgresql In Visual Studio Code
- Visual Studio Connect To Postgresql
- Connect to PostgreSQL instances
- Manage connection profiles
- Connect to a different Postgres instance or database in each tab
- View object DDL with 'Go to Definition' and 'Peek Definition'
- Write queries with IntelliSense
- Run queries and save results as JSON, csv, or Excel
PostgresSql for Visual Studio Code. This extension the following features when working with pgsql files in VS Code: Colorization; Snippets; Execute Current File using psql (vs command) Completion Lists for global postgres functions (copied from the Postgres official documentation). PostgreSQL for Visual Studio Code is an open source tool with 183 GitHub stars and 9 GitHub forks. Here's a link to PostgreSQL for Visual Studio Code's open source repository on GitHub. Pros of PostgreSQL for Visual Studio Code. The Visual Studio Code PostgreSQL extension, by Microsoft. Update Ubuntu: sudo apt update; Get the PostgreSQL extension (by Microsoft) in the VSCode Marketplace. Install Postgres: sudo apt install postgresql postgresql-contrib; Verify version: psql -version; Once you get a version number, you’re already very far through.
Install link: https://marketplace.visualstudio.com/items?itemName=ms-ossdata.vscode-postgresql
Quickstart
Open the Command Palette (Ctrl + Shift + P).
Search and select 'PostgreSQL: New Query'
In the command palette, select 'Create Connection Profile'. Follow the prompts to enter your Postgres instance's hostname, database, username, and password.
You are now connected to your Postgres database. You can confirm this via the Status Bar (the ribbon at the bottom of the VS Code window). It will show your connected hostname, database, and user.
You can type a query like 'SELECT * FROM pg_stat_activity';
Right-click, select 'Execute Query' and the results will show in a new window.
You can save the query results to JSON, csv or Excel.
Offline Installation
The extension will download and install a required PostgreSQL Tools Service package during activation. For machines with no Internet access, you can still use the extension by choosing theInstall from VSIX...
option in the Extension view and installing a bundled release from our Releases page.Each operating system has a .vsix file with the required service included. Pick the file for your OS, download and install to get started.We recommend you choose a full release and ignore any alpha or beta releases as these are our daily builds used in testing.
Support
Support for this extension is provided on our GitHub Issue Tracker. You can submit a bug report, a feature suggestion or participate in [discussions].
Contributing to the Extension
See the developer documentation for details on how to contribute to this extension.
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Privacy Statement
The Microsoft Enterprise and Developer Privacy Statement describes the privacy statement of this software.
License
This extension is licensed under the MIT License. Please see the third-party notices file for additional copyright notices and license terms applicable to portions of the software.
PostgreSQL can be built using the Visual C++ compiler suite from Microsoft. These compilers can be either from Visual Studio, Visual Studio Express or some versions of the Platform SDK. If you do not already have a Visual Studio environment set up, the easiest way us to use the compilers in the Platform SDK, which is a free download from Microsoft.
PostgreSQL supports the compilers from Visual Studio 2005 and Visual Studio 2008. When using the Platform SDK only, or when building for 64-bit Windows, only Visual Studio 2008 is supported. Visual Studio 2010 is not yet supported.
When building using the Platform SDK, versions 6.0 to 7.0 of the SDK are supported. Older or newer versions will not work. In particular, versions from 7.0a and later will not work, since they include compilers from Visual Studio 2010.
The tools for building using Visual C++, are in the src/tools/msvc directory. When building, make sure there are no tools from MinGW or Cygwin present in your system PATH. Also, make sure you have all the required Visual C++ tools available in the PATH. In Visual Studio, start the Visual Studio Command Prompt. In the Platform SDK, start the CMD shell listed under the SDK on the Start Menu. If you wish to build a 64-bit version, you must use the 64-bit version of the command, and vice versa. All commands should be run from the srctoolsmsvc directory.
Before you build, you may need to edit the file config.pl to reflect any configuration options you want to change, or the paths to any third party libraries to use. The complete configuration is determined by first reading and parsing the file config_default.pl, and then apply any changes from config.pl. For example, to specify the location of your Python installation, put the following in config.pl:
You only need to specify those parameters that are different from what's in config_default.pl.
If you need to set any other environment variables, create a file called buildenv.pl and put the required commands there. For example, to add the path for bison when it's not in the PATH, create a file containing:
16.1.1. Requirements
The following additional products are required to build PostgreSQL. Use the config.pl file to specify which directories the libraries are available in.

It is recommended that you upgrade to the latest available version of the Microsoft Platform SDK, available for download from http://www.microsoft.com/downloads/.
You must always include the Windows Headers and Libraries part of the SDK. If you install the Platform SDK including the Visual C++ Compilers, you don't need Visual Studio to build.
ActiveState Perl is required to run the build generation scripts. MinGW or Cygwin Perl will not work. It must also be present in the PATH. Binaries can be downloaded from http://www.activestate.com (Note: version 5.8 or later is required, the free Standard Distribution is sufficient).
The following additional products are not required to get started, but are required to build the complete package. Use the config.pl file to specify which directories the libraries are available in.
Required for building PL/TCL (Note: version 8.4 is required, the free Standard Distribution is sufficient).
Bison and Flex are required to build from Git, but not required when building from a release file. Note that only Bison 1.875 or versions 2.2 and later will work. Also, Flex version 2.5.31 or later is required. Bison can be downloaded from http://gnuwin32.sourceforge.net. Flex can be downloaded from http://www.postgresql.org/ftp/misc/winflex/.
Note: The Bison distribution from GnuWin32 appears to have a bug that causes Bison to malfunction when installed in a directory with spaces in the name, such as the default location on English installations C:Program FilesGnuWin32. Consider installing into C:GnuWin32 instead.
Diff is required to run the regression tests, and can be downloaded from http://gnuwin32.sourceforge.net.
Gettext is required to build with NLS support, and can be downloaded from http://gnuwin32.sourceforge.net. Note that binaries, dependencies and developer files are all needed.
Required for Kerberos authentication support. MIT Kerberos can be downloaded from http://web.mit.edu/Kerberos/dist/index.html.
Required for XML support. Binaries can be downloaded from http://zlatkovic.com/pub/libxml or source from http://xmlsoft.org. Note that libxml2 requires iconv, which is available from the same download location.
Required for SSL support. Binaries can be downloaded from http://www.slproweb.com/products/Win32OpenSSL.html or source from http://www.openssl.org.
Required for UUID-OSSP support (contrib only). Source can be downloaded from http://www.ossp.org/pkg/lib/uuid/.


Required for building PL/Python. Binaries can be downloaded from http://www.python.org.
Required for compression support in pg_dump and pg_restore. Binaries can be downloaded from http://www.zlib.net.
16.1.2. Special considerations for 64-bit Windows
PostgreSQL will only build for the x64 architecture on 64-bit Windows, there is no support for Itanium processors.
Mixing 32- and 64-bit versions in the same build tree is not supported. The build system will automatically detect if it's running in a 32- or 64-bit environment, and build PostgreSQL accordingly. For this reason, it is important to start the correct command prompt before building.
To use a server-side third party library such as python or openssl, this library must also be 64-bit. There is no support for loading a 32-bit library in a 64-bit server. Several of the third party libraries that PostgreSQL supports may only be available in 32-bit versions, in which case they cannot be used with 64-bit PostgreSQL.
16.1.3. Building
To build all of PostgreSQL in release configuration (the default), run the command:
To build all of PostgreSQL in debug configuration, run the command:

To build just a single project, for example psql, run the commands:
To change the default build configuration to debug, put the following in the buildenv.pl file:
Visual Studio Code Postgresql Connection
It is also possible to build from inside the Visual Studio GUI. In this case, you need to run:
from the command prompt, and then open the generated pgsql.sln (in the root directory of the source tree) in Visual Studio.
16.1.4. Cleaning and installing
Most of the time, the automatic dependency tracking in Visual Studio will handle changed files. But if there have been large changes, you may need to clean the installation. To do this, simply run the clean.bat command, which will automatically clean out all generated files. You can also run it with the dist parameter, in which case it will behave like make distclean and remove the flex/bison output files as well.
By default, all files are written into a subdirectory of the debug or release directories. To install these files using the standard layout, and also generate the files required to initialize and use the database, run the command:
16.1.5. Running the regression tests

To run the regression tests, make sure you have completed the build of all required parts first. Also, make sure that the DLLs required to load all parts of the system (such as the Perl and Python DLLs for the procedural languages) are present in the system path. If they are not, set it through the buildenv.pl file. To run the tests, run one of the following commands from the srctoolsmsvc directory:
To change the schedule used (default is parallel), append it to the command line like:
For more information about the regression tests, see Chapter 30.
16.1.6. Building the documentation
Building the PostgreSQL documentation in HTML format requires several tools and files. Create a root directory for all these files, and store them in the subdirectories in the list below.
Download from http://sourceforge.net/projects/openjade/files/openjade/1.3.1/openjade-1_3_1-2-bin.zip/download and uncompress in the subdirectory openjade-1.3.1.
Download from http://www.oasis-open.org/docbook/sgml/4.2/docbook-4.2.zip and uncompress in the subdirectory docbook.
Download from http://sourceforge.net/projects/docbook/files/docbook-dsssl/1.79/docbook-dsssl-1.79.zip/download and uncompress in the subdirectory docbook-dsssl-1.79.
Postgresql In Visual Studio Code
Download from http://www.oasis-open.org/cover/ISOEnts.zip and uncompress in the subdirectory docbook.
Edit the buildenv.pl file, and add a variable for the location of the root directory, for example:
Visual Studio Connect To Postgresql
To build the documentation, run the command builddoc.bat. Note that this will actually run the build twice, in order to generate the indexes. The generated HTML files will be in docsrcsgml.
