How to install trigram in postgresql?

Hello,

I’ve installed the pg_search gem in a Rails project and I got this error:

PG::UndefinedFunction: ERROR:  function word_similarity(unknown, text) does not exist

In my dev environment I simply connected to my local DB and executed this command:

CREATE EXTENSION pg_trgm;

I got the same error when deployed to Fly, connected to the DB using fly pg connect --app xxxx and tried to run the same query but with no success this time.

How should I install trigram in production?

Hi, can you detail how “no success” looks like? did you get an error like above?

Can you connect to your database fly pg connect --app xxxx and use this query to confirm the pg_trgm extension was created / added to the db?

select * from pg_extension;

  • Daniel

Thanks for your response, @roadmr.

The extension was created successfully, look:

But I’m getting the same error in my logs.

I found the issue: when I run fly pg connect --app xxx it gets connected to the default database. So I installed the extension in that database, not in the one the app is currently using. I had to connect to that database with the \c database_name command and then run the command again.

Also, I had to reboot the database with fly pg restart.

Now everything works!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.