A sequence generator is a database object that returns the next number according to configured rules each time it is called. It is often used for keys or reference numbers, but reserving a value and storing a row are separate operations. This makes a sequence more flexible than an identity column for multiple tables or pre-insert work, while gaps can be normal after rollbacks or caching.
An identity column is configured so the database supplies a sequence value when a new row is inserted. It is commonly used for an internal row ID, but the feature only generates values; it does not by itself guarantee uniqueness, gap-free numbering, or secrecy.
A generated column is a database column whose value is computed from other columns in the same row. For example, a database can recompute `line_total` whenever an order line's quantity or unit price changes. This keeps one calculation rule in the database instead of duplicating it across queries and applications.
Learn how foreign keys keep references valid, how optional and composite links work, what to decide when a parent changes, and how to add a constraint to existing data.
Learn how database-enforced uniqueness differs from a primary key, how NULL and conditional rules behave, and how to add a rule safely when data already exists.
Learn when a combination of columns should identify a row, how it differs from a multicolumn index, and what to consider for references and query performance.
Learn how an entity-relationship diagram models entities, attributes, cardinality, and optionality, then translate the model into keys and constraints.
Database partitioning stores one logically unified large table as multiple physical pieces. It can help queries skip pieces that cannot match their conditions, and it can make it faster to detach or remove old data as a unit. It is useful when a table is large and its access or retention rules are clear. Partitioning does not automatically make queries faster: if the partition key does not match query predicates, or if there are too many partitions, planning and operational costs can increase instead.
Sharding is a horizontal scaling method that divides one logical data set among multiple database servers and routes requests to the server responsible for each part. It can help when a single server is approaching its storage or write-throughput limits, but query routing, data rebalancing, backups, and failure recovery become more complex. If reads alone are the bottleneck, consider read replicas or caching first. Consider sharding only after measuring storage or write limits that cannot be addressed by scaling one instance.
Database replication propagates changes from one server to another so that the second server maintains a separate copy of the data. A standby may be promoted after a failure, or read requests may be distributed across replicas. But a replica is neither a perfectly current backup nor a universal way to accept writes safely on several servers. The purpose—high availability, read scaling, or data distribution—determines the replication method and the lag or data-loss risk you must accept.
Denormalization is a deliberate design choice to copy or precompute some normalized data so a read path or response better fits a workload. Duplication also adds update responsibilities and the risk of inconsistency. Consider it only after the source tables and constraints are sound, a real read bottleneck has been measured, and you have a plan to synchronize or rebuild the copy.
Database normalization is the process of arranging data into relations and rules so that repeated facts do not cause inconsistencies or insertion, update, and deletion problems. It does not mean simply creating more tables. First identify functional dependencies and candidate keys from the business rules, then choose decompositions that preserve the information and constraints the design needs.
A deadlock is a cycle in which two or more transactions wait for locks held by one another, so none can proceed. Unlike ordinary lock contention, waiting alone cannot resolve a cycle. PostgreSQL detects the cycle, cancels one involved transaction, and lets the others continue. An application must be able to retry the canceled transaction safely.
A lock coordinates access when transactions or administrative tasks touch the same data. Databases automatically take the locks needed for commands such as `UPDATE` and `DELETE`; an application can also request a row lock when it must keep another request from changing a value between checking it and acting on it. Locks reduce some concurrency problems but can create waits and deadlocks, so protect only the needed scope and keep the transaction short.
An isolation level defines when concurrent transactions can see one another’s changes and how the database handles conflicting work. A lower level can handle many common operations simply, but some query results may change during a transaction. A stronger level offers stricter guarantees and may require transaction retries. In PostgreSQL 18, the default `READ COMMITTED` is sufficient for many tasks, while work that reads several rows and checks a business rule may need additional protection.