mirror of
https://github.com/postgres/postgres.git
synced 2026-02-17 17:55:04 -05:00
Align blocks stored in incremental files to BLCKSZ, so that the incremental backups work well with CoW filesystems. The header of the incremental file is padded with \0 to a multiple of BLCKSZ, so that the block data (also BLCKSZ) is aligned to BLCKSZ. The padding is added only to files containing block data, so files with just the header remain small. This adds a bit of extra space, but as the number of blocks increases the overhead gets negligible very quickly. And as the padding is \0 bytes, it does compress extremely well. The alignment is important for CoW filesystems that usually require the blocks to be aligned to filesystem page size for features like block sharing, deduplication etc. to work well. With the variable sized header the blocks in the increments were not aligned at all, negating the benefits of the CoW filesystems. This matters even for non-CoW filesystems, for example when placed on a RAID array. If the block is not aligned, it may easily span multiple devices, causing read and write amplification. It might be better to align the blocks to the filesystem page, not BLCKSZ, but we have no good way to determine that. Even if we determine the page size at the time of taking the backup, the backup may move. For now the BLCKSZ seems sufficient - the filesystem page is usually 4K, so the default BLCKSZ (8K by default) is aligned to that. Author: Tomas Vondra Reviewed-by: Robert Haas, Jakub Wartak Discussion: https://postgr.es/m/3024283a-7491-4240-80d0-421575f6bb23%40enterprisedb.com
56 lines
1.8 KiB
C
56 lines
1.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* basebackup_incremental.h
|
|
* API for incremental backup support
|
|
*
|
|
* Portions Copyright (c) 2010-2024, PostgreSQL Global Development Group
|
|
*
|
|
* src/include/backup/basebackup_incremental.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef BASEBACKUP_INCREMENTAL_H
|
|
#define BASEBACKUP_INCREMENTAL_H
|
|
|
|
#include "access/xlogbackup.h"
|
|
#include "common/relpath.h"
|
|
#include "storage/block.h"
|
|
#include "utils/palloc.h"
|
|
|
|
#define INCREMENTAL_MAGIC 0xd3ae1f0d
|
|
|
|
typedef enum
|
|
{
|
|
BACK_UP_FILE_FULLY,
|
|
BACK_UP_FILE_INCREMENTALLY
|
|
} FileBackupMethod;
|
|
|
|
struct IncrementalBackupInfo;
|
|
typedef struct IncrementalBackupInfo IncrementalBackupInfo;
|
|
|
|
extern IncrementalBackupInfo *CreateIncrementalBackupInfo(MemoryContext);
|
|
|
|
extern void AppendIncrementalManifestData(IncrementalBackupInfo *ib,
|
|
const char *data,
|
|
int len);
|
|
extern void FinalizeIncrementalManifest(IncrementalBackupInfo *ib);
|
|
|
|
extern void PrepareForIncrementalBackup(IncrementalBackupInfo *ib,
|
|
BackupState *backup_state);
|
|
|
|
extern char *GetIncrementalFilePath(Oid dboid, Oid spcoid,
|
|
RelFileNumber relfilenumber,
|
|
ForkNumber forknum, unsigned segno);
|
|
extern FileBackupMethod GetFileBackupMethod(IncrementalBackupInfo *ib,
|
|
const char *path,
|
|
Oid dboid, Oid spcoid,
|
|
RelFileNumber relfilenumber,
|
|
ForkNumber forknum,
|
|
unsigned segno, size_t size,
|
|
unsigned *num_blocks_required,
|
|
BlockNumber *relative_block_numbers,
|
|
unsigned *truncation_block_length);
|
|
extern size_t GetIncrementalFileSize(unsigned num_blocks_required);
|
|
extern size_t GetIncrementalHeaderSize(unsigned num_blocks_required);
|
|
|
|
#endif
|