Skip to main content

"Installing pg_trgm on Windows: A Step-by-Step Guide"

Updated by Tim Rabbetts on
Installing pg_trgm on Windows: A Step-By-Step Guide

Installing pg_trgm on Windows: A Step-By-Step Guide

If you are a developer working with PostgreSQL on a Windows machine, you may encounter the need to install pg_trgm, a PostgreSQL extension that provides fuzzy string matching capabilities. This step-by-step guide will walk you through the process of installing pg_trgm on a Windows environment.

Step 1: Download the Extension

The first step is to download the pg_trgm extension from the PostgreSQL Extension Network (https://www.postgresql.org/ftp/source/v11/pg_trgm-1.5.tar.gz). Make sure to download the version that is compatible with your PostgreSQL installation.

Step 2: Extract the Files

Once the download is complete, extract the contents of the downloaded file to a directory on your computer. You will find a set of files related to the pg_trgm extension in the extracted folder.

Step 3: Build the Extension

Next, open a command prompt window and navigate to the directory where you extracted the files. Run the following command to build the extension:

$ cd path/to/pg_trgm
$ make
$ make install

Step 4: Modify the PostgreSQL Configuration

After successfully building and installing the extension, you need to modify the PostgreSQL configuration to enable the pg_trgm extension. Open the postgresql.conf file located in the data directory of your PostgreSQL installation and add the following line:

shared_preload_libraries = 'pg_trgm'

Step 5: Restart PostgreSQL

Save the changes to the postgresql.conf file and restart the PostgreSQL service to apply the modifications. You can do this using the following command:

$ pg_ctl restart

Step 6: Verify the Installation

To verify that the pg_trgm extension has been successfully installed, connect to your PostgreSQL database and run the following query:

SELECT * FROM pg_extension WHERE extname = 'pg_trgm';

If the query returns a row with the name 'pg_trgm', then the installation was successful.

Conclusion

By following these steps, you should be able to successfully install the pg_trgm extension on a Windows machine running PostgreSQL. This extension will allow you to perform fuzzy string matching operations within your PostgreSQL database, enhancing the capabilities of your applications.

References:

  1. PostgreSQL Extension Network: https://www.postgresql.org/ftp/source/v11/pg_trgm-1.5.tar.gz