Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sqlalchemy.pool+;psycopg2超时问题_Python_Postgresql_Sqlalchemy_Psycopg2 - Fatal编程技术网

Python sqlalchemy.pool+;psycopg2超时问题

Python sqlalchemy.pool+;psycopg2超时问题,python,postgresql,sqlalchemy,psycopg2,Python,Postgresql,Sqlalchemy,Psycopg2,我有一个web应用程序超时问题,我怀疑错误在数据库中。查询运行的时间太长 如何增加安装程序允许的运行时间 我通过使用sqlalchemy和psycopg2使用数据库池 我的数据库是一个Postgres数据库 import psycopg2 import sqlalchemy.pool as pool def generate_conn_string(db_name): db_name = db_name.upper() conn_string = "

我有一个web应用程序超时问题,我怀疑错误在数据库中。查询运行的时间太长

如何增加安装程序允许的运行时间

我通过使用
sqlalchemy
psycopg2
使用数据库池

我的数据库是一个Postgres数据库

  import psycopg2
  import sqlalchemy.pool as pool

  def generate_conn_string(db_name):
        db_name = db_name.upper()
        conn_string = "host='{}' port='{}' dbname='{}' user='{}' password='{}' ".format(
            os.environ.get('DB_HOST_' + db_name),
            os.environ.get('DB_PORT_' + db_name),
            os.environ.get('DB_NAME_' + db_name),
            os.environ.get('DB_USER_' + db_name),
            os.environ.get('DB_PASSWORD_' + db_name))
        return conn_string

   def get_conn_():
        db_name = "mydb"
        conn_string = Pooling.generate_conn_string(db_name)
        conn = psycopg2.connect(conn_string)
        return conn

   connection_pool = pool.QueuePool(get_conn, max_overflow=30, pool_size=5)

我想你是在问PostgreSQL。使用SQLAlchemy的方式有点奇怪,但是一个普通的SQLAlchemy构造函数接受一个额外的
connect\u args
参数,可以这样使用

engine = create_engine(..., connect_args={"options": "-c statement_timeout=5000"})
请注意,超时时间以毫秒为单位。在您的情况下,您可以与straight psycopg2/libpq一起使用:

conn = psycopg2.connect(conn_string, , options='-c statement_timeout=5000')

相关问题:

您能否提供一些您提到的超时信息的回溯或日志?