2017-06-06 7 views
1

データベースはdockerでpostgresql-9.5.1です。私のホストマシンは3.75GBのメモリ、linuxを持っています。いくつかの方法では、以下のコードでpsycopg2を使用して490000行を1つずつ挿入しています。python psycopg2を使用して行を挿入すると、docker 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) 

これは私のデータベースのドッキングウィンドウのメモリが一杯に思わせ、これらのエラーを与える:私は連続したクエリが、間にいくつかの睡眠時間をかけてみました

Inner exception
SSL SYSCALL error: EOF detected


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

スクリプトは、そのログを提供します同じ結果が得られました。それには何か制限がありますか? また、クエリごとに接続と切断を試みましたが、同じ結果が得られました。これらは私の接続と切断の方法です。

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

カスタムメモリコマンドを 'docker run'に渡していますか? – Robert

+0

いいえ、単にドッカー実行コマンド –

+0

あなたのホストの 'dmesg'コマンドをチェックしてください。たぶん*メモリ不足の問題かもしれません。そこにはPostgresが殺されているのが見えます。 – Robert

答えて

0

これは私がしたものです。実際、私の記憶は十分に満ちていました。だからこそ、Linux OSはPostgreSQLのプロセスを強制終了するために使われたのです。すべての挿入プロセスには1Mの値がありました。トリックは、データリストをチャンクに分割し、100kで100kを試しました。それはとてもうまくいく。あなたのお手伝いをありがとう。