PostgreSQL 支持动态跟踪, 可以通过dtrace或者systemtap工具统计相关探针的信息.
安装systemtap
yum install systemtap kernel-debuginfo kernel-devel
将安装以下包
systemtap-devel-1.8-6.el5
systemtap-client-1.8-6.el5
systemtap-runtime-1.8-6.el5
后面将使用的stap命令
[root@db-172-16-3-39 ~]# rpm -qf /usr/bin/stap
systemtap-devel-1.8-6.el5
systemtap-client-1.8-6.el5检查stap是否正常
[root@db-172-16-3-39 ~]# stap
stap:/usr/lib64/libelf.so.1: version `ELFUTILS_1.5'not found (required by stap)
stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.148'not found (required by stap)
stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.138'not found (required by stap)
stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.142'not found (required by stap)
stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.143'not found (required by stap)
stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.149'not found (required by stap)
这个错误的原因是库文件版本不正确, 用来老版本, 使用eu-readelf查看stap文件的两个环境变量, 如下 :
[root@db-172-16-3-39 ~]# eu-readelf -d /usr/bin/stap|grep -E "RPATH|RUNPATH"RPATH             Library rpath: [/usr/lib64/systemtap]RUNPATH           Library runpath: [/usr/lib64/systemtap]
将路径加入到LD_LIBRARY_PATH中.
[root@db-172-16-3-39 ~]# export LD_LIBRARY_PATH=/usr/lib64/systemtap:$LD_LIBRARY_PATH
stap现在正常了
[root@db-172-16-3-39 ~]# stap
A script must be specified.
Systemtap translator/driver (version 1.8/0.152 non-git sources)
Copyright (C)2005-2012Red Hat, Inc. and others
Thisis free software; see the source forcopying conditions.
enabled features: AVAHI LIBRPM LIBSQLITE3 NSS BOOST_SHARED_PTR TR1_UNORDERED_MAP NLS
Usage: stap [options] FILE         Run scriptinfile.or: stap [options]-Run script on stdin.or: stap [options]-e SCRIPT    Run given script.or: stap [options]-l PROBE     List matching probes.or: stap [options]-L PROBE     List matching probes and local variables.
测试 :
[root@db-172-16-3-39pg94]# vi tps.d
probe begin
{printf("hello\n")exit()
}
[root@db-172-16-3-39pg94]# stap tps.d
Checking"/lib/modules/2.6.18-274.el5/build/.config"failed with error: No such file or directory
Incorrect version or missing kernel-devel package, use: yum install kernel-devel-2.6.18-274.el5.x86_64
这个错误是由于未安装当前正在运行的kernel对应的kernel-devel包.
[root@db-172-16-3-39 pg94]# rpm -qa|grep kernel
kernel-headers-2.6.18-274.el5
kernel-xen-devel-2.6.18-274.el5
kernel-xen-2.6.18-274.el5
kernel-2.6.18-274.el5
[root@db-172-16-3-39 ~]# uname -a
Linux db-172-16-3-39.sky-mobi.com 2.6.18-274.el5 #1 SMP Fri Jul 22 04:43:29 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux安装对应的kernel-devel版本.
yum install kernel-devel-2.6.18-274.el5.x86_64
如果yum源中没有这个版本的kernel-devel包, 可以去安装光盘中找一找.
或者同时更新内核版本至新版本.yum install-y kernel.x86_64 kernel-devel.x86_64
Package kernel-2.6.18-348.12.1.el5.x86_64 already installed and latest version
Package kernel-devel-2.6.18-348.12.1.el5.x86_64 already installed and latest version
vi/boot/grub/grub.confdefault=0timeout=5splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-348.12.1.el5)root (hd0,0)kernel/boot/vmlinuz-2.6.18-348.12.1.el5 ro root=LABEL=/rhgb quietinitrd/boot/initrd-2.6.18-348.12.1.el5.img
重启服务器
现在stap工作正常了 :
[root@db-172-16-3-39 postgresql-5e3e8e4]# stap -ve 'probe begin { log("hello world") exit() }'Pass1: parsed user script and 85 library script(s) using 146788virt/23676res/3000shr/21384data kb, in 170usr/0sys/173real ms.
Pass2: analyzed script: 1 probe(s), 2 function(s), 0 embed(s), 0 global(s) using 147316virt/24396res/3224shr/21912data kb, in 10usr/0sys/6real ms.
Pass3: using cached /root/.systemtap/cache/3b/stap_3b2eaec778ce9832b394535505dde575_838.c
Pass4: using cached /root/.systemtap/cache/3b/stap_3b2eaec778ce9832b394535505dde575_838.ko
Pass5: starting run.
hello world
Pass5: run completed in 0usr/20sys/306real ms.
stap调试好后, 就可以用来跟踪postgresql了.
PostgreSQL编译时必须开启dtrace支持. 开启dtrace后, 数据库将启用代码中的探针或跟踪点.
PostgreSQL内建探针参考如下 :
src/backend/utils/probes.d
http://www.postgresql.org/docs/devel/static/dynamic-trace.html
检查你的PostgreSQL是否开启了dtrace支持, 如下 :
pg94@db-172-16-3-39-> pg_config --configure'--prefix=/home/pg94/pgsql9.4devel' '--with-pgport=2999' '--with-perl' '--with-tcl' '--with-python' '--with-openssl' '--with-pam' '--without-ldap' '--with-libxml' '--with-libxslt' '--enable-thread-safety' '--with-wal-blocksize=16' '--enable-dtrace'如果没有--enable-dtrace, 那么需要重新编译一下你的PostgreSQL软件.stap测试脚本1.
[root@db-172-16-3-39 pg94]# cat postgresql-query.stpglobalquery_time, query_summaryprobe process("/home/pg94/pgsql9.4devel/bin/postgres").mark("query__start") {query_time[tid(), $arg1]=gettimeofday_us();
}probe process("/home/pg94/pgsql9.4devel/bin/postgres").mark("query__done") {p=tid()t=query_time[p, $arg1]; delete query_time[p, $arg1]if(t) {query_summary[p]<<< (gettimeofday_us() -t);}
}probe end {printf("\ntid count min(us) avg(us) max(us)\n");foreach (p inquery_summary) {printf("%d %d %d %d %d\n", p, @count(query_summary[p]),@min(query_summary[p]), @avg(query_summary[p]), @max(query_summary[p]));}
}
执行stap :
[root@db-172-16-3-39 pg94]# stap postgresql-query.stp
执行以下SQL :
[root@db-172-16-3-39 pg94]# stap postgresql-query.stp
digoal=# begin;
BEGIN
digoal=# select * from test forupdate;id----12345678910(10rows)
digoal=# end;
COMMIT
digoal=# selecttxid_current();txid_current--------------5969062(1row)
结束stap, 输出 :
[root@db-172-16-3-39 pg94]# stap postgresql-query.stp
按键Ctrl+C, 输出 :
tid count min(us) avg(us) max(us)17112 4 46 3794 14885这个tid对应PostgreSQL background process
[root@db-172-16-3-39 pg94]# ps -ewf|grep 17112pg9417112 17005  0 15:15 ?        00:00:00postgres: postgres digoal [local] idle
digoal=# selectpg_backend_pid();pg_backend_pid----------------17112(1row)[小结]1. 安装systemtap注意 :--需要安装kernel相关, 并且版本要一致, 启动的kernel版本也要一致 :
kernel
kernel-debuginfo
kernel-devel
kernel-debuginfo的安装要用到debug源.
[root@db-172-16-3-39 pg94]# cd /etc/yum.repos.d/[root@db-172-16-3-39yum.repos.d]# ll
total36
-rw-r--r-- 1 root root 1926 Aug 29  2011 CentOS-Base.repo-rw-r--r-- 1 root root  631 Aug 29  2011 CentOS-Debuginfo.repo-rw-r--r-- 1 root root  626 Aug 29  2011 CentOS-Media.repo-rw-r--r-- 1 root root 5390 Aug 29  2011 CentOS-Vault.repo
[root@db-172-16-3-39 yum.repos.d]# cat CentOS-Debuginfo.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should usethis forCentOS updates
# unless you are manually picking other mirrors.
## All debug packagesfrom all the various CentOS-5releases
# are merged into a single repo, split by BaseArch
#
# Note: packagesinthe debuginfo repo are currently not signed
#[debug]
name=CentOS-5 -Debuginfo
baseurl=http://debuginfo.centos.org/5/$basearch/
gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
enabled=0这里用到的源名为debug.
yum--enablerepo=debug list kernel-debuginfo
yum--enablerepo=debug install kernel-debuginfo
安装细节参考此文 :
http://pic.dhe.ibm.com/infocenter/lnxinfo/v3r0m0/topic/liaai.systemTap/liaaisystap_pdf.pdf2. postgresql编译时必须加上--enable-dtrace参数, 否则stap时会出现类似以下错误.
[root@db-172-16-3-39pg93]# stap test.stp
semantic error:while resolving probe point: identifier 'process' at test.stp:3:7source: probe process("/opt/pgsql9.3beta2/bin/postgres").mark("lock__wait__start")^semantic error: no match
semantic error:while resolving probe point: identifier 'process' at :8:7source: probe process("/opt/pgsql9.3beta2/bin/postgres").mark("lock__wait__done")^semantic error:while resolving probe point: identifier 'process' at :17:7source: probe process("/opt/pgsql9.3beta2/bin/postgres").mark("lwlock__wait__start")^semantic error:while resolving probe point: identifier 'process' at :22:7source: probe process("/opt/pgsql9.3beta2/bin/postgres").mark("lwlock__wait__done")^semantic error:while resolving probe point: identifier 'process' at :32:7source: probe process("/opt/pgsql9.3beta2/bin/postgres").mark("lwlock__condacquire__fail")^Pass2: analysis failed.  Try again with another '--vp 01'option.3. 允许stap需要root权限, 或者将用户加入stapdev或者stapsys, 以及stapusr组.
如果普通用户不加入这两个组, 执行stap将报错 :
pg93@db-172-16-3-39-> stap -ve 'probe begin { log("hello world") exit() }'You are trying to run systemtapasa normal user.
You should either be root, or be part of the group"stapusr" and possibly one of the groups "stapsys" or "stapdev".
Systemtap translator/driver (version 1.8/0.152 non-git sources)
加完组后正常
# usermod-G stapdev,stapusr pg94
pg94@db-172-16-3-39-> stap -ve 'probe begin { log("hello world") exit() }'Pass1: parsed user script and 85 library script(s) using 148892virt/23772res/3068shr/21396data kb, in 160usr/10sys/172real ms.
Pass2: analyzed script: 1 probe(s), 2 function(s), 0 embed(s), 0 global(s) using 149420virt/24492res/3292shr/21924data kb, in 10usr/0sys/6real ms.
Pass3: translated to C into "/tmp/stapcqtmUe/stap_758dbd41826239e5e3211a815f6bfc58_838_src.c" using 149420virt/24760res/3540shr/21924data kb, in 0usr/0sys/0real ms.
Pass4: compiled C into "stap_758dbd41826239e5e3211a815f6bfc58_838.ko" in 910usr/110sys/1028real ms.
Pass5: starting run.
hello world

http://blog.163.com/digoal@126/blog/static/16387704020137140265557/

PostgreSQL SystemTap on Linux 转相关推荐

  1. systemtap调试linux内核源码,内核调试工具SystemTap:适合懒人的printk替代品

    SystemTap是一个Linux调试和性能分析工具,可用于应用层和内核层的分析,但主要侧重内核层.SystemTab可以在不修改内核代码.不重复编译内核.不重启机器的情况下,收集运行内核的信息并使信 ...

  2. linux postgresql 创建数据库,Linux下创建Postgresql数据库的方法步骤

    Linux下创建Postgresql数据库的方法步骤 前言 PostgreSQL (也叫 Postgres)是一个自由的对象-关系数据库服务器(数据库管理系统),它在灵活的 BSD-风格许可证下发行. ...

  3. 【SystemTap】 Linux下安装使用SystemTap源码安装SystemTap

    文章 http://blog.csdn.net/zklth/archive/2010/09/28/5912785.aspx 介绍的是使用CentOS默认的SystemTap,这里介绍使用SystemT ...

  4. pg linux 的启动命令,PostgreSQL数据库在Linux下的安装与启动与使用

    我跟你说这个玩意要多坑有多坑,多坑的程度取决于你看的网上教程帖子有多烂的程度 PS:本文命令全部在root权限下执行,测试过PostgreSQL 9.3 ,9.4, 9.5多个版本,发行版为debia ...

  5. linux登录指令 pgsql_命令行方式登录PostgreSQL

    目录: 一.在默认配置条件下,本机访问PostgreSQL 二.创建新用户来访问PostgreSQL 三.最简单的做法 四.开启远程访问 一.在默认配置条件下,本机访问PostgreSQL 切换到Li ...

  6. linux系统yum 安装postgresql

    1.查看系统版本号(此次操作系统为redhat) cat /etc/issue,此命令也适用于所有的Linux发行版. cat /etc/redhat-release,这种方法只适合Redhat系的L ...

  7. PostgreSQL安装详细步骤(linux)

    官方安装文档:http://www.postgresql.org/download/linux/redhat/ 1. 检查PostgreSQL 是否已经安装 Linux-软件包管理-rpm命令管理-查 ...

  8. linux下安装 postgresql 14

    一,linux下安装postgresql         PostgreSQL: Linux downloads (Red Hat family) https://www.postgresql.org ...

  9. Linux下安装PostgreSQL

    Linux下安装PostgreSQL 一.PostgreSQL简介 二.Linux 上安装 PostgreSQL 1.二进制已编绎安装包方式安装 (1)下载二进制包 (2)创建postgres用户 ( ...

最新文章

  1. HBase结合MapReduce批量导入
  2. 吴恩达机器学习:神经网络 | 反向传播算法
  3. python编程入门教学下载-Python编程从入门到实践的PDF教程免费下载
  4. 第一次运行OSG入门程序失败记和搞定的情况
  5. 「JupyterNotebook」Linux下安装Anaconda3以及后续打开jupyter notebook
  6. python3.6字典有序_一日一技:Python 3.6以后,字典有序
  7. 高效便捷地创建单元格数据图表
  8. mysql 日期类型比价_MySQL 日期时间类型怎么选?
  9. 1010 一元多项式求导(C语言)
  10. 分布式存储系统学习笔记(一)—什么是分布式系统(4)—容错机制
  11. 使用X-shell管理员root连接ubuntu17.10服务器拒绝密码的一个失误!
  12. CMYK、RGB颜色对照表
  13. 使用已有流量进行RFC2544测试—信而泰网络测试仪实操
  14. ArcGIS API For Javascript之地图基本加载与显示,地图切换、缩放、定位、比例尺、鹰眼图、坐标显示、查询搜索功能实现
  15. 使用Arduino开发ESP32(15):模块基本信息与复位原因获取
  16. IDEA启动My Eclipse项目
  17. python中怎么打印出表格_怎么使用python脚本实现表格打印?
  18. 王者荣耀天赐语音包怎么获得?天赐语音包获取方法介绍
  19. 沟通的艺术(笔记)——前言
  20. python中文朗读_用python实现的文字朗读

热门文章

  1. 3 域名正则_一个正则表达式怎么会引起线上CPU狂飙?
  2. 域控限制软件安装_谷歌调整Android Q安装第三方APP策略,每次都需要手动解除限制...
  3. 【CV秋季划】模型算法与落地很重要,如何循序渐进地学习好?
  4. 【AutoML】进化算法如何用于自动模型搜索(NAS)
  5. 【通知】2020年有三AI-CV夏季划升级倒计时,最后两天
  6. 速卖通消费电子行业市场分析热销及需求品类推荐
  7. 全球及中国铝行业产销需求与未来前景预测分析报告2022-2028年版
  8. Ubuntu下对双显卡的支持问题
  9. 精准扶贫探索新融合模式-农业大健康·李龙:谋定乡村振兴
  10. 全球农业发展中国方案-国际农民丰收节贸易会:榜样力量