我有一个由许多节点脚本组成的系统,它们一直在 Postgres 数据库上自动读取和/或写入。其中一个脚本随机陷入僵局。我想对此进行调试,但问题是我不知道哪个其他查询导致死锁。(我使用pg)
所以我的问题是:
如果我发现这样的错误
{ error: deadlock detected
at Connection.parseE (/data/jenkins/workspace/03-10-Lotti-watcher-lotti-mod/import/node_modules/pg/lib/connection.js:604:13)
at Connection.parseMessage (/data/jenkins/workspace/03-10-Lotti-watcher-lotti-mod/import/node_modules/pg/lib/connection.js:403:19)
at Socket.<anonymous> (/data/jenkins/workspace/03-10-Lotti-watcher-lotti-mod/import/node_modules/pg/lib/connection.js:123:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:150:17)
name: 'error',
length: 336,
severity: 'ERROR',
code: '40P01',
detail:
'Process 2376 waits for ShareLock on transaction 55837412; blocked by process 22585.\nProcess 22585 waits for ShareLock on transaction 55837411; blocked by process 2376.',
hint: 'See server log for query details.',
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: 'while locking tuple (226684,50) in relation "lotti"',
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'deadlock.c',
line: '1146',
routine: 'DeadLockReport' }
我可以获取其他进程的查询和/或用户以隔离和识别问题吗?或者类似的东西,如果它有意义的话。
当然。只需查看 PostgreSQL 日志文件。
出于安全原因,此信息不会发送给客户端:否则,您可以制作与其他查询死锁的 SQL 语句,以查看其他人的语句,其中可能包含机密数据。