2017-06-06 13 views
1

數據庫是PostgreSQL的-9.5.1在碼頭工人。我的主機有3.75 GB內存,linux。在一些方法,我將49萬行彼此使用psycopg2與下面的代碼之後。當使用python psycopg2插入行,搬運工postgres進程被終止

student_list = [(name, surname, explanation)] 
args_str = ','.join(cur.mogrify("(%s,%s,%s)", x) for x in student_list) 
cur.execute('INSERT INTO students (name, surname, explanation) VALUES ' + args_str) 

這使得我的數據庫中泊塢窗記憶似乎完全並給出了這些錯誤:

LOG: server process (PID 11219) was terminated by signal 9: Killed
DETAIL: Failed process was running
LOG: terminating any other active server processes
[email protected]_db WARNING: terminating connection because of crash of another server process
[email protected]_db DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
[email protected]_db HINT: In a moment you should be able to reconnect to the database and repeat your command.
[email protected]_db WARNING: terminating connection because of crash of another server process
[email protected]_db DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
... [email protected]_db FATAL: the database system is in recovery mode
LOG: all server processes terminated; reinitializing
LOG: database system was interrupted; last known up at 2017-06-06 09:39:40 UTC
LOG: database system was not properly shut down; automatic recovery in progress
[email protected]_db FATAL: the database system is in recovery mode
[email protected]_db FATAL: the database system is in recovery mode
[email protected]_db FATAL: the database system is in recovery mode
LOG: autovacuum launcher started

腳本給出日誌:

Inner exception
SSL SYSCALL error: EOF detected

我試圖把連續查詢,但之間的一些睡眠時間得到同樣的結果。這有什麼限制嗎? 我也試着連接和斷開每個查詢,但得到了同樣的結果。這些是我的連接和斷開方法。

def connect(): 
    conn = psycopg2.connect(database=database_name, 
          user=database_user, 
          host=database_host, 
          port=database_port) 
    conn 
    .set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) 
    cur = conn.cursor() 
    return conn, cur 

def disconnect(conn, cur): 
    cur.close() 
    conn.close() 
+0

你傳遞一些自定義的內存命令'泊塢窗run'? – Robert

+0

沒有,只是泊塢窗運行命令 –

+0

檢查'dmesg'在你的主機命令。這可能是一些*內存不足的問題。你應該在那裏看到Postgres正在被殺害。 – Robert

回答

0

這是我做的。其實我的記憶足夠了。這就是爲什麼Linux操作系統用於殺死Postgresql中的進程的原因。每個插入過程中有1M個值。訣竅是我將數據列表分成大塊,並嘗試了100k到100k。這很好。感謝您的幫助。

相關問題