yoklainterview sim

Database Pg Transactions Locking Interview Questions

75 verified Database Pg Transactions Locking interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Pg Transactions LockingDifficulty 1
What is the default transaction isolation level in PostgreSQL when a client connects without changing any settings?
  • aREAD COMMITTED
  • bREAD UNCOMMITTED
  • cREPEATABLE READ
  • dSERIALIZABLE
Explanation:PostgreSQL's default isolation level is READ COMMITTED. Each statement in a transaction gets its own fresh snapshot as of that statement's start, unlike REPEATABLE READ or SERIALIZABLE, which snapshot once at transaction start.
Pg Transactions LockingDifficulty 1
A single UPDATE statement is executed with no surrounding BEGIN/COMMIT. What happens in PostgreSQL?
  • aIt is not committed until an explicit COMMIT is issued later
  • bIt runs and commits as its own implicit transaction
  • cIt is queued until the next BEGIN block starts
  • dIt fails because DML statements require an explicit transaction
Explanation:Outside of an explicit BEGIN...COMMIT block, PostgreSQL wraps every individual statement in its own implicit transaction, so it commits immediately once it succeeds.
Pg Transactions LockingDifficulty 1
Inside an explicit BEGIN block, several UPDATE statements are executed, and then ROLLBACK is issued (no SAVEPOINTs used). What is the result?
  • aOnly the last UPDATE statement is undone
  • bStatements run before some internal checkpoint remain applied
  • cAll changes made since BEGIN are discarded
  • dROLLBACK asks for confirmation before undoing any DML
Explanation:Without SAVEPOINTs to control the granularity, ROLLBACK undoes every change made since BEGIN, restoring the database to the state it was in before the transaction started.
Pg Transactions LockingDifficulty 1
In pg_stat_activity, a session shows state = 'idle in transaction'. What does this mean?
  • aThe transaction has committed and the connection is now free
  • bThe backend process crashed and needs to be restarted
  • cThe session is currently waiting on disk I/O for a query
  • dA transaction is open, but the client isn't sending a query
Explanation:'idle in transaction' means the client opened a transaction (e.g. via BEGIN) and is currently not sending any query — the transaction is still open, holding whatever snapshot and locks it acquired.
Pg Transactions LockingDifficulty 1
In a fresh session, with no prior configuration changes, the following is run:
SHOW transaction_isolation;

What does it print?
  • aread committed
  • bserializable
  • crepeatable read
  • dread uncommitted
Explanation:Verified by running SHOW transaction_isolation; in a fresh session against PostgreSQL 18: it prints read committed, the server's default isolation level.
Pg Transactions LockingDifficulty 1
A developer runs a single INSERT statement (no BEGIN) that violates a NOT NULL constraint and fails. They then run a SELECT to check whether any row was inserted. What do they find?
  • aA partial row exists, with NULL stored in the failed column
  • bNo row was inserted; the failed statement's transaction rolled back
  • cThe table is now locked until a manual VACUUM runs
  • dThe row was inserted but is marked as invalid
Explanation:Since the standalone statement runs in its own implicit transaction, a constraint violation aborts that transaction as a whole, so nothing from it is ever committed.

Test yourself against the 2475-question Database bank.

Start interview