使用docker-compose的Postgres db的初始化脚本正在运行,但是更改似乎没有生效

时间:2020-03-13 16:44:14

标签: postgresql docker docker-compose

在我的docker-compose文件中,我具有以下内容:

services:
  delivery_psql:
    container_name: delivery_psql
    image: postgres:11.6
    restart: always
    environment:
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
    volumes:
      - ./databases/delivery_psql/init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - 5432:5432

init.sql的内容是:

CREATE DATABASE delivery;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE SCHEMA IF NOT EXISTS test;

我运行docker-compose stop delivery_psql && docker-compose rm delivery_psql && docker-compose up delivery_psql

我得到以下输出,告诉我init.sql中的命令已执行-安装了扩展名并创建了测试模式:

delivery_psql                   | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
delivery_psql                   | CREATE DATABASE
delivery_psql                   | CREATE EXTENSION
delivery_psql                   | CREATE SCHEMA
delivery_psql                   |
delivery_psql                   |
delivery_psql                   | 2020-03-13 16:38:38.776 UTC [44] LOG:  received fast shutdown request
delivery_psql                   | waiting for server to shut down....2020-03-13 16:38:38.778 UTC [44] LOG:  aborting any active transactions
delivery_psql                   | 2020-03-13 16:38:38.784 UTC [44] LOG:  background worker "logical replication launcher" (PID 51) exited with exit code 1
delivery_psql                   | 2020-03-13 16:38:38.785 UTC [46] LOG:  shutting down
delivery_psql                   | 2020-03-13 16:38:38.824 UTC [44] LOG:  database system is shut down
delivery_psql                   |  done
delivery_psql                   | server stopped
delivery_psql                   |
delivery_psql                   | PostgreSQL init process complete; ready for start up.
delivery_psql                   |
delivery_psql                   | 2020-03-13 16:38:38.895 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
delivery_psql                   | 2020-03-13 16:38:38.895 UTC [1] LOG:  listening on IPv6 address "::", port 5432
delivery_psql                   | 2020-03-13 16:38:38.899 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
delivery_psql                   | 2020-03-13 16:38:38.919 UTC [71] LOG:  database system was shut down at 2020-03-13 16:38:38 UTC
delivery_psql                   | 2020-03-13 16:38:38.928 UTC [1] LOG:  database system is ready to accept connections

但是,当我输入数据库时​​,\dx不会显示已安装扩展,而\dn不会显示已创建测试模式。

关于为什么初始化脚本似乎正在运行的任何想法,但是我看不到psql容器中的更改?

编辑:

我还尝试通过更改init.sql来弄乱权限和搜索路径,但还是没有运气:

CREATE DATABASE delivery;
create schema extensions;

-- make sure everybody can use everything in the extensions schema
grant usage on schema extensions to public;
grant execute on all functions in schema extensions to public;

-- include future extensions
alter default privileges in schema extensions
   grant execute on functions to public;

alter default privileges in schema extensions
   grant usage on types to public;

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" schema extensions;

set search_path = extensions;

0 个答案:

没有答案