-
-
Save muneneevans/b2074548d63bbf6e740edb25900e1516 to your computer and use it in GitHub Desktop.
ALTER owner to tables, sequences and views on PostgreSQL databases using bash
This file contains hidden or 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
| #!/bin/bash | |
| DB=[YOUR_DB_NAME] | |
| OWNER=[NEW_OWNER] | |
| # alter tables owner | |
| for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $DB` ; do psql -c "alter table \"$tbl\" owner to $OWNER" $DB ; done | |
| # alter sequences owner | |
| for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $DB` ; do psql -c "alter table \"$tbl\" owner to $OWNER" $DB ; done | |
| # alter views owner | |
| for tbl in `psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" $DB` ; do psql -c "alter table \"$tbl\" owner to $OWNER" $DB ; done | |
| #set timezone | |
| psql -c "ALTER DATABASE\"$DB\" SET timezone TO 'Africa/Nairobi';" $DB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment