2016-04-18 23 views
0

私は単純なアプリケーションをpostgresデータベースにリンクしています。アプリケーションをロードすると約30行のデータが読み込まれます。しかし、今はそれがロードされず、いつ私は私のサーバーを見てエラーが発生しました:接続が終了しました。PostgreSQLエラー:接続が終了しました

通常、短い時間間隔で数回ロードするとします。

これはなぜ起こっているのでしょうか?あまりにも頑張っていますか?

コードは以下の通りです:

function getDB(callback){ 
     console.log('inside getDB') 
     Client.connect(function(err){ 
      if(err){ 
       return console.log('connection error', err) 
      } 
      Client.query('SELECT * FROM gallery', function(err, result){ 
       if(err){ 
        return console.log('error receiving data', err) 
       } else{ 
       callback(null, result.rows) 
       } 
       Client.end() 
      }) 

     }) 
    } 

答えて

0

あなたがnode-postgresを使用しているように見えます。接続プーリングの使用を検討する必要があります。ドキュメントから:

"Generally you will access the PostgreSQL server through a pool of clients. A client takes a non-trivial amount of time to establish a new connection. A client also consumes a non-trivial amount of resources on the PostgreSQL server - not something you want to do on every http request. Good news: node-postgres ships with built in client pooling."

多くは、新しい接続を作成するときに行くと、あなたが可能な場合、それを避けるためになりますがあります。あなたの状況でプーリングを利用することは役に立ちます。

関連する問題