- [注1]:資料庫使用者名稱
- [注2]:資料庫使用者密碼
- [注3]:資料庫名稱,例:greening
建立 account 及 greening_[注3] 資料表
[ischool@xxx ~]$ sudo su - postgres
Last login: Thu Jan 29 04:53:01 UTC 2015 on pts/0
-bash-4.1$ psql
psql (9.2.9)
Type "help" for help.
postgres=# CREATE USER [注1] WITH PASSWORD '[注2]';
CREATE ROLE
postgres=# CREATE DATABASE [注3];
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE [注3] to [注1];
GRANT
postgres=# \du
List of roles
Role name | Attributes | Member of
----------+------------------------------------------------+-----------
[注1] | | {}
postgres | Superuser, Create role, Create DB, Replication | {}
postgres=# ALTER USER [注1] WITH SUPERUSER;
ALTER ROLE
postgres=# \q
-bash-4.1$ exit
logout
還原資料庫
pg_restore -U "postgres" --dbname "[注3]" --verbose "[備份檔來源位置]"
移除[注1]的superuser權限
[ischool@xxx ~]$ sudo su - postgres
Last login: Thu Jan 29 04:53:01 UTC 2015 on pts/0
-bash-4.1$ psql
psql (9.2.9)
Type "help" for help.
postgres=# ALTER USER [注1] WITH NOSUPERUSER;
ALTER ROLE
postgres=# \q
-bash-4.1$ exit
logout