title: PostgreSQL: Load testing throws error - Npgsql.PostgresException: '53300: sorry, too many clients already'
body: <p>i have a simple code that tries to simulate a load test for my Postgres database</p>
  <pre><code>            List&lt;Values&gt; values = new List&lt;Values&gt;();
  
              for (int i = 0; i &lt; 200; i++)
              {
                  var mythread = new Thread(() =&gt;
                  {
                      DatabaseConnection db = new DatabaseConnection();
                      using (var conn = db.GetDatabaseConnection())
                      {
                          var cmd = new NpgsqlCommand();
                          cmd.Connection = conn;
                          cmd.CommandText = &quot;SELECT val.id, val.name FROM val.myvalue val&quot;;
                          cmd.Prepare();
                          var reader = cmd.ExecuteReader();
                          try
                          {
                              while (reader.Read())
                              {
                                  Values value = new Values();
                                  value.Id = reader.GetInt64(0);
                                  value.Name = reader.GetString(1);
  
                                  values.Add(value);
                              }
                              reader.Close();
                          }
                          catch (Exception ex)
                          {
                              reader.Close();
                              var exception = ex;
                              throw exception;
                          }
                      }
                  });
  
                  mythread.Start();
              }
  </code></pre>
  <p>but when I run this I get the error <strong>Npgsql.PostgresException: '53300: sorry, too many clients already'</strong></p>
  <p>Database connection class</p>
  <pre><code>public class DatabaseConnection
  {
      public NpgsqlConnection GetDatabaseConnection()
      {
          var connectionstring = &quot;User ID=myuser;Password=mypassword;Server=localhost;Port=5432;Database=myvaluesdb;Pooling=True;Minimum Pool Size=10;Maximum Pool Size=100;Trust Server Certificate=true;Connection Idle Lifetime=300;keepalive=10;Timeout=60&quot;;
          NpgsqlConnection connection = null;
  
          try
          {
              connection = new NpgsqlConnection(connectionstring);
              connection.Open();
          }
          catch (Exception)
          {
              // try to reconnect
              connection = new NpgsqlConnection(connectionstring);
              connection.Open();
          }
  
          if (connection.State == ConnectionState.Open)
              Console.WriteLine(&quot;connection status = OPEN&quot;);
          else
          {
              var exception = new Exception(&quot;could not get DB connection&quot;);
              throw exception;
          }
  
          return connection;
      }
  }
  </code></pre>
  <p>checking the max_connections shows 100
  <br/>
  so my question is is this normal or is there something am doing wrong that needs to be corrected and if so how can i correct this
  <br/>
  Thanks</p>