47 lines
890 B
Python
47 lines
890 B
Python
import psycopg2
|
|
|
|
# ===== TEST DATA =====
|
|
# id = 600
|
|
source_node = "node1"
|
|
message = "from python with love "
|
|
|
|
conn = None
|
|
|
|
try:
|
|
conn = psycopg2.connect(
|
|
host="172.16.10.123",
|
|
port=5444,
|
|
database="postgres",
|
|
user="postgres",
|
|
password="postgres"
|
|
)
|
|
|
|
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute("""
|
|
INSERT INTO test_replication (source_node, message)
|
|
VALUES (%s, %s)
|
|
RETURNING id
|
|
""", (source_node, message))
|
|
|
|
# Get the ID generated by PostgreSQL
|
|
generated_id = cursor.fetchone()[0]
|
|
|
|
conn.commit()
|
|
|
|
print("LOCAL COMMIT: SUCCESS")
|
|
print("Generated ID:", generated_id)
|
|
print("Source:", source_node)
|
|
print("Message:", message)
|
|
|
|
except Exception as e:
|
|
if conn:
|
|
conn.rollback()
|
|
|
|
print("LOCAL COMMIT: FAILED")
|
|
print("Error:", e)
|
|
|
|
finally:
|
|
if conn:
|
|
conn.close() |