-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add markdown lock trace report #15
Conversation
Conceptually cool and fun to play with, but added lots of extra complexity for not so much benefit. This is preparation to instead do plain text and markdown output in a more sensible/simple way.
806caf9
to
1e1d7e1
Compare
cdf3aa0
to
9af65d9
Compare
Eugene 🔒 trace of
|
Started at | Total duration (ms) | Number of dangerous locks |
---|---|---|
2024-05-04T23:18:19.997774940+00:00 | 1002 | 1 ❌ |
All locks acquired
Schema | Object | Mode | Relkind | OID | Safe | Duration held (ms) |
---|---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ | 1001 |
Dangerous locks found
AccessExclusiveLock
would block the following operations onpublic.books
:SELECT
+FOR UPDATE
+FOR NO KEY UPDATE
+FOR SHARE
+FOR KEY SHARE
+UPDATE
+DELETE
+INSERT
+MERGE
Statement number 1 for 1 ms
SQL
create table authors(name text not null);
Locks at start
No locks held at the start of this statement.
New locks taken
No new locks taken by this statement.
Statement number 2 for 0 ms
SQL
alter table books alter column title set not null;
Locks at start
No locks held at the start of this statement.
New locks taken
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
Statement number 3 for 1001 ms
SQL
select pg_sleep(1);
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
New locks taken
No new locks taken by this statement.
Statement number 4 for 0 ms
SQL
select * from books;
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
New locks taken
No new locks taken by this statement.
9af65d9
to
93e9b6f
Compare
Eugene 🔒 trace of
|
Started at | Total duration (ms) | Number of dangerous locks |
---|---|---|
2024-05-04T23:20:37.765772580+00:00 | 1003 | 1 ❌ |
All locks acquired
Schema | Object | Mode | Relkind | OID | Safe | Duration held (ms) |
---|---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ | 1001 |
public | books | AccessShareLock | Table | 16389 | ✅ | 0 |
public | books_pkey | AccessShareLock | Index | 16395 | ✅ | 0 |
Dangerous locks found
AccessExclusiveLock
would block the following operations onpublic.books
:SELECT
FOR UPDATE
FOR NO KEY UPDATE
FOR SHARE
FOR KEY SHARE
UPDATE
DELETE
INSERT
MERGE
Statement number 1 for 2 ms
SQL
create table authors(name text not null);
Locks at start
No locks held at the start of this statement.
New locks taken
No new locks taken by this statement.
Statement number 2 for 0 ms
SQL
alter table books alter column title set not null;
Locks at start
No locks held at the start of this statement.
New locks taken
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
Statement number 3 for 1001 ms
SQL
select pg_sleep(1);
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
New locks taken
No new locks taken by this statement.
Statement number 4 for 0 ms
SQL
select * from books;
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessExclusiveLock | Table | 16389 | ❌ |
New locks taken
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public | books | AccessShareLock | Table | 16389 | ✅ |
public | books_pkey | AccessShareLock | Index | 16395 | ✅ |
93e9b6f
to
df045fa
Compare
Eugene 🔒 trace of
|
Started at | Total duration (ms) | Number of dangerous locks |
---|---|---|
2024-05-04T23:25:16.715110214+00:00 | 1002 | 1 ❌ |
All locks acquired
Schema | Object | Mode | Relkind | OID | Safe | Duration held (ms) |
---|---|---|---|---|---|---|
public |
books |
AccessExclusiveLock |
Table | 16389 | ❌ | 1001 |
public |
books_pkey |
AccessShareLock |
Index | 16395 | ✅ | 0 |
public |
books |
AccessShareLock |
Table | 16389 | ✅ | 0 |
Dangerous locks found
AccessExclusiveLock
would block the following operations onpublic.books
:SELECT
FOR UPDATE
FOR NO KEY UPDATE
FOR SHARE
FOR KEY SHARE
UPDATE
DELETE
INSERT
MERGE
Statement number 1 for 1 ms
SQL
create table authors(name text not null);
Locks at start
No locks held at the start of this statement.
New locks taken
No new locks taken by this statement.
Statement number 2 for 0 ms
SQL
alter table books alter column title set not null;
Locks at start
No locks held at the start of this statement.
New locks taken
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public |
books |
AccessExclusiveLock |
Table | 16389 | ❌ |
Statement number 3 for 1001 ms
SQL
select pg_sleep(1);
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public |
books |
AccessExclusiveLock |
Table | 16389 | ❌ |
New locks taken
No new locks taken by this statement.
Statement number 4 for 0 ms
SQL
select * from books;
Locks at start
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public |
books |
AccessExclusiveLock |
Table | 16389 | ❌ |
New locks taken
Schema | Object | Mode | Relkind | OID | Safe |
---|---|---|---|---|---|
public |
books_pkey |
AccessShareLock |
Index | 16395 | ✅ |
public |
books |
AccessShareLock |
Table | 16389 | ✅ |
Add a first draft markdown report of a lock trace, something suitable to post as a comment on a merge request. This PR is big because it also deletes the machinery that was in place for supporting multiple formats and detail levels, in favor of doing something simpler -- just working with strings. Here's the example report:
Lock trace of
mig.sql
In the below trace, a lock is considered dangerous if it conflicts with application code queries, such as
SELECT
orINSERT
.We should aim to hold dangerous locks for as little time as possible. If a dangerous lock is held while doing an operation that does not require it, we should split the migration into two steps.
For example, it often will make sense to add a new column in one migration, then backfill it in a separate one, since adding a column requires an
AccessExclusiveLock
while backfilling can do with aRowExclusiveLock
which is much less likely to block concurrent transactions.Overall Summary
All locks acquired
Dangerous locks explanation
AccessExclusiveLock
would block the following operations onpublic.books
:SELECT
FOR UPDATE
FOR NO KEY UPDATE
FOR SHARE
FOR KEY SHARE
UPDATE
DELETE
INSERT
MERGE
Statement number 1 for 26 ms
SQL
Locks at start
No locks held at the start of this statement.
New locks taken
No new locks taken by this statement.
Statement number 2 for 1 ms
SQL
Locks at start
No locks held at the start of this statement.
New locks taken
Statement number 3 for 1007 ms
SQL
Locks at start
New locks taken
No new locks taken by this statement.
Statement number 4 for 3 ms
SQL
Locks at start
New locks taken
No new locks taken by this statement.