wiki:jazz/PostgreSQL

Version 2 (modified by jazz, 6 years ago) (diff)

--

PostgreSQL

修改管理者密碼

~$ sudo su - postgres
~$ psql
postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# \q

資料庫列表

~$ sudo su - postgres
~$ psql
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | zh_TW.UTF-8 | zh_TW.UTF-8 | 
 template0 | postgres | UTF8     | zh_TW.UTF-8 | zh_TW.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_TW.UTF-8 | zh_TW.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

新增使用者

~$ sudo su - postgres
-bash-4.2$ createuser 使用者名稱

新增資料庫

~$ sudo su - postgres
-bash-4.2$ createdb 資料庫名稱

允許使用者可以管理指定資料庫

~$ sudo su - postgres
-bash-4.2$ psql -d postgres ### 使用 postgres 資料庫
postgres=# ALTER USER 使用者名稱 WITH ENCRYPTED PASSWORD '密碼';
postgres=# GRANT ALL PRIVILEDGES ON DATABASE 資料庫名稱 TO 使用者名稱;

新增使用者為管理者

~$ sudo su - postgres
-bash-4.2$ psql -d postgres ### 使用 postgres 資料庫
postgres=# ALTER USER 使用者名稱 WITH SUPERUSER;