1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-06-20 01:17:49 +02:00

Allow process priority to be set.

Decreasing process priority makes the pgBackRest processes less likely to interfere with the normal operation of PostgreSQL.
This commit is contained in:
David Steele
2025-11-11 21:06:42 +02:00
committed by GitHub
parent 8b9a19e078
commit 0fc7e96f5a
8 changed files with 144 additions and 3 deletions
+13
View File
@@ -1,5 +1,18 @@
<release date="XXXX-XX-XX" version="2.58.0dev" title="Under Development">
<release-core-list>
<release-feature-list>
<release-item>
<github-pull-request id="2693"/>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="douglas.j.hunley"/>
</release-item-contributor-list>
<p>Allow process priority to be set.</p>
</release-item>
</release-feature-list>
<release-improvement-list>
<release-item>
<github-pull-request id="2692"/>
+6
View File
@@ -849,6 +849,12 @@ option:
-command: server
-command: server-ping
priority:
section: global
type: integer
required: false
allow-range: [-20, 19]
process-max:
section: global
type: integer
+10
View File
@@ -325,6 +325,16 @@
<example>n</example>
</config-key>
<config-key id="priority" name="Set Process Priority">
<summary>Set process priority.</summary>
<text>
<p>Defines how much priority (i.e. niceness) will be given to the process by the kernel scheduler. Positive values decrease priority and negative values increase priority. In most case processes do not have permission to increase their priority.</p>
</text>
<example>19</example>
</config-key>
<config-key id="spool-path" name="Spool Path">
<summary>Path where transient data is stored.</summary>
+3 -1
View File
@@ -101,6 +101,7 @@ Option constants
#define CFGOPT_PAGE_HEADER_CHECK "page-header-check"
#define CFGOPT_PG "pg"
#define CFGOPT_PG_VERSION_FORCE "pg-version-force"
#define CFGOPT_PRIORITY "priority"
#define CFGOPT_PROCESS "process"
#define CFGOPT_PROCESS_MAX "process-max"
#define CFGOPT_PROTOCOL_TIMEOUT "protocol-timeout"
@@ -140,7 +141,7 @@ Option constants
#define CFGOPT_VERBOSE "verbose"
#define CFGOPT_VERSION "version"
#define CFG_OPTION_TOTAL 188
#define CFG_OPTION_TOTAL 189
/***********************************************************************************************************************************
Option value constants
@@ -476,6 +477,7 @@ typedef enum
cfgOptPgSocketPath,
cfgOptPgUser,
cfgOptPgVersionForce,
cfgOptPriority,
cfgOptProcess,
cfgOptProcessMax,
cfgOptProtocolTimeout,
+14
View File
@@ -4,6 +4,7 @@ Configuration Load
#include "build.auto.h"
#include <string.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -466,6 +467,19 @@ cfgLoad(const unsigned int argListSize, const char *argList[])
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
umask(0000);
if (cfgOptionValid(cfgOptPriority) && cfgOptionSource(cfgOptPriority) != cfgSourceDefault)
{
// Sign conversion is ignored here due to type conflicts between setpriority() and getpid() on different platforms.
// Linux returns _pid_t (int) from getpid() but accepts id_t (unsigned int) in setpriority(). FreeBSD (but not MacOS)
// uses int for both. Presumably implicit conversion will work appropriately on each platform so just let that happen.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
THROW_ON_SYS_ERROR(
setpriority(PRIO_PROCESS, getpid(), cfgOptionInt(cfgOptPriority)) == -1, KernelError,
"unable to set process priority");
#pragma GCC diagnostic pop
}
// Initialize TCP settings
if (cfgOptionValid(cfgOptSckKeepAlive))
{
+94 -1
View File
@@ -7,11 +7,12 @@ Automatically generated by 'build-code config' -- do not modify directly.
/***********************************************************************************************************************************
Rule Strings
***********************************************************************************************************************************/
#define PARSE_RULE_VAL_STR(value) PARSE_RULE_U32_1(parseRuleValStr##value)
#define PARSE_RULE_VAL_STR(value) PARSE_RULE_U32_2(parseRuleValStr##value)
static const StringPubConst parseRuleValueStr[] =
{
PARSE_RULE_STRPUB("-1"), // val/str
PARSE_RULE_STRPUB("-20"), // val/str
PARSE_RULE_STRPUB("-5"), // val/str
PARSE_RULE_STRPUB("-7"), // val/str
PARSE_RULE_STRPUB("/tmp/pgbackrest"), // val/str
@@ -31,6 +32,7 @@ static const StringPubConst parseRuleValueStr[] =
PARSE_RULE_STRPUB("15s"), // val/str
PARSE_RULE_STRPUB("16KiB"), // val/str
PARSE_RULE_STRPUB("16MiB"), // val/str
PARSE_RULE_STRPUB("19"), // val/str
PARSE_RULE_STRPUB("1B"), // val/str
PARSE_RULE_STRPUB("1GiB"), // val/str
PARSE_RULE_STRPUB("1MiB"), // val/str
@@ -144,6 +146,7 @@ static const StringPubConst parseRuleValueStr[] =
typedef enum
{
parseRuleValStrQT_DS_1_QT, // val/str/enum
parseRuleValStrQT_DS_20_QT, // val/str/enum
parseRuleValStrQT_DS_5_QT, // val/str/enum
parseRuleValStrQT_DS_7_QT, // val/str/enum
parseRuleValStrQT_FS_tmp_FS_pgbackrest_QT, // val/str/enum
@@ -163,6 +166,7 @@ typedef enum
parseRuleValStrQT_15s_QT, // val/str/enum
parseRuleValStrQT_16KiB_QT, // val/str/enum
parseRuleValStrQT_16MiB_QT, // val/str/enum
parseRuleValStrQT_19_QT, // val/str/enum
parseRuleValStrQT_1B_QT, // val/str/enum
parseRuleValStrQT_1GiB_QT, // val/str/enum
parseRuleValStrQT_1MiB_QT, // val/str/enum
@@ -480,6 +484,7 @@ Rule Ints
static const int parseRuleValueInt[] =
{
-20, // val/int
-7, // val/int
-5, // val/int
-1, // val/int
@@ -490,6 +495,7 @@ static const int parseRuleValueInt[] =
6, // val/int
9, // val/int
12, // val/int
19, // val/int
22, // val/int
32, // val/int
256, // val/int
@@ -507,6 +513,7 @@ static const int parseRuleValueInt[] =
static const uint8_t parseRuleValueIntStrMap[] =
{
parseRuleValStrQT_DS_20_QT, // val/int/strmap
parseRuleValStrQT_DS_7_QT, // val/int/strmap
parseRuleValStrQT_DS_5_QT, // val/int/strmap
parseRuleValStrQT_DS_1_QT, // val/int/strmap
@@ -517,6 +524,7 @@ static const uint8_t parseRuleValueIntStrMap[] =
parseRuleValStrQT_6_QT, // val/int/strmap
parseRuleValStrQT_9_QT, // val/int/strmap
parseRuleValStrQT_12_QT, // val/int/strmap
parseRuleValStrQT_19_QT, // val/int/strmap
parseRuleValStrQT_22_QT, // val/int/strmap
parseRuleValStrQT_32_QT, // val/int/strmap
parseRuleValStrQT_256_QT, // val/int/strmap
@@ -534,6 +542,7 @@ static const uint8_t parseRuleValueIntStrMap[] =
typedef enum
{
parseRuleValIntDS_20, // val/int/enum
parseRuleValIntDS_7, // val/int/enum
parseRuleValIntDS_5, // val/int/enum
parseRuleValIntDS_1, // val/int/enum
@@ -544,6 +553,7 @@ typedef enum
parseRuleValInt6, // val/int/enum
parseRuleValInt9, // val/int/enum
parseRuleValInt12, // val/int/enum
parseRuleValInt19, // val/int/enum
parseRuleValInt22, // val/int/enum
parseRuleValInt32, // val/int/enum
parseRuleValInt256, // val/int/enum
@@ -4632,6 +4642,88 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
), // opt/pg-version-force
), // opt/pg-version-force
// -----------------------------------------------------------------------------------------------------------------------------
PARSE_RULE_OPTION // opt/priority
( // opt/priority
PARSE_RULE_OPTION_NAME("priority"), // opt/priority
PARSE_RULE_OPTION_TYPE(Integer), // opt/priority
PARSE_RULE_OPTION_RESET(true), // opt/priority
PARSE_RULE_OPTION_REQUIRED(false), // opt/priority
PARSE_RULE_OPTION_SECTION(Global), // opt/priority
// opt/priority
PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST // opt/priority
( // opt/priority
PARSE_RULE_OPTION_COMMAND(Annotate) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchiveGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchivePush) // opt/priority
PARSE_RULE_OPTION_COMMAND(Backup) // opt/priority
PARSE_RULE_OPTION_COMMAND(Check) // opt/priority
PARSE_RULE_OPTION_COMMAND(Expire) // opt/priority
PARSE_RULE_OPTION_COMMAND(Info) // opt/priority
PARSE_RULE_OPTION_COMMAND(Manifest) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoLs) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoPut) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoRm) // opt/priority
PARSE_RULE_OPTION_COMMAND(Restore) // opt/priority
PARSE_RULE_OPTION_COMMAND(Server) // opt/priority
PARSE_RULE_OPTION_COMMAND(ServerPing) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaCreate) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaDelete) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaUpgrade) // opt/priority
PARSE_RULE_OPTION_COMMAND(Start) // opt/priority
PARSE_RULE_OPTION_COMMAND(Stop) // opt/priority
PARSE_RULE_OPTION_COMMAND(Verify) // opt/priority
), // opt/priority
// opt/priority
PARSE_RULE_OPTION_COMMAND_ROLE_ASYNC_VALID_LIST // opt/priority
( // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchiveGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchivePush) // opt/priority
), // opt/priority
// opt/priority
PARSE_RULE_OPTION_COMMAND_ROLE_LOCAL_VALID_LIST // opt/priority
( // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchiveGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchivePush) // opt/priority
PARSE_RULE_OPTION_COMMAND(Backup) // opt/priority
PARSE_RULE_OPTION_COMMAND(Restore) // opt/priority
PARSE_RULE_OPTION_COMMAND(Verify) // opt/priority
), // opt/priority
// opt/priority
PARSE_RULE_OPTION_COMMAND_ROLE_REMOTE_VALID_LIST // opt/priority
( // opt/priority
PARSE_RULE_OPTION_COMMAND(Annotate) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchiveGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(ArchivePush) // opt/priority
PARSE_RULE_OPTION_COMMAND(Backup) // opt/priority
PARSE_RULE_OPTION_COMMAND(Check) // opt/priority
PARSE_RULE_OPTION_COMMAND(Expire) // opt/priority
PARSE_RULE_OPTION_COMMAND(Info) // opt/priority
PARSE_RULE_OPTION_COMMAND(Manifest) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoGet) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoLs) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoPut) // opt/priority
PARSE_RULE_OPTION_COMMAND(RepoRm) // opt/priority
PARSE_RULE_OPTION_COMMAND(Restore) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaCreate) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaDelete) // opt/priority
PARSE_RULE_OPTION_COMMAND(StanzaUpgrade) // opt/priority
PARSE_RULE_OPTION_COMMAND(Verify) // opt/priority
), // opt/priority
// opt/priority
PARSE_RULE_OPTIONAL // opt/priority
( // opt/priority
PARSE_RULE_OPTIONAL_GROUP // opt/priority
( // opt/priority
PARSE_RULE_OPTIONAL_ALLOW_RANGE // opt/priority
( // opt/priority
PARSE_RULE_VAL_INT(DS_20), // opt/priority
PARSE_RULE_VAL_INT(19), // opt/priority
), // opt/priority
), // opt/priority
), // opt/priority
), // opt/priority
// -----------------------------------------------------------------------------------------------------------------------------
PARSE_RULE_OPTION // opt/process
( // opt/process
PARSE_RULE_OPTION_NAME("process"), // opt/process
@@ -11555,6 +11647,7 @@ static const uint8_t optionResolveOrder[] =
cfgOptPgSocketPath, // opt-resolve-order
cfgOptPgUser, // opt-resolve-order
cfgOptPgVersionForce, // opt-resolve-order
cfgOptPriority, // opt-resolve-order
cfgOptProcess, // opt-resolve-order
cfgOptProcessMax, // opt-resolve-order
cfgOptProtocolTimeout, // opt-resolve-order
+1
View File
@@ -269,6 +269,7 @@ testRun(void)
" --lock-path path where lock files are stored\n"
" [default=/tmp/pgbackrest]\n"
" --neutral-umask use a neutral umask [default=y]\n"
" --priority set process priority\n"
" --process-max max processes to use for\n"
" compress/transfer [default=1]\n"
" --protocol-timeout protocol timeout [default=31m]\n"
+3 -1
View File
@@ -849,7 +849,7 @@ testRun(void)
TEST_RESULT_UINT(ioBufferSize(), 333, "buffer size not updated by help command");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("command takes lock and opens log file and uses custom tcp settings");
TEST_TITLE("command takes lock, opens log file, uses custom tcp settings, and sets priority");
socketLocal = (struct SocketLocal){.init = false};
struct stat statLog;
@@ -867,6 +867,7 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptTcpKeepAliveCount, "11");
hrnCfgArgRawZ(argList, cfgOptTcpKeepAliveIdle, "2222");
hrnCfgArgRawZ(argList, cfgOptTcpKeepAliveInterval, "888");
hrnCfgArgRawZ(argList, cfgOptPriority, "19");
strLstAddZ(argList, CFGCMD_BACKUP);
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "lock and open log file");
@@ -878,6 +879,7 @@ testRun(void)
TEST_RESULT_INT(socketLocal.tcpKeepAliveCount, 11, "check socketLocal.tcpKeepAliveCount");
TEST_RESULT_INT(socketLocal.tcpKeepAliveIdle, 2222, "check socketLocal.tcpKeepAliveIdle");
TEST_RESULT_INT(socketLocal.tcpKeepAliveInterval, 888, "check socketLocal.tcpKeepAliveInterval");
TEST_RESULT_INT(getpriority(PRIO_PROCESS, (id_t)getpid()), 19, "check priority");
cmdLockReleaseP();