#!/bin/bash

# create extension timescaledb in initial databases
psql -U postgres postgres -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
psql -U postgres template1 -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"

if [ "$POSTGRES_DB" != 'postgres' ]; then
  psql -U postgres ${POSTGRES_DB} -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
fi

#!/bin/bash

# create extension timescaledb in initial databases
psql -U "${POSTGRES_USER}" postgres -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
psql -U "${POSTGRES_USER}" template1 -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"

if [ "$POSTGRES_DB" != 'postgres' ]; then
  psql -U "${POSTGRES_USER}" "${POSTGRES_DB}" -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
fi

Use POSTGRES_USER instead of hardcoded user name
Use POSTGRES_USER instead of hardcoded user name
