当多个 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>
-
wait
:如果指定wait
子选项,则db2pd
只显示事务当前正在等待的锁,以及对等待情形负责的锁。这个子选项大大简化了锁等待分析,因为它将输出限制为参与锁等待情形的锁。 -
db2pd database
和file
选项不是特定于锁监视的,但是适用于(几乎)所有db2pd
调用。database
选项将db2pd
返回的监视器数据限制为某个数据库的监视器数据。而file
选项则允许定义一个文件,以便将db2pd
输出写到该文件。
锁等待分析场景
接下来,我们开始使用前面介绍的 db2pd
选项来分析一个示例锁等待情形。为此,我们创建 DB2
SAMPLE
数据库:
清单 2. 创建
SAMPLE
数据库<br>db2sampl<br> |
用户 A 执行事务 A,以根据每个经理的薪水为他们提供 10% 的奖金:
清单 3. 事务 A 执行的更新操作
<br>UPDATE EMPLOYEE<br>SET BONUS = SALARY * 0.1<br>WHERE JOB = 'MANAGER'<br> |
当事务 A 仍然在运行(因为用户 A 还没有使用 COMMIT
或 ROLLBACK
终止该事务)时,用户 B 执行事务 B,以将每个雇员的薪水提高 2%:
清单 4. 事务 B 执行的更新操作
<br>UPDATE EMPLOYEE<br>SET SALARY = SALARY * 0.02<br> |
由于事务 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> |
db2pd
报告 ID 为 2 的表空间中一个 ID 为 6 的表上有一个行锁存在锁等待情形。通过检查
SYSCAT.TABLES
,DBA 断定表 EMPLOYEE
上的确存在锁等待。
清单 6. 确定锁等待情形所涉及的表
请点击此处查看全文

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool