code: def _connect(self):
          
          # Attempt to get a cached connection from the connection pool
          try:
              connection = self._pool_manager.get(self.pid, self)
              LOGGER.debug("Re-using connection for %s", self.pid)
          except pool.NoIdleConnectionsError:
              if self._pool_manager.is_full(self.pid):
                  raise
  
              # Create a new PostgreSQL connection
              kwargs = utils.uri_to_kwargs(self._uri)
              LOGGER.debug("Creating a new connection for %s", self.pid)
              connection = self._psycopg2_connect(kwargs)
  
              self._pool_manager.add(self.pid, connection)
              self._pool_manager.lock(self.pid, connection, self)
  
              # Added in because psycopg2ct connects and leaves the connection in
              # a weird state: consts.STATUS_DATESTYLE, returning from
              # Connection._setup without setting the state as const.STATUS_OK
              if utils.PYPY:
                  connection.reset()
  
              # Register the custom data types
              self._register_unicode(connection)
              self._register_uuid(connection)
  
          return connection
docs: Connect to PostgreSQL, either by reusing a connection from the pool
          if possible, or by creating the new connection.
  
          :rtype: psycopg2.extensions.connection
          :raises: pool.NoIdleConnectionsError