The "Extension does not exist" error occurs when trying to use or drop an extension that hasn't been installed in the current database. Extensions provide additional functionality like full-text search, encryption, or specialized data types.
Impact
This error prevents use of extension features, can break applications relying on extension functions, and blocks migrations that expect extensions to be available.
Common Causes
- Extension not installed in database
- Extension package not installed on system
- Working in wrong database
- Insufficient privileges to install extension
- Extension renamed or deprecated in newer PostgreSQL versions
Troubleshooting and Resolution Steps
List available and installed extensions:
-- Show all available extensions SELECT * FROM pg_available_extensions ORDER BY name; -- Show installed extensions \dx -- OR SELECT * FROM pg_extension; -- Check specific extension SELECT * FROM pg_available_extensions WHERE name = 'pgcrypto';Install extension:
-- Install extension CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS pg_trgm; -- Install in specific schema CREATE EXTENSION IF NOT EXISTS pgcrypto SCHEMA public;Install system package if extension not available:
# Ubuntu/Debian sudo apt-get update sudo apt-get install postgresql-contrib-15 sudo apt-get install postgresql-15-postgis-3 # RedHat/CentOS sudo yum install postgresql15-contrib sudo yum install postgis33_15 # After installing, connect and create extension psql -d mydb -c "CREATE EXTENSION postgis;"Common useful extensions:
-- UUID generation CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; SELECT uuid_generate_v4(); -- Cryptographic functions CREATE EXTENSION IF NOT EXISTS pgcrypto; SELECT crypt('password', gen_salt('bf')); -- Full-text search improvements CREATE EXTENSION IF NOT EXISTS pg_trgm; -- JSON functions (usually built-in) CREATE EXTENSION IF NOT EXISTS btree_gin; -- PostGIS for geographic data CREATE EXTENSION IF NOT EXISTS postgis;Drop and reinstall extension:
-- Drop extension (cascade drops dependent objects) DROP EXTENSION IF EXISTS pgcrypto CASCADE; -- Reinstall CREATE EXTENSION pgcrypto;Check extension version:
-- View installed extensions with versions SELECT extname AS extension_name, extversion AS version FROM pg_extension; -- Update extension to newer version ALTER EXTENSION pgcrypto UPDATE TO '1.3';Grant extension usage:
-- After creating extension, grant usage GRANT USAGE ON SCHEMA public TO appuser; -- For functions in extension GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO appuser;
Additional Information
- Extensions are per-database, not server-wide
- Most common extensions come with postgresql-contrib package
- Some extensions require superuser to install
- Extensions can depend on other extensions
- Check PostgreSQL version compatibility for extensions
Frequently Asked Questions
Q: Do I need to install extensions in every database?
A: Yes, extensions are database-specific. Install in each database where needed.
Q: Can non-superusers install extensions?
A: Some extensions can be installed by database owners if granted appropriate privileges. Others require superuser.
Q: Where can I find more extensions?
A: Check PGXN (PostgreSQL Extension Network) at pgxn.org and the contrib package included with PostgreSQL.
Q: What if the extension I need isn't available?
A: Install the system package first, then CREATE EXTENSION. Some extensions require manual compilation.