diff --git a/src/cluster.py b/src/cluster.py index c025e6d4e7..3f57250bc3 100644 --- a/src/cluster.py +++ b/src/cluster.py @@ -32,6 +32,7 @@ PGBACKREST_CONFIGURATION_FILE, POSTGRESQL_CONF_PATH, POSTGRESQL_DATA_PATH, + POSTGRESQL_LOGS_PATH, POSTGRESQL_SNAP_NAME, REWIND_USER, TLS_CA_FILE, @@ -467,6 +468,7 @@ def render_patroni_yml_file( connectivity=connectivity, is_creating_backup=is_creating_backup, log_path=PATRONI_LOGS_PATH, + postgresql_log_path=POSTGRESQL_LOGS_PATH, data_path=POSTGRESQL_DATA_PATH, enable_tls=enable_tls, member_name=self.member_name, diff --git a/src/constants.py b/src/constants.py index b7bd0aefbe..2f135a0ebe 100644 --- a/src/constants.py +++ b/src/constants.py @@ -32,7 +32,7 @@ # Snap constants. PGBACKREST_EXECUTABLE = "charmed-postgresql.pgbackrest" POSTGRESQL_SNAP_NAME = "charmed-postgresql" -SNAP_PACKAGES = [(POSTGRESQL_SNAP_NAME, {"revision": "70"})] +SNAP_PACKAGES = [(POSTGRESQL_SNAP_NAME, {"revision": "78"})] SNAP_COMMON_PATH = "/var/snap/charmed-postgresql/common" SNAP_CURRENT_PATH = "/var/snap/charmed-postgresql/current" @@ -49,6 +49,7 @@ POSTGRESQL_CONF_PATH = f"{SNAP_CONF_PATH}/postgresql" POSTGRESQL_DATA_PATH = f"{SNAP_DATA_PATH}/postgresql" +POSTGRESQL_LOGS_PATH = f"{SNAP_LOGS_PATH}/postgresql" PGBACKREST_CONFIGURATION_FILE = f"--config={PGBACKREST_CONF_PATH}/pgbackrest.conf" diff --git a/src/grafana_dashboards/postgresql-metrics.json b/src/grafana_dashboards/postgresql-metrics.json index 727567eeab..c6595bb8f1 100644 --- a/src/grafana_dashboards/postgresql-metrics.json +++ b/src/grafana_dashboards/postgresql-metrics.json @@ -3033,7 +3033,7 @@ "style": "dark", "tags": [ "postgres", - "db", + "db" ], "templating": { "list": [ diff --git a/templates/patroni.yml.j2 b/templates/patroni.yml.j2 index 69469a263b..e875a38283 100644 --- a/templates/patroni.yml.j2 +++ b/templates/patroni.yml.j2 @@ -63,6 +63,26 @@ bootstrap: archive_command: /bin/true {%- endif %} archive_mode: on + log_autovacuum_min_duration: 60000 + log_checkpoints: 'on' + log_destination: 'stderr' + log_directory: '{{ postgresql_log_path }}' + log_file_mode: '0600' + log_filename: 'postgresql-%w_%H%M.log' + log_hostname: 'off' + log_line_prefix: '%t [%p]: user=%u,db=%d,app=%a,client=%h,line=%l ' + log_min_duration_sample: -1 + log_recovery_conflict_waits: 'on' + log_replication_commands: 'on' + log_rotation_age: 1 + log_rotation_size: 0 + log_statement: ddl + log_statement_sample_rate: 1 + log_statement_stats: 'off' + log_temp_files: 1 + log_timezone: 'GMT' + log_truncate_on_rotation: 'on' + logging_collector: 'on' wal_level: logical {%- if restoring_backup %} diff --git a/tests/integration/test_tls.py b/tests/integration/test_tls.py index 5778380be0..b3eb0e7876 100644 --- a/tests/integration/test_tls.py +++ b/tests/integration/test_tls.py @@ -131,12 +131,11 @@ async def test_tls_enabled(ops_test: OpsTest) -> None: # Check the logs to ensure TLS is being used by pg_rewind. primary = await get_primary(ops_test, primary) - logs = await run_command_on_unit( - ops_test, primary, "journalctl -u snap.charmed-postgresql.patroni.service" + await run_command_on_unit( + ops_test, + primary, + "grep 'connection authorized: user=rewind database=postgres SSL enabled' /var/snap/charmed-postgresql/common/var/log/postgresql/postgresql-*.log", ) - assert ( - "connection authorized: user=rewind database=postgres SSL enabled" in logs - ), "TLS is not being used on pg_rewind connections" # Remove the relation. await ops_test.model.applications[DATABASE_APP_NAME].remove_relation( diff --git a/tests/unit/test_cluster.py b/tests/unit/test_cluster.py index 24e7257892..24afe390af 100644 --- a/tests/unit/test_cluster.py +++ b/tests/unit/test_cluster.py @@ -15,6 +15,7 @@ PATRONI_CONF_PATH, PATRONI_LOGS_PATH, POSTGRESQL_DATA_PATH, + POSTGRESQL_LOGS_PATH, REWIND_USER, ) @@ -245,6 +246,7 @@ def test_render_patroni_yml_file(self, _, _render_file, _get_postgresql_version) conf_path=PATRONI_CONF_PATH, data_path=POSTGRESQL_DATA_PATH, log_path=PATRONI_LOGS_PATH, + postgresql_log_path=POSTGRESQL_LOGS_PATH, member_name=member_name, peers_ips=self.peers_ips, scope=scope,