无法弄清楚DB URI Postgres Azure [英] Can't Figure Out DB URI Postgres Azure

查看:119
本文介绍了无法弄清楚DB URI Postgres Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Azure上启动了一个Postgres数据库,但在确定数据库URI时遇到了很多麻烦。凭据看起来像这样:

I recently spun up a Postgres database on Azure and I'm having a lot of trouble figuring out my DB URI. The creds look something like:

服务器:name.postgres.database.azure.com

Server: name.postgres.database.azure.com

用户(管理员角色):admin @ name

User (admin role): admin@name

密码:mypassword

Password: mypassword

数据库名称:postgres

DB name: postgres

因此,我尝试使用 psql 并传入连接字符串 psql postgresql:// admin @ name :mypassword@name.postgres.database.azure.com:5432 / postgres

So I'm trying to use psql and pass in the connection string, psql postgresql://admin@name:mypassword@name.postgres.database.azure.com:5432/postgres

但这给我一个错误


psql:无法将主机名 name转换为地址:提供的节点名或
servname,或者未知

psql: could not translate host name "name" to address: nodename nor servname provided, or not known

有趣的是,它起作用:

psql -h name.postgres.database。 azure.com -p 5432 -U admin @ name postgres

我问的原因是因为我想使用Python和sqlalchemy并且想要

The reason why I ask is because I want to use Python and sqlalchemy and want to pass in the DB uri string.

推荐答案

至少对我来说,这可行。

Ok at least for me, this works. Posting here in case others run into the same issue.


  1. 用于连接到SQLAlchemy并传递此数据库URI对我有用:
    postgresql://用户:密码@主机名:端口/数据库名。例如,

postgresql:// admin @ name:password@name.postgres.database.azure.com:5432 / postgres

postgresql://admin@name:password@name.postgres.database.azure.com:5432/postgres


  1. 在命令行中使用 psql 时,以下方法适用我:
    psql dbname = postgres host = name.postgres.database.azure.com user = admin @ name password = password port = 5432

  1. For using psql in command line, the following worked for me: psql "dbname=postgres host=name.postgres.database.azure.com user=admin@name password=password port=5432"

注意,请小心转义任何特殊字符(例如,输入密码)。例如,我正在使用bash外壳,并使用特殊字符抛出了一些怪异的东西。

Note, be careful to escape any special characters (e.g. for your password). For example, I'm using a bash shell and having special characters threw some weird oddities.


  1. 用于连接到psycopg2我按照此处的说明进行操作: https://docs.microsoft.com/ zh-cn / azure / postgresql / connect-python

  1. For connecting to psycopg2 I followed the instructions here: https://docs.microsoft.com/en-us/azure/postgresql/connect-python

您还可以按照此处的说明解析网址:< a href = https://stackoverflow.com/questions/15634092/connect-to-an-uri-in-postgres>连接到postgres中的URI

You can also parse a URL following the instructions here: Connect to an URI in postgres

这篇关于无法弄清楚DB URI Postgres Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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