Commit b70ab6ce by Owo Sugiana

Cek mirror yang lebih baik

1 parent 54d13ab3
0.8 16-5-2023
-------------
- Pemahaman konfigurasi mirror yang lebih baik
0.7 2-7-2021
------------
- Tambah mirror_status
......
......@@ -81,7 +81,7 @@ def save(lines, line_id, waktu):
print(' sudah ada')
db_session.rollback()
return
raise(e)
raise e
def read_once(log_file, start_from):
......
......@@ -112,8 +112,20 @@ def pg_port(conf_file):
def is_mirror(pg_conf):
r = Reader(pg_conf)
port = r['port']
# Versi 11 - 15
cmd_psql = f'psql -p {port} -c "SHOW primary_conninfo"'
cmd1 = ['su', '-', 'postgres', '-c', cmd_psql]
cmd2 = ['grep', 'user']
p1 = Popen(cmd1, stdout=PIPE)
p2 = Popen(cmd2, stdin=p1.stdout, stdout=PIPE)
out, err = p2.communicate()
if not err:
s = out.decode('utf-8')
if s:
return True
if 'include_dir' in r:
# Versi 12 - 14
# Versi 12 - 15
conf_dir = os.path.split(pg_conf)[0]
mirror_conf = os.path.join(conf_dir, r['include_dir'], 'recovery.conf')
if os.path.exists(mirror_conf):
......@@ -125,6 +137,21 @@ def is_mirror(pg_conf):
return 'recovery_target_timeline' in r
def is_db_exists(version, port, db_name):
psql_bin = pg_bin(version, 'psql')
sql = f"SELECT 1 FROM pg_database WHERE datname='{db_name}'"
cmd_psql = f'{psql_bin} -p {port} -c "{sql}"'
cmd = ['su', '-', 'postgres', '-c', cmd_psql]
p = Popen(cmd, stdout=PIPE)
out, err = p.communicate()
s = out.decode('utf-8')
found = RE_COUNT_ROW.search(s)
if found:
count = found.group(1)
return int(count)
sys.exit()
# Pastikan database server hanya bisa diakses oleh user postgres secara local
# Abaikan bila cluster adalah mirror
def pg_local_conf():
......@@ -164,21 +191,6 @@ def pg_original_conf():
os.rename(pg_hba_bak_file, pg_hba_file)
def is_db_exists(version, port, db_name):
psql_bin = pg_bin(version, 'psql')
sql = f"SELECT 1 FROM pg_database WHERE datname='{db_name}'"
cmd_psql = f'{psql_bin} -p {port} -c "{sql}"'
cmd = ['su', '-', 'postgres', '-c', cmd_psql]
p = Popen(cmd, stdout=PIPE)
out, err = p.communicate()
s = out.decode('utf-8')
match = RE_COUNT_ROW.search(s)
if match:
count = match.group(1)
return int(count)
sys.exit()
def run_as_postgres(cmd):
cmd = ['su', '-', 'postgres', '-c', cmd]
run_list(cmd)
......
......@@ -3,7 +3,9 @@ RE_PREFIX = r'([\d]*)-([\d]*)-([\d]*) ([\d]*):([\d]*):([\d]*).([\d]*) '\
# 2022-01-03 07:04:42.728 WIB [1268975] LOG: started streaming WAL from
# primary at 3/B6000000 on timeline 1
RE_OK = RE_PREFIX + 'LOG: started streaming WAL'
# 2023-05-09 07:29:49.335 WIB [3811560] DETAIL: Last completed transaction was
# at log time 2023-05-09 07:28:19.547035+07.
RE_OK = RE_PREFIX + '(LOG: started streaming WAL|DETAIL: Last completed)'
# 2022-01-03 07:04:10.757 WIB [1258171] FATAL: terminating walreceiver due to
# timeout
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!