1

On Windows with NTFS, is it safe to defragment files that are currently being written to and read from other processes?

I believe I may be hitting into an issue with an extremely fragmented large SQLite database. So I'm thinking of possible solutions once I confirm that that's the issue. I was thinking of periodically running Contig from Sysinternals, but the file is huge so it takes ages to complete.

However, assuming it's safe to do so, I could just run Contig in the background, while the database is being used.

  • Welcome to Server Fault. Personally, I wouldn't try it. – LeRouteur Dec 22 '20 at 11:21
  • 1
    Dear @relatively_random well this question could be leaded in opinionbases answers. However Usually you cant prevent write during defragmentation - you may only do so if you safeboot this device and defrag from a other OS which has no reference to this disk. However usually in my guess its safe to do so, but remind to have always a backup :) – djdomi Dec 23 '20 at 05:46
  • @djdomi I don't believe it's opinion-based at all since I'm asking for facts. Even if there's no definitive answer based on official documentation, you can post evidence for why it's probably safe or unsafe. Or just not answer - it wouldn't be the first nor last unanswered Stack Exchange question. – relatively_random Dec 23 '20 at 08:42

1 Answers1

2

Unless there is an error on the drive, it is unlikely that defragmenting will cause any problems while files are being read and written.

My personal preference is to close open apps & programs and let defrag run overnight.

If that will not work for you, you can try: https://docs.microsoft.com/en-us/windows/win32/fileio/defragmenting-files which is a more hands-on approach.

Tee_Bee
  • 31
  • 3