public function connect(): self
    {
        if ($this->resource) {
            return $this;
        }

        $connectionWarnings = [];
        set_error_handler(function ($errno, $errstr) use (&$connectionWarnings) {
            $connectionWarnings[] = $errstr;
            return true;
        }, E_WARNING);

        $this->resource = pg_connect($this->connectionString, PGSQL_CONNECT_FORCE_NEW);

        restore_error_handler();
        if (false === $this->resource) {
            throw new exceptions\ConnectionException(
                __METHOD__ . ': ' . implode("\n", $connectionWarnings)
            );
        }
        $serverVersion = pg_parameter_status($this->resource, 'server_version');
        if (version_compare($serverVersion, '9.2.0', '<')) {
            $this->disconnect();
            throw new exceptions\ConnectionException(
                __METHOD__ . ': PostgreSQL versions earlier than 9.2 are no longer supported, '
                . 'connected server reports version ' . $serverVersion
            );
        }
        pg_set_error_verbosity($this->resource, PGSQL_ERRORS_VERBOSE);

        return $this;
    }