我建議的cluster parameter設定 |
log_connections=on |
log_disconnections=on |
log_temp_files=512000 |
log_lock_waits = on |
log_autovacuum_min_duration=300000 |
rds.force_autovacuum_logging_level=log |
log_min_duration_statement=60000 |
log_statement=ddl |
rds.force_admin_logging_level=log |
log_checkpoints = on -- 這個確定應該是不能設定 |
auto_explain.log_min_duration = '3s' log_destination = stderr,csv -- 因為要透過log_fdw從sql 介面茶系統記錄 |
看到上述參數,當然就是要在shared_preload_libraries |
指定要預載的函式庫 |
3秒....當然AP單位回饋我的 |
執行超過3秒的SQL 語句 |
我才能從系統紀錄檔看被拋出來的執行計畫 |
不然哩~~怎麼debug |
憑空想像嗎 ?? |
再來就是pg_stat_statements 的數據 |
3秒的比對 | |
當然就是看我標紅色的那個欄位的數值 | |
它是total/calls, 就是平均值袂 | |
如果有看到超過3的數值 | |
我就知道該去看系統紀錄 | |
調出相應的執行計畫 | |
不過從數據看起來 | |
這個外包寫的程式算漂亮 | |
數值是來自於pg_stat_statements模組 | |
當然也得指定preload參數預載 | |
安裝及使用 | |
進到postgres 資料庫 | |
當然也可以放在user資料庫 | |
但何必哩~~ | |
postgres> create extension pg_stat_statements; | |
預設的參數值應該就可以使用了 | |
壓測開始前清空數據 | |
SELECT pg_stat_statements_reset() | |
結束後就透過下列語法撈取數據 | |
SELECT userid,round((100 * total_time / sum(total_time) OVER ())::numeric, 2) percent, | |
round(total_time::numeric, 2) AS total, | |
calls, | |
round(mean_time::numeric, 2) AS mean, | |
round(stddev_time::numeric, 2) AS steddev, | |
substring(query, 1, 100) | |
--FROM enterprisedb.pg_stat_statements | |
FROM pg_stat_statements | |
ORDER BY calls desc ,total_time DESC | |
LIMIT 10; |
Aurora Serverless 的設計如下: |
By design, Aurora Serverless connects to a proxy fleet of DB instances that scales automatically. There isn't a direct DB instance to access and host the log files. |
反正db instance不是固定的 |
因此pg_stat_statements的數據撈一撈 |
可能就會突然不見 |
因此當你發現數據不動的時候 |
就不能再refresh執行sql 語句 |
把數據存檔,以供後續使用 |
#2020/08/15 補充 | |||||||||||||||
時區的部分,如果要抓台北的時間 | |||||||||||||||
資料庫的參數 timezone, log_timezone | |||||||||||||||
得由預設的UTC改成 UTC-8 |