Last active
July 4, 2016 15:49
-
-
Save VojtechVitek/b13150903709cba714756f210b24aa28 to your computer and use it in GitHub Desktop.
Postgres in Docker: Modify Owner of all Tables + Sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ref.: http://stackoverflow.com/a/36635029/385548