2

大量の行を挿入していますが、postgress が追いつかないようです。少しグーグルで検索しましたが、自動コミットをオフにすることをお勧めします。すぐに値をコミットする必要はありません。何か問題が発生した場合に再度取得できるデータです。

自動コミットをオフにする方法を検索すると、探しているものが見つかりません。dbpool コンストラクターで autocommit=False を指定しようとしました。

dbpool = adbapi.ConnectionPool('psycopg2', user="xxx", password="xxx", database="postgres", host="localhost", autocommit=False)

2013-01-27 18:24:42,254 - コレクター.EventLogItemController - 警告 - [失敗インスタンス: トレースバック:: 無効な接続オプション「autocommit」

4

3 に答える 3

1

autocommitpsycopg2 は、次のキーワード引数をサポートするとは主張していませんconnect

connect(dsn=None, database=None, user=None, password=None, host=None, port=None, connection_factory=None, async=False, **kwargs)
    Create a new database connection.

    The connection parameters can be specified either as a string:

        conn = psycopg2.connect("dbname=test user=postgres password=secret")

    or using a set of keyword arguments:

        conn = psycopg2.connect(database="test", user="postgres", password="secret")

    The basic connection parameters are:

    - *dbname*: the database name (only in dsn string)
    - *database*: the database name (only as keyword argument)
    - *user*: user name used to authenticate
    - *password*: password used to authenticate
    - *host*: database host address (defaults to UNIX socket if not provided)
    - *port*: connection port number (defaults to 5432 if not provided)

    Using the *connection_factory* parameter a different class or connections
    factory can be specified. It should be a callable object taking a dsn
    argument.

    Using *async*=True an asynchronous connection will be created.

    Any other keyword parameter will be passed to the underlying client
    library: the list of supported parameter depends on the library version.

現在のpostgresqlのドキュメントでは、「autocommit」パラメータについても議論されていません:

http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING

おそらく問題は、これが psycopg2 接続の自動コミットを無効にする正しい方法ではないことです。それとは別に、自動コミットをオフにしても実際にはまったく役に立たないことがわかります。 adbapi.ConnectionPool明示的なトランザクションを開始してコミットするため、動作autocommitモードを回避することができます。

于 2013-01-27T20:43:39.323 に答える
0

adbapiの問題は、次のとおりです。1)一部のデータベースバックエンドに固有の機能が欠落している2)偽の非同期API。内部的には、スレッドプールを使用し、ブロッキングメソッドを呼び出します。

postgresについては、txpostgresライブラリを使用することをお勧めします(ソースはここにあります:https ://github.com/wulczer/txpostgres )。psycopg2の非同期APIを使用しており、接続文字列を指定できます。ここに例があります:http://txpostgres.readthedocs.org/en/latest/usage.html#customising-the-connection-and-cursor-factories

于 2013-01-27T19:33:53.977 に答える