0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[PrismaClientInitializationError] remaining connection slots are reserved for non-replication superuser connections

Last updated at Posted at 2022-12-26

supabaseのdbを使っていた際に生じたエラー。
ORMにはPrismaを使っていた

エラー内容

PrismaError {
  message: PrismaClientInitializationError:
  Invalid `prisma.maker.findMany()` invocation:


  Error querying the database: db error: FATAL: remaining connection slots are reserved for non-replication superuser connections
      at RequestHandler.handleRequestError 
  # ...
  name: 'PrismaError'
}

結論

どこかでエラーが生じ(例えばフロントで無限レンダリングされてるとか。。)、その結果prismaが大量にアクセスしたことが原因の可能性がある。
スクリーンショット 2022-12-26 17.49.45.png

調査

/* 最大でコネクション貼れる数 */
SHOW max_connections;
/* 現状のコネクション数 */
SELECT count(*) FROM pg_stat_activity;

/* コネクションを切る */
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE query_start < current_timestamp;

あまり関係なかった方法

project > settingから再起動したのちConnection Poolingを「オフ」にする
スクリーンショット_2022-12-26_16_24_44.png

原因はdbに繰り返しアクセスが生じ connection poolingの上限に達したためだと考えられる。
開発環境でsupabaseを用いてたためconnection poolingはオフで良い。
ちなみにconnection poolingはDBMSへの接続を切断せず維持するシステム

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?