Skip to main content

在数据库中存储大对象或 BLOB

Optimize 提供的建议可帮助你识别和解决由在数据库中存储大型对象引起的性能问题。它还建议了其他方法来缓解这些挑战。

¥Optimize provides recommendations to help identify and resolve performance issues caused by storing large objects in the database. It also suggests alternative approaches to mitigate these challenges.

以下模型使用 Bytes 类型:

¥The following model uses the Bytes type:

model User {
id Int @id @default(autoincrement())
name String?
// Storing raw image data directly in the database
avatarBytes Bytes?
}

问题是什么?

¥What is the problem?

在数据库中存储大型二进制对象(例如图片)可能会带来一些挑战:

¥Storing large binary objects (such as images) in the database can lead to several challenges:

  • 存储使用量过大:大对象在数据库中占用大量空间,使管理变得复杂。

    ¥Excessive storage usage: Large objects occupy significant space in the database, complicating management.

  • I/O 负载增加:处理大对象会给数据库的输入/输出操作增加负担。

    ¥Increased I/O load: Handling large objects adds strain to the database's input/output operations.

  • 查询性能较慢:大多数传统数据库并未针对高效处理大型二进制内容进行优化,导致查询或更新期间的性能下降。

    ¥Slower query performance: Most traditional databases are not optimized for efficiently serving large binary content, resulting in performance degradation during queries or updates.

此外,将大型对象直接存储在数据库中可能会导致备份文件过大,从而增加恢复过程所需的时间。通过数据库提供这些文件也会造成性能瓶颈,尤其是在高流量或频繁访问的情况下。

¥Moreover, storing large objects directly in the database can cause backups to become disproportionately large, increasing the time required for restoration processes. Serving these files through the database also creates a performance bottleneck, particularly under high traffic or frequent access scenarios.