Skip to content

Instantly share code, notes, and snippets.

@mkjasinski
Created March 31, 2016 14:56
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 mkjasinski/6e67480ce11ca375552173e8001f6b5f to your computer and use it in GitHub Desktop.
Save mkjasinski/6e67480ce11ca375552173e8001f6b5f to your computer and use it in GitHub Desktop.
[PostgreSQL] change owner
#!/bin/bash
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" [db-name]` ; do
psql -c "alter table $tbl owner to \"[db-user]\"" [db-name] ;
done
for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" [db-name]` ; do
psql -c "alter table \"$tbl\" owner to \"[db-user]\"" [db-name] ;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment