简体   繁体   中英

SQL Server 2008 R2: How do I “pause” a clustered index while the server is being written to?

I'm wondering if its possible to "pause" a clustered index whenever bulk data is being written?

The reason is that:

  • Bulk inserts are slow ( 10,000 rows/second) if I have a clustered index on "DateTime".
  • Bulk inserts are fast ( 180,000 rows/second) if I have an inactive clustered index on "DateTime".

I don't mind if the clustered index is rebuilt overnight, eg from 1am to 6am.

You can't disable a clustered index and still use the table.

Since the clustered index IS THE TABLE having it disabled means you can't access any of the data.

From MSDN:

The data rows of the disabled clustered index cannot be accessed except to drop or rebuild the clustered index.

You can...

  • disable any nonclustered indexes and rebuild them overnight. This will help greatly
  • DROP all indexes (including clustered) and insert, then CREATE them overnight. This will render the table basically unusable, though.

My preferred solution for this is a little more complicated:

  • INSERT into a staging table that has the same clustered index key as your target table
  • INSERT from staging into target overnight and update indexes as needed then

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM