def format_dsn(self, params: Dict[str, Any]) -> str:
        """Format connection string from connection parameters.

        .. note::
            only parameters from the below list are considered and values are escaped.

        :param params: :class:`dict` object with connection parameters.

        :returns: a connection string in a format "key1=value2 key2=value2"
        """
        # A list of keywords that can be found in a conninfo string. Follows what is acceptable by libpq
        keywords = ('dbname', 'user', 'passfile' if params.get('passfile') else 'password', 'host', 'port',
                    'sslmode', 'sslcompression', 'sslcert', 'sslkey', 'sslpassword', 'sslrootcert', 'sslcrl',
                    'sslcrldir', 'application_name', 'krbsrvname', 'gssencmode', 'channel_binding',
                    'target_session_attrs', 'sslnegotiation')

        def escape(value: Any) -> str:
            return re.sub(r'([\'\\ ])', r'\\\1', str(value))

        key_ver = {'target_session_attrs': 100000, 'gssencmode': 120000, 'channel_binding': 130000,
                   'sslpassword': 130000, 'sslcrldir': 140000, 'sslnegotiation': 170000}
        return ' '.join('{0}={1}'.format(kw, escape(params[kw])) for kw in keywords
                        if params.get(kw) is not None and self._postgresql.major_version >= key_ver.get(kw, 0))
Format connection string from connection parameters.

        .. note::
            only parameters from the below list are considered and values are escaped.

        :param params: :class:`dict` object with connection parameters.

        :returns: a connection string in a format "key1=value2 key2=value2"
        
patroni/postgresql/config.py