PostgreSQL

データベース一覧確認

psql -l
または
psql
postgres=# ¥l

データベース作成

# su - posgres
$ createdb -U postgres -O testuser01 testdb
$ psql -l
    名前    |    所有者    | エンコーディング |  照合順序   | Ctype(変換演算子) |      アクセス権
------------+--------------+------------------+-------------+-------------------+-----------------
testdb | testuser01 | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
postgres   | postgres     | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
template0  | postgres     | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
                 |                    |                      |                   |                          | postgres=CTc/postgres
template1  | postgres     | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
                 |                    |                      |                   |                           | postgres=CTc/postgres

データベースの所有者変更

postgres=# alter database hogedb01 owner to hogeuser01;
ALTER DATABASE

データベースの権限確認

psql 
postgres=#
postgres=# ¥c 対象のデータベース名(例:testdb)
testdb=# ¥z
 Schema |                       Name                        |   Type   |                    Access privileges
--------+---------------------------------------------------+----------+---------------------------------------------------------
public | dtb_alliances                                     | table    | 

Access pribileges の部分が空だとselectすらも出来ない。

アクセス権付与

psql 
postgres=#
postgres=# ¥c 対象のデータベース名(例:testdb)
testdb=# grant all on テーブル名 to ユーザー名
testdb=# ¥z
※テーブルごと
※全テーブルへのアクセス権付与についてはPostgreSQL8.5以降でないとダメらしい。

全テーブルへアクセス権を付与するシェル

#!/bin/bash
for table in `echo '\dtvs' | psql -t -A -F ',' データベース名 | cut -f 2 -d ','`
do
 #echo $table
 echo "GRANT ALL ON TABLE $table to ユーザー名;"
 echo "GRANT ALL ON TABLE $table to ユーザー名;" | psql データベース名
done

参考:http://yanor.net/wiki/?PostgreSQL%2F%E3%83%A6%E3%83%BC%E3%82%B6%E7%AE%A1%E7%90%86%E3%83%BB%E3%83%AD%E3%83%BC%E3%83%AB%2F%E5%85%A8%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%82%92GRANT%E3%81%99%E3%82%8B


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-06-30 (木) 01:40:11