rgeo/activerecord-postgis-adapter

"PG::UndefinedFile: ERROR: could not open extension control file" when creating DB

Croge32 opened this issue ยท 9 comments

So I've set up the database according to the README regarding installation of the gem and adjusting the database.yml file. I also installed postgis via Homebrew as well as downloaded the Postgres.app.

I'm getting this issue when I either run rails db:create or rails db:gis:setup:

PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS postgis
Couldn't create database for {"adapter"=>"postgis", "database"=>"db_name", "encoding"=>"utf8", "username"=>"postgres", "password"=>nil, "host"=>"db", "min_messages"=>"warning", "pool"=>5, "reaping_frequency"=>10, "timeout"=>5000}
rails aborted!
ActiveRecord::StatementInvalid: PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory

My database.yml:

development: &default
  adapter: postgis
  database: db_name
  encoding: utf8
  username: <%= ENV.fetch("DB_USER", "postgres") %>
  password:
  host: <%= ENV.fetch("DB_HOST") %>
  min_messages: warning
  pool: <%= Integer(ENV.fetch("DB_POOL", 5)) %>
  reaping_frequency: <%= Integer(ENV.fetch("DB_REAPING_FREQUENCY", 10)) %>
  timeout: 5000

test:
  <<: *default
  database: db_name

production: &deploy
  <<: *default
  encoding: utf8
  min_messages: warning
  pool: <%= [Integer(ENV.fetch("MAX_THREADS", 5)), Integer(ENV.fetch("DB_POOL", 5))].max %>
  timeout: 5000
  url:  <%= ENV.fetch("DATABASE_URL", "") %>

staging: *deploy

Any idea where the issue is in my setup? Seems like maybe I don't have PostGis installed properly? This app/database lives on a docker container as well, if that's relevant or requires some special setup.

lym commented

@Croge32 What is the underlying Operating System in your container? It might help to install/include your OS's equivalence of this in your image.

You're probably missing the PostGIS scripts. On Ubuntu, they're in a separate package (see comment from @lym). Try doing psql -c "create extension postgis".

Closing, as this is not a bug with this adapter.

For me i run this below command on Ubuntu and all is well settled now.
sudo apt install postgresql-10-postgis-scripts

@geobudex Thanks, it works.

For future reference

  1. if you have upgraded from postgres10 to 11 then you will have reinstall the postgis extension again.
  2. if that also does not work then you will have to purge postgres 10 completely from the system and then install postgis.

I can confirm that the following worked for me as well. This is indeed a problem on postgres10 kicking around along postgres11.
$ sudo apt install postgresql-10-postgis-scripts

For MacOS, installing postgis worked for me using below command:

brew install postgis

For Ubuntu, below command works:

sudo apt install postgresql-10-postgis-scripts

Hi @faisalrazap
It does work for me. It's very helpful for me.
Thank you.