Skip to content

Commit

Permalink
Merge branch 'pglog-upload-tags' of github.com:FxKu/spilo into pglog-…
Browse files Browse the repository at this point in the history
…upload-tags
  • Loading branch information
FxKu committed Sep 17, 2024
2 parents 36b016d + c2a9970 commit 5d2de01
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 5d2de01

Please sign in to comment.