diff --git a/doc/src/sgml/pageinspect.sgml b/doc/src/sgml/pageinspect.sgml index d4ee34ee0f..4e29b7e00c 100644 --- a/doc/src/sgml/pageinspect.sgml +++ b/doc/src/sgml/pageinspect.sgml @@ -153,6 +153,92 @@ test=# SELECT fsm_page_contents(get_raw_page('pg_class', 'fsm', 0)); + + + + get_compress_address_header(relname text, segno integer) returns record + + get_compress_address_header + + + + + + get_compress_address_header returns global + information about the compressed address file for a compressed + relation. For example: + +test=# select * from get_compress_address_header('tb1',0); + nblocks | allocated_chunks | chunk_size | algorithm | last_synced_nblocks | last_synced_allocated_chunks +---------+------------------+------------+-----------+---------------------+------------------------------ + 5 | 0 | 1024 | 3 | 0 | 0 +(1 row) + + The returned columns correspond to the fields in the + PageCompressHeader struct. + See src/include/storage/page_compression.h for details. + + + + + + + get_compress_address_items(relname text, segno integer) returns setof record + + get_compress_address_items + + + + + + get_compress_address_items shows space allocation + information for each page of the compression relation. For example: + +test=# select * from get_compress_address_items('tb1',0); + blkno | nchunks | allocated_chunks | chunknos +-------+---------+------------------+------------ + 0 | 2 | 3 | {1,2,3} + 1 | 2 | 3 | {4,5,6} + 2 | 2 | 3 | {7,8,9} + 3 | 2 | 3 | {10,11,12} + 4 | 1 | 3 | {13,14,15} +(5 rows) + + The returned columns correspond to the fields in the + PageCompressAddr struct. + See src/include/storage/page_compression.h for details. + + + + + + + page_compress(page bytea, algorithm text, level integer) returns bytea + + page_compress + + + + + + page_compress returns compressed content for a page. + It can be used to evaluate the compression ratio of a relation, based on + which the appropriate + storage parameter can be determined. + + + A page image obtained with get_raw_page should be + passed as argument. For example: + +test=# SELECT octet_length(page_compress(get_raw_page('tb1', 'main', 0), 'zstd', 0)); + octet_length +-------------- + 1213 +(1 row) + + + + diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_index.sgml index a5bac9f737..42a68ca6a4 100644 --- a/doc/src/sgml/ref/create_index.sgml +++ b/doc/src/sgml/ref/create_index.sgml @@ -440,6 +440,110 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] + + The B-tree, hash, Gin, GiST and SP-GiST index methods all + accept the following compression parameters: + + + + + compresstype (enum) + + compresstype + + + + + This parameter sets the compression method for index. + The supported compression methods are none, + pglz, lz4 and + zstd(lz4 requires PostgreSQL + to be compiled with and + zstd with ). + And this parameter cannot be modified by ALTER INDEX. + The default is none, means do not enable compression. + + + It should be noted that freed space at the end of a compressed relation + cannot be released to the operating system. All space allocated to a + relation remains associated with that relation for reuse only within + that relation unless explicitly freed (for example, with + VACUUM FULL or REINDEX). + And for compressed relations, pg_rewind will + copy the entire relation files, not just the changed blocks. + + + + + + compresslevel (enum) + + compresslevel + + + + + This parameter sets the compression level for a compressed relation. + Currently, compression level is only supported by + zstd, and will be ignore when use other compression + method. For zstd the compression level should be an + integer between -127 and 22, a + value greater than 22 will be treated as + 22, and a value less than -127 will + be treated as -127. + The default is 0, means the default compression level + for the specific compression method. For zstd, the + default compression level is 1. + + + + + + compress_chunk_size (enum) + + compress_chunk_size + + + + + This parameter sets the chunk size for a compressed relation. For + compressed relations, storage space is allocated in chunks, and the data + of each block is stored in one or more chunks. + The chunk size must be BLCKSZ/16, + BLCKSZ/8, BLCKSZ/4 or + BLCKSZ/2. For typically BLCKSZ of + 8kB, the value of + compress_chunk_size should be one of + 512, 1024, 2048 + and 4096. A smaller chunk size can achieve a higher + compression ratio, but it is also prone to storage fragmentation. + And this parameter cannot be modified by ALTER INDEX. + The default is BLCKSZ/2. + + + + + + compress_prealloc_chunks (enum) + + compress_prealloc_chunks + + + + + This parameter sets the minimum number of chunks allocated for each block + of a compressed relation. Proper settings can effectively reduce storage + fragmentation, especially when + is small. The valid + maximum value for this parameter is + BLCKSZ/compress_chunk_size - 1. + The default is 0. + + + + + + B-tree indexes additionally accept this parameter: diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 6bbf15ed1a..d12f337a55 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -1808,6 +1808,106 @@ WITH ( MODULUS numeric_literal, REM + + compresstype (enum) + + compresstype + storage parameter + + + + + This parameter sets the compression method for table. + The supported compression methods are none, + pglz, lz4 and + zstd(lz4 requires PostgreSQL + to be compiled with and + zstd with ). + And this parameter cannot be modified by ALTER TABLE. + The default is none, means do not enable compression. + + + It should be noted that freed space at the end of a compressed relation + cannot be released to the operating system. All space allocated to a + relation remains associated with that relation for reuse only within + that relation unless explicitly freed (for example, with + VACUUM FULL). + And for compressed relations, pg_rewind will + copy the entire relation files, not just the changed blocks. + + + + + + compresslevel (enum) + + compresslevel + storage parameter + + + + + This parameter sets the compression level for a compressed relation. + Currently, compression level is only supported by + zstd, and will be ignore when use other compression + method. For zstd the compression level should be an + integer between -127 and 22, a + value greater than 22 will be treated as + 22, and a value less than -127 will + be treated as -127. + The default is 0, means the default compression level + for the specific compression method. For zstd, the + default compression level is 1. + + + + + + compress_chunk_size (enum) + + compress_chunk_size + storage parameter + + + + + This parameter sets the chunk size for a compressed relation. For + compressed relations, storage space is allocated in chunks, and the data + of each block is stored in one or more chunks. + The chunk size must be BLCKSZ/16, + BLCKSZ/8, BLCKSZ/4 or + BLCKSZ/2. For typically BLCKSZ of + 8kB, the value of + compress_chunk_size should be one of + 512, 1024, 2048 + and 4096. A smaller chunk size can achieve a higher + compression ratio, but it is also prone to storage fragmentation. + And this parameter cannot be modified by ALTER TABLE. + The default is BLCKSZ/2. + + + + + + compress_prealloc_chunks (enum) + + compress_prealloc_chunks + storage parameter + + + + + This parameter sets the minimum number of chunks allocated for each block + of a compressed relation. Proper settings can effectively reduce storage + fragmentation, especially when + is small. The valid + maximum value for this parameter is + BLCKSZ/compress_chunk_size - 1. + The default is 0. + + + +