如何在 docker 中为 postgresql 创建 postgis 扩展?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27547933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create postgis extension for postgresql in docker?
提问by user1685095
I'm getting errors when trying to create postgis extensions.
尝试创建 postgis 扩展时出现错误。
Here is what my dockerfile looks like.
这是我的 dockerfile 的样子。
from postgres
RUN apt-get update && apt-get install postgis -y
ADD /create_postgis_extension.sh /docker-entrypoint-initdb.d/
create.bla-bla..sh
create.bla-bla..sh
#!/bin/sh
POSTGRES="gosu postgres postgres"
$POSTGRES --single -E <<EOSQL
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
EOSQL
And here is the error when running the image
这是运行图像时的错误
backend> statement: CREATE EXTENSION postgis;
后端> 语句:CREATE EXTENSION postgis;
ERROR: type addbandarg[] does not exist STATEMENT: CREATE EXTENSION postgis;
错误:类型 addbandarg[] 不存在声明:创建扩展 postgis;
backend> statement: CREATE EXTENSION postgis_topology;
后端> 语句:CREATE EXTENSION postgis_topology;
backend> ERROR: required extension "postgis" is not installed
后端> 错误:未安装所需的扩展“postgis”
I'm doing something wrong obviously, but I don't know what. Why is postgis in not installed if I've installed postgis with apt-get.
我显然做错了什么,但我不知道是什么。如果我用 apt-get 安装了 postgis,为什么没有安装 postgis。
回答by Solway01
I am using CentOS rather than Debian but ran into the same problem. The solution basically came down to using pg_ctl to start/stop postgres.
我正在使用 CentOS 而不是 Debian,但遇到了同样的问题。解决方案基本上归结为使用 pg_ctl 来启动/停止 postgres。
sudo -u postgres pg_ctl start -w -D ${PGDATA}
sudo -u postgres createdb postgis_template -E UTF8
sudo -u postgres psql -d postgis_template -c "create extension if not exists postgis;"
sudo -u postgres pg_ctl stop -w
回答by LittleEaster
It is possible that you installed the wrong version of postgis for that postgres?
addbang[] exists from version 2.1.0, there was an issue around that between 2.0 and 2.1.
RedHat family has less of those issues due their behavior of getting updates less frequently (who go slow...)
您可能为该 postgres 安装了错误版本的 postgis?
addbang[] 从版本 2.1.0 开始存在,在 2.0 和 2.1 之间存在一个问题。
RedHat 系列的问题较少,因为他们更新更新的频率较低(谁变慢了......)
That being said.
The docker-entrypoint-initdb.d is managed by docker-entrypoint.sh internal script , this runs only when the PGDATA folder do NOT exists.
This init script is able to manage some files: .sh, .sql and .sql.tar.gz.
Those are executed in alphabetic order by docker's user postgres.
话虽如此。
docker-entrypoint-initdb.d 由 docker-entrypoint.sh 内部脚本管理,这仅在 PGDATA 文件夹不存在时运行。
这个 init 脚本能够管理一些文件:.sh、.sql 和 .sql.tar.gz。
这些由 docker 的用户postgres按字母顺序执行。
Rather than use sh to do sql, use sql.
create_postgis_extension.sql:
与其用sh做sql,不如用sql。
create_postgis_extension.sql:
CREATE EXTENSION IF NOT EXISTS POSTGIS;
CREATE EXTENSION IF NOT EXISTS POSTGIS_TOPOLOGY;
clean&simple
干净简单
Regards.
问候。