Help › Stay safe

Lock waits and timeouts

See which sessions wait on your open transaction, get reminded of a transaction left open, and limit how long your statements wait for a lock or run.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

A transaction you leave open keeps its locks. Other people's statements, and the application's, can pile up behind it without anyone noticing who is in the way. Querlyn watches for that and tells you. It only tells: it never commits, rolls back or ends anything for you.

When your transaction blocks others

While a tab's transaction is open, Querlyn checks every few seconds whether other sessions wait for a lock it holds. If so:

  • A red alert appears next to Commit and Roll Back in the bar above the editor, for example "Blocking 3 sessions · 40 s". The time is the longest any of them has waited.
  • The tab's mark reads "blocking 3", so you see it from another tab.

The alert comes up to five seconds after someone starts waiting, and goes when nobody waits any more or the transaction ends.

See who is waiting

Click the alert, or choose Query › Show Sessions Waiting on This Transaction. You can do this whenever the tab has a transaction open, also to see that nobody waits. A small window shows:

  • how long the transaction has been open, and how long nothing has run in it,
  • the connection and its environment,
  • each waiting session: who it is, what it is running, how long it has waited, and whether it waits for you directly or behind another waiter,
  • when Querlyn last checked.
ButtonWhat it does
CommitCommits your transaction, which lets the others go on.
Roll BackRolls it back, which does the same.
Show in Server ActivityOpens Server Activity with the first waiting session selected (Command Palette › Query: Show Waiting Sessions in Server Activity). Cancelling or ending someone's session is done there.
CloseCloses the window. ⎋ on macOS or Esc on Windows and Linux and a click outside do too.

The keyboard starts in the list, where ↩ on macOS or Enter on Windows and Linux does nothing, so opening this window and pressing ↩ on macOS or Enter on Windows and Linux can never commit by accident.

Querlyn's own sessions count too. If another of your tabs waits on this one, it is listed by its tab's name.

Where it works

DatabaseQuerlyn can see who waits
PostgreSQLYes
MySQL 8.0.1 and laterYes. Your login needs PROCESS and the right to read performance_schema, which must be turned on.
MariaDBYes, with PROCESS. A session waiting for a table's structure lock, such as an ALTER TABLE behind your transaction, is not reported.
SQL Server, Oracle DatabaseYes
TiDBYes, for pessimistic transactions (TiDB's default); optimistic ones never wait.
Amazon Redshift, SQLite, DuckDB, CockroachDB, YugabyteDB, SingleStore, BigQuery, MongoDBNo
ClickHouse, Snowflake, CassandraDoes not apply: no transaction stays open between runs.

Where Querlyn cannot see lock waits, or your login is not allowed to, no alert appears and no error is shown. The small window then says "Lock waits can't be seen here" with the reason.

To check, Querlyn opens one more connection to the server while a transaction has been open for two seconds or longer, and closes it when it is no longer needed. The checks are listed in the statement console under Lock check.

A transaction left open

When a transaction has been open for a while with nothing running in it, its tab says so: the alert in the bar reads, for example, "Transaction open for 12 min", and the tab is marked "12 min".

EnvironmentReminds after
Production2 minutes
Testing, Staging5 minutes
Local, Development15 minutes

The time counts while nothing runs; running a statement starts it again. The reminder is only a label. It never becomes a dialog or a sound, and nothing is rolled back.

Lock timeout

A statement that has to wait for a lock another session holds can wait a long time, and other statements then queue behind it. So Querlyn limits how long a statement in a query tab waits:

EnvironmentA statement waits for a lock at most
Production10 seconds
Testing, Staging30 seconds
Local, DevelopmentNo limit from Querlyn

A statement that waits longer fails with "Stopped by Querlyn's lock timeout: the statement waited more than 10 s for a lock another session holds." Nothing was changed by it. Find out who holds the lock in Server Activity, and run the statement again when the lock is gone.

This works on PostgreSQL, MySQL, MariaDB and SQL Server. Other databases have no such setting that Querlyn can use.

Statement timeout

You can also limit how long a statement may run. This is off everywhere at the start, because a long report is a legitimate thing to run.

It works on PostgreSQL and MariaDB for every statement, and on MySQL for SELECT statements only.

Change the times

In Querlyn › Open Settings, under Safety, there are three blocks: Open-transaction reminder, Lock timeout and Statement timeout. Each has a row for high, medium and low risk, with − and + to step the value from 5 seconds to 2 hours, or to Off.

Things to know:

  • A changed limit applies to tabs that connect from then on. A tab that is already connected keeps the limit it was opened with until it reconnects: disconnect the connection and connect it again.
  • The limits apply to what you run in query and table tabs, row edits included, and to each connection of a run on several connections, both sides of a data comparison and a whole-table profile. A copy of tables takes the lock timeout of the connection it copies into, and no statement timeout. Imports, exports, backups and Querlyn's own reading are not cut short by them.
  • If you set a timeout yourself in a tab, with SET lock_timeout for example, the database uses yours. Querlyn's message may then name the wrong time.
  • These settings stay on this computer; they are not synced.

See also [safety.lock_timeout] and its neighbours in Settings reference.

Help for Querlyn 0.1.0. All help topics