MCQs on Transactions and Concurrency Control | PostgreSQL Database

Explore Transactions and Concurrency Control in PostgreSQL with a deep dive into ACID properties, transaction handling, isolation levels, and locking mechanisms. Strengthen your database expertise with these essential concepts.


Understanding ACID Properties

  1. Which of the following is NOT a characteristic of ACID properties?
    • A) Atomicity
    • B) Consistency
    • C) Indifference
    • D) Durability
  2. Atomicity ensures that:
    • A) All transactions are logged.
    • B) A transaction is completed fully or not at all.
    • C) Data remains isolated during execution.
    • D) No locks are required.
  3. The consistency property of ACID refers to:
    • A) Uniform transaction duration.
    • B) Maintaining database integrity after a transaction.
    • C) Automatic locking mechanisms.
    • D) Parallel execution of transactions.
  4. Durability in ACID is achieved through:
    • A) Immediate transaction logging.
    • B) Rollback operations.
    • C) Temporary storage in memory.
    • D) Isolation levels.
  5. Which ACID property ensures that a database remains unaffected by failed transactions?
    • A) Atomicity
    • B) Isolation
    • C) Consistency
    • D) Durability
  6. What is the main role of isolation in ACID properties?
    • A) Preventing system crashes.
    • B) Allowing transactions to execute without interference.
    • C) Ensuring durability of the database.
    • D) Enforcing database schema.

Basic Transactions (BEGIN, COMMIT, ROLLBACK)

  1. What does the BEGIN command in PostgreSQL signify?
    • A) Starts a new session.
    • B) Initiates a new transaction.
    • C) Commits the current transaction.
    • D) Rolls back the previous transaction.
  2. What is the result of a COMMIT operation?
    • A) Temporarily saves changes.
    • B) Abandons all changes in a transaction.
    • C) Permanently saves changes made by the transaction.
    • D) Resumes a paused transaction.
  3. What happens if a ROLLBACK command is issued?
    • A) The database restores to its state before the last transaction.
    • B) Changes are partially saved.
    • C) Logs are cleared for the current session.
    • D) Transaction status remains unchanged.
  4. Which of the following best describes a transaction?
  • A) A single query execution.
  • B) A series of operations treated as a single unit.
  • C) An automatic backup operation.
  • D) A user session in PostgreSQL.
  1. A transaction is automatically started in PostgreSQL when:
  • A) BEGIN is issued.
  • B) The first SQL statement is executed.
  • C) COMMIT is called.
  • D) The database restarts.
  1. What is the default behavior of transactions in PostgreSQL if no explicit BEGIN is issued?
  • A) Automatic rollback.
  • B) Auto-commit.
  • C) Transactions are queued.
  • D) Transactions are skipped.
  1. Which of the following statements is correct about ROLLBACK?
  • A) It only works within a transaction block.
  • B) It saves changes permanently.
  • C) It can recover deleted records from earlier sessions.
  • D) It cannot undo a COMMIT.
  1. What is a savepoint in PostgreSQL?
  • A) A point to restart a failed query.
  • B) A named point in a transaction to partially roll back.
  • C) A snapshot of the database.
  • D) A backup mechanism.

Isolation Levels Overview

  1. Which of the following is NOT an isolation level in PostgreSQL?
  • A) Read Uncommitted
  • B) Read Committed
  • C) Serializable
  • D) Immediate
  1. Which isolation level ensures no dirty reads occur?
  • A) Read Committed
  • B) Serializable
  • C) Repeatable Read
  • D) Read Uncommitted
  1. Read Committed isolation level ensures:
  • A) Dirty reads are possible.
  • B) Only committed data is read.
  • C) All transactions are serialized.
  • D) All data is locked during execution.
  1. At which isolation level can phantom reads occur?
  • A) Serializable
  • B) Read Uncommitted
  • C) Read Committed
  • D) Repeatable Read
  1. Which isolation level provides the highest level of data consistency?
  • A) Serializable
  • B) Repeatable Read
  • C) Read Committed
  • D) Read Uncommitted
  1. What is a dirty read?
  • A) Reading uncommitted changes from another transaction.
  • B) Reading stale data from outdated indexes.
  • C) Reading corrupted data.
  • D) Reading locked rows.

Locking Basics

  1. What is the primary purpose of locking in PostgreSQL?
  • A) Improve query performance.
  • B) Prevent data conflicts in concurrent transactions.
  • C) Encrypt sensitive data.
  • D) Execute faster queries.
  1. Which lock type is automatically acquired when a table is queried in PostgreSQL?
  • A) Share lock
  • B) Row lock
  • C) Access Share lock
  • D) Exclusive lock
  1. When a transaction updates a row, what lock type is placed?
  • A) Share lock
  • B) Row Exclusive lock
  • C) Access Exclusive lock
  • D) Row Share lock
  1. What happens if two transactions try to update the same row at the same time?
  • A) One transaction blocks the other.
  • B) Both transactions proceed.
  • C) Both updates are combined.
  • D) Both transactions fail.
  1. Which lock prevents other transactions from reading or writing to a table?
  • A) Access Exclusive lock
  • B) Row Share lock
  • C) Share lock
  • D) Access Share lock
  1. What is the default behavior when a deadlock occurs in PostgreSQL?
  • A) Both transactions proceed.
  • B) PostgreSQL terminates one of the transactions.
  • C) The database crashes.
  • D) The deadlock is ignored.
  1. What command can you use to explicitly acquire a lock in PostgreSQL?
  • A) ACQUIRE LOCK
  • B) LOCK TABLE
  • C) GET LOCK
  • D) SET LOCK
  1. How can you detect deadlocks in PostgreSQL?
  • A) Using pg_stat_activity
  • B) Reviewing server logs
  • C) Monitoring pg_locks table
  • D) All of the above
  1. Which command releases all locks held by a transaction?
  • A) COMMIT
  • B) ROLLBACK
  • C) RELEASE ALL LOCKS
  • D) SAVEPOINT
  1. How does PostgreSQL prevent inconsistent reads during updates?
  • A) By using MVCC (Multi-Version Concurrency Control).
  • B) By locking the entire database.
  • C) By delaying all reads during writes.
  • D) By using snapshots.

Answer Key

QnoAnswer
1C) Indifference
2B) A transaction is completed fully or not at all
3B) Maintaining database integrity after a transaction
4A) Immediate transaction logging
5A) Atomicity
6B) Allowing transactions to execute without interference
7B) Initiates a new transaction
8C) Permanently saves changes made by the transaction
9A) The database restores to its state before the last transaction
10B) A series of operations treated as a single unit
11B) The first SQL statement is executed
12B) Auto-commit
13A) It only works within a transaction block
14B) A named point in a transaction to partially roll back
15D) Immediate
16A) Read Committed
17B) Only committed data is read
18C) Read Committed
19A) Serializable
20A) Reading uncommitted changes from another transaction
21B) Prevent data conflicts in concurrent transactions
22C) Access Share lock
23B) Row Exclusive lock
24A) One transaction blocks the other
25A) Access Exclusive lock
26B) PostgreSQL terminates one of the transactions
27B) LOCK TABLE
28D) All of the above

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top