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;
查詢目前連線數
- 查連線總數
postgres=# SELECT count(*) FROM pg_stat_activity;
count
-------
52
(1 row)
- 依資料庫查詢各別連線數
postgres=# SELECT datname, count(*) FROM pg_stat_activity GROUP BY datname;
修改同時連線數上限
查詢同時連線數上限
效能調校