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l_key_file = 'server.key' EOCONF cat > "$PGDATA/pg_hba.conf" <<-EOCONF # TYPE DATABASE USER ADDRESS METHOD host all pass_user 0.0.0.0/0 password host all md5_user 0.0.0.0/0 md5 host all scram_user 0.0.0.0/0 scram-sha-256 host all pass_user ::0/0 password host all md5_user ::0/0 md5 host all scram_user ::0/0 scram-sha-256 hostssl all ssl_user 0.0.0.0/0 trust hostssl all ssl_user ::0/0 trust host all ssl_user 0.0.0.0/0 reject host all ssl_user ::0/0 reject # IPv4 local connections: host all postgres 0.0.0.0/0 trust # IPv6 local connections: host all postgres ::0/0 trust # Unix socket connections: local all postgres trust EOCONF psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL CREATE ROLE pass_user PASSWORD 'password' LOGIN; CREATE ROLE md5_user PASSWORD 'password' LOGIN; SET password_encryption TO 'scram-sha-256'; CREATE ROLE scram_user PASSWORD 'password' LOGIN; CREATE ROLE ssl_user LOGIN; CREATE EXTENSION hstore; CREATE EXTENSION citext; CREATE EXTENSION ltree; EOSQL