Skip to content

Commit

Permalink
Merge branch 'master' into pglog-upload-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
FxKu authored Sep 17, 2024
2 parents 97e3dcb + 14470e6 commit c2a9970
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions postgres-appliance/bootstrap/maybe_pg_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
#!/usr/bin/env python
import datetime
import logging
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

Expand Down

0 comments on commit c2a9970

Please sign in to comment.