Changes between Version 11 and Version 12 of jazz/PostgreSQL


Ignore:
Timestamp:
Apr 10, 2018, 4:06:41 PM (6 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • jazz/PostgreSQL

    v11 v12  
    55* psql 指令說明 - https://www.postgresql.org/docs/current/static/app-psql.html
    66
    7 == 修改管理者密碼 ==
     7== 管理者 ==
     8
     9=== 修改管理者密碼 ===
    810
    911{{{
     
    1618}}}
    1719
    18 == 資料庫列表 ==
     20== 新增使用者為管理者 ==
     21
     22{{{
     23~$ sudo su - postgres
     24-bash-4.2$ psql -d postgres ### 使用 postgres 資料庫
     25postgres=# ALTER USER 使用者名稱 WITH SUPERUSER;
     26}}}
     27
     28
     29== 使用者 ==
     30
     31=== 新增使用者 ===
     32
     33{{{
     34~$ sudo su - postgres
     35-bash-4.2$ createuser 使用者名稱
     36}}}
     37
     38== 系統 ==
     39
     40=== 查詢目前連線數 ===
     41* 查連線總數
     42{{{
     43postgres=#  SELECT count(*) FROM pg_stat_activity;
     44 count
     45-------
     46    52
     47(1 row)
     48}}}
     49* 依資料庫查詢各別連線數
     50{{{
     51postgres=#  SELECT datname, count(*) FROM pg_stat_activity GROUP BY datname;
     52}}}
     53
     54=== 修改同時連線數上限 ===
     55
     56* 修改 postgresql.conf
     57{{{
     58$ sudo grep max_connections /var/lib/postgresql/postgresql.conf
     59max_connections = 300                   # (change requires restart)
     60# Note:  Increasing max_connections costs ~400 bytes of shared memory per
     61# max_locks_per_transaction * (max_connections + max_prepared_transactions)
     62}}}
     63
     64=== 查詢同時連線數上限 ===
     65
     66* 使用 `SHOW` 指令
     67{{{
     68postgres=# SHOW max_connections;
     69}}}
     70* 或從 `pg_settings` 資料表查詢
     71{{{
     72postgres=# SELECT * FROM pg_settings WHERE  name = 'max_connections';
     73}}}
     74* [https://stackoverflow.com/questions/8288823/query-a-parameter-postgresql-conf-setting-like-max-connections 參考]
     75
     76
     77
     78== 資料庫 ==
     79
     80=== 資料庫列表 ===
    1981
    2082{{{
     
    3496}}}
    3597
    36 == 新增使用者 ==
    37 
    38 {{{
    39 ~$ sudo su - postgres
    40 -bash-4.2$ createuser 使用者名稱
    41 }}}
    42 
    4398== 新增資料庫 ==
    4499
     
    56111postgres=# GRANT ALL PRIVILEDGES ON DATABASE 資料庫名稱 TO 使用者名稱;
    57112}}}
    58 
    59 == 新增使用者為管理者 ==
    60 
    61 {{{
    62 ~$ sudo su - postgres
    63 -bash-4.2$ psql -d postgres ### 使用 postgres 資料庫
    64 postgres=# ALTER USER 使用者名稱 WITH SUPERUSER;
    65 }}}
    66 
    67 == 查詢目前連線數 ==
    68 * 查連線總數
    69 {{{
    70 postgres=#  SELECT count(*) FROM pg_stat_activity;
    71  count
    72 -------
    73     52
    74 (1 row)
    75 }}}
    76 * 依資料庫查詢各別連線數
    77 {{{
    78 postgres=#  SELECT datname, count(*) FROM pg_stat_activity GROUP BY datname;
    79 }}}
    80 
    81 == 修改同時連線數上限 ==
    82 
    83 * 修改 postgresql.conf
    84 {{{
    85 $ sudo grep max_connections /var/lib/postgresql/postgresql.conf
    86 max_connections = 300                   # (change requires restart)
    87 # Note:  Increasing max_connections costs ~400 bytes of shared memory per
    88 # max_locks_per_transaction * (max_connections + max_prepared_transactions)
    89 }}}
    90 
    91 == 查詢同時連線數上限 ==
    92 
    93 * 使用 `SHOW` 指令
    94 {{{
    95 postgres=# SHOW max_connections;
    96 }}}
    97 * 或從 `pg_settings` 資料表查詢
    98 {{{
    99 postgres=# SELECT * FROM pg_settings WHERE  name = 'max_connections';
    100 }}}
    101 * [https://stackoverflow.com/questions/8288823/query-a-parameter-postgresql-conf-setting-like-max-connections 參考]
    102113
    103114== 效能調校 ==