飞行迁移挂起了postgres CREATE INDEX CONCURRENTLY

时间:2015-04-13 20:25:29

标签: postgresql maven flyway

我正在尝试对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 idle in transaction的{​​{1}}的flyway查询阻止了postgres继续创建索引。

如何解决冲突,以便postgres继续迁移?有没有人能够通过flyway将这种迁移应用到postgres?

1 个答案:

答案 0 :(得分:5)

meantime中,flyway中包含一个解析器,用于查找文件名中的一些魔法。

只需添加前缀' NT' (对于 N o- T ransaction)到您的迁移文件,i。即

V01__usual_migration_1.sql

V02__another_migration.sql

NTV03__migration_that_does_not_run_in_transaction.sql

V04__classical_migration_4.sql