PROPOSAL: Support global and local disabling of indexes
PROPOSAL: Support global and local disabling of indexes
От:
Paul Martinez <hellopfm@gmail.com>
Дата:
Hey, hackers, Adding and removing indexes is a regular part of database maintenance, but in a large database, removing an index can be a very risky operation. Removing the wrong index could have disastrous consequences for performance, and it could take tens of minutes, or even hours, to rebuild the entire index. I propose adding an ALTER INDEX command that can enable or disable an index on a global level: ALTER INDEX index_name ENABLE; ALTER INDEX index_name DISABLE; A disabled index is still updated, and still enforces constraints, but it will not be used for queries. Whether or not the index is disabled could also be specified at index creation: CREATE INDEX index_name ON table_name (col1, col2) ENABLED; -- default CREATE INDEX index_name ON table_name (col1, col2) DISABLED; This would be useful if a user anticipates index creation to take a long time and they want to be able to carefully monitor the database once the index starts getting used. It would also be useful to be able to enable and disable indexes locally in the context of a single session to easily and safely verify that a query can still be executed efficiently without an index: ALTER INDEX index_name DISABLE SESSION; It might also be reasonable to "unset" any local override to what's actually set on the index itself, but this would probably require slightly different syntax: SET ENABLED = true / false / DEFAULT maybe? I am unsure of how a user would query this information; maybe a function like pg_disabled_index_overrides() ? The permanent state of an index should be reflected in the output of \d
Re: PROPOSAL: Support global and local disabling of indexes
От:
Julien Rouhaud <rjuju123@gmail.com>
Дата:
Hi, On Thu, Mar 17, 2022 at 11:16:24PM -0700, Paul Martinez wrote: > > Adding and removing indexes is a regular part of database maintenance, > but in a large database, removing an index can be a very risky operation. > Removing the wrong index could have disastrous consequences for > performance, and it could take tens of minutes, or even hours, to rebuild > the entire index. > > I propose adding an ALTER INDEX command that can enable or disable an > index on a global level: > > ALTER INDEX index_name ENABLE; > ALTER INDEX index_name DISABLE; > > A disabled index is still updated, and still enforces constraints, but it > will not be used for queries. > > Whether or not the index is disabled could also be specified at index > creation: > > CREATE INDEX index_name ON table_name (col1, col2) ENABLED; -- default > CREATE INDEX index_name ON table_name (col1, col2) DISABLED; > > This would be useful if a user anticipates index creation to take a long > time and they want to be able to carefully monitor the database once the > index starts getting used. > > It would also be useful to be able to enable and disable indexes locally > in the context of a single session to easily and safely verify that a > query can still be executed efficiently without an index: > > ALTER INDEX index_name DISABLE SESSION; For the record, all of that is already doable using plantuner extension: https://github.com/postgrespro/plantuner.
Re: PROPOSAL: Support global and local disabling of indexes
От:
Justin Pryzby <pryzby@telsasoft.com>
Дата:
On Thu, Mar 17, 2022 at 11:16:24PM -0700, Paul Martinez wrote: > I propose adding an ALTER INDEX command that can enable or disable an > index on a global level: See also this thread: https://commitfest.postgresql.org/34/2937/ https://www.postgresql.org/message-id/flat/CANbhV-H35fJsKnLoZJuhkYqg2MO4XLjR57Qwf=3-xOvG2+2UEg@mail.gmail.com -- Justin
Re: PROPOSAL: Support global and local disabling of indexes
От:
Adam Brusselback <adambrusselback@gmail.com>
Дата:
Just wanted to mention that this would be a useful feature for me. Had previously been bitten by this: https://www.postgresql.org/message-id/flat/CAMjNa7c4pKLZe%2BZ0V49isKycnXQ6Y%3D3BO-4Gsj3QAwsd2r7Wrw%40mail.gmail.com
Ended up "solving" by putting a where clause on all my exclusion constraints I didn't want used for most queries (WHERE 1=1). That allowed me "disable" that index for all queries unless they explicitly have a 1=1 constant in the where clause.