A non-repeatable read occurs when one transaction reads the same row twice, but another transaction changes and commits that row in between, so the second read returns a different value. For example, an order screen reads a product price of 100; another transaction changes it to 120 and commits; a later read in the same workflow now sees 120. This can happen under `READ COMMITTED`, while `REPEATABLE READ` differs across DBMSs. Do not infer behavior from the isolation-level name alone. [PostgreSQL 19: transaction isolation](https://www.postgresql.org/docs/19/transaction-iso.html) · [SQL Server: SET TRANSACTION ISOLATION LEVEL](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver17)
A dirty read occurs when one transaction reads another transaction’s **uncommitted change**. The writer may later roll back, so the value read may never become part of committed database state. `READ UNCOMMITTED` permits this behavior where a DBMS implements it, making results less reliable and reproducible. The same isolation-level name does not mean the same implementation everywhere. [PostgreSQL 19: transaction isolation](https://www.postgresql.org/docs/19/transaction-iso.html) · [SQL Server: SET TRANSACTION ISOLATION LEVEL](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver17)
A phantom read occurs when a transaction repeats a query with the same search condition but gets a different set of rows because another transaction committed an insert or delete. Unlike a non-repeatable read, where an already-read row changes, a phantom is a change to which rows satisfy the predicate. Whether it can happen, and how to prevent it, depends on the DBMS, isolation level, and kind of read. [PostgreSQL 19: transaction isolation](https://www.postgresql.org/docs/19/transaction-iso.html) · [MySQL 8.4: phantom rows in InnoDB](https://dev.mysql.com/doc/refman/8.4/en/innodb-next-key-locking.html)
An advisory lock lets an application ask the database to lock a logical resource identified by a name or key. Instead of automatically locking a particular row, it coordinates tasks such as generating a report or running a monthly billing job, which may not map to an existing row. The DBMS does not enforce the application’s protocol: every code path that uses the same resource must use the same key and follow the same rules. [PostgreSQL 19: explicit and advisory locking](https://www.postgresql.org/docs/19/explicit-locking.html) · [MySQL 8.4: locking functions](https://dev.mysql.com/doc/refman/8.4/en/locking-functions.html)
A row-level lock limits changes to, or incompatible lock requests on, selected data rows instead of an entire table. Transactions that change the same row may wait, but ordinary reads are not always blocked. Even a query that appears to target one row can lock a wider scanned index range depending on the DBMS and isolation level, so verify scope in product documentation and the query plan. [PostgreSQL 19: explicit locking](https://www.postgresql.org/docs/19/explicit-locking.html) · [MySQL 8.4: locks set by InnoDB statements](https://dev.mysql.com/doc/refman/8.4/en/innodb-locks-set.html)
Pessimistic locking acquires a database lock before changing data that may be contested, making conflicting transactions wait while one transaction reads, decides, and writes. It can help with short operations such as decrementing inventory or changing a balance through several steps. Locks may last until the transaction ends, so keep transactions short and lock only the needed rows to limit waits, timeouts, and deadlocks. [PostgreSQL 19: explicit locking](https://www.postgresql.org/docs/19/explicit-locking.html) · [MySQL 8.4: InnoDB locking reads](https://dev.mysql.com/doc/refman/8.4/en/innodb-locking-reads.html)
Optimistic locking assumes conflicts are uncommon, so it does not block other users when data is read. At save time, a conditional UPDATE checks whether the version originally read is still current. If it changed, the application reports a conflict instead of silently overwriting newer data. This is useful when several people may edit the same record, but the application and database must still define conflict resolution and protection for rules spanning multiple rows. [SQLAlchemy 2.0: version counters](https://docs.sqlalchemy.org/en/20/orm/versioning.html) · [EF Core: handling concurrency conflicts](https://learn.microsoft.com/en-us/ef/core/saving/concurrency)
Multiversion concurrency control (MVCC) is a technique that lets concurrent transactions see data versions appropriate to their work. A reader can use a committed older version while another transaction writes a new one, reducing cases where reads and writes must wait for each other. MVCC does not eliminate locks or isolation levels: the database still handles conflicting writes, old-version cleanup, and rules that determine which version is visible. [PostgreSQL 19: MVCC introduction](https://www.postgresql.org/docs/19/mvcc-intro.html)
Snapshot isolation is an MVCC approach in which each transaction reads a snapshot of committed data from a point near its start. Concurrent transactions can often read without waiting for one another, and a conflict may abort one that writes the same data. But snapshot isolation can allow write skew: two transactions update different rows while jointly violating a business rule. A stable view alone does not make that rule safe. [Berenson et al., Snapshot Isolation](https://15721.courses.cs.cmu.edu/spring2019/papers/02-transactions/p1-berenson.pdf) · [PostgreSQL 18 transaction isolation](https://www.postgresql.org/docs/18/transaction-iso.html)
Monotonic reads is a consistency guarantee that prevents a session from later seeing an older data state than one it has already observed. For example, after seeing a new comment on one replica, a refresh routed to a lagging replica should not make that comment disappear. This does not guarantee that the first read is current, and it differs from read-your-writes, which concerns your own earlier writes. [MongoDB on consistency and recency](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/) · [Terry et al., Session Guarantees](https://www.cs.cornell.edu/courses/cs734/2000FA/cached%20papers/SessionGuaranteesPDIS_1.html)
PgBouncer is a lightweight pooler between an application and PostgreSQL. It accepts client connections and lets requests reuse a smaller set of server connections. This can reduce connection setup overhead and the number of open PostgreSQL connections, but it does not make a running query faster or cache results. Transaction pooling does not preserve connection-specific session state, so choose a mode that matches the application's behavior. [PgBouncer features](https://www.pgbouncer.org/features.html)
A database connection timeout means the client stopped waiting because it could not open a connection or borrow one from a pool within its configured limit. Similar error text can refer to network/login setup, waiting for a pooled connection, or running a command after connection. Find the failing stage first: blindly raising a limit can hide faults and leave more requests waiting. Microsoft timeout troubleshooting
A parameterized query sends the SQL structure and runtime values separately through a database driver. This keeps quotes or SQL-looking text inside a value from becoming query syntax, making parameter binding a core SQL injection defense. Parameters cannot stand in for table names or sort directions, and binding alone does not check a user's permissions or business rules. OWASP SQL Injection Prevention
A prepared statement lets a database or driver prepare SQL structure first and supply input values separately for each execution. Depending on the system, this can reduce parsing work, reuse an execution plan, or make value transfer more efficient. But not every driver uses server-side preparation, and a short statement executed once is not guaranteed to run faster. Separate the security value of binding parameters from the performance question of whether the server reuses a prepared statement. PostgreSQL 19: PREPARE MySQL 8.4: Prepared Statements
Lazy relationship loading lets an ORM read a related object or collection with a separate SQL statement when code first accesses that relationship, instead of fetching it with the primary object. This can make object-oriented code convenient, but a normal-looking property access can hide database I/O. Repeated access while iterating a list, use after a session closes, or ordinary synchronous access in async code can cause performance problems or errors. Design the access path explicitly. SQLAlchemy 2.0: Relationship Loading Techniques SQLAlchemy 2.0: Async ORM
Eager relationship loading tells an ORM to prepare related objects or collections when it returns the primary objects. It can fetch them in one joined result or with additional SELECT statements after loading the parents. Choose what to eager-load for the page or task that needs it instead of applying one strategy blindly to every model. SQLAlchemy 2.0: Relationship Loading Techniques Django 5.2: QuerySet API
An N+1 query occurs when an application first fetches a list with one query, then separately fetches related data for each row whose relation is not loaded, making N+1 database round trips. The results may still be correct, but the number of calls can grow with the data and increase response time. The goal is not to force every operation into one query; identify which relationships the page or task actually uses, then choose a suitable loading strategy. [SQLAlchemy 2.0: Working with Related Objects](https://docs.sqlalchemy.org/en/20/tutorial/orm_related_objects.html) [Hibernate ORM User Guide](https://docs.hibernate.org/stable/core/introduction/html_single/)
Unit of Work is a pattern that collects object changes affecting a database during one business task and coordinates the writes when that task is ready. Instead of sending SQL immediately after each object changes, it tracks what to add, update, or delete and applies those changes together. An ORM’s `flush()` is a common synchronization point, but a Unit of Work and a database transaction are closely related, distinct concepts. [Martin Fowler: Unit of Work](https://martinfowler.com/eaaCatalog/unitOfWork.html)
An Identity Map is a pattern that keeps one object for each entity type and primary key within a work context, and reuses that object when the same database row is requested again. This reduces the risk of treating one record as two objects with conflicting in-memory state. It is not the same as a general query-result cache: a primary-key lookup may return an in-memory object, while a criteria query can still go to the database. [Martin Fowler: Identity Map](https://martinfowler.com/eaaCatalog/identityMap.html)
Data Mapper is a mapping layer that moves values between domain objects and a relational database while keeping the two structures independent. Unlike Active Record, which puts persistence operations and table knowledge closer to the model object, a domain object in Data Mapper need not know that a database exists. The trade-off is that mapping rules must be designed and maintained separately. [Martin Fowler: Data Mapper](https://martinfowler.com/eaaCatalog/dataMapper.html)