<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr" -->

---
title: How one connection kills a database — PlanetScale
description: A single stuck database connection can cascade into a full outage: an unhandled exception leaves a transaction open, blocking a schema migration that needs an...
canonical: https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How one connection kills a database — PlanetScale | daily.dev
og:description: A single stuck database connection can cascade into a full outage: an unhandled exception leaves a transaction open, blocking a schema migration that needs an...
og:url: https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr
og:image: https://api.daily.dev/og/posts/hj8Rz7uHr.png
og:image:alt: How one connection kills a database — PlanetScale
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How one connection kills a database — PlanetScale

**[PlanetScale](https://daily.dev/sources/planetscale)** · 5 min read · 0 upvotes · 0 comments

## Summary

A single stuck database connection can cascade into a full outage: an unhandled exception leaves a transaction open, blocking a schema migration that needs an exclusive lock, which in turn blocks every subsequent query on that table. The piece walks through a concrete Postgres example (idle SELECT holding a lock, blocked ALTER TABLE, queued reads) and notes the fix of setting idle_in_transaction_session_timeout. It then introduces PlanetScale's new connection management tooling — a dashboard Connections tab and CLI commands (pscale branch connections top/show) — that let users view active connections, see blocked queries, and cancel queries, terminate transactions, or terminate connections, even when the database is out of connection slots.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://planetscale.com/blog/debugging-live-database-connections>

## Questions this post answers

### Why does an ALTER TABLE migration in Postgres get stuck behind other queries?

An ALTER TABLE statement needs an ACCESS EXCLUSIVE lock, which blocks all other access to the table. If an earlier connection holds an open transaction on that table (for example, a SELECT that never received a COMMIT or ROLLBACK due to an unhandled application exception), the migration waits for that lock, and every subsequent query on the table queues up behind the stuck migration.

_Teams debugging locked migrations can track fixes like this by following database engineering posts on daily.dev._

### How do I stop Postgres transactions from staying open forever after an app exception?

Set the idle_in_transaction_session_timeout configuration parameter, which is disabled by default. Without a value set, Postgres holds a connection open indefinitely if a transaction never receives a COMMIT or ROLLBACK, such as when an application throws an unhandled exception mid-transaction. Giving this setting a timeout value forces Postgres to close abandoned transactions automatically.

_Anyone hardening Postgres configs against connection leaks can keep track of practical fixes like this via daily.dev._

### What are the options for killing a stuck database connection on PlanetScale?

PlanetScale's connection management offers three levels of disruption: cancel query stops the running statement but leaves the connection open; terminate transaction rolls back the open transaction and closes the connection, only if that transaction is still active; and terminate connection drops the backend entirely regardless of its state. These are available via the dashboard Connections tab or the pscale branch connections CLI commands.

_Engineers evaluating tools for managing database incidents can compare options like this on daily.dev._

## Similar posts on daily.dev

- [The four horsemen behind thousands of Postgres outages](https://daily.dev/posts/the-four-horsemen-behind-thousands-of-postgres-outages-tu19ush18) · Hacker News · 2 upvotes · 1 comments
- [The Postgres Migration That Looked Safe and Still Took Down Production](https://daily.dev/posts/the-postgres-migration-that-looked-safe-and-still-took-down-production-q9lxjuhhc) · The T-Shaped Dev · 0 upvotes · 0 comments
- [PostgreSQL Lockup vs Stale Connection: How to Tell Them Apart](https://daily.dev/posts/postgresql-lockup-vs-stale-connection-how-to-tell-them-apart-ctzk0b0lo) · Planet PostgreSQL · 0 upvotes · 0 comments
- [Postgres Postmaster does not scale](https://daily.dev/posts/postgres-postmaster-does-not-scale-fee3cv3ni) · Hacker News · 45 upvotes · 1 comments

---

Tags: [#database](https://daily.dev/tags/database), [#postgresql](https://daily.dev/tags/postgresql), [#mysql](https://daily.dev/tags/mysql), [#planetscale](https://daily.dev/tags/planetscale)

[View this post on daily.dev](https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How one connection kills a database — PlanetScale","url":"https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr"},"datePublished":"2026-09-10T14:53:19.118Z","dateModified":"2026-10-15T02:22:25.135Z","description":"A single stuck database connection can cascade into a full outage: an unhandled exception leaves a transaction open, blocking a schema migration that needs an...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/37c5644f09a157e9f528fa26374c57c5?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/37c5644f09a157e9f528fa26374c57c5?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"PlanetScale","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"PlanetScale","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/09515c29cafc45618b3f117eab4fccf8","url":"https://daily.dev/squads/planetscale"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,postgresql,mysql,planetscale","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"PlanetScale","item":"https://daily.dev/squads/planetscale"},{"@type":"ListItem","position":3,"name":"How one connection kills a database — PlanetScale"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-one-connection-kills-a-database-planetscale-hj8rz7uhr#faq","mainEntity":[{"@type":"Question","name":"Why does an ALTER TABLE migration in Postgres get stuck behind other queries?","acceptedAnswer":{"@type":"Answer","text":"An ALTER TABLE statement needs an ACCESS EXCLUSIVE lock, which blocks all other access to the table. If an earlier connection holds an open transaction on that table (for example, a SELECT that never received a COMMIT or ROLLBACK due to an unhandled application exception), the migration waits for that lock, and every subsequent query on the table queues up behind the stuck migration. Teams debugging locked migrations can track fixes like this by following database engineering posts on daily.dev."}},{"@type":"Question","name":"How do I stop Postgres transactions from staying open forever after an app exception?","acceptedAnswer":{"@type":"Answer","text":"Set the idle_in_transaction_session_timeout configuration parameter, which is disabled by default. Without a value set, Postgres holds a connection open indefinitely if a transaction never receives a COMMIT or ROLLBACK, such as when an application throws an unhandled exception mid-transaction. Giving this setting a timeout value forces Postgres to close abandoned transactions automatically. Anyone hardening Postgres configs against connection leaks can keep track of practical fixes like this via daily.dev."}},{"@type":"Question","name":"What are the options for killing a stuck database connection on PlanetScale?","acceptedAnswer":{"@type":"Answer","text":"PlanetScale's connection management offers three levels of disruption: cancel query stops the running statement but leaves the connection open; terminate transaction rolls back the open transaction and closes the connection, only if that transaction is still active; and terminate connection drops the backend entirely regardless of its state. These are available via the dashboard Connections tab or the pscale branch connections CLI commands. Engineers evaluating tools for managing database incidents can compare options like this on daily.dev."}}]}
```

