当升级到 TeamCity 2023.05(使用 Docker 镜像)时,我收到错误“当未持有数据库锁时无法采取独占锁”和详细说明:
<pre>java.lang.IllegalStateException: Can't take an exclusive lock when db lock is not held
at jetbrains.buildServer.serverSide.db.Heartbeat.tryGetExclusiveLock(Heartbeat.java:726)
at jetbrains.buildServer.serverSide.db.TeamCityDatabaseManager.tryGetExclusiveLock(TeamCityDatabaseManager.java:857)
at jetbrains.buildServer.maintenance.StartupProcessor.lockDatabaseExclusively(StartupProcessor.java:860)
at jetbrains.buildServer.maintenance.StartupProcessor.doUpgradeRequired(StartupProcessor.java:773)
at jetbrains.buildServer.maintenance.StartupProcessor.checkUpgradeRequired(StartupProcessor.java:826)
at jetbrains.buildServer.maintenance.StartupProcessor.doDatabaseChecking(StartupProcessor.java:1377)
at jetbrains.buildServer.maintenance.StartupProcessor.access$1000(StartupProcessor.java:1410)
at jetbrains.buildServer.maintenance.StartupProcessor$3.call(StartupProcessor.java:12)
at jetbrains.buildServer.util.NamedThreadFactory.executeWithNewThreadName(NamedThreadFactory.java:91)
at jetbrains.buildServer.maintenance.StartupProcessor.processConcreteStage(StartupProcessor.java:779)
at jetbrains.buildServer.maintenance.StartupProcessor.processConcreteStageSafe(StartupProcessor.java:1165)
at jetbrains.buildServer.maintenance.StartupProcessor.processTeamCityLifecycle(StartupProcessor.java:1100)
at jetbrains.buildServer.maintenance.StartupProcessor.access$000(StartupProcessor.java:1120)
at jetbrains.buildServer.maintenance.StartupProcessor$1.run(StartupProcessor.java:3)
at java.base/java.lang.Thread.run(Thread.java:833)
</pre>
我花了很多时间试图查明这个问题的根源,因为我最初以为是实际数据库出了问题,但却找不到任何锁。
答案1
db_heartbeat
解决方案是删除teamcity 数据库表中的记录。
检查是否有任何记录:
select * from db_heartbeat;
[...]
删除所有记录:
TRUNCATE TABLE db_heartbeat;
验证它们是否被丢弃:
select * from db_heartbeat;
[...]
完成后,您应该能够重新启动 TeamCity 并重新进行迁移。