Neon Extensions: Every Postgres Extension Supported
Neon supports a wide and growing range of PostgreSQL extensions, allowing you to leverage powerful specialized functionalities directly within your managed PostgreSQL database.
Here’s how you can explore and enable extensions in Neon, along with a look at some of the most commonly used ones.
Discovering Available Extensions
Neon automatically makes many popular PostgreSQL extensions available. You don’t need to install them in the traditional sense; you just need to enable them for your database.
To see the extensions currently available in your Neon project, you can query the pg_available_extensions catalog table. Connect to your Neon database using psql or any other client:
psql "postgresql://[user]:[password]@[neon_host]:5432/[db_name]?sslmode=require"
Once connected, run:
SELECT name, default_version, installed_version, comment
FROM pg_available_extensions
ORDER BY name;
This will list all extensions that Neon has pre-packaged, their default version, and whether they are currently installed in your database.
Enabling Extensions
To enable an extension in your Neon database, use the CREATE EXTENSION command. This command makes the extension’s functions, data types, and other objects available within your current database.
For example, to enable the uuid-ossp extension, which provides functions for generating universally unique identifiers:
CREATE EXTENSION "uuid-ossp";
If you try to create an extension that is already installed, PostgreSQL will issue a notice but won’t fail. You can check if an extension is installed by querying pg_extension:
SELECT extname FROM pg_extension WHERE extname = 'uuid-ossp';
Common and Useful Extensions in Neon
Neon supports a broad spectrum of extensions. Here are some that are frequently used and highly beneficial:
-
pgcrypto: This extension provides cryptographic functions for tasks like hashing passwords, encrypting data, and generating random numbers. It’s essential for security-sensitive applications.CREATE EXTENSION IF NOT EXISTS pgcrypto; -
uuid-ossp: As mentioned, this is invaluable for generating various types of UUIDs, which are useful for primary keys and unique identifiers without relying on sequential values.CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -
hstore: This extension adds a data type for storing sets of key/value pairs within a single PostgreSQL value. It’s excellent for semi-structured data.CREATE EXTENSION IF NOT EXISTS hstore; -
postgis: For geospatial data, PostGIS is the de facto standard. It adds support for geographic objects, allowing you to perform spatial queries and analyses.CREATE EXTENSION IF NOT EXISTS postgis; -
citext: This extension provides a case-insensitive character string type. It’s simpler and often more performant than usinglower()functions on text columns for case-insensitive comparisons.CREATE EXTENSION IF NOT EXISTS citext; -
pg_trgm: Useful for fuzzy string matching and speeding upLIKEqueries using trigram matching. It can significantly improve performance for text searches.CREATE EXTENSION IF NOT EXISTS pg_trgm; -
jsonb_plpython3u: If you need to process JSONB data using Python, this extension allows you to write functions in Python that can operate on JSONB types.CREATE EXTENSION IF NOT EXISTS plpython3u; -- Note: plpython3u is often a prerequisite for other Python extensions
Managing Extensions
To remove an extension from your database, use the DROP EXTENSION command. This will remove the extension’s objects from your database. Be cautious, as this can break queries or applications that rely on the extension.
DROP EXTENSION "uuid-ossp";
If you try to drop an extension that is not installed, PostgreSQL will issue an error. You can use DROP EXTENSION IF EXISTS to avoid this.
The pg_available_extensions View
The pg_available_extensions view is your primary tool for understanding what’s on offer. It’s a system catalog view that reflects the extensions compiled into the PostgreSQL server binary that your Neon instance is running. Neon manages the underlying PostgreSQL versions, and as those versions are updated, the set of available extensions can change.
The default_version column shows the version of the extension that will be installed if you run CREATE EXTENSION extension_name; without specifying a version. The installed_version column will be NULL if the extension is not currently enabled in your database.
When you CREATE EXTENSION, Neon ensures that the necessary files and configurations are in place for that specific extension within the context of your database. This is different from traditional self-hosted PostgreSQL where you might need to install extension packages at the operating system level or compile them from source.
Beyond the commonly used extensions, Neon also supports many others that cater to specific needs, such as full-text search enhancements (tsm_system_rows, tsm_system_time), foreign data wrappers, and more. The pg_available_extensions view is always the definitive source for what’s immediately ready for use in your Neon environment. If you require an extension not listed there, you might need to consider alternative approaches like custom extensions or application-level logic.
The next step after enabling extensions is often learning how to integrate their functionalities into your SQL queries and application logic to unlock their full potential.