Instantly share code, notes, and snippets.

Embed
What would you like to do?
Postgres in Docker: Modify Owner of all Tables + Sequences
export new_user="your_user"
export dbname="your_db_name"
cat <<EOF | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname" | grep ALTER | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname"
SELECT 'ALTER TABLE '||schemaname||'.'||tablename||' OWNER TO $new_user;'
FROM pg_tables WHERE schemaname = 'public';
SELECT 'ALTER SEQUENCE '||relname||' OWNER TO $new_user;' FROM pg_class WHERE relkind = 'S';
EOF
@VojtechVitek

This comment has been minimized.

Owner

VojtechVitek commented Jul 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment