segment_size reports how many blocks PostgreSQL will put in one file before it starts the next. Since PostgreSQL keeps no authoritative record of how long a table is, it is also how the server decides where one ends.
It is a preset, like block_size: context internal, fixed when the binary was compiled, and not settable by any means. (Put it in postgresql.conf anyway and the server logs parameter "segment_size" cannot be changed and refuses to start.) The default is 1GB, which the parameter reports in blocks: 131072 of them at the usual 8kB. SHOW segment_size multiplies it back out and says 1GB, while pg_settings.setting says 131072 with a unit of 8kB. The build option behind it is --with-segsize, in gigabytes, which has been a configure switch since 8.4 in 2009; before that you edited a header file.
A table or index bigger than one segment is stored as several files. The first is named for the relation’s filenode, say base/5/16388. The next gigabyte goes in 16388.1, then 16388.2, and so on, up to 32,768 of them for a table at the 32TB limit. The comment that explains the default says the point is to stay under the 2GB or 4GB file-size limit of a 32-bit operating system without large-file support, with 1GB chosen to keep clear of integer-overflow bugs in the OS. Outside Windows, where off_t is still 32 bits and a 2025 bug report found a build with 8GB segments unable to grow a file past 2GB, it has been a while since anyone needed that. The default has not moved.
This is the only kind of segment the parameter describes. WAL files have their own wal_segment_size, an initdb option since 11, and temporary files are cut at 1GB by a separate constant however the server was built.
PostgreSQL has no authoritative record of how many segments a relation should have. pg_class.relpages is a planner estimate that VACUUM and ANALYZE refresh. When the server needs the real length, it opens the first file and measures it; if that file holds exactly segment_size blocks, it opens the next one, and so on until it reaches a file that is short or a file that is not there. That is the end of the relation. The code once created the next file when it was missing. It no longer does, and the comment in md.c says why: a segment may have “vanished through some operating system misadventure” and re-creating it would hide the error that a later read of it ought to raise. That works for a plain index scan. A sequential scan asks how long the table is first, and never gets that far.
I tested what that means on 18.6 and on the 19 release candidate, using a 2,400 MB table of 2,150,000 rows in three segment files, restored from a pg_basebackup copy from which the middle file, 16388.1, had been removed. The server starts and logs nothing unusual. A sequential scan returns 917,504 rows, which is the contents of the first file, and no error. pg_dump writes out those 917,504 rows and exits 0. pg_relation_size() reports 1024 MB. The third file, holding 314,992 intact rows, is still on disk and is now unreachable. Of the queries I tried, only a plain index scan that has to fetch a row in or beyond the missing file objects:
1 ERROR: could not open file "base/5/16388.1" (target block 142857): No such file or directory
A bitmap scan for the same rows returns nothing, without complaint. An index-only scan objects only if it has to visit the table: on the freshly vacuumed table, count(*) ran from the index alone and returned 2,150,000. pg_checksums --check passes, because every page that is present is fine. pg_amcheck --heapallindexed --parent-check passes. For a while pg_class.relpages still says 307,143 for a table that is now 131,072 blocks long, which makes comparing it with pg_relation_size() a cheap test right after a restore; then the next ANALYZE corrects it, and the statistics agree with the damage.
That is the benign version, and it does not stay benign. The next insert that extends the table re-creates 16388.1 and starts filling it, so new rows take the block numbers the lost rows had, and the index entries for the lost rows now point at them. Once my test table had grown back, WHERE id = 1000000 returned the row whose id was 3082496.
The other version is what happens when the restore goes on to replay WAL, as a point-in-time recovery does. With full_page_writes on, the first change to any page after a checkpoint is logged as an image of the whole page. When recovery meets an image for a block beyond what it believes is the end of the relation, it extends the relation with zeroed pages up to that block, which is the right thing to do for a table that grew after the backup was taken. Here, a few single-row updates after the backup, to one page in the lost segment and one page in the segment after it, were enough for recovery to re-create 16388.1 as a full gigabyte in which 131,071 of the 131,072 blocks were zeros. (The exception was the page WAL had an image of.) An all-zero page is a valid empty page and has no checksum to fail. The table was 2,400 MB again. Recovery logged nothing above LOG. After a clean restart, pg_checksums and pg_amcheck both passed, pg_dump exited 0, and looking up a row from the lost segment returned no rows and no error. All but a handful of 917,504 rows were gone, and the nearest thing to a symptom was an index-only count(*) that disagreed with a sequential one.
One tool noticed, and it was the one holding a list. pg_verifybackup, run on the copy before starting it, printed "base/5/16388.1" is present in the manifest but not on disk and exited 1. pg_basebackup has written that manifest by default since 13.
The everyday cost of 1GB segments is the file count. A 1TB table is 1,024 files, and since finding its length means walking the chain, a backend opens every one of them the first time it plans a query against the table. I faked a 1TB table out of sparse files to watch it happen: the first EXPLAIN in a new session took 2 to 3 ms, where the same thing against a three-file table took under a millisecond, and it left the backend holding 985 open segment files. That is very nearly the whole default max_files_per_process, spent before the query read a row, and it is why that post says to count files and not tables. It is also the one reason the documentation offers for building with a larger segment size.
Don’t. The server is careful about this. Started on a data directory made by a build with a different value, it refuses:
1 FATAL: database files are incompatible with server
2 DETAIL: The database cluster was initialized with RELSEG_SIZE 262144, but the server was compiled with RELSEG_SIZE 131072.
pg_upgrade will not go between builds that differ either, so every later major version has to be a custom build as well (or a dump and restore). The tools around the server are less careful. A page checksum has the page’s block number mixed into it, and the block number of a page in the second file depends on how long the first file is supposed to be. I built 18.6 and 19rc1 with 2GB segments and ran the PGDG packages’ pg_checksums --check against a clean cluster. It reported 44,999 bad checksums, one for every page in the second file. pg_checksums has refused a mismatched block size since 2019, and nobody added the same test for segment size. I turned checksums off and asked the packaged tool to --enable them again; it rewrote all 44,999 pages with checksums for the wrong block numbers and reported success, after which the server could not read the table past 2GB:
1 ERROR: invalid page in block 262144 of relation "base/5/16384"
pgBackRest 2.60.0 has 1GB compiled in as a constant, under a comment saying other sizes are unsupported because they are not well tested; it backed up the 18.6 cluster and warned of invalid checksums on those same pages. WAL-G has the same constant. The project’s own CI covers the segment code by running one build with six-block segments (a switch added in 16 for the purpose), which tests the boundaries thoroughly and your backup tool not at all. A 2023 proposal that became a patch to make the size an initdb option was last revised in March 2024, and neither 18 nor 19 has it.
Leave it at 1GB, which is easy, since you have no choice. What it asks of you is elsewhere: size file-descriptor limits by the gigabytes in your largest tables, keep your hands out of base/, and after any file-level copy of a cluster, check the copy against a list made at the source before you start it. “It came up fine” is not evidence. A cluster missing a gigabyte of a table comes up fine.