Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create index concurrently fails in standard migrations #3

Open
markmansour-zz opened this issue Sep 21, 2012 · 5 comments
Open

create index concurrently fails in standard migrations #3

markmansour-zz opened this issue Sep 21, 2012 · 5 comments

Comments

@markmansour-zz
Copy link

Creating concurrent indexes cannot be done within a transaction in PG.

All AR migrations occur within a transaction.

If you try, you'll get the following error

PGError: ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block

to work around this issue I needed to do the following in my migration

    execute "END"  # manually end the current transaction
    create_index 'index_appointments_on_cancellation_reason', :appointments, { :column => :cancellation_reason}, { :concurrently => true }
    execute "BEGIN" # manually start a new transaction

it would be nice to somehow remove this boilerplate.

@dark-panda
Copy link
Owner

I'll take a look at this when I have a chance. This looks like it has to do with migrations being wrapped completely in transactions to allow for rollbacks on DDL changes.

@ordinaryzelig
Copy link

I think Rails 4 will take care of this

@dark-panda
Copy link
Owner

Sweet. We aren't ready to make the jump to Rails 4 yet, but I have done some work on Rails 4 compatibility in the rails-4 branch. Wonder if this would be worth a backport.

@jaggederest
Copy link

For anyone seeing this from a google search, in modern rails you can add disable_ddl_transaction! to the top of your migration class to avoid this.

@amandakievet
Copy link

I got the same error message using Goose for GoLang and this worked --

(removing the execute commands and adding the semicolons)

END;  # manually end the current transaction
CREATE INDEX CONCURRENTLY index_appointments_on_cancellation_reason ON appointments (cancellation_reason);
BEGIN; # manually start a new transaction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants