Skip to content

Allow CREATE/DROP INDEX without CONCURRENTLY #81

Closed

Description

@provokateurin

It is not always desirable to create/drop indexes concurrently, so it should be possible to switch it off.

Activity

  1. bplunkett-stripe commented on Jan 8, 2024

    @bplunkett-stripe
    Contributor

    Hi provokateurin!

    In what scenarios would you like to not build an index concurrently? I realize it does consume more CPU than a normal index build. Is that the primary use case?

  2. provokateurin commented on Jan 8, 2024

    @provokateurin
    Author

    In the use-case we want to run all migrations in a transaction, so the index can't be built concurrently.
    The other problem is that concurrent indexes are not really safe. You have come back later and check if the index was actually built.

    cc @GeertJohan

  3. bplunkett-stripe commented on Jan 8, 2024

    @bplunkett-stripe
    Contributor

    I see!

    I'd argue transactional DDL isn't super critical because you can always roll it back (with exceptions of deletes) via plan(oldSchema).

    Concurrent index builds can't silently fail, so you'll know if a concurrent index build failed. And to get your database out of a partially migrated state, you can do plan(newSchema) again, or even plan(oldSchema). pg-schema-diff will identify invalid indexes from concurrent index build failures and REINDEX them.

  4. mortenson commented on Jan 8, 2024

    @mortenson

    If this gets changed please make non-concurrency opt-in - concurrent index builds are really important/preferred in production to me. During development and for a small number of rows I can see how the multiple transactions are not great, though.

  5. provokateurin commented on Jan 8, 2024

    @provokateurin
    Author

    pg-schema-diff will identify invalid indexes from concurrent index build failures and REINDEX them.

    We are only using pg-schema-diff for generating the migration statements, so we are not able to use the automatic reindexing.

    If this gets changed please make non-concurrency opt-in

    Agreed, it should be an option and not remove the existing functionality.

  6. bplunkett-stripe commented on Jan 8, 2024

    @bplunkett-stripe
    Contributor

    We are only using pg-schema-diff for generating the migration statements, so we are not able to use the automatic reindexing.

    As in, you're persisting your migration to your codebase?

    If this gets changed please make non-concurrency opt-in - concurrent index builds are really important/preferred in production to me. During development and for a small number of rows I can see how the multiple transactions are not great, though.

    Our philosophy is to make migration as online-as-possible, so if we did add this option in, it absolutely would be disabled by default.

    I think I'm leaning towards supporting this in the future, but right now, I want to focus on the core of the library:

    • Making more migrations online
    • Adding support for more SQL objects and schemas

    What do you folks think?

  7. provokateurin commented on Jan 9, 2024

    @provokateurin
    Author

    As in, you're persisting your migration to your codebase?

    Yes, the are saved as a file. The process of generating the migration and applying the migration are not the same. The migration is generated while the changes are developed and they are only applied when a new version is deployed.

  8. bplunkett-stripe commented on Jan 10, 2024

    @bplunkett-stripe
    Contributor

    Yes, the are saved as a file. The process of generating the migration and applying the migration are not the same. The migration is generated while the changes are developed and they are only applied when a new version is deployed.

    Any thoughts on changing this process such that the migration is generated and applied when the version is deployed? This also prevents a proliferation of {x}.sql files in y our repo

  9. provokateurin commented on Jan 11, 2024

    @provokateurin
    Author

    But we want to store all migrations as sql files, so this is exactly our use-case. I don't think there is much we want to change about it.
    Anyway, this is getting a bit off topic. Let's just add the option to disable concurrent indexes and we are done :)

  10. bplunkett-stripe commented on Jan 11, 2024

    @bplunkett-stripe
    Contributor

    Totally understand! Forgive my questions! I'm just trying to understand your use case and poke its edges to see how pg-schema-diff can slot into it.

    I think, to rephrase the ask a bit, is generate DDL that can be run entirely in one transaction (as opposed to just getting rid of concurrent index builds). If we do implement this type of behavior, it will be disabled by default.

  11. provokateurin commented on Jan 11, 2024

    @provokateurin
    Author

    Sorry, I didn't want to come off as rude if that was the case!

    Yes, we want to be able to generate DDL that can be run in a transaction. So far we only found the concurrent indexes to be a problem, but maybe more still show up later.

  12. bplunkett-stripe commented on Jan 12, 2024

    @bplunkett-stripe
    Contributor

    No worries! I suspect you folks might run into issues with the "online [check|not null] constraint" addition and "online index replacement" (assuming no concurrently). I haven't really tested if that works transactionally.

  13. matiasbattocchia commented on Aug 21, 2025

    @matiasbattocchia

    Hi there. I'm experimenting with Supabase declarative schemas. I've generated a migration file from a schema that have indexes. I could not apply the migration (CREATE INDEX CONCURRENTLY cannot be executed within a pipeline error). I had to edit the migration to the remove the CONCURRENTLY. I also think it could be nice to switch them off.

  14. bplunkett-stripe commented on Sep 1, 2025

    @bplunkett-stripe
    Contributor

    Should be fixed with the above PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions