苍穹性能测试-- PostgreSQL性能指标
在做苍穹性能测试或者分析数据库问题的时候可以采用以下一些内容作为衡量数据库性能的指标。
指标分类 | 指标项 | 值 | 获取值方法 |
主机 | 数据库机器cpu使用率 | <80% | top,sar 命令 |
数据库机器负载 | <cpu核数*0.7 | top,uptime 命令 | |
数据库机器磁盘IO使用率 | <80% | iostat命令 | |
数据库机器内存使用率 | <90% | top,free命令,/proc/meminfo | |
数据库机器磁盘空间 | 使用率<90% | df | |
数据库机器网卡流量 | <100% | iftop,sar | |
网络延迟 | <0.5ms | ping,hping3 | |
数据库 | 表大小 | 核心单表<10G | select table_catalog, tablename, pg_size_pretty(tablesize) as table_size from ( select table_catalog, ( table_schema||'.'|| table_name ) as tablename, pg_table_size( table_schema||'.'|| table_name ) as tablesize from information_schema.tables where pg_table_size( table_schema||'.'|| table_name ) > 10737418240 order by pg_table_size(table_schema||'.'|| table_name ) desc ) as all_tables ; |
最大连接数 | <=5000 | select count(1) from pg_stat_activity; | |
活跃连接数 | <=1000 | select count(1) from pg_stat_activity where state ='active'; | |
实时慢SQL | 不能有大量>60s | 查看后台慢日志记录 | |
错误日志 | 不能出现有error的日志 | 查看数据库pg_log错误日志 | |
wal日志 | 产生wal日志<1min | 查看pg_wal目录的wal日志生成情况 | |
阻塞事务 | 不能出现大量阻塞SQL | with t_wait as ( select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted, a.objid,a.objsubid,a.pid,a.virtualtransaction,a.virtualxid,a.transactionid,a.fastpath, b.state,b.query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name from pg_locks a,pg_stat_activity b where a.pid=b.pid and not a.granted ), t_run as ( select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted, a.objid,a.objsubid,a.pid,a.virtualtransaction,a.virtualxid,a.transactionid,a.fastpath, b.state,b.query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name from pg_locks a,pg_stat_activity b where a.pid=b.pid and a.granted ), t_overlap as ( select r.* from t_wait w join t_run r on ( r.locktype is not distinct from w.locktype and r.database is not distinct from w.database and r.relation is not distinct from w.relation and r.page is not distinct from w.page and r.tuple is not distinct from w.tuple and r.virtualxid is not distinct from w.virtualxid and r.transactionid is not distinct from w.transactionid and r.classid is not distinct from w.classid and r.objid is not distinct from w.objid and r.objsubid is not distinct from w.objsubid and r.pid <> w.pid ) ), t_unionall as ( select r.* from t_overlap r union all select w.* from t_wait w ) select locktype,datname,relation::regclass,page,tuple,virtualxid,transactionid::text,classid::regclass,objid,objsubid, string_agg( 'Pid: '||case when pid is null then 'NULL' else pid::text end||chr(10)|| 'Lock_Granted: '||case when granted is null then 'NULL' else granted::text end||' , Mode: '||case when mode is null then 'NULL' else mode::text end||' , FastPath: '||case when fastpath is null then 'NULL' else fastpath::text end||' , VirtualTransaction: '||case when virtualtransaction is null then 'NULL' else virtualtransaction::text end||' , Session_State: '||case when state is null then 'NULL' else state::text end||chr(10)|| 'Username: '||case when usename is null then 'NULL' else usename::text end||' , Database: '||case when datname is null then 'NULL' else datname::text end||' , Client_Addr: '||case when client_addr is null then 'NULL' else client_addr::text end||' , Client_Port: '||case when client_port is null then 'NULL' else client_port::text end||' , Application_Name: '||case when application_name is null then 'NULL' else application_name::text end||chr(10)|| 'Xact_Start: '||case when xact_start is null then 'NULL' else xact_start::text end||' , Query_Start: '||case when query_start is null then 'NULL' else query_start::text end||' , Xact_Elapse: '||case when (now()-xact_start) is null then 'NULL' else (now()-xact_start)::text end||' , Query_Elapse: '||case when (now()-query_start) is null then 'NULL' else (now()-query_start)::text end||chr(10)|| 'SQL (Current SQL in Transaction): '||chr(10)|| case when query is null then 'NULL' else query::text end, chr(10)||'--------'||chr(10) order by ( case mode when 'INVALID' then 0 when 'AccessShareLock' then 1 when 'RowShareLock' then 2 when 'RowExclusiveLock' then 3 when 'ShareUpdateExclusiveLock' then 4 when 'ShareLock' then 5 when 'ShareRowExclusiveLock' then 6 when 'ExclusiveLock' then 7 when 'AccessExclusiveLock' then 8 else 0 end ) desc, (case when granted then 0 else 1 end) ) as lock_conflict from t_unionall group by locktype,datname,relation,page,tuple,virtualxid,transactionid::text,classid,objid,objsubid ; | |
未提交事务 | 不能出现大量没有提交的事务 | select count(1) from pg_stat_activity where state ='idle in transaction'; | |
死锁 | 不能出现大量死锁 | 查看日志文件 | |
QPS | 单机实例QPS<1w | 一般情况QPS不能出现大的波动 with a as (select sum(calls) s from pg_stat_statements), b as (select sum(calls) s from pg_stat_statements , pg_sleep(1)) select b.s-a.s qps from a,b; | |
TPS | <QPS*0.5 | create or replace procedure dba.tps() as $$ declare v1 int8; v2 int8; begin select txid_snapshot_xmax(txid_current_snapshot()) into v1; commit; perform pg_sleep(1); select txid_snapshot_xmax(txid_current_snapshot()) into v2; commit; raise notice 'tps: %', v2-v1; end; $$ language plpgsql ; | |
主从延迟 | 主从延迟<5min | pg_autoctl show state/select application_name,client_addr,client_hostname,client_port,state,sync_priority,sync_state,pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lag)) from pg_stat_replication; |
苍穹性能测试-- PostgreSQL性能指标
在做苍穹性能测试或者分析数据库问题的时候可以采用以下一些内容作为衡量数据库性能的指标。指标分类指标项值获取值方法主机数据库机器cpu...
点击下载文档
上一篇:如何在单据上添加地址控件下一篇:应用场景
本文2024-09-23 00:21:08发表“云苍穹知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-cangqiong-138911.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
- 鼎捷EAI整合規範文件V3.1.07 (集團).pdf
- 鼎捷OpenAPI應用場景說明_基礎資料.pdf
- 鼎捷OpenAPI應用場景說明_財務管理.pdf
- 鼎捷T100 API設計器使用手冊T100 APIDesigner(V1.0).docx
- 鼎新e-GoB2雲端ERP B2 線上課程E6-2應付票據整批郵寄 領取.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A4使用者建立權限設定.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程C3會計開帳與會計傳票.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程E6-1應付票據.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A5-1進銷存參數設定(初階篇).pdf
- 鼎新e-GoB2雲端ERP B2 線上課程D2帳款開帳與票據開帳.pdf
热门文章