Extensions
An extension adds types, functions and operators to PostgreSQL, such as the vector type from pgvector. You turn on an extension in your Amplify backend database with a migration, and a deployment applies the migration to the environment that you deploy to.
Turn on an extension
Add a create extension statement to a migration. Use the same form for every extension:
-- The quotes keep a name such as "uuid-ossp" valid. -- "cascade" first installs the extensions that this one needs, such as cube -- for earthdistance, and puts the languages pltcl and plv8 in -- pg_catalog, where they must go. create extension if not exists "vector" with schema extensions cascade;
Commit the migration, and run the following command to deploy it to preview:
aws amplifygen3 deploy --env preview
To turn on the extension in another environment, such as production, deploy the migration to that environment.
For more information about creating and deploying migrations, see Tables and migrations.
Use an extension
You use an extension’s types and functions in SQL without a schema name, because the extensions schema is on the search path of every database login. The following migration adds a vector column to a table:
create table public.documents ( id bigint generated always as identity primary key, body text not null, embedding vector(3) );
The data API serves only the public schema. To call an extension’s function from your app, wrap it in a function in public, and call that function. The following migration wraps similarity from pg_trgm:
create function public.search_projects(term text) returns setof public.projects language sql stable as $$ select * from public.projects order by similarity(name, term) desc limit 10 $$; grant execute on function public.search_projects(text) to authenticated;
For more information about calling a function from your app, see Call database functions.
Turn off an extension
To turn off an extension, write a migration that drops the objects that use it, and then drops the extension:
alter table public.documents drop column embedding; drop extension if exists "vector";
Allowed extensions
You can turn on the following 28 extensions in a deployed backend.
| Use | Extensions | Note |
|---|---|---|
|
Vector search |
|
|
|
Geospatial data |
|
|
|
Text search and matching |
|
|
|
Data types |
|
|
|
Indexes and query plans |
|
|
|
IDs and cryptography |
|
|
|
Procedural languages |
|
|
|
Crosstab queries |
|
|
|
Change notifications |
|
|
|
Table sampling |
|
pg_available_extensions also lists extensions that aren’t in this table, such as pg_cron, dblink, postgres_fdw and pg_stat_statements. A migration that creates one of them fails the deployment with permission denied to create extension (42501).
For the version of each extension, see Extensions supported for Aurora PostgreSQL 17.
PostgreSQL includes gen_random_uuid(), full-text search with to_tsvector and to_tsquery, and GIN indexes on jsonb columns, with no extension to turn on.
Extensions on the local backend
For the allowed extensions that the local backend includes, and how to work with the others, see Local database.
Extension errors
| Error | Cause | Fix |
|---|---|---|
|
|
The extension isn’t in Allowed extensions. The deployment fails |
Use an allowed extension, or remove the statement |
|
|
|
Add |
|
|
|
Add |
|
|
|
Drop the objects that use the extension, then drop the extension without |
For other migration errors, see Tables and migrations.