Postgresql 中文操作指南

35.2. Implementation Features #

大型对象实现将大型对象分解为“块”,并将这些块存储在数据库中的行中。B 树索引确保在执行随机访问读取和写入时快速搜索正确的块号。

The large object implementation breaks large objects up into “chunks” and stores the chunks in rows in the database. A B-tree index guarantees fast searches for the correct chunk number when doing random access reads and writes.

为大型对象存储的块不必是连续的。例如,如果某个应用程序打开了一个新的大型对象,seek 到偏移量 1000000,并在那里写入了一些字节,这不会导致分配 1000000 字节的存储;仅分配覆盖实际写入的数据字节范围的块。但是,读取操作将对最后一个现有块之前的任何未分配位置读取零。这与 Unix 文件系统中“稀疏分配”文件的常见行为相对应。

The chunks stored for a large object do not have to be contiguous. For example, if an application opens a new large object, seeks to offset 1000000, and writes a few bytes there, this does not result in allocation of 1000000 bytes worth of storage; only of chunks covering the range of data bytes actually written. A read operation will, however, read out zeroes for any unallocated locations preceding the last existing chunk. This corresponds to the common behavior of “sparsely allocated” files in Unix file systems.

从 PostgreSQL 9.0 开始,大型对象拥有一个所有者和一组访问权限,可以使用 GRANTREVOKE 来管理。需要 SELECT 权限来读取大型对象,需要 UPDATE 权限来写入或截断大型对象。只有大型对象的所有者(或数据库超级用户)才能删除、注释或更改大型对象的所有者。要调整此行为以与先前版本兼容,请参见 lo_compat_privileges 运行时参数。

As of PostgreSQL 9.0, large objects have an owner and a set of access permissions, which can be managed using GRANT and REVOKE. SELECT privileges are required to read a large object, and UPDATE privileges are required to write or truncate it. Only the large object’s owner (or a database superuser) can delete, comment on, or change the owner of a large object. To adjust this behavior for compatibility with prior releases, see the lo_compat_privileges run-time parameter.