【问题标题】:Missing pg_locks and pg_stat_activity tables while trying to diagnose ActiveRecord::ConcurrentMigrationError尝试诊断 ActiveRecord::ConcurrentMigrationError 时缺少 pg_locks 和 pg_stat_activity 表
【发布时间】:2019-10-17 22:04:34
【问题描述】:

我有一个停滞的 Rails 迁移,所以我 ctrl-C 退出它并尝试重新运行它。我收到以下错误:

ActiveRecord::ConcurrentMigrationError: 

Cannot run migrations because another migration process is currently running.

我已经尝试过this post 中的解决方案。我运行了以下命令,但没有输出:

richiethomas=# \c re_app_development
psql (9.6.11, server 11.2)
WARNING: psql major version 9.6, server major version 11.
         Some psql features might not work.
You are now connected to database "re_app_development" as user "richiethomas".

re_app_development=# SELECT DISTINCT age(now(), query_start) AS age, pg_stat_activity.pid,pg_locks.granted,pg_stat_activity.application_name,pg_stat_activity.backend_start, pg_stat_activity.xact_start, pg_stat_activity.state_change, pg_stat_activity.waiting, pg_stat_activity.state, pg_stat_activity.query_start, left(pg_stat_activity.query, 60)
re_app_development-#     FROM pg_stat_activity, pg_locks
re_app_development-#     WHERE pg_locks.pid = pg_stat_activity.pid
re_app_development-# 

我很困惑为什么没有输出,所以我开始寻找pg_lockspg_stat_activity 表。下面是我数据库中的所有表(请注意,我稍微重新排列了表的顺序,将我创建的表分组到底部组,将 Rails 或我的 gem 生成的表分组到第一组):

re_app_development-# \dt
                   List of relations
 Schema |          Name          | Type  |    Owner     
--------+------------------------+-------+--------------
 public | ar_internal_metadata   | table | richiethomas
 public | flipper_features       | table | richiethomas
 public | flipper_gates          | table | richiethomas
 public | schema_migrations      | table | richiethomas

 public | reports                | table | richiethomas
 public | users                  | table | richiethomas
 public | categories             | table | richiethomas
 public | responses              | table | richiethomas
 public | zip_code_hpis          | table | richiethomas
 public | zip_codes              | table | richiethomas
(13 rows)

如您所见,上述查询中的两个表都丢失了。

我唯一能想到的是,选择数据库时的警告与此处相关:

WARNING: psql major version 9.6, server major version 11.
         Some psql features might not work.

我的问题是 - 我在哪里可以找到这些表,以便我可以移除锁定并重新运行我的迁移?

【问题讨论】:

    标签: ruby-on-rails postgresql activerecord database-migration


    【解决方案1】:

    我从来不知道这两个丢失的表在哪里,但我可以通过简单地运行brew services stop postgresqlbrew services start postgresql 来删除advisory_lock。不必放弃我的数据库或任何东西。 :-)

    【讨论】:

      猜你喜欢
      • 2011-03-19
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多