From a037d3f584ab8318e07400921818817b27119f35 Mon Sep 17 00:00:00 2001 From: bobjolliffe Date: Mon, 15 Dec 2025 15:41:00 +0000 Subject: [PATCH 1/3] Modify postgresql config parameters --- config/postgresql/conf.d/10-memory.conf | 3 +++ config/postgresql/conf.d/30-logging.conf | 4 ++-- config/postgresql/conf.d/40-wal.conf | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 config/postgresql/conf.d/40-wal.conf diff --git a/config/postgresql/conf.d/10-memory.conf b/config/postgresql/conf.d/10-memory.conf index 86d1a69..1dbb1c5 100644 --- a/config/postgresql/conf.d/10-memory.conf +++ b/config/postgresql/conf.d/10-memory.conf @@ -3,4 +3,7 @@ work_mem = 16MB # memory per sort/hash operation maintenance_work_mem = 128MB effective_cache_size = 6GB # usually ~75% of RAM +# for locally attached spinning disk +random_page_cost = 1.1 + # max_wal_size = 5GB diff --git a/config/postgresql/conf.d/30-logging.conf b/config/postgresql/conf.d/30-logging.conf index 986e6cd..bc0742b 100644 --- a/config/postgresql/conf.d/30-logging.conf +++ b/config/postgresql/conf.d/30-logging.conf @@ -1,5 +1,5 @@ log_destination = 'stderr' logging_collector = off # disable writing to files -log_statement = 'ddl' # or 'all' if you want full query logging -log_min_duration_statement = 500 # log queries slower than 500ms +log_statement = 'none' # or 'all' if you want full query logging +log_min_duration_statement = 300s # log queries slower than 5 minutes log_timezone = 'UTC' diff --git a/config/postgresql/conf.d/40-wal.conf b/config/postgresql/conf.d/40-wal.conf new file mode 100644 index 0000000..75fef0a --- /dev/null +++ b/config/postgresql/conf.d/40-wal.conf @@ -0,0 +1,3 @@ +checkpoint_completion_target = 0.8 +synchronous_commit = off +wal_writer_delay = 10000ms From 70206216211d55bd9917c4b39dfb3fc7cda835f7 Mon Sep 17 00:00:00 2001 From: bobjolliffe Date: Tue, 16 Dec 2025 21:43:14 +0000 Subject: [PATCH 2/3] Added and edited some postgresql configuration options. Modified README to clarify the way config settings are applied to a running postgresql server --- README.md | 12 +++++++++++- config/postgresql/postgresql.conf | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a4746f..f9ff1bd 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,22 @@ Open http://dhis2-127-0-0-1.nip.io in your favourite browser. Custom configuration for Postgresql can be done by adding to the files in the `./config/postgresql/conf.d/` directory. If your configuration doesn't belong in either of the existing files, you can create a new file. However, it's advised not to make changes to the [postgresql.conf](config/postgresql/postgresql.conf) file. -Any changes to these files won't take effect until the container is restarted or the below command is executed: +Some postgresql configuration parameters can be applied by reloading the configuration. Others will only take effect when the database is restarted. The detailed description of each configuration option (on postgresql v16) is avalable [here](https://www.postgresql.org/docs/16/runtime-config.html). The documentation for each setting generally indicates whether the setting requires a restart in order to take effect. + +A configuration reload can be triggered by executing the following SQL command: ```sql SELECT pg_reload_conf(); ``` +If you need to restart the database server, it is safest to stop the application container first, restart the database, then start the application again. This will mean some minutes of downtime for your users so it is best to co-ordinate such operations with users or execute during quiet times of the day. A typical sequence might look like: + +```bash +docker stop docker-deployment-app-1 +docker restart docker-deployment-database-1 +docker start docker-deployment-app-1 +``` + ## Overlays ### Traefik Dashboard diff --git a/config/postgresql/postgresql.conf b/config/postgresql/postgresql.conf index bac11f8..62fcd32 100644 --- a/config/postgresql/postgresql.conf +++ b/config/postgresql/postgresql.conf @@ -1,2 +1,11 @@ +# These settings are required to run DHIS2 +# Make local customisations under /etc/postgresql/conf.d listen_addresses = '*' + +# affects the performance of program indicators +jit = off + +# required for flyway +max_locks_per_transaction = 128 + include_dir = '/etc/postgresql/conf.d' From 16192fd5d6e81aa32c8c0df65d52f9bd0fd6c2ca Mon Sep 17 00:00:00 2001 From: Bob Jolliffe Date: Wed, 17 Dec 2025 14:47:28 +0000 Subject: [PATCH 3/3] Update README.md changed postgres restart instructions as ber suggestion Co-authored-by: tonsV2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9ff1bd..a3384f7 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ SELECT pg_reload_conf(); If you need to restart the database server, it is safest to stop the application container first, restart the database, then start the application again. This will mean some minutes of downtime for your users so it is best to co-ordinate such operations with users or execute during quiet times of the day. A typical sequence might look like: ```bash -docker stop docker-deployment-app-1 -docker restart docker-deployment-database-1 -docker start docker-deployment-app-1 +docker compose stop app +docker compose restart database +docker compose start app ``` ## Overlays