From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EFr0Co9hBWDJPQAA0tVLHw (envelope-from ) for ; Mon, 18 Jan 2021 10:23:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 2PrQBo9hBWCpUQAA1q6Kng (envelope-from ) for ; Mon, 18 Jan 2021 10:23:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AFD639404E8 for ; Mon, 18 Jan 2021 10:23:10 +0000 (UTC) Received: from localhost ([::1]:47968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Rgj-0001F7-Mi for larch@yhetil.org; Mon, 18 Jan 2021 05:23:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Rbn-0005wh-8Y for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34874) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1Rbm-0006jz-7f for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1Rbm-0005K5-45 for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45860] [PATCH v2 1/5] services: postgresql: Use Guile datatypes. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Jan 2021 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 45860@debbugs.gnu.org Received: via spool by 45860-submit@debbugs.gnu.org id=B45860.161096502720363 (code B ref 45860); Mon, 18 Jan 2021 10:18:02 +0000 Received: (at 45860) by debbugs.gnu.org; 18 Jan 2021 10:17:07 +0000 Received: from localhost ([127.0.0.1]:46410 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Ras-0005IK-1m for submit@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39566) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Rak-0005H5-Rj for 45860@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:02 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52244) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Raf-0006CB-K1; Mon, 18 Jan 2021 05:16:53 -0500 Received: from [2a01:e0a:19b:d9a0:1538:87ab:3a95:7600] (port=55432 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l1Rae-0001QJ-P3; Mon, 18 Jan 2021 05:16:53 -0500 From: Mathieu Othacehe Date: Mon, 18 Jan 2021 11:16:24 +0100 Message-Id: <20210118101628.202607-2-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118101628.202607-1-othacehe@gnu.org> References: <20210118101628.202607-1-othacehe@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mathieu Othacehe Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 3.64 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: AFD639404E8 X-Spam-Score: 3.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: IWfeISPb6vBx * gnu/services/databases.scm (postgresql-config-file-compiler): Support Guile datatypes in the "extra-config" field. * gnu/tests/databases.scm (%postgresql-os): Test it. * doc/guix.texi (Database Services): Document it. --- doc/guix.texi | 18 ++++++++++++------ gnu/services/databases.scm | 38 ++++++++++++++++++++++---------------- gnu/tests/databases.scm | 10 +++++++++- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index dc41fe9aea..3ec5e3be15 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19382,12 +19382,12 @@ local all all trust host all all 127.0.0.1/32 md5 host all all ::1/128 md5")) (extra-config - '(("session_preload_libraries" "'auto_explain'") - ("random_page_cost" "2") - ("auto_explain.log_min_duration" "'100ms'") - ("work_mem" "'500MB'") - ("logging_collector" "on") - ("log_directory" "'/var/log/postgresql'"))))))) + '(("session_preload_libraries" "auto_explain") + ("random_page_cost" 2) + ("auto_explain.log_min_duration" "100 ms") + ("work_mem" "500 MB") + ("logging_collector" #t) + ("log_directory" "/var/log/postgresql"))))))) @end lisp @table @asis @@ -19407,6 +19407,12 @@ List of additional keys and values to include in the PostgreSQL config file. Each entry in the list should be a list where the first element is the key, and the remaining elements are the values. +The values can be numbers, booleans or strings and will be mapped to +PostgreSQL parameters types @code{Boolean}, @code{String}, +@code{Numeric}, @code{Numeric with Unit} and @code{Enumerated} described +@uref{https://www.postgresql.org/docs/current/config-setting.html, +here}. + @end table @end deftp diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index d2dc5f0da8..bb0e40632e 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -115,22 +115,28 @@ host all all ::1/128 md5")) (match file (($ log-destination hba-file ident-file extra-config) - (define (single-quote string) - (if string - (list "'" string "'") - '())) - - (define contents - (append-map - (match-lambda - ((key) '()) - ((key . #f) '()) - ((key values ...) `(,key " = " ,@values "\n"))) - - `(("log_destination" ,@(single-quote log-destination)) - ("hba_file" ,@(single-quote hba-file)) - ("ident_file" ,@(single-quote ident-file)) - ,@extra-config))) + ;; See: https://www.postgresql.org/docs/current/config-setting.html. + (define (format-value value) + (cond + ((boolean? value) + (list (if value "on" "off"))) + ((number? value) + (list (number->string value))) + (else + (list "'" value "'")))) + + (define contents + (append-map + (match-lambda + ((key) '()) + ((key . #f) '()) + ((key values ...) + `(,key " = " ,@(append-map format-value values) "\n"))) + + `(("log_destination" ,log-destination) + ("hba_file" ,hba-file) + ("ident_file" ,ident-file) + ,@extra-config))) (gexp->derivation "postgresql.conf" diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 31d5ae4c6a..7338007919 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -218,7 +218,15 @@ (simple-operating-system (service postgresql-service-type (postgresql-configuration - (postgresql postgresql-10))))) + (postgresql postgresql-10) + (config-file + (postgresql-config-file + (extra-config + '(("session_preload_libraries" "auto_explain") + ("random_page_cost" 2) + ("auto_explain.log_min_duration" "100 ms") + ("work_mem" "500 MB") + ("debug_print_plan" #t))))))))) (define (run-postgresql-test) "Run tests in %POSTGRESQL-OS." -- 2.29.2