postgis / docker-postgis

Docker image for PostGIS
https://hub.docker.com/r/postgis/postgis/
MIT License
1.39k stars 466 forks source link

incorrect ctype and collation in database #198

Closed UlrichKnaack closed 4 years ago

UlrichKnaack commented 4 years ago

I've tried to apply german character encoding in my database, but I got C.UTF-8. This is my setup:

version: "3"

services:
    pgis:
        image: postgis/postgis:12-3.0
        container_name: pgis
        volumes:
            - pgisdb:/var/lib/postgresql/data/
            - ./init/:/docker-entrypoint-initdb.d/
            # - ./init/sql/:/docker-entrypoint-initdb.d/sql/
        ports:
            - "5432:5432"
        restart: always
        env_file: env-pgis

    pgadmin4:
        image: dpage/pgadmin4:4.21
        volumes:
            - pgadmin4:/pgadmin4
            - pgadmin4lib:/var/lib/pgadmin
        ports:
            - "8085:80"
        env_file: env-pgadmin

volumes:
    pgisdb:
    pgadmin4:
    pgadmin4lib:
    init:

env-pgis:

POSTGRES_USER=bop
POSTGRES_PASSWORD=mypass
POSTGRES_DBNAME=pgis
DEFAULT_COLLATION=de_DE.UTF-8
DEFAULT_CTYPE=de_DE.UTF-8
DEFAULT_ENCODIG=UTF8

Output (extract) from docker-compose logs:

pgis        | The database cluster will be initialized with locale "en_US.utf8".
pgis        | The default database encoding has accordingly been set to "UTF8".
pgis        | The default text search configuration will be set to "english".
ImreSamu commented 4 years ago

imho:

see https://hub.docker.com/_/postgres "Locale Customization" part. just replace the FROM part to postgis/postgis:12-3.0 and build a new docker image - for yourself ..

FROM postgis/postgis:12-3.0
RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8
ENV LANG de_DE.utf8

and don't forget ... it is only working for empty postgresql data .... ( in your spec: - pgisdb:/var/lib/postgresql/data/ ) https://www.postgresql.org/docs/12/locale.html#id-1.6.10.3.4 "Locale support is automatically initialized when a database cluster is created .... "

ImreSamu commented 4 years ago

or a similar solution :

UlrichKnaack commented 4 years ago

thank you, now it works as expected.