查找文件基本结束,不过,某些某些relation比较大,记录比较多,会导致磁盘文件超大,为了防止文件系统对磁盘文件大小的限制而导致的写入失败,PostgreSQL做了分段的机制。以我的friends为例,如果随着记录的不断插入,最后friends对应的磁盘文件16385越来越大,当超过1G的时候,PostgreSQL就会新建一个磁盘文件叫16385.1,超过2G的时候PostgreSQL再次分段,新建文件16385.2 。这个1G就是有Block size = 8KB和blockS per segment of large relation=128K(个)共同决定的。
源码中的定义上面有注释,解释了很多内容:
/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus,
the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger
than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be
less than your OS' limit on file size. This is often 2 GB or 4GB in a
32-bit operating system, unless you have large file support enabled. By
default, we make the limit 1 GB to avoid any possible integer-overflow
problems within the OS. A limit smaller than necessary only means we divide
a large relation into more chunks than necessary, so it seems best toerr
in the direction of a small limit. A power-of-2 value is recommended to
save a few cycles in md.c, but isnot absolutely required. Changing