PG::UndefinedFile: ERROR: could not open extension control file

PG::UndefinedFile: ERROR: could not open extension control file

升级 Postgres 后,当我尝试迁移数据库时出现以下错误。

enable_extension(:postgis)
  SQL (17.2ms)  CREATE EXTENSION IF NOT EXISTS "postgis"
PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS "postgis"
   (0.3ms)  ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS "postgis"/Users/harshamv/Sites/clink/db/migrate/20150812164615_enable_postgis.rb:3:in `change'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS "postgis"
/Users/harshamv/Sites/clink/db/migrate/20150812164615_enable_postgis.rb:3:in `change'
-e:1:in `<main>'
PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory
/Users/harshamv/Sites/clink/db/migrate/20150812164615_enable_postgis.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

不确定从哪里开始。大多数其他问题似乎与 Linux 有关,当我尝试创建符号链接时它也不起作用。

你应该安装 postgresql-9.4-postgis-2.1

对于 MacOS,我使用以下命令安装 postgis:

brew install postgis

对于 Ubuntu,以下命令有效:

sudo apt install postgresql-10-postgis-scripts

检测可用的 postgresql postgis 版本

sudo apt-cache search postgis

安装

sudo apt install postgresql-12-postgis-3-scripts 

切换 postgres 用户

sudo -i -u postgres

创建一个数据库,然后连接它。在此之后运行 postgis 扩展激活命令

CREATE EXTENSION postgis;

以后可以通过

查看验证
SELECT PostGIS_version();