Extensions, PostGIS, and Full Text Search Dictionaries on Heroku Postgres
Last updated May 12, 2023
Table of Contents
Extensions allow related pieces of functionality, such as datatypes and functions, to be bundled together and installed in a database with a single command. Heroku Postgres supports many Postgres extensions as well as features such as full text search that aren’t bundled as part of the extensions system. A beta version of the PostGIS spatial database extension is also available. Only the following extensions in this article are supported and can be installed on Heroku Postgres.
Query your database for the list of supported extensions:
$ echo 'show extwlist.extensions' | heroku pg:psql extwlist.extensions ----------------------------- ...bloom,btree_gin,btree_gist,cube,dblink,dict_int...
Install an Extension
To create any supported extension, open a session with
heroku pg:psql and run the appropriate
CREATE EXTENSION command:
$ heroku pg:psql DATABASE_URL -a example-app --> Connecting to postgresql-octagonal-12345 psql (13.2, server 11.12 (Ubuntu 11.12-1.pgdg16.04+1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. example-app::DATABASE=> CREATE EXTENSION hstore; CREATE EXTENSION example-app::DATABASE=>
Previously, all newly created extensions on Heroku Postgres databases were installed in the
heroku_ext schema. To install extensions outside of the
heroku_ext schema in a new database, set the
--allow-extensions-on-public-schema flag when provisioning your Postgres database:
$ heroku addons:create heroku-postgresql:standard-0 \ --allow-extensions-on-public-schema
This flag works all production-tier Heroku Postgres plans (Standard, Premium, Private, and Shield).
To install extensions outside of the
heroku_ext schema in an existing production-tier database, see the Heroku Data Labs: Extensions on Any Schema for Heroku Postgres article.
Upgrade an Extension
To see if your Heroku Postgres add-on has extension upgrades enabled, run the
heroku pg:info command and check the
Upgradable Extensions line. If this value is set to
No, then extensions are upgradable after the next scheduled maintenance.
=== DATABASE_URL Plan: Standard 0 Status: Available Data Size: 2.15 GB Tables: 4 PG Version: 15.2 Connections: 32/120 Connection Pooling: Available Credentials: 1 Fork/Follow: Available Rollback: earliest from 2023-04-21 17:14 UTC Created: 2023-04-17 19:06 Region: us Data Encryption: In Use Continuous Protection: On Enhanced Certificates: Off Upgradable Extensions: Yes Maintenance: not required Maintenance window: Mondays 17:30 to 21:30 UTC Add-on: postgresql-trapezoidal-57207
To upgrade an extension, run the
ALTER EXTENSION command on the extension you want to upgrade in a
heroku pg:psql session:
$ heroku pg:psql DATABASE_URL -a example-app --> Connecting to postgresql-octagonal-12345 psql (13.2, server 11.12 (Ubuntu 11.12-1.pgdg16.04+1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. example-app::DATABASE=> CREATE EXTENSION btree-gin VERSION '1.0'; CREATE EXTENSION example-app::DATABASE=> ALTER EXTENSION btree_gin UPDATE to '1.1'; ALTER EXTENSION example-app::DATABASE=>
Bloom provides space-efficient bloom filter indexes.
create extension bloom
Case Insensitive Text. Case insensitive text datatype. Although strings stored in citext do retain case information, they’re case insensitive when used in queries.
create extension citext
Cube: Multi-dimensional cubes.
create extension cube
HStore: Key value store inside Postgres.
create extension hstore
Label Tree: Tree-like hierarchies, with associated functions.
create extension ltree
Large Objects: Provides stream-style access to user data that is stored in a special large-object structure.
create extension lo
Product Numbering: Store product IDs and serial numbers such as UPC, ISBN, and ISSN.
create extension isn
Seg: Provides a type for representing segments or floating point intervals.
create extension seg
Foreign Data Wrappers
- postgres_fdw Allows a Postgres database to talk to another Postgres database as a foreign server.
Foreign data wrappers aren’t available for Essential-tier databases.
Address Standardizer: Single line address parser that normalizes addresses around a set of defined rules
create extension address_standardizer. A set of rules for US addresses is already included
create extension address_standardizer_data_us.
Autoinc: Stores the next value of a sequence into an integer field.
create extension autoinc
Earth Distance: Functions for calculating the distance between points on the earth.
create extension earthdistance
Fuzzy Match: Another method for determining the similarity between strings. Limited UTF-8 support.
create extension fuzzystrmatch.
Insert Username: Inserts the current user’s name into a text field.
create extension insert_username
Intarray: Sorting, manipulate, and create indexes on null-free arrays of integers.
create extension intarray
ModDateTime: Inserts the current timestamp into a timestamp field.
create extension moddatetime
PGCrypto: Cryptographic functions allow for encryption within the database
create extension pgcrypto.
pg_partman: Create and manage both time-based and serial-based table partition sets. Sub-partitioning is also supported.
pg_prewarm: Preload data into the operating system, or database buffer cache to help normalize performance on a freshly started, or quiescent database.
pg_partman and pg_prewarm aren’t available for Essential-tier databases.
sslinfo: Provides functions to query SSL information about connecting clients.
create extension sslinfo
Table Functions & Pivot Tables: Functions returning full tables, including the ability to manipulate query results in a manner similar to spreadsheet pivot tables
create extension tablefunc.
tcn: Provides a trigger function for notifying listeners of changes to tables.
create extension tcn
Timetravel: Adds functions for querying historical data.
create extension timetravel
Trigram: Determine the similarity (or lack thereof) of alphanumeric string based on trigram matching. Useful for natural language processing problems such as search.
create extension pg_trgm.
tsm_system_rows Provides table sampling via system rows.
create extension tsm_system_rows
tsm_system_time Provides table sampling via system time.
create extension tsm_system_time
UUID Generation: Generate v1, v3, v4, and v5 UUIDs in-database. Works great with the existing UUID datatype
create extension "uuid-ossp".
- Row Locking: Show row lock information for a table.
create extension pgrowlocks
btree-gist: A GiST index operator. It’s generally inferior to the standard B-tree index, except for multi-column indexes that can’t be used with B-tree and exclusion constraints.
create extension btree_gist
btree-gin: A GIN index operator. It’s generally inferior to the standard B-tree index, except for developing new GIN operator classes or creating a multicolumn GIN index for both GIN-indexable and btree-indexable columns.
Full Text Search Dictionaries
dict-int - A full-text search dictionary for full-text search that controls how integers are indexed.
create extension dict_int
unaccent - A filtering text dictionary that removes accents from characters.
create extension unaccent
Additionally, the following dictionaries are installed by default and don’t require creation via the extension system:
$ heroku pg:psql => \dFd List of text search dictionaries Schema | Name | Description ------------+-----------------+------------------------------- pg_catalog | danish_stem | snowball stemmer for danish language pg_catalog | dutch_stem | snowball stemmer for dutch language pg_catalog | english_stem | snowball stemmer for english language pg_catalog | finnish_stem | snowball stemmer for finnish language pg_catalog | french_stem | snowball stemmer for french language pg_catalog | german_stem | snowball stemmer for german language pg_catalog | hungarian_stem | snowball stemmer for hungarian language pg_catalog | italian_stem | snowball stemmer for italian language pg_catalog | norwegian_stem | snowball stemmer for norwegian language pg_catalog | portuguese_stem | snowball stemmer for portuguese language pg_catalog | romanian_stem | snowball stemmer for romanian language pg_catalog | russian_stem | snowball stemmer for russian language pg_catalog | simple | simple dictionary: just lower case and check for stopword pg_catalog | spanish_stem | snowball stemmer for spanish language pg_catalog | swedish_stem | snowball stemmer for swedish language pg_catalog | turkish_stem | snowball stemmer for turkish language
dblink Adds support for querying between Postgres databases. With dblink you can query between separate Heroku Postgres databases or to and from external Postgres databases.
dblink isn’t available for Essential-tier databases
The pg_stat_statements module provides a means for tracking execution statistics of all SQL statements executed by a server.
pg_stat_statements can be used to track performance problems. It provides a view called pg_stat_statements that displays each query that has been executed, and associated costs, including the number of times the query was executed, the total system time execution has taken in aggregate, and the total number of blocks in shared memory hit in aggregate.
pg_stat_statements doesn’t capture any queries that were canceled, no matter how long they ran beforehand. This means that long running queries canceled by
statement_timeout isn’t reflected in the pg_stat_statements view. You must use the Postgres logs to diagnose expensive canceled queries effectively.
The PostGIS module adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS “spatially enables” the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS).
PostGIS support on Heroku Postgres is in beta and is subject to change in the future.
You can use PostGIS with Standard-tier or higher databases and on Essential-tier databases.
The current latest supported versions of PostGIS on Heroku Postgres are:
- PostGIS v2.5, for databases running on PostgreSQL 13 or earlier
- PostGIS v3.3, for databases running on PostgreSQL 14 or later
PostGIS support can be added like any other extension, as long as your database meets the requirements earlier.
To install PostGIS in an existing Heroku Postgres database, open a
psql session, and run
CREATE EXTENSION postgis;:
$ heroku pg:psql DATABASE_URL -a example-app --> Connecting to postgresql-octagonal-12345 psql (13.2, server 11.12 (Ubuntu 11.12-1.pgdg16.04+1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. example-app::DATABASE=> CREATE EXTENSION postgis; CREATE EXTENSION
To check if PostGIS is installed on a database, run the following query from
=> SELECT postgis_version(); postgis_version --------------------------------------- 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 (1 row)
Extensions That Are No Longer Supported
- PLV8 - During the Heroku beta period for this extension, the PLV8 package maintenance was discontinued for PG11+ for Debian/Ubuntu. Read more here. If this changes, we reinstitute PLV8.