Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tail_postgres_logs to support any log rotation plan #955

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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