用 db2pd 工具分析 DB2 for Linux,UNIX,and Windows 中锁的等
当多个 DB2? 用户并发地访问一个数据库时,锁等待会导致响应变慢。锁等待是临时性的,因而难以捕捉。然而,当出现锁等待情形时,需要由数据库管理员负责确定锁等待的原因。本文通过例子演示如何使用用于 DB2 for Linux?, UNIX?, and Windows? 的 db2pd 和 db
当多个 DB2? 用户并发地访问一个数据库时,锁等待会导致响应变慢。锁等待是临时性的,因而难以捕捉。然而,当出现锁等待情形时,需要由数据库管理员负责确定锁等待的原因。本文通过例子演示如何使用用于 DB2 for Linux?, UNIX?, and Windows? 的db2pd
和db2pdcfg
实用程序完成该任务。
用于锁监视的 db2pd
选项
db2pd
是用于监视各种 DB2 数据库活动以及故障排除的实用程序。它是从 DB2 V8.2 开始随 DB2
引擎发布的一个独立的实用程序,其外观和功能类似于 Informix onstat
实用程序。db2pd
是从命令行以一种可选的交互模式执行的。该实用程序运行得非常快,因为它不需要获取任何锁,并且在引擎资源以外运行(这意味着它甚至能在一个挂起的引擎上工作)。通过快照监视还可以收集
db2pd
提供的很多监视器数据,但是 db2pd
和快照监视的输出格式却有很大不同。这使 DBA
可以选择更符合用户需求的监视替代方法。本文关注用于锁监视的 db2pd
选项。有一篇由 Sam Poon 撰写的
developerWorks 文章(参见 参考资料 小节)对
db2pd
的监视功能作了更广泛的介绍。
下面的图展示了用于锁监视的 db2pd
选项:
图 1. 用于锁监视的
db2pd
选项
-
TranHdl
:用于指定事务句柄,以便只监视由特定事务持有的锁。 -
showlocks
:这个子选项将锁名称扩展成有意义的解释。对于一个行锁,该选项显示以下信息:表空间 ID、表 ID、分区 ID、页和槽。通过使用编目视图SYSCAT.TABLES
上的一个查询,很容易将表空间 ID 和表 ID 映射到相应的表名:
清单 1. 将表空间 ID、表 ID 映射到表模式、表名
<br>SELECT TABSCHEMA, TABNAME<br>FROM SYSCAT.TABLES<br>WHERE TBSPACEID = tbspaceid AND TABLEID = tableid<br>
Copy after login
-
wait
:如果指定wait
子选项,则db2pd
只显示事务当前正在等待的锁,以及对等待情形负责的锁。这个子选项大大简化了锁等待分析,因为它将输出限制为参与锁等待情形的锁。 -
db2pd database
和file
选项不是特定于锁监视的,但是适用于(几乎)所有db2pd
调用。database
选项将db2pd
返回的监视器数据限制为某个数据库的监视器数据。而file
选项则允许定义一个文件,以便将db2pd
输出写到该文件。
锁等待分析场景
接下来,我们开始使用前面介绍的 db2pd
选项来分析一个示例锁等待情形。为此,我们创建 DB2
SAMPLE
数据库:
清单 2. 创建
SAMPLE
数据库<br>db2sampl<br> Copy after login |
用户 A 执行事务 A,以根据每个经理的薪水为他们提供 10% 的奖金:
清单 3. 事务 A 执行的更新操作
<br>UPDATE EMPLOYEE<br>SET BONUS = SALARY * 0.1<br>WHERE JOB = 'MANAGER'<br> Copy after login |
当事务 A 仍然在运行(因为用户 A 还没有使用 COMMIT
或 ROLLBACK
终止该事务)时,用户 B 执行事务 B,以将每个雇员的薪水提高 2%:
清单 4. 事务 B 执行的更新操作
<br>UPDATE EMPLOYEE<br>SET SALARY = SALARY * 0.02<br> Copy after login |
由于事务 B 没有完成,用户 B 请求 DBA 确定问题的原因。于是,DBA 调用
db2pd
,看是否存在锁等待情形:
清单 5. 检查锁等待情形
<br>db2pd -db sample -locks wait showlocks<br><br>Database Partition 0 -- Database SAMPLE -- Active -- Up 3 days 08:33:05<br><br>Locks:<br>Address TranHdl Lockname Type Mode Sts Owner Dur <br>0x050A0240 6 02000600050040010000000052 Row ..X W 2 1 <br>0x050A0DB0 2 02000600050040010000000052 Row ..X G 2 1 <br><br>HoldCount Att ReleaseFlg<br>0 0x00 0x40000000 TbspaceID 2 TableID 6 PartitionID 0 Page 320 Slot 5<br>0 0x00 0x40000000 TbspaceID 2 TableID 6 PartitionID 0 Page 320 Slot 5<br> Copy after login |
db2pd
报告 ID 为 2 的表空间中一个 ID 为 6 的表上有一个行锁存在锁等待情形。通过检查
SYSCAT.TABLES
,DBA 断定表 EMPLOYEE
上的确存在锁等待。
清单 6. 确定锁等待情形所涉及的表
请点击此处查看全文

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



DebianSniffer is a network sniffer tool used to capture and analyze network packet timestamps: displays the time for packet capture, usually in seconds. Source IP address (SourceIP): The network address of the device that sent the packet. Destination IP address (DestinationIP): The network address of the device receiving the data packet. SourcePort: The port number used by the device sending the packet. Destinatio

This article introduces several methods to check the OpenSSL configuration of the Debian system to help you quickly grasp the security status of the system. 1. Confirm the OpenSSL version First, verify whether OpenSSL has been installed and version information. Enter the following command in the terminal: If opensslversion is not installed, the system will prompt an error. 2. View the configuration file. The main configuration file of OpenSSL is usually located in /etc/ssl/openssl.cnf. You can use a text editor (such as nano) to view: sudonano/etc/ssl/openssl.cnf This file contains important configuration information such as key, certificate path, and encryption algorithm. 3. Utilize OPE

To improve the security of DebianTomcat logs, we need to pay attention to the following key policies: 1. Permission control and file management: Log file permissions: The default log file permissions (640) restricts access. It is recommended to modify the UMASK value in the catalina.sh script (for example, changing from 0027 to 0022), or directly set filePermissions in the log4j2 configuration file to ensure appropriate read and write permissions. Log file location: Tomcat logs are usually located in /opt/tomcat/logs (or similar path), and the permission settings of this directory need to be checked regularly. 2. Log rotation and format: Log rotation: Configure server.xml

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

This article discusses the network analysis tool Wireshark and its alternatives in Debian systems. It should be clear that there is no standard network analysis tool called "DebianSniffer". Wireshark is the industry's leading network protocol analyzer, while Debian systems offer other tools with similar functionality. Functional Feature Comparison Wireshark: This is a powerful network protocol analyzer that supports real-time network data capture and in-depth viewing of data packet content, and provides rich protocol support, filtering and search functions to facilitate the diagnosis of network problems. Alternative tools in the Debian system: The Debian system includes networks such as tcpdump and tshark

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

This article discusses the DDoS attack detection method. Although no direct application case of "DebianSniffer" was found, the following methods can be used for DDoS attack detection: Effective DDoS attack detection technology: Detection based on traffic analysis: identifying DDoS attacks by monitoring abnormal patterns of network traffic, such as sudden traffic growth, surge in connections on specific ports, etc. This can be achieved using a variety of tools, including but not limited to professional network monitoring systems and custom scripts. For example, Python scripts combined with pyshark and colorama libraries can monitor network traffic in real time and issue alerts. Detection based on statistical analysis: By analyzing statistical characteristics of network traffic, such as data
