如何处理Postgresql URL连接字符串的密码中的特殊字符? [英] How to handle special characters in the password of a Postgresql URL connection string?

查看:1086
本文介绍了如何处理Postgresql URL连接字符串的密码中的特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Postgresql URL连接字符串,其格式为:

Using a Postgresql URL connection string in the format of:

postgresql://user:secret@localhost

如何处理该字符串中的特殊字符(例如, $

How do I handle special characters in that string (e.g., $) so that it will actually function when I connect to my postgres database?

我尝试过简单地对其进行URL编码,因此,例如, test $变为 test%24。 ..但这似乎是个问题,因为尝试使用它时出现致命错误:密码验证失败错误。

I've tried simply URL encoding it, so for example, "test$" becomes "test%24" ... but that seems to be a problem as I get a "FATAL: password authentication failed " error when attempting to use it.

推荐答案

请参见文档中的连接URI

有些问题在您的问题中似乎不太正确:

There are a few things that don't seem quite right in your question:


  • URIs仅从版本 9.2 开始受postgres支持,因此对于 9.1 客户端不起作用完全没有或者您使用的客户端本身实现了连接URI。

  • URIs are supported by postgres since version 9.2 only, so with a 9.1 client that's not supposed to work at all. Or you're using a client that implements connection URIs itself.

百分号编码受支持。每个文档:

Percent-sign encoding is supported. Per doc:


百分比编码可用于在任何URI部分中包含具有特殊含义的符号

Percent-encoding may be used to include symbols with special meaning in any of the URI parts.


  • 对于美元字符,甚至不需要百分比编码。

  • Percent-encoding is not even necessary for a dollar character.

    尝试过9.3:

    sql>更改用户的丹尼尔密码'p $ ass';

    $ psql 'postgresql://daniel:p$ass@localhost/test'
    

    works

    $ psql 'postgresql://daniel:p%24ass@localhost'
    

    有效

    psql 'postgresql://daniel:pass@localhost/test'
    

    失败:密码错误。

    这篇关于如何处理Postgresql URL连接字符串的密码中的特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆