64

I just want to know how to install the module pg_tgrm as used in the trigram indexing scheme that allows you to do un-anchored search patterns on an index.

WHERE foo LIKE '%bar%';
1
  • I cleaned up this question, because it's a good question but has nothing to do with PostGIS or any of that stuff. Mar 28, 2018 at 1:34

3 Answers 3

78

pg_trgm is an extension, so:

CREATE EXTENSION pg_trgm;

If you get the following error

ERROR: could not open extension control file ".../extension/pg_trgm.control":
No such file or directory"

then you need to install the module for your operating system. For example:

  • Ubuntu/Debian:

      sudo apt install postgresql-contrib
    
  • Redhat/Centos

      sudo dnf install postgresql12-contrib
    
  • Fedora

      sudo dnf install postgresql-contrib
    
  • FreeBSD

      sudo pkg install postgresql12-contrib
    

Of course, "12" can be replaced with whatever version number is appropriate.

1
  • 2
    I experienced on MaxOSX following: if you install postgresql using conda/pip, then there seems to be no way to install the postgresql-contrib module; however, if you install postgresql using Homebrew, then this module is automatically installed.
    – chAlexey
    Aug 18, 2020 at 12:43
15

1) Log into postgres

psql -U <DB_USERNAME>

2) After you are connected, switch to the DB you want to install the extension for:

\c <DB_NAME>

3) Then install the extension as answered previously:

CREATE EXTENSION pg_trgm;

Installing the extension initially gave me issues because I was not doing step 2. I thought the installation was a global thing but it seems its per DB

0

To complete the answer of @Jendrusk for :

  • CentOs system you can also use
yum install postgresql-contrib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.