I am using PostgreSQL and
Flas-SQLAlchemy extension for Flask.
app = Flask(__name__) app.config['SQLALCHEMY_POOL_SIZE'] = 20 db = SQLAlchemy(app)
user = User(***) db.session.add(user) db.session.commit()
Note that I am not closing the connection as suggested by documentation:
You have to commit the session, but you don’t have to remove it at the end of the request, Flask-SQLAlchemy does that for you.
However, when I run the following PostgreSQL query I can see some
SELECT * FROM pg_stat_activity;
Does it mean that I have a problem with Flask-SQLAlchemy not closing connections? I am worried about it because recently I got
remaining connection slots are reserved for non-replication superuser connections error.