How to Fix PostgreSQL Error: Extension Does Not Exist

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

  1. Extension not installed in database
  2. Extension package not installed on system
  3. Working in wrong database
  4. Insufficient privileges to install extension
  5. Extension renamed or deprecated in newer PostgreSQL versions

Troubleshooting and Resolution Steps

  1. 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';
    
  2. 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;
    
  3. 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;"
    
  4. 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;
    
  5. Drop and reinstall extension:

    -- Drop extension (cascade drops dependent objects)
    DROP EXTENSION IF EXISTS pgcrypto CASCADE;
    
    -- Reinstall
    CREATE EXTENSION pgcrypto;
    
  6. 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';
    
  7. 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.

Pulse - Elasticsearch Operations Done Right

Pulse can solve your Elasticsearch issues

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.