LoginSignup
2
2

More than 3 years have passed since last update.

OperationalError: (psycopg2.OperationalError)でエラーが出た

Posted at

はじめに

flaskのアプリをpsycopg2で動かしていたら下のようなエラーが出た。

OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

解決方法

from flask_sqlalchemy import SQLAlchemy as _BaseSQLAlchemy

class SQLAlchemy(_BaseSQLAlchemy):
    def apply_pool_defaults(self, app, options):
        super(SQLAlchemy, self).apply_pool_defaults(self, app, options)
        options["pool_pre_ping"] = True

db = SQLAlchemy(app)

上のプログラムを入れると解決しました。下の参考URLには他の解決方法も載っていたりするので英語が得意だったら見てみてください。

参考URL

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2