[PostgreSQL] Wraparound 테스트를 위한 XID 생성 Python Script

Ja L·2024년 6월 10일
0

[PostgreSQL] Test

목록 보기
1/1
import psycopg2
import threading

# PostgreSQL 연결 정보
DB_NAME = 'vacuum'
DB_USER = 'agens'
DB_PASSWORD = 'agens'
DB_HOST = '192.168.54.52'
DB_PORT = '53333'

# wraparound 테스트에 사용할 스레드 수
THREAD_COUNT = 100

# 각 스레드에서 추가할 값의 범위
START_VALUE = 40
END_VALUE = 100000000

# 스레드에서 실행할 함수
def insert_values():
    conn = psycopg2.connect(
        dbname=DB_NAME,
        user=DB_USER,
        password=DB_PASSWORD,
        host=DB_HOST,
        port=DB_PORT
    )
    conn.autocommit=True
    cursor = conn.cursor()
    
    for i in range(START_VALUE, END_VALUE + 1):
        cursor.execute("INSERT INTO vacuum6 (int) VALUES (%s)", (i,))
    
    conn.commit()
    conn.close()

# 스레드 생성 및 실행
threads = []
for _ in range(THREAD_COUNT):
    thread = threading.Thread(target=insert_values)
    threads.append(thread)
    thread.start()

# 모든 스레드가 종료될 때까지 대기
for thread in threads:
    thread.join()

print("값 추가 완료")
profile
DB Engineer

0개의 댓글