From 1d44fbd779fb90f44f9e63f8fc2b8dd97dbc9a61 Mon Sep 17 00:00:00 2001 From: liuzhanfeng2 Date: Mon, 20 May 2024 11:28:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6gs=5Fprobackup=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_probackup/pg_probackup.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bin/pg_probackup/pg_probackup.cpp b/src/bin/pg_probackup/pg_probackup.cpp index 11ee5eec8..362aff48a 100644 --- a/src/bin/pg_probackup/pg_probackup.cpp +++ b/src/bin/pg_probackup/pg_probackup.cpp @@ -739,6 +739,20 @@ static void check_dss_input() } } +static void check_threads_num_option() +{ +#ifdef _SC_NPROCESSORS_ONLN + int nprocs = sysconf(_SC_NPROCESSORS_ONLN); + if (nprocs <= 0) { + elog(ERROR, "Failed to get the number of available cores."); + } + if (num_threads > nprocs * 10) { + elog(ERROR, "Invalid value for '-j' option: %d, the number of cores available is %d, " + "more than 10 times is not allowed.", num_threads, nprocs); + } +#endif +} + int main(int argc, char *argv[]) { char *command = NULL, @@ -852,6 +866,8 @@ int main(int argc, char *argv[]) check_restore_option(command_name); + check_threads_num_option(); + /* * Parse set-backup options into set_backup_params structure. */