PostgreSQL SystemTap on Linux

Source: Internet
Author: User
Tags gpg postgresql systemtap

Http://;jsessionid=3949B03DE151DA0E55D807466C5E630B.yqblog35-8010? Blogid=fks_087064087086083071087082094069072087087064092081081067080086&showrest=true&p=2&[email Protected

With @digoal 2013-08-14 15:57

The reason for this error is that the library file version is incorrect for the old version, using Eu-readelf to view the two environment variables of the STAP file, as follows:

[Email protected] ~]# eu-readelf-d/usr/bin/stap|grep-e "rpath| Runpath "RPATH library RPATH: [/usr/lib64/systemtap] Runpath library Runpath: [/usr/lib64/systemta P] joins the path to the Ld_library_path.

[Email protected] ~]# export LD_LIBRARY_PATH=/USR/LIB64/SYSTEMTAP: $LD _library_pathstap now normal.

[Email protected] ~]# STAP A script must be specified. Systemtap translator/driver (version 1.8/0.152 non-git sources) Copyright (C) 2005-2012 Red Hat, Inc. and Othersthis is fre e software; See the source for copying conditions.enabled features:avahi librpm LIBSQLITE3 NSS boost_shared_ptr tr1_unordered_map NLS   Usage:stap [Options] File Run script in file.   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. Test:

[[Email protected] pg94]# VI tps.d probe begin{printf ("hello\n") exit ()}[[email protected] pg94]# STAP tps.d Checking " /lib/modules/2.6.18-274.el5/build/.config "failed with error:no such file or Directoryincorrect version or missing kernel -devel package, Use:yum install kernel-devel-2.6.18-274.el5.x86_64 This error is due to the fact that the kernel-devel packages that are currently running kernel are not installed.

[Email protected] pg94]# Rpm-qa|grep Kernelkernel-headers-2.6.18-274.el5kernel-xen-devel-2.6.18-274.el5kernel-xen-2.6.18-274.el5kernel-2.6.18-274.el5 [Email protected] ~]# uname-alinux 2.6.18-274.el5 #1 SMP Fri Jul 04:43:29 EDT x86_64 x86_64 x86_64 Gnu/linux installs the corresponding Kernel-devel version.

Yum install kernel-devel-2.6.18-274.el5.x86_64 If the Yum source does not have this version of the Kernel-devel package, you can go to the installation CD to find it. or update the kernel version to a new version at the same time.

Yum install-y kernel.x86_64 kernel-devel.x86_64package kernel-2.6.18-348.12.1.el5.x86_64 already installed and latest Versionpackage kernel-devel-2.6.18-348.12.1.el5.x86_64 already installed and latest versionvi/boot/grub/ Grub.confdefault=0timeout=5splashimage= (hd0,0)/boot/grub/splash.xpm.gzhiddenmenutitle 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 quiet initrd/boot/in Itrd-2.6.18-348.12.1.el5.img Restart the server now STAP working properly:

[[email protected] postgresql-5e3e8e4]# stap-ve ' probe begin {log ("Hello World") exit ()} '
Pass 1:parsed user script and the library script (s) using 146788virt/23676res/3000shr/21384data KB, in 170usr/0sys/173real Ms.
Pass 2: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.
Pass 3:using cached/root/.systemtap/cache/3b/stap_3b2eaec778ce9832b394535505dde575_838.c

Pass 4:using Cached/root/.systemtap/cache/3b/stap_3b2eaec778ce9832b394535505dde575_838.ko
Pass 5:starting run.
Hello World
Pass 5:run completed in 0usr/20sys/306real Ms.

STAP after debugging, it can be used to track PostgreSQL. DTrace support must be turned on at PostgreSQL compile time. When DTrace is turned on, the database will enable probes or trace points in your code. The PostgreSQL built-in probe reference is as follows: src/backend/utils/probes.d dynamic-trace.html Check if your PostgreSQL has enabled DTrace support, as follows:

[Email protected]> 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 '-- Enable-thread-safety '--with-wal-blocksize=16 '--enable-dtrace ' if there is no--enable-dtrace, then you need to recompile your PostgreSQL software. STAP test script 1.

[email protected] pg94]# cat POSTGRESQL-QUERY.STP Global Query_time, query_summary probe process ("/home/pg94/ Pgsql9.4devel/bin/postgres "). Mark (" Query__start ") {Query_time[tid (), $arg 1] = Gettimeofday_us ();} Probe process ("/ Home/pg94/pgsql9.4devel/bin/postgres "). Mark (" Query__done ") {p = tid () t = query_time[p, $arg 1]; Delete query_time[p, $a  RG1] if (t) {query_summary[p] <<< (Gettimeofday_us ()-T);  }} probe End {printf ("\ntid Count min (US) AVG (US) max (US) \ n"); foreach (P in query_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])); }}

Execution STAP:

[[email protected] pg94]# STAP POSTGRESQL-QUERY.STP execute the following sql:

[Email protected] pg94]# STAP POSTGRESQL-QUERY.STP digoal=# begin; begindigoal=# SELECT * from test for update; ID----1 2 3 4 5 6 7 8 9 ten rows digoal=# end; commitdigoal=# select Txid_current (); Txid_current--------------5969062 (1 row) end STAP, output:

[[email protected] pg94]# STAP POSTGRESQL-QUERY.STP Key ctrl + C, output: Tid count min (US) AVG (US) max (US) 17112 4 46 3794 14885 This Tid corresponds to PostgreSQL background process

[[email protected] pg94]# ps-ewf|grep 17112pg94 17112 17005 0 15:15? 00:00:00 postgres:postgres digoal [local] idledigoal=# select Pg_backend_pid (); Pg_backend_pid----------------17112 (1 row) [summary]1. Installation Systemtap Note:--need to install kernel related, and the version to be consistent, start the kernel version of the same: Kernelkernel-debuginfokernel-devel

The debug source is used to install the kernel-debuginfo.

[[email protected] pg94]# cd/etc/yum.repos.d/[[email protected] yum.repos.d]# lltotal 36-rw-r--r--1 root Root 1926  2011 centos-base.repo-rw-r--r--1 root root  631  2011 centos-debuginfo.repo-rw-r- -r--1 root root  626  2011 centos-media.repo-rw-r--r--1 root root 5390  2011 CENTOS-VAULT.R Epo[[email protected] 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 is updated to and# Geograp Hically close to the client.  you should use this for CentOS updates# unless you is manually picking other mirrors.# # all debug packages fr Om all the various CentOS-5 releases# is merged into a mono repo, split by basearch## Note:packages in the Debuginfo R EPO is currently not signed# [debug]name=centos-5-debuginfobaseurl=$basearch/ gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-5enabled=0

The source name used here is Debug.

Yum--enablerepo=debug list Kernel-debuginfoyum--enablerepo=debug install Kernel-debuginfo Installation Details reference this article:/http 2. PostgreSQL must be compiled with the--enable-dtrace parameter, otherwise an error similar to the following will appear when Stap.

[[email protected] pg93]# STAP test.stp semantic error:while resolving probe point:identifier ' process ' at TES t.stp:3:7        Source:probe process ("/opt/pgsql9.3beta2/bin/postgres"). Mark ("lock__wait__ Start ")                       ^ semantic Error:no Matchsemanti C Error:while resolving probe point:identifier ' process ' at:8:7        Source:probe process ("/opt/ Pgsql9.3beta2/bin/postgres "). Mark (" Lock__wait__done ")                   & nbsp   ^ semantic error:while resolving probe point:identifier ' process ' at:17:7        Source : Probe process ("/opt/pgsql9.3beta2/bin/postgres"). Mark ("Lwlock__wait__start")                       ^ semantic error:while resolving probe point:identifier ' process ' at:22: 7        Source:probe Process ("/opt/pgsql9.3beta2/bin/postgres"). Mark ("Lwlock__wait__done")                       ^ semantic error:while resolving probe point:identifier ' process ' at:32:7        Source:probe process ("/opt/pgsql9.3beta2/bin/postgres"). Mark ("Lwlock__condacquire__fail")                       ^ pass 2:analysis failed.  try again with another '--VP "option.

3. Allow STAP to require root privileges, or to add users to Stapdev or Stapsys, and to the STAPUSR group. If the average user does not join these two groups, execution STAP will error:

[email protected]> Stap-ve ' probe begin {log ("Hello World") exit ()} ' is trying to run Systemtap as a normal User. You should either is 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) normal  # usermod-g stapdev,stapusr Pg94[email after group addition  protected]> Stap-ve ' probe begin {log ("Hello World") exit ()} ' Pass 1:parsed user script and the library script ( s) using 148892virt/23772res/3068shr/21396data KB, in 160usr/10sys/172real Ms. Pass 2: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. Pass 3:translated to C into "/tmp/stapcqtmue/stap_758dbd41826239e5e3211a815f6bfc58_838_src.c" using 149420virt/ 24760res/3540shr/21924data KB, in 0usr/0sys/0real Ms. Pass 4:compiled C into "Stap_758dbd41826239e5e3211a815f6bfc58_838.ko" in 910usr/110sys/1028real Ms. Pass 5:starting Run.hello WorlDpass 5:run completed in 10usr/20sys/307real Ms.

This article explains how to use PostgreSQL's probes next time.


1. Probing-postgresql-dtrace-and-systemtap3. . dtrace-dynamic-tracing-in-oracle-solaris-mac-os-x-and-freebsd.html6. Pg_perf_bootcamp.pdf7. Homepage11. /2009/05/postgresql-with-systemtap.html13. 1ccb0466-79b7-4090-9a5d-9371358ac54d/b8434e3e3b3130ce72422b9ae067e7b914. Infocenter/lnxinfo/v3r0m0/topic/liaai.systemtap/liaaisystap_pdf.pdf15. 201305/395819.htm


PostgreSQL SystemTap on Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.