When you switch PostgreSQL's block size from 8kB to 16kB and attempt to start it on an existing database cluster, the server will fail to start. Here's why and what happens:
1. Block Size is Fixed at Cluster Initialization
PostgreSQL's block size (typically 8kB by default) is set permanently when you run initdb to create the database cluster.
The pg_control file (metadata in the data directory) records this block size. All data files (tables, indexes) are structured around this size.
2. Startup Block Size Mismatch
When you start PostgreSQL with -B 16384 (or set block_size = 16384 in postgresql.conf):
The server checks pg_control and detects a mismatch between the configured block size (16kB) and the initialized block size (8kB).
Result: Immediate fatal error. Example log entry:
log
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized with block size 8192, but the server was compiled with block size 16384.
3. Why This Fails
On-disk layout: Tables/indexes store data in fixed-size blocks (8kB in your case). Switching to 16kB would corrupt reads/writes.
Shared buffers: PostgreSQL's shared memory expects the configured block size.
Metadata: Critical files (e.g., pg_xact, pg_multixact) rely on the original block size.
How to Safely Change Block Size
To use 16kB blocks:
Dump all data using pg_dumpall.
Shut down the old cluster.
Create a new cluster with 16kB blocks:
bash
initdb -D /new/data -B 16384 # Set block size during initialization
Start the new cluster and restore the dump.
Update configurations (e.g., postgresql.conf) to use block_size = 16384 permanently.
Key Notes
❌ Never change block_size on an existing cluster.
💡 Block size cannot be altered without recreating the cluster.
⚠️ Changing block size affects performance (e.g., 16kB may improve sequential scans but increase I/O for small rows). Test thoroughly.
Recovery from Mistake
If you modified postgresql.conf and caused a startup failure:
Revert block_size to 8192 (or remove the setting to use the default 8kB).
Restart PostgreSQL. The server will start normally with the original 8kB blocks.
Verification
Check your current cluster's block size:
sql
SHOW block_size; -- Returns 8192 (8kB) in your case
Switching block sizes requires a new database cluster. The existing data directory is tied to its original block size. Always dump/reload data when changing this parameter.