Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
maintenance
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b70ab6ce
authored
May 16, 2023
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Cek mirror yang lebih baik
1 parent
54d13ab3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
CHANGES.txt
log2db/__init__.py
maintenance/__init__.py
mirror_status/structure.py
CHANGES.txt
View file @
b70ab6c
0.8 16-5-2023
-------------
- Pemahaman konfigurasi mirror yang lebih baik
0.7 2-7-2021
0.7 2-7-2021
------------
------------
- Tambah mirror_status
- Tambah mirror_status
...
...
log2db/__init__.py
View file @
b70ab6c
...
@@ -81,7 +81,7 @@ def save(lines, line_id, waktu):
...
@@ -81,7 +81,7 @@ def save(lines, line_id, waktu):
print
(
' sudah ada'
)
print
(
' sudah ada'
)
db_session
.
rollback
()
db_session
.
rollback
()
return
return
raise
(
e
)
raise
e
def
read_once
(
log_file
,
start_from
):
def
read_once
(
log_file
,
start_from
):
...
...
maintenance/__init__.py
View file @
b70ab6c
...
@@ -112,8 +112,20 @@ def pg_port(conf_file):
...
@@ -112,8 +112,20 @@ def pg_port(conf_file):
def
is_mirror
(
pg_conf
):
def
is_mirror
(
pg_conf
):
r
=
Reader
(
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
:
if
'include_dir'
in
r
:
# Versi 12 - 1
4
# Versi 12 - 1
5
conf_dir
=
os
.
path
.
split
(
pg_conf
)[
0
]
conf_dir
=
os
.
path
.
split
(
pg_conf
)[
0
]
mirror_conf
=
os
.
path
.
join
(
conf_dir
,
r
[
'include_dir'
],
'recovery.conf'
)
mirror_conf
=
os
.
path
.
join
(
conf_dir
,
r
[
'include_dir'
],
'recovery.conf'
)
if
os
.
path
.
exists
(
mirror_conf
):
if
os
.
path
.
exists
(
mirror_conf
):
...
@@ -125,6 +137,21 @@ def is_mirror(pg_conf):
...
@@ -125,6 +137,21 @@ def is_mirror(pg_conf):
return
'recovery_target_timeline'
in
r
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
# Pastikan database server hanya bisa diakses oleh user postgres secara local
# Abaikan bila cluster adalah mirror
# Abaikan bila cluster adalah mirror
def
pg_local_conf
():
def
pg_local_conf
():
...
@@ -164,21 +191,6 @@ def pg_original_conf():
...
@@ -164,21 +191,6 @@ def pg_original_conf():
os
.
rename
(
pg_hba_bak_file
,
pg_hba_file
)
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
):
def
run_as_postgres
(
cmd
):
cmd
=
[
'su'
,
'-'
,
'postgres'
,
'-c'
,
cmd
]
cmd
=
[
'su'
,
'-'
,
'postgres'
,
'-c'
,
cmd
]
run_list
(
cmd
)
run_list
(
cmd
)
...
...
mirror_status/structure.py
View file @
b70ab6c
...
@@ -3,7 +3,9 @@ RE_PREFIX = r'([\d]*)-([\d]*)-([\d]*) ([\d]*):([\d]*):([\d]*).([\d]*) '\
...
@@ -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
# 2022-01-03 07:04:42.728 WIB [1268975] LOG: started streaming WAL from
# primary at 3/B6000000 on timeline 1
# 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
# 2022-01-03 07:04:10.757 WIB [1258171] FATAL: terminating walreceiver due to
# timeout
# timeout
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment