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 does not block table reads #15

Closed
seanpascoe opened this issue Jul 18, 2024 · 4 comments · Fixed by #16
Closed

CREATE INDEX does not block table reads #15

seanpascoe opened this issue Jul 18, 2024 · 4 comments · Fixed by #16

Comments

@seanpascoe
Copy link

Folks at my company have been passing this repo and associated article around like it's gospel, but I'm pretty sure you're wrong on creating postgres indexes and blocking table reads:

Creating an index will block both reads and writes in Postgres.

CREATE INDEX will block table writes but not reads in postgres

With Postgres, instead create the index concurrently which does not block reads.

creating the index concurrently will not block writes.

From the postgresql docs regarding CONCURRENTLY

When this option is used, PostgreSQL will build the index without taking any locks that prevent concurrent inserts, updates, or deletes on the table; whereas a standard index build locks out writes (but not reads) on the table until it's done. There are several caveats to be aware of when using this option — see Building Indexes Concurrently.

@dbernheisel
Copy link
Collaborator

Thanks, there's definitely an inconsistency here. The example is correct in stating "which will block writes" but the description says (incorrectly) it will also block reads. This must've been some copy-paste error; sorry about that. I'll get a PR up to resolve.

@dbernheisel
Copy link
Collaborator

Also see some notes I left in #8

@seanpascoe
Copy link
Author

Thanks, though you still have the language under the "Good", suggesting postgres normally blocks reads without concurrently:

With Postgres, instead create the index concurrently which does not block reads. There are two options:

@dbernheisel
Copy link
Collaborator

fixed!

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

Successfully merging a pull request may close this issue.

2 participants