sql >> データベース >  >> RDS >> PostgreSQL

docker-entrypoint-initdb.dでスクリプトを実行した後、postgresの再起動を作成します

    簡単に言えば、これは意図的に発生します。作者は初期化の一部としてそれを行います。

    いくつかの答えが画像のエントリポイントシェルスクリプトにあるようです:

    _main() {
        # if first arg looks like a flag, assume we want to run postgres server
        if [ "${1:0:1}" = '-' ]; then
            set -- postgres "[email protected]"
        fi
    
        if [ "$1" = 'postgres' ] && ! _pg_want_help "[email protected]"; then
            docker_setup_env
            # setup data directories and permissions (when run as root)
            docker_create_db_directories
            if [ "$(id -u)" = '0' ]; then
                # then restart script as postgres user
                exec gosu postgres "$BASH_SOURCE" "[email protected]"
            fi
    
            # only run initialization on an empty data directory
            if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
                docker_verify_minimum_env
    
                # check dir permissions to reduce likelihood of half-initialized database
                ls /docker-entrypoint-initdb.d/ > /dev/null
    
                docker_init_database_dir
                pg_setup_hba_conf
    
                # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
                # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
                export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
                docker_temp_server_start "[email protected]"
    
                docker_setup_db
                docker_process_init_files /docker-entrypoint-initdb.d/*
    
                docker_temp_server_stop
                unset PGPASSWORD
    
                echo
                echo 'PostgreSQL init process complete; ready for start up.'
                echo
            else
                echo
                echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
                echo
            fi
        fi
    
        exec "[email protected]"
    }
    

    「なんで?」特権の少ないユーザーとして実行したいという願望のためだと思います。

    次のように作成ファイルでボリュームを指定することで、問題を「解決」できます。

        volumes:
           - ./data/pgsql:/var/lib/postgresql/data
    

    次に、ルーチンをスキップして、DATABASE_ALREADY_EXISTSを確認します。 。

    または、それが役に立たない場合は、エントリポイントスクリプトをもう少し掘り下げることができます。



    1. IDのリストから値のリストを一括更新する

    2. PL / SQLでビューを動的に作成し、CLOBを使用する場合のORA-00907

    3. 行を更新するときに重複キーエラーが発生するのはなぜですか?

    4. 最終日で結合されたSQL