PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

psycopg2 COPY mit cursor.copy_from() friert bei großen Eingaben ein

Dies ist nur eine Problemumgehung, aber Sie können einfach etwas in psql leiten. Ich verwende dieses Rezept manchmal, wenn ich zu faul bin, um psycopg2 auszuschalten

import subprocess
def psql_copy_from(filename, tablename, columns = None):
    """Warning, this does not properly quote things"""
    coltxt = ' (%s)' % ', '.join(columns) if columns else ''
    with open(filename) as f:
        subprocess.check_call([
            'psql',
            '-c', 'COPY %s%s FROM STDIN' % (tablename, coltxt),
            '--set=ON_ERROR_STOP=true', # to be safe
            # add your connection args here
        ], stdin=f)

Benutzt du in Bezug auf deine Sperrung mehrere Threads oder so etwas?

Protokolliert Ihr Postgres irgendetwas wie eine geschlossene Verbindung oder einen Deadlock? Können Sie die Laufwerksaktivität nach dem Absturz sehen?