Skip to content

Instantly share code, notes, and snippets.

@ricardovelero
Forked from AlexVKO/add_unaccent_to_postgres
Created December 28, 2022 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardovelero/e1b070a10e16fd1a79123492468847a8 to your computer and use it in GitHub Desktop.
Save ricardovelero/e1b070a10e16fd1a79123492468847a8 to your computer and use it in GitHub Desktop.
Adding extensions to Postgresql database with Rails
The default Postgresql installation on Mac OS X using homebrew includes a single extension - plpgsql (PL/pgSQL procedural language) but there are a number of them available in the lib directory (/usr/local/Cellar/postgresql/9.2.1/lib on my machine)
To install an extension into the database, the easiest way I found was to open a database console using the 'rails db' command and then create it directly. I have seen mention of doing this in a Rails migration but this did not work for me.
Note that an extension is installed in a specific database, rather than being added to all databases.
The command to list the installed extensions is '\dx'
$ rails db
psql (9.2.1)
Type "help" for help.
tabs_development=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
tabs_development=# create extension unaccent;
CREATE EXTENSION
tabs_development=# \dx
List of installed extensions
Name | Version | Schema | Description
----------+---------+------------+---------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
unaccent | 1.0 | public | text search dictionary that removes accents
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment