BIT352 · TU past paper
Database Administration 2081 question paper
The complete TU 2081 exam paper for Database Administration (BIT352), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- 110 marksLocking levels in oracleHideAnswer
Describe levels of locking in oracle. Discuss the methods used to acquire locks in oracle.[10]
Levels of Locking in Oracle and Methods to Acquire Locks
Note: The reference notes did not contain specific content on this topic. The following answer is based on standard Oracle database concepts as taught in database management system courses at the BSc CSIT level.
Introduction to Locking in Oracle
A lock is a mechanism that prevents destructive interaction between transactions accessing a shared resource. Oracle Database uses a multi-level locking strategy to provide maximum concurrency while maintaining data integrity and consistency.
Oracle's locking philosophy is:
- Locks are acquired automatically (implicitly) by DML statements.
- Oracle never escalates locks (a key difference from many other RDBMS).
- Readers do not block writers, and writers do not block readers.
Levels of Locking in Oracle
Oracle implements locking at multiple granularity levels:
1. Row-Level Locks (TX Locks - Transaction Locks)
- The finest granularity of locking in Oracle.
- When a transaction modifies a row (
INSERT,UPDATE,DELETE,SELECT FOR UPDATE), Oracle places an exclusive lock on that specific row. - Other transactions can read the row (using MVCC - Multi-Version Concurrency Control) but cannot modify it until the lock is released.
- Row-level locks are stored within the data block itself (in the row header), not in a separate lock table.
- This allows Oracle to lock millions of rows without lock escalation.
Example:
UPDATE employees SET salary = 5000 WHERE emp_id = 101; -- Only row with emp_id = 101 is locked
2. Table-Level Locks (TM Locks - DML Locks)
- Placed on the entire table to protect the table structure while row-level locks are held.
- Table locks do not prevent other transactions from accessing rows; they prevent DDL operations (like
DROP TABLEorALTER TABLE) from conflicting with ongoing DML. - Oracle supports five modes of table-level locks:
Mode Abbreviation Description Row Share RS (SS) Allows concurrent access; prevents exclusive table lock Row Exclusive RX (SX) Used during DML; prevents share and exclusive locks Share S Allows only reads; prevents DML by others Share Row Exclusive SRX (SSX) More restrictive than Share; only one transaction can hold it Exclusive X Full exclusive access; no other DML or DDL allowed Lock Compatibility Matrix:
RS RX S SRX X RS Y Y Y Y N RX Y Y N N N S Y N Y N N SRX Y N N N N X N N N N N (Y = Compatible, N = Incompatible)
3. Page/Block-Level Locks
- Oracle does not use page-level or block-level locking as a standard locking granularity.
- This is a deliberate design choice to avoid unnecessary contention.
- Lock information is embedded in the block header (Interested Transaction List - ITL), but this is not a separate locking level.
4. Database-Level Locks (DDL Locks)
- Protect the definition (schema) of database objects during DDL operations.
- Three types:
- Exclusive DDL Lock: Acquired during
DROP,ALTER,CREATEoperations. No other DDL or DML allowed on the object. - Share DDL Lock: Acquired during
CREATE PROCEDURE,CREATE VIEW. Allows other share DDL locks but not exclusive. - Breakable Parse Lock: Held by SQL statements in the shared pool. Can be broken if a DDL operation requires it.
- Exclusive DDL Lock: Acquired during
5. System/Dictionary Locks (Internal Locks and Latches)
- Latches: Low-level serialization mechanisms protecting internal Oracle memory structures (e.g., SGA, buffer cache). They are not user-visible.
- Internal Locks: Protect internal database structures like data file headers and control files.
- These are managed entirely by Oracle and are not accessible to users.
Methods Used to Acquire Locks in Oracle
Oracle provides both implicit (automatic) and explicit (manual) methods to acquire locks.
Method 1: Implicit (Automatic) Locking
Oracle automatically acquires locks when DML statements are executed. The user does not need to request them.
SQL Statement Row Lock Table Lock Mode INSERTExclusive (X) on new row RX UPDATEExclusive (X) on modified rows RX DELETEExclusive (X) on deleted rows RX SELECTNo lock No lock (MVCC used) Example:
UPDATE departments SET dept_name = 'HR' WHERE dept_id = 10; -- Oracle automatically acquires: Row X lock + Table RX lockLocks are automatically released when the transaction ends (
COMMITorROLLBACK).
Method 2: SELECT ... FOR UPDATE (Explicit Row Lock)
- Used to explicitly lock rows that a transaction intends to modify later.
- Prevents other transactions from modifying or locking the same rows.
- Useful when a transaction reads data and then updates it later in the same transaction.
Syntax:
SELECT column_list FROM table_name WHERE condition FOR UPDATE [OF column] [NOWAIT | WAIT n | SKIP LOCKED];Options:
NOWAIT: Returns an error immediately if the lock cannot be acquired.WAIT n: Waits fornseconds before returning an error.SKIP LOCKED: Skips rows that are already locked.
Example:
SELECT emp_id, salary FROM employees WHERE dept_id = 10 FOR UPDATE NOWAIT; -- The selected rows are locked in exclusive mode until COMMIT or ROLLBACK
Method 3: LOCK TABLE (Explicit Table Lock)
- Used when a transaction wants to lock an entire table rather than individual rows.
- The lock mode is stated explicitly, which lets the developer decide how much concurrency to give up.
Syntax:
LOCK TABLE table_name IN lock_mode MODE [NOWAIT];Common lock modes:
Mode Meaning ROW SHARE (RS) Allows concurrent access, only prevents exclusive table locks ROW EXCLUSIVE (RX) Acquired automatically by INSERT, UPDATE and DELETE SHARE (S) Allows other readers, blocks all writers SHARE ROW EXCLUSIVE (SRX) Allows readers only, one transaction at a time EXCLUSIVE (X) Strictest, only queries are allowed on the table Example:
LOCK TABLE employees IN EXCLUSIVE MODE NOWAIT;
Method 4: DDL Locks (Acquired Automatically)
- Oracle takes a DDL lock on an object whenever a DDL statement such as
ALTER TABLEorDROP TABLErefers to it, so the definition cannot change under a statement that is still compiling or executing. - These locks are never requested by the user; they are held only for the duration of the DDL statement.
Conclusion
Oracle locks at several granularities, from the row level (TX locks, the normal case) up through table level (TM locks), block level, and the DDL and internal locks that protect the data dictionary. Locks are acquired in two ways: implicitly, when a DML statement runs and Oracle takes the row and table locks it needs, and explicitly, through
SELECT ... FOR UPDATEfor rows orLOCK TABLEfor whole tables. Oracle's default is deliberately conservative in favour of concurrency, since readers never block writers and writers never block readers thanks to multiversion read consistency, and every lock is released automatically atCOMMITorROLLBACK. - 210 marksOracle database architecture overviewHideAnswer
Explain architecture of oracle database with suitable diagram.[10]
Note: The reference notes did not contain this topic. The following answer is based on standard Oracle Database architecture as taught in Database Management Systems courses at TU BSc CSIT level. --- Oracle Database has a well-defined ar...
- 310 marksSpace management and segment creationHideAnswer
What is space management? How space management is done? How can you create tables without segments?[10]
Space management refers to the process of efficiently allocating, monitoring, and reclaiming storage space within a database. It involves managing how data is stored in segments, extents, and data blocks to ensure optimal use of physical...
- 45 marksRoles and responsibilities of database admHideAnswer
What are the roles and responsibilities of Database Administrator? [5]
Roles and Responsibilities of Database Administrator (DBA)
A Database Administrator (DBA) is a person responsible for managing, maintaining, and securing the database system in an organization. The DBA acts as a central authority over the database environment.
Key Roles and Responsibilities of a DBA
1. Schema Definition
- The DBA is responsible for creating the original database schema by writing a set of definitions in the DDL (Data Definition Language).
- This includes defining tables, views, constraints, and relationships.
2. Storage Structure and Access Method Definition
- The DBA defines how data is physically stored on storage devices.
- Decides on appropriate access methods (e.g., indexing, hashing) to ensure efficient data retrieval.
3. Schema and Physical Organization Modification
- When requirements change, the DBA modifies the schema or physical organization.
- This includes altering tables, adding new attributes, or reorganizing storage to improve performance.
4. Granting Authorization for Data Access
- The DBA controls who can access what data by granting or revoking access privileges.
- Ensures that only authorized users can read, write, or modify specific data.
5. Routine Maintenance
The DBA performs regular maintenance tasks such as:
- Backup and Recovery: Periodically backing up data and recovering it in case of failure.
- Performance Monitoring: Monitoring the database for slow queries and tuning performance.
- Disk Space Management: Ensuring sufficient storage is available for database operations.
6. Integrity Constraint Definition
- The DBA defines integrity constraints (e.g., primary keys, foreign keys, check constraints) to maintain data accuracy and consistency.
7. Liaison with Users
- Acts as a bridge between end users and the database system.
- Understands user requirements and translates them into appropriate database structures.
Summary Table
Responsibility Description Schema Definition Define database structure using DDL Access Control Grant/revoke user privileges Backup & Recovery Protect data from loss Performance Tuning Optimize query and system performance Integrity Constraints Ensure data accuracy and consistency
Note: The DBA holds the highest level of authority in a database environment and is essential for the smooth, secure, and efficient operation of any database system.
- 55 marksAdding new tablespaces and datafilesHideAnswer
What is tablespace and datafile in oracle? How can we add new tablespace and datafiles in oracle database? [5]
Tablespace and Datafile in Oracle
Tablespace
A tablespace is a logical storage unit in an Oracle database that groups related logical structures (tables, indexes, etc.) together. It is the bridge between the physical and logical components of an Oracle database. Every Oracle database has at least one tablespace called the SYSTEM tablespace.
Key points:
- It is a logical storage container
- A database is divided into one or more tablespaces
- Each tablespace belongs to only one database
Datafile
A datafile is a physical operating system file that actually stores the data on disk. Every tablespace is made up of one or more datafiles.
Key points:
- It is a physical file stored on the disk (e.g.,
.dbffile) - One tablespace can have multiple datafiles
- One datafile belongs to only one tablespace
Relationship:
Database --> Tablespace (Logical) --> Datafile (Physical)
Adding a New Tablespace
Use the
CREATE TABLESPACEstatement:CREATE TABLESPACE my_tablespace DATAFILE '/u01/oradata/mydb/my_tablespace01.dbf' SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 500M;Explanation of clauses:
Clause Meaning DATAFILESpecifies the physical file path and name SIZEInitial size of the datafile AUTOEXTEND ONAutomatically extends when full NEXTSize by which file extends each time MAXSIZEMaximum size the file can grow to
Adding a New Datafile to an Existing Tablespace
Use the
ALTER TABLESPACEstatement:ALTER TABLESPACE my_tablespace ADD DATAFILE '/u01/oradata/mydb/my_tablespace02.dbf' SIZE 50M AUTOEXTEND ON NEXT 5M MAXSIZE 200M;This adds a second datafile to the existing tablespace
my_tablespace, increasing its total storage capacity.
Summary
Concept Type Description Tablespace Logical Groups database objects logically Datafile Physical Actual file on disk storing data CREATE TABLESPACEDDL Creates a new tablespace with datafile ALTER TABLESPACE ... ADD DATAFILEDDL Adds a new datafile to existing tablespace - 65 marksPrivilege definition and importanceHideAnswer
What is privilege? Write commands to create user, grant privilege, revoke privilege and drop user in oracle database. [5]
Privilege in Oracle Database
What is Privilege?
A privilege is a right or permission granted to a database user to perform a specific operation or to access a specific database object. Privileges control what actions a user can perform in the database system.
There are two types of privileges in Oracle:
- System Privileges - Allow users to perform specific database operations (e.g., CREATE TABLE, CREATE SESSION)
- Object Privileges - Allow users to perform operations on specific database objects like tables, views, etc. (e.g., SELECT, INSERT, UPDATE, DELETE on a table)
Oracle Database Commands
1. Create User
CREATE USER username IDENTIFIED BY password;Example:
CREATE USER john IDENTIFIED BY john123;
2. Grant Privilege
GRANT privilege_name TO username;Example (System Privilege):
GRANT CREATE SESSION TO john; GRANT CREATE TABLE TO john;Example (Object Privilege):
GRANT SELECT, INSERT ON employees TO john;The
WITH GRANT OPTIONallows the user to further grant the privilege to others:GRANT SELECT ON employees TO john WITH GRANT OPTION;
3. Revoke Privilege
REVOKE privilege_name FROM username;Example (System Privilege):
REVOKE CREATE TABLE FROM john;Example (Object Privilege):
REVOKE SELECT, INSERT ON employees FROM john;
4. Drop User
DROP USER username;Example:
DROP USER john;If the user owns database objects (tables, views, etc.), use
CASCADEto drop the user along with all their objects:DROP USER john CASCADE;
Summary Table
Operation Command Syntax Create User CREATE USER name IDENTIFIED BY password;Grant Privilege GRANT privilege TO user;Revoke Privilege REVOKE privilege FROM user;Drop User DROP USER name [CASCADE]; - 75 marksOracle AWR overviewHideAnswer
What is Oracle AWR? How AWR report is viewed in oracle? [5]
Oracle AWR (Automatic Workload Repository)
What is Oracle AWR?
AWR (Automatic Workload Repository) is a built-in Oracle Database feature that automatically collects, processes, and maintains performance statistics for problem detection and self-tuning purposes.
Note: The following answer is based on standard Oracle Database documentation, as no specific curriculum notes were provided.
Key Characteristics of AWR:
- AWR is a repository of historical performance data stored in the SYSAUX tablespace of the Oracle database.
- It collects snapshots of database performance statistics at regular intervals (default: every 60 minutes).
- Snapshots are retained for a default period of 8 days, after which they are automatically purged.
- It is managed by the MMON (Manageability Monitor) background process.
Data Collected by AWR:
Category Examples Wait statistics Top wait events, wait times SQL statistics High-load SQL statements System statistics CPU usage, I/O, memory Object statistics Segment-level access info Time model statistics DB time, parse time Purpose of AWR:
- Identify performance bottlenecks
- Compare database performance between two time periods
- Support the Automatic Database Diagnostic Monitor (ADDM)
- Assist DBAs in capacity planning and tuning
How AWR Report is Viewed in Oracle
AWR reports can be generated and viewed using the following methods:
Method 1: Using SQL*Plus Script
Oracle provides a built-in script to generate the AWR report:
@$ORACLE_HOME/rdbms/admin/awrrpt.sqlSteps:
-
Connect to the database as SYSDBA:
sqlplus / as sysdba -
Run the AWR report script:
@$ORACLE_HOME/rdbms/admin/awrrpt.sql -
The script prompts for:
- Report format: HTML or TEXT
- Number of days: to list available snapshots
- Beginning Snapshot ID
- Ending Snapshot ID
- Report filename
-
The report is saved as an
.htmlor.txtfile and can be opened in a browser.
Method 2: Using Oracle Enterprise Manager (OEM)
- Navigate to: Performance > AWR > AWR Report
- Select the begin and end snapshot
- Click Generate Report
- View the report directly in the browser interface
Method 3: Using DBMS_WORKLOAD_REPOSITORY Package
SELECT output FROM TABLE( DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML( l_dbid => &dbid, l_inst_num => 1, l_bid => &begin_snap, l_eid => &end_snap ) );
Key Sections in an AWR Report:
- Report Summary - DB time, load profile
- Top 5 Timed Events - Major wait events
- SQL Statistics - Top SQL by CPU, elapsed time
- Instance Activity Statistics
- I/O Statistics
- Memory Statistics
Summary
Feature Detail Storage location SYSAUX tablespace Default snapshot interval 60 minutes Default retention 8 days Background process MMON Report script awrrpt.sqlAWR is a critical tool for Oracle DBAs to diagnose, monitor, and tune database performance effectively.
- 85 marksRole definition and purposeHideAnswer
What is Role? Explain its role in privilege management with suitable example. [5]
A role is a named collection of privileges (permissions) that can be granted to users or other roles. Instead of assigning individual privileges directly to each user, privileges are grouped into a role, and that role is then assigned to...
- 95 marksSQL tuning definition and processHideAnswer
What is SQL Tuning? Explain SQL Tuning Process in Oracle? [5]
SQL Tuning (also called SQL Optimization) is the iterative process of improving the performance of SQL statements so that they execute faster, consume fewer resources (CPU, memory, I/O), and place less load on the database server. The go...
- 105 marksUser profiles and profile assignmentHideAnswer
What is user profile? Create a simple user profile and assign the profile to new user in oracle. [5]
A user profile in Oracle is a named set of resource limits and password management parameters that can be assigned to one or more database users. It controls and restricts the use of database resources such as CPU time, logical reads, se...
- 115 marksListener definition and purposeHideAnswer
What is listener? Explain about listener.ora and tnsnames.ora file in oracle database. [5]
Listener, listener.ora, and tnsnames.ora in Oracle Database
Listener
A listener is a server-side network process in Oracle Database that listens for incoming client connection requests on a specific network protocol (usually TCP/IP) and a specific port (default port: 1521).
When a client wants to connect to an Oracle database, it sends a connection request to the listener. The listener receives the request, verifies it, and then hands off (redirects) the connection to the appropriate Oracle database instance.
Key points about Listener:
- It runs on the database server machine.
- It is managed using the lsnrctl (Listener Control) utility.
- Common commands:
lsnrctl start,lsnrctl stop,lsnrctl status - Without a running listener, remote clients cannot connect to the Oracle database.
listener.ora File
The
listener.orafile is a server-side configuration file that defines the listener's properties and settings.Location:
$ORACLE_HOME/network/admin/listener.oraIt contains:
- The name of the listener (default:
LISTENER) - The protocol, host, and port on which the listener listens
- The Oracle database services/SIDs it serves
Example:
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = myserver.example.com) (PORT = 1521) ) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = ORCL) (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1) ) )Key parameters:
Parameter Description PROTOCOLNetwork protocol (TCP/IP) HOSTServer hostname or IP address PORTPort number (default 1521) SID_NAMEOracle System Identifier
tnsnames.ora File
The
tnsnames.orafile is a client-side configuration file that maps logical service names (aliases) to Oracle database connection descriptors (host, port, service name).Location:
$ORACLE_HOME/network/admin/tnsnames.oraWhen a client application uses a connect string like
sqlplus user/pass@ORCL, Oracle looks upORCLintnsnames.orato find the actual connection details.Example:
ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = myserver.example.com) (PORT = 1521) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.example.com) ) )Key parameters:
Parameter Description ORCLNet service name (alias used by client) HOSTIP address or hostname of the database server PORTPort number of the listener SERVICE_NAMEThe Oracle database service name SERVERConnection type (DEDICATED or SHARED)
Difference Between listener.ora and tnsnames.ora
Feature listener.ora tnsnames.ora Location Server side Client side Purpose Configures the listener process Maps alias to connection details Used by Oracle Listener Client applications Managed by DBA (server) DBA / end user (client)
In summary: The listener acts as a gatekeeper on the server;
listener.oratells the listener how to operate; andtnsnames.oratells the client where and how to connect to the database. - 125 marksEvent-based schedule creationHideAnswer
How event based schedules are created? Explain. [5]
An event-based schedule (also called an event-driven schedule) is a scheduling approach where task execution is triggered by the occurrence of specific events rather than by a fixed time interval or clock tick. The scheduler responds to ...