---
# System prepended metadata

title: 超級腳本(更換表格權限)

---

# 超級腳本(更換表格權限)
```
#achilles script
#!/bin/bash

HOST=$1
PASSWORD=$2
SCHEMA=$3
DATABASE=$4
GROUP=$5

echo HOST=$HOST
echo PASSWORD=$PASSWORD
echo SCHEMA=$SCHEMA
echo DATABASE=$DATABASE
echo GROUP=$GROUP

export PGPASSWORD="$PASSWORD"

export LD_LIBRARY_PATH=/var/vcap/packages/postgres/postgresql-10.1/lib

for tbl in `psql -h $HOST --username postgres -qAt -c "select tablename from pg_tables where schemaname = '$SCHEMA';" "$DATABASE"` ; do psql -h $HOST --username postgres  -c "alter table \"$SCHEMA\".\"$tbl\" owner to \"$GROUP\"" "$DATABASE"; done

for tbl in `psql -h $HOST --username postgres   -qAt -c "select viewname from pg_views where schemaname = '$SCHEMA';" "$DATABASE"` ; do psql -h $HOST --username postgres  -c "alter view \"$SCHEMA\".\"$tbl\" owner to \"$GROUP\"" "$DATABASE"; done

for tbl in `psql -h $HOST --username postgres  -qAt -c "select sequencename from pg_sequences where schemaname = '$SCHEMA';" "$DATABASE"` ; do psql -h $HOST --username postgres  -c "alter sequence \"$SCHEMA\".\"$tbl\" owner to \"$GROUP\"" "$DATABASE"; done

```
