From 250213838ef02480181858a5083208dab78bd1d4 Mon Sep 17 00:00:00 2001 From: annieli Date: Mon, 4 Dec 2023 16:45:25 -0800 Subject: [PATCH 1/2] update tail_postgres_logs to support any log rotation plan --- .../bootstrap/maybe_pg_upgrade.py | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/postgres-appliance/bootstrap/maybe_pg_upgrade.py b/postgres-appliance/bootstrap/maybe_pg_upgrade.py index b3d08e02e..a1b40b5db 100644 --- a/postgres-appliance/bootstrap/maybe_pg_upgrade.py +++ b/postgres-appliance/bootstrap/maybe_pg_upgrade.py @@ -4,33 +4,18 @@ import os import subprocess import sys +import glob logger = logging.getLogger(__name__) -def tail_postgres_log(weekday): +def tail_postgres_logs(): logdir = os.environ.get('PGLOG', '/home/postgres/pgdata/pgroot/pg_log') - logfile = os.path.join(logdir, 'postgresql-{0}.csv'.format(weekday)) + csv_files = glob.glob(os.path.join(logdir, '*.csv')) + # Find the last modified CSV file + logfile = max(csv_files, key=os.path.getmtime) return subprocess.check_output(['tail', '-n5', logfile]).decode('utf-8') - -def tail_postgres_logs(): - weekday = datetime.datetime.today().isoweekday() - try: - ret = tail_postgres_log(weekday) - except Exception: - ret = '' - if not ret: - weekday += 6 - if weekday > 7: - weekday %= 7 - try: - ret = tail_postgres_log(weekday) # maybe log just switched? try yesterday - except Exception: - ret = '' - return ret - - def wait_end_of_recovery(postgresql): from patroni.utils import polling_loop From fcb5d97e2d09f6463fc2637a2b6397cccab34167 Mon Sep 17 00:00:00 2001 From: annieli Date: Mon, 4 Dec 2023 22:24:51 -0800 Subject: [PATCH 2/2] fix nits --- postgres-appliance/bootstrap/maybe_pg_upgrade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres-appliance/bootstrap/maybe_pg_upgrade.py b/postgres-appliance/bootstrap/maybe_pg_upgrade.py index a1b40b5db..ea6d6a039 100644 --- a/postgres-appliance/bootstrap/maybe_pg_upgrade.py +++ b/postgres-appliance/bootstrap/maybe_pg_upgrade.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -import datetime import logging import os import subprocess @@ -16,6 +15,7 @@ def tail_postgres_logs(): logfile = max(csv_files, key=os.path.getmtime) return subprocess.check_output(['tail', '-n5', logfile]).decode('utf-8') + def wait_end_of_recovery(postgresql): from patroni.utils import polling_loop