skip to Main Content

I’ve a problem when creating extension postgis, in postgresql and Docker. I’ve read many post and tutorials, but I’ve failed 🙂
I’m working on WSL :

# uname -a
Linux 6019b3c71dfc 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux

# psql -U user -d database -h db
psql (11.14 (Debian 11.14-0+deb10u1), server 10.18)
Type "help" for help.

massifs=# CREATE EXTENSION postgis;
ERROR:  could not open extension control file "/usr/local/share/postgresql/extension/postgis.control": No such file or directory

So, I find the postgis.control file :

#  find /usr -name postgis.control
/usr/share/postgresql/11/extension/postgis.control

And copy it (and change permissions if needed) in the right folder : cp /usr/share/postgresql/11/extension/postgis.control /usr/local/share/postgresql/extension

But the error is the same 🙁

I’ve installed all the libs required :

# dpkg -l | grep postgis
ii  postgis                              2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL
ii  postgis-doc                          2.5.1+dfsg-1                 all          Geographic objects support for PostgreSQL -- documentation
ii  postgis-gui                          2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL -- GUI programs
ii  postgresql-11-postgis-2.5            2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL 11
ii  postgresql-11-postgis-2.5-scripts    2.5.1+dfsg-1                 all          Geographic objects support for PostgreSQL 11 -- SQL scripts

Same error 🙁

My docker-compose.yaml :

#./dj/docker-compose.yml
version: '3.7'

services:
  web:
    env_file:
      - ./env/django.env
    build:
         context: ./myproject
         dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./myproject:/opt/myproject
    ports:
      - "8050:8000"
    depends_on:
      - db
    restart: always

  db:
    env_file:
      - ./env/postgresql.env
    image: postgis/postgis
    #image: postgres:10-alpine
    container_name: postgres_container_myproject
    hostname: db
    volumes:
      - /var/lib/postgresql/data-myproject:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: always

  pgadmin:
    env_file:
      - ./env/pgadmin.env
    image: dpage/pgadmin4
    container_name: pgadmin_container_myproject
    ports:
      - "8059:80"
    volumes:
      - /var/lib/pgadmin/data:/var/lib/pgadmin/data
    links:
      - "db:pgsql-server"
    restart: always
    logging:
      driver: none

volumes:
  pgadmin_data:
  postgres_data:
    driver: local

Have you an idea please ?

2

Answers


  1. Note that you are connecting to the wrong server or have a server of a wrong version:

    psql (11.14 (Debian 11.14-0+deb10u1), server 10.18)
    

    reports a server version of 10 (10.18) which is definitly not installed by the package postgresql-11-postgis-2.5 (that is for version 11).

    I assume you are connecting to a different machine/container (not localhost) that does not have the correct packages installed.

    Login or Signup to reply.
  2. I’ve been using postgis/docker-postgis for if you want to check how they are doing it the Dockerfile is a good place

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search