DB2 UDB Interview Questions and Answers
Basic Level
Q: What is DB2 UDB and how does it differ from other RDBMS like Oracle or SQL Server?
A: DB2 UDB (Universal Database) is IBM's RDBMS that supports both structured and unstructured
data. Compared to Oracle or SQL Server, it is platform-independent and known for its support for
high-performance, scalable applications. DB2 supports SQL, XML, and NoSQL data types.
Q: Explain the difference between a tablespace and a bufferpool.
A: A tablespace is a logical storage structure used to store database objects like tables and indexes,
while a bufferpool is a memory area that caches data pages to improve performance.
Q: What are the different types of tablespaces in DB2?
A: DB2 has three main types of tablespaces: System Managed Space (SMS), Database Managed
Space (DMS), and Automatic Storage tablespaces.
Q: How do you take a backup of a DB2 database?
A: Using the command: `db2 backup db <dbname> to <path>`, which can be either online or offline
depending on availability requirements.
Q: What are container types in DB2 tablespaces?
A: Containers are physical storage units (files, devices, or directories) used to store data for DMS or
SMS tablespaces.
Intermediate Level
Q: Explain the DB2 instance structure.
A: A DB2 instance is an independent environment for running databases, including memory,
background processes, and configuration files.
Q: What is runstats and why is it important?
A: `RUNSTATS` collects statistics about tables and indexes which help the optimizer create efficient
access plans for queries.
Q: How would you perform a redirected restore?
A: Use `RESTORE DATABASE ... REDIRECT` followed by `SET TABLESPACE CONTAINERS
FOR ...` and `RESTORE DATABASE ... CONTINUE` to relocate the tablespace containers.
Q: How is locking handled in DB2?
A: DB2 supports row, page, and table-level locks. It uses lock escalation to switch from fine-grained
to coarse-grained locks under pressure.
Q: How do you monitor long-running queries?
A: Using `db2pd`, `mon_get_pkg_cache_stmt`, or `db2top` to check for high CPU time or elapsed
time queries.
Advanced Level
Q: Explain how DB2 handles crash recovery.
A: DB2 uses transaction logs to perform roll-forward recovery. Uncommitted transactions are rolled
back and committed ones are reapplied.
Q: How is HADR set up and monitored in DB2?
A: HADR involves primary and standby servers with log shipping. Use `db2pd -hadr` or
`mon_get_hadr` views to monitor status.
Q: How do you perform rolling upgrades in an HADR environment?
A: Upgrade the standby, switch roles using `TAKEOVER`, then upgrade the former primary.
Resume HADR after upgrades.
Q: What are the common causes of lock escalation and how do you prevent it?
A: Lock escalation occurs when too many row-level locks are held. Prevent using appropriate
commit frequency and `LOCKMAX` setting.
Q: How do you secure a DB2 database at the OS and database level?
A: Use OS file permissions, DB2 authorization (SYSADM, DBADM), encryption (native or external),
and auditing features.