title: PSQLException: FATAL: sorry, too many clients already Akka HTTP
body: <p>I have an application with a connection to PostgreSQL database, API and Akka stream usage to extract tweets using Twitter4J. Extracted tweets are written to the database and then they are queried using Slick. Using Akka HTTP I have created an API to send queries to db.  So my problem is that after a few requests I get this error:</p>
  
  <p><a href="https://i.stack.imgur.com/3B7RH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3B7RH.jpg" alt="enter image description here"></a></p>
  
  <p>I am not sure where is the problem and why it is happening as I am closing Actor system on complete.</p>
  
  <pre><code>object Main extends ApiRoute {
  
    def main(args: Array[String]): Unit = {
      implicit val system = ActorSystem()
      implicit val materializer = ActorMaterializer()
      implicit val executionContext = system.dispatcher
      val twitterStream = TwitterStreamFilters.configureTwitterStream()
      val counter = new Counter
      twitterStream.addListener(counter)
      val bindingFuture = Http().bindAndHandle(routes, "localhost", 8080)
      println("Server started!")
      StdIn.readLine()
      bindingFuture
        .flatMap(_.unbind())
        .onComplete(_ =&gt; system.terminate())
    } 
  </code></pre>
  
  <p>And application.conf file:</p>
  
  <pre><code>scalaxdb = {
    dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
    properties = {
      driver = "org.postgresql.Driver"
      url = "jdbc:postgresql://localhost/twitter2.0?user=user&amp;password=password"
    }
  }
  </code></pre>
  
  <p>I would be grateful for any help!</p>