【发布时间】:2015-06-19 07:13:16
【问题描述】:
我正在尝试对 Postgres 9.2 数据库运行 CREATE INDEX CONCURRENTLY 命令。我实现了一个 MigrationResolver,如问题 655 中所示。当通过mvn flyway:migrate 或类似方式运行此迁移步骤时,命令会启动,但会在等待模式下挂起。
我验证该命令是通过pg_stat_activity 表执行的:
test_2015_04_13_110536=# select * from pg_stat_activity;
datid | datname | pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | state_change | waiting | state | query
-------+------------------------+-------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+---------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
21095 | test_2015_04_13_110536 | 56695 | 16385 | postgres | psql | | | -1 | 2015-04-13 11:10:01.127768-06 | 2015-04-13 11:13:08.936651-06 | 2015-04-13 11:13:08.936651-06 | 2015-04-13 11:13:08.936655-06 | f | active | select * from pg_stat_activity;
21095 | test_2015_04_13_110536 | 56824 | 16385 | postgres | | 127.0.0.1 | | 52437 | 2015-04-13 11:12:55.438927-06 | 2015-04-13 11:12:55.476442-06 | 2015-04-13 11:12:55.487139-06 | 2015-04-13 11:12:55.487175-06 | f | idle in transaction | SELECT "version_rank","installed_rank","version","description","type","script","checksum","installed_on","installed_by","execution_time","success" FROM "public"."schema_version" ORDER BY "version_rank"
21095 | test_2015_04_13_110536 | 56825 | 16385 | postgres | | 127.0.0.1 | | 52438 | 2015-04-13 11:12:55.443687-06 | 2015-04-13 11:12:55.49024-06 | 2015-04-13 11:12:55.49024-06 | 2015-04-13 11:12:55.490241-06 | t | active | CREATE UNIQUE INDEX CONCURRENTLY person_restrict_duplicates_2_idx ON person(name, person_month, person_year)
(3 rows)
复制此问题的示例项目可以在我的 github 中找到:chrisphelps/flyway-experiment
我怀疑针对 schema version 的 flyway 查询是 idle in transaction 正在阻止 postgres 继续创建索引。
如何解决冲突,以便 postgres 继续迁移?有没有人能够通过flyway将这种迁移应用到postgres?
【问题讨论】:
-
我不明白它为什么会死锁,因为索引与 flyway (schema_version) 使用的表位于不同的表上。嗯...
-
你能确认 repo 中的行为吗?
标签: postgresql maven flyway