v1
This commit is contained in:
commit
ba69e7c774
7 files changed
+361
No files matched your search
@@ -0,0 +1,47 @@
|
||||
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()
|
||||
Reference in new issue
Block a user