[Solved] How to solve: `could not open extension control file "/opt/homebrew/opt/postgresql@13/share/postgresql@13/extension/postgis.control`? – Postgresql

by
Maya Patel
homebrew macos postgis postgresql

Quick Fix: If you encounter the error "could not open extension control file", it might be due to version incompatibility. Try switching to a compatible version of PostgreSQL and PostGIS using Homebrew services.

The Problem:

While attempting to restore databases from .sql files using pgAdmin4 on macOS 13.5.2 with Apple M2 chip, an error message is encountered:

pg_restore: error: could not execute query: ERROR: could not open extension control file "/opt/homebrew/opt/postgresql@13/share/postgresql@13/extension/postgis.control": No such file or directory

Additionally, trying to create the ‘postgis’ extension in the psql terminal results in the same error message.

Relevant information:

  1. which psql returns: /opt/homebrew/opt/postgresql@13/bin/psql.
  2. which pg_config returns: /opt/homebrew/opt/postgresql@13/bin/pg_config.
  3. brew info postgis shows: postgis: stable 3.3.4 (bottled), HEAD.
  4. brew info postgresql@13 indicates: postgresql@13: stable 13.12 (bottled) [keg-only].

The goal is to resolve the error and enable successful database restoration and extension creation.

The Solutions:

Solution 1: Downgrade to PostgreSQL 14

The issue may arise due to version incompatibility between PostgreSQL and PostGIS. In this case, the installed versions are PostgreSQL 13 and PostGIS 3.3.4, which are not compatible. To resolve the problem, downgrade PostgreSQL to version 14, which is compatible with PostGIS 3.3.4.

  1. Stop the current PostgreSQL service:
  2. brew services stop postgresql@15
  3. Start PostgreSQL 14:
  4. brew services start postgresql@14
  5. Try creating/using the PostGIS extension again. The error should be resolved.

Q&A

How to solve "could not open extension control file "/opt/homebrew/opt/postgresql@13/share/postgresql@13/extension/postgis.control"?"

The error could be caused by version mismatched. Try using compatible versions of postgresql and postgis.

What to do if I am using the same compatible versions of Postgis and Postgresql?

Try running "brew reinstall postgis" to reinstall postgis latest version.

Video Explanation:

The following video, titled "How to Solve Excel Cannot Open the File ... Because the File Format ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

How to Solve Excel Cannot Open the File ... Because the File Format or File Extension Is Not Valid. Did you get an error message of 'Excel ...