SShortSingh.
Back to feed

One SQL line prevents database outages during table migrations, yet few use it

0
·25 views

A common PostgreSQL migration pattern — adding a nullable column with no default — can silently take an entire table offline, not because the operation is slow, but because it queues behind any idle transaction holding a lock. Since ALTER TABLE requires an ACCESS EXCLUSIVE lock, it blocks in the queue, and every subsequent read or write then stacks behind it, effectively freezing application traffic. Engineers at DEV Community reproduced this on PostgreSQL 16, where a 26-millisecond point-read waited over 26 seconds due to an idle session holding an unrelated lock. The fix is a single line added before the migration: SET lock_timeout = '2s', which causes the ALTER to abort after two seconds of waiting rather than clogging the lock queue. Unlike statement_timeout, lock_timeout only limits how long a statement waits for a lock, making it safe to use without risking cancellation of legitimate long-running operations like index builds.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Actuator Requirements for Robot Hands: Torque Density, Precision, and Compliance

The article explains that robot hands are among the most demanding actuator applications, since they must simultaneously meet requirements for precision, dexterity, force generation, compactness, safety, efficiency, and reliability. Unlike large industrial robot joints, robot hands must deliver human-like functions within very limited space, making actuator selection a central design decision. Key requirements include high torque density and power density, appropriate speed trade-offs, and precise positioning with low backlash and high-resolution feedback. The text also highlights repeatability, compliance for handling fragile objects and interacting with humans, precise force control, and backdrivability as critical considerations.

0
ProgrammingDEV Community ·

Why an AML 'Low Risk' Score Doesn't Guarantee a Wallet Is Clean

A crypto wallet receiving a low-risk anti-money-laundering rating does not fully settle the question of its safety, the article argues. Such scores are built from varied inputs, including direct and indirect links to flagged addresses, sanctions attribution, and unusual transaction patterns, and different providers can reach different conclusions for the same wallet. Direct exposure to a suspicious address is generally treated differently from a distant, multi-hop connection, since the number of intermediaries, timing, and quality of attribution all shape what a warning means. Blockchain history can reveal useful patterns, but it does not identify an owner or prove criminal intent. Users are advised to check what triggered an assessment, the source and currency of the data, and what the screening tool actually covers.

0
ProgrammingDEV Community ·

Robot Finger Mechanism Design: Degrees of Freedom, Kinematics, and Compliance

The article explains that robot finger mechanism design is foundational to robot hand engineering, since finger structure governs grasp stability, dexterity, payload, durability, and overall system intelligence. It notes that finger design differs from industrial arm design because fingers operate in constrained, contact-rich environments where friction, compliance, and force distribution must be considered from the outset. Key decisions discussed include the number of degrees of freedom, which trades manipulation capability against complexity, cost, and control difficulty, and the kinematic layout of links and joints, often modeled loosely on the human hand. The text also contrasts fully actuated designs with underactuated ones that use springs, tendons, or differential mechanisms, and emphasizes compliance as a means to adapt to uncertain object shapes and reduce impact failures. It concludes by highlighting the balance engineers must strike between stiffness and compliance, typically supported by finite element analysis, and noting that transmission design also strongly affects performance.

0
ProgrammingDEV Community ·

Python asyncio: Running Waiting Tasks Concurrently Without Threads

A small shop checking stock with four suppliers illustrates the problem: doing each slow check in sequence wastes time while the program sits idle. The article explains that asyncio helps when work is dominated by waiting, such as network calls or database queries, but not when the work is CPU-bound. It also notes that asyncio requires async-compatible libraries, since a blocking call stalls the whole event loop. The author advises limiting concurrency for large numbers of tasks and using plain sequential code for simple one-off scripts. The example uses asyncio.gather with simulated delays to show that four waits finish in roughly the time of the longest one.