In my docker-compose file i have the following:
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
The contents of init.sql are:
CREATE DATABASE delivery;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE SCHEMA IF NOT EXISTS test;
When I run docker-compose stop delivery_psql && docker-compose rm delivery_psql && docker-compose up delivery_psql
I get the following output, which tells me the commands in init.sql were executed -- the extension was installed and the test schema was created:
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
But when I enter the db, \dx does not show the extension was installed and \dn does not show the test schema was created.
Any thoughts on why the init script seems to be running, but i am unable to see the changes in my psql container?
EDIT:
I've also tried messing with permissions and search path, by altering init.sql to this, but still no luck:
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;