Creating a table in single user mode in postgres

前端 未结 3 1858
星月不相逢
星月不相逢 2021-01-12 09:12

Im trying to create a Dockerfile from the postgres image. The repo says that initialization should be handled by placing a shell script in /docker-entrypoint-initdb.d/. I pu

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 09:48

    @a_horse_with_no_name got me on the right track with his comment. I decided to ditch the single user mode even if it was "recommended". Instead I start postgres with pg_ctl, load some sql files containing my table creations, and stop the server with pg_ctl.

    My shell script looks like this:

    #!/bin/bash
    echo "******CREATING DOCKER DATABASE******"
    
    echo "starting postgres"
    gosu postgres pg_ctl -w start
    
    echo "bootstrapping the postgres db"
    gosu postgres psql -h localhost -p 5432 -U postgres -a -f /db/bootstrap.sql
    
    echo "initializing tables"
    gosu postgres psql -h localhost -p 5432 -U postgres -d orpheus -a -f /db/setup.sql
    
    echo "stopping postgres"
    gosu postgres pg_ctl stop
    
    echo "stopped postgres"
    
    
    echo ""
    echo "******DOCKER DATABASE CREATED******"
    

提交回复
热议问题