-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpgoutput-cli.py
More file actions
executable file
·64 lines (55 loc) · 1.65 KB
/
pgoutput-cli.py
File metadata and controls
executable file
·64 lines (55 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import os
import sys
import getopt
import pypgoutput
def print_help():
print("Usage: pgoutput-cli --host=<host> --port=<port> --database=<database> --user=<user> --password=<password> --publication<publication> --slot=<slot>", file=sys.stderr)
def main(argv):
host = ''
port = 0
database = ''
user = ''
password = ''
publication = ''
slot = ''
try:
opts, args = getopt.getopt(argv,"h",["help","host=","port=","database=","user=","password=","publication=","slot="])
except getopt.GetoptError:
print_help()
sys.exit(1)
for opt, arg in opts:
if opt in ("-h", '--help'):
print_help()
sys.exit(0)
elif opt in ("--host"):
host = arg
elif opt in ("--port"):
port = arg
elif opt in ("--database"):
database = arg
elif opt in ("--user"):
user = arg
elif opt in ("--password"):
password = arg
elif opt in ("--publication"):
publication = arg
elif opt in ("--slot"):
slot = arg
if (host == '' or port == 0):
print_help()
sys.exit(1)
cdc_reader = pypgoutput.LogicalReplicationReader(
publication_name=publication,
slot_name=slot,
host=host,
database=database,
port=port,
user=user,
password=password,
)
for message in cdc_reader:
print(message.model_dump_json(indent=2))
cdc_reader.stop()
if __name__ == "__main__":
main(sys.argv[1:])