Db: migrate freezes during simple migration

I am using PostgreSQL, Rails 3.1.3 and Ruby 1.9.3. I am struggling to use db:migrate as described here .

This is what I see in the terminal:

 funkdified@funkdified-laptop :~/railsprojects/hartl$ bundle exec rake db:migrate --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:migrate == AddEmailUniquenessIndex: migrating ======================================== -- add_index(:users, :email, {:unique=>true}) 

and then the code hangs at this point. Any ideas why?

From: development.log

 [1m[36m (0.1ms)[0m [1mSHOW search_path[0m [1m[35m (0.5ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations" Migrating to CreateUsers (20120124022843) Migrating to AddEmailUniquenessIndex (20120124093922) [1m[36m (0.1ms)[0m [1mBEGIN[0m [1m[35m (3.6ms)[0m SELECT distinct i.relname, d.indisunique, d.indkey, t.oid FROM pg_class t INNER JOIN pg_index d ON t.oid = d.indrelid INNER JOIN pg_class i ON d.indexrelid = i.oid WHERE i.relkind = 'i' AND d.indisprimary = 'f' AND t.relname = 'users' AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) ) ORDER BY i.relname 
+6
source share
2 answers

I had the same problem .. I found out that there was an idle transaction that blocked further requests in this table.

Run:

 heroku pg:ps --app=... 

To view database processes. You have to kill downtime:

 heroku pg:kill 913 --force --app=... 

(913 - id of an idle process → change it to your needs)

+6
source

I had a similar problem when a very simple migration stalled for no apparent reason. I believe that the problem is due to the inability to connect to the database. I logged out of the rails console session, which was open in another terminal, and then the migration ended right away without any problems.

+8
source

Source: https://habr.com/ru/post/906746/


All Articles