Help › Change a database's structure
Migration lock warnings
Querlyn marks schema changes that would make other sessions wait on a large table, says how large the table is, and offers a form that does not block.
Querlyn 0.1.0 is not released yet. This help describes it ahead of release.
Some schema changes are harmless on a small table and stop an application
on a large one. CREATE INDEX on PostgreSQL, for example, blocks every
write to the table until the index is built: a moment for 500 rows, many
minutes for 50 million.
Querlyn knows which statements do this on which version of the database, looks up how large the table is, and tells you before the statement runs. It warns and offers the safe form. It never changes by itself what a statement does.
Where it works
| Database | Lock warnings |
|---|---|
| PostgreSQL 10 and later | Yes. Table sizes are shown from PostgreSQL 12. |
| MySQL 8.0 and later | Yes, for InnoDB tables |
| MariaDB 11.2 and later | Yes, for InnoDB tables |
| CockroachDB and TiDB | No warnings: they change schemas online, and the editor marks a schema change with a note that says so |
| Every other database, and older versions of these | No warnings |
Note: On MySQL and MariaDB the warnings describe InnoDB tables. Querlyn does not read a table's storage engine, so a change to a table of another engine, such as MyISAM, can block without a warning.
In the editor
In a query tab on a connected database, a statement that would make others wait is underlined. Point at it to read what the database will do:
- what happens: for example "Builds the index under a SHARE lock on “orders”: writes to the table wait until it finishes."
- how large the table is: for example "48 GB (about 310 million rows)". These are the database's own estimates; Querlyn counts nothing and does not touch the table.
- the safe way to make the same change, and how to get it written for you.
The message of the statement your cursor is in is also shown in the status bar.
There are three strengths:
| Heading | Underline | Meaning |
|---|---|---|
| Lock warning | Amber | Other sessions wait while the database works through the table's rows, or until your transaction ends (LOCK TABLE). |
| Lock hint | Muted | The same, on a table known to be small, so the wait is short. |
| Lock note | Accent color | A brief lock that a non-blocking form avoids, or work that grows with the table but blocks nobody. |
A table whose size Querlyn could not read counts as large.
Before a tab is connected, Querlyn cannot know the table's size or the exact version, so it shows notes only, and only for what holds on every supported version. A tab with no connection chosen gets nothing.
Let Querlyn rewrite the statement
Put the cursor in a statement with a warning and choose , or press ⌃T on macOS or Ctrl+Shift+R on Windows and Linux (), where the fix is listed first.
| Fix | What it writes |
|---|---|
| Add CONCURRENTLY | CREATE INDEX CONCURRENTLY, DROP INDEX CONCURRENTLY, REINDEX … CONCURRENTLY (PostgreSQL 12 and later) |
| Add NOT VALID, Then Validate Separately | For a foreign key or a check: the constraint with NOT VALID, and a separate VALIDATE CONSTRAINT, which does not block |
| Prove NOT NULL With a Check First | Four statements that make a column NOT NULL without reading the table under an exclusive lock (PostgreSQL 12 and later) |
| Build the Index Concurrently First | For a unique constraint or primary key: CREATE UNIQUE INDEX CONCURRENTLY, then the constraint USING INDEX |
| Let the Server Choose Algorithm and Lock | On MySQL and MariaDB: the statement without the ALGORITHM=COPY or LOCK= clause that forces the wait |
A fix that only adds a word is applied at once and is one step to undo. A fix that writes several statements is shown first, for you to accept. If a fix cannot be written, for example because the constraint has no name, a message next to the cursor says why.
Note: A statement with CONCURRENTLY cannot run inside a transaction.
Run it with auto-commit on; Querlyn does not change the tab's commit
mode for you. See Commit and roll back changes.
Some changes have no safe form that is a rewrite, such as changing a
column's type or VACUUM FULL. For those the message says what to do
instead.
opens the database's own documentation of the rule at the cursor in your browser.
Before a statement runs
On connections where Querlyn asks before destructive statements (Testing, Staging and Production, unless you changed that), it also asks before a statement with a lock warning. The question lists the statement with what it does and the table's size.
- A statement on a table known to be small does not ask.
- If the size cannot be read within five seconds, Querlyn asks all the same.
- On Local and Development connections nothing asks.
In generated scripts
The table designer, the ER diagram and schema compare check the statements they write by the same rules. A statement with a warning is marked Rewrites table or Locks table in the preview, with the same sentence, and applying asks as a run does.
These marks are always shown, also when lock warnings are turned off.
In pending migrations
The Migrations tab checks the SQL of the migrations a linked project folder still holds by the same rules, as one script in the order the migration tool would run it, and marks each pending migration that would make other sessions wait on a large table, before you deploy it. Unlike generated scripts, this check follows the Warn about lock hazards setting.
Settings
In , under Safety, the block Migration lock warnings has two settings:
| Setting | What it does |
|---|---|
| Warn about lock hazards | Turns the warnings in the editor, and the question before a run or an apply, on or off (). On at the start. |
| Small table | The size under which a table counts as small: 100 MB at the start, from 1 MB to 10 GB, or None so that no table is small. It is the size of the table with its indexes. The steps are and . |
Both apply to every connection. See also Settings reference.
What it does not see
- Locks a statement takes on other tables through triggers or cascading foreign keys.
- Whether a PostgreSQL table is partitioned.
- Statements it does not fully understand. For those it says nothing rather than guess.
TRUNCATEandDROP TABLE: these are destructive statements, and are asked about as such.- How long the wait would be in seconds.
Help for Querlyn 0.1.0. All help topics