postgres 的 Flyway 迁移挂起 CREATE INDEX CONCURRENTLY

2024-04-19

我正在尝试对 Postgres 9.2 数据库运行 CREATE INDEX CONCURRENTLY 命令。我实现了一个 MigrationResolver,如问题所示655 https://github.com/flyway/flyway/issues/655。当通过以下方式运行此迁移步骤时mvn flyway:migrate或类似的,命令启动但挂起在等待模式。

我验证该命令正在通过pg_stat_activity table:

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 中找到复制此问题的示例项目:克里斯普斯/飞路实验 https://github.com/chrisphelps/flyway-experiment

我的怀疑是针对的飞行路线查询schema version这是idle in transaction阻止 postgres 继续创建索引。

如何解决冲突以便 postgres 继续进行迁移?有谁能够通过 Flyway 将这种迁移应用到 postgres 吗?


In the meantime https://github.com/flyway/flyway/pull/1027,flyway 中包含一个解析器,它会在文件名中查找一些魔法。

只需添加前缀“NT”(对于No-T交易)到您的迁移文件,i。 e.

V01__usual_migration_1.sql

V02__another_migration.sql

NTV03__migration_that_does_not_run_in_transaction.sql

V04__classical_migration_4.sql

etc.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

postgres 的 Flyway 迁移挂起 CREATE INDEX CONCURRENTLY 的相关文章

随机推荐