mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Allow on-line enabling and disabling of data checksums
This makes it possible to turn checksums on in a live cluster, without the previous need for dump/reload or logical replication (and to turn it off). Enabling checkusm starts a background process in the form of a launcher/worker combination that goes through the entire database and recalculates checksums on each and every page. Only when all pages have been checksummed are they fully enabled in the cluster. Any failure of the process will revert to checksums off and the process has to be started. This adds a new WAL record that indicates the state of checksums, so the process works across replicated clusters. Authors: Magnus Hagander and Daniel Gustafsson Review: Tomas Vondra, Michael Banck, Heikki Linnakangas, Andrey Borodin
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "funcapi.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/checksumhelper.h"
|
||||
#include "replication/walreceiver.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/builtins.h"
|
||||
@ -698,3 +699,61 @@ pg_backup_start_time(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_DATUM(xtime);
|
||||
}
|
||||
|
||||
/*
|
||||
* Disables checksums for the cluster, unless already disabled.
|
||||
*
|
||||
* Has immediate effect - the checksums are set to off right away.
|
||||
*/
|
||||
Datum
|
||||
disable_data_checksums(PG_FUNCTION_ARGS)
|
||||
{
|
||||
/*
|
||||
* If we don't need to write new checksums, then clearly they are already
|
||||
* disabled.
|
||||
*/
|
||||
if (!DataChecksumsNeedWrite())
|
||||
ereport(ERROR,
|
||||
(errmsg("data checksums already disabled")));
|
||||
|
||||
ShutdownChecksumHelperIfRunning();
|
||||
|
||||
SetDataChecksumsOff();
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* Enables checksums for the cluster, unless already enabled.
|
||||
*
|
||||
* Supports vacuum-like cost-based throttling, to limit system load.
|
||||
* Starts a background worker that updates checksums on existing data.
|
||||
*/
|
||||
Datum
|
||||
enable_data_checksums(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int cost_delay = PG_GETARG_INT32(0);
|
||||
int cost_limit = PG_GETARG_INT32(1);
|
||||
|
||||
if (cost_delay < 0)
|
||||
ereport(ERROR,
|
||||
(errmsg("cost delay cannot be less than zero")));
|
||||
if (cost_limit <= 0)
|
||||
ereport(ERROR,
|
||||
(errmsg("cost limit must be a positive value")));
|
||||
|
||||
/*
|
||||
* Allow state change from "off" or from "inprogress", since this is how
|
||||
* we restart the worker if necessary.
|
||||
*/
|
||||
if (DataChecksumsNeedVerify())
|
||||
ereport(ERROR,
|
||||
(errmsg("data checksums already enabled")));
|
||||
|
||||
SetDataChecksumsInProgress();
|
||||
if (!StartChecksumHelperLauncher(cost_delay, cost_limit))
|
||||
ereport(ERROR,
|
||||
(errmsg("failed to start checksum helper process")));
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
Reference in New Issue
Block a user