如何处理Postgresql URL连接字符串的密码中的特殊字符?

编程入门 行业动态 更新时间:2024-10-23 21:25:02
本文介绍了如何处理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连接字符串的密码中的特殊字符?

    本文发布于:2023-10-29 09:55:08,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1539390.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字符串   如何处理   特殊字符   密码   URL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!