Skip to content

Instantly share code, notes, and snippets.

@VojtechVitek
Last active July 4, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VojtechVitek/b13150903709cba714756f210b24aa28 to your computer and use it in GitHub Desktop.
Save VojtechVitek/b13150903709cba714756f210b24aa28 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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