dsdf64562672
2017-03-14 16:09
采纳率: 0%
浏览 167

如何在golang lib / pq postgresql驱动程序中设置应用程序名称?

I'm writing a golang application and using the golang postgres driver - https://github.com/lib/pq/

I use a connection string like this

'name:pass@host:port/dbname'

I try to add aplication_name param in conn string, but this doesn't work

'name:pass@host:port/dbname?application_name=myapp'

Is it possible to set the application name from golang? (standard way)

图片转代码服务由CSDN问答提供 功能建议

我正在编写golang应用程序并使用golang postgres驱动程序- https://github.com/lib/pq/

我使用这样的连接字符串< / p>

 'name:pass @ host:port / dbname'
   
 
 

我尝试在conn字符串中添加aplication_name参数 ,但这不起作用

 'name:pass @ host:port / dbname?application_name = myapp'
   
 
  

是否可以通过golang设置应用程序名称? (标准方式)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duandaotuo5542 2017-03-14 16:16
    已采纳

    If you look to the documentation a application_name option is not suuported. Maybe you could use:

    fallback_application_name - An application_name to fall back to if one isn't provided.

    name:pass@host:port/dbname?fallback_application_name=myapp
    
    打赏 评论
  • douwenpin0428 2019-05-03 03:25

    Even though it's not mentioned in the documentation, if you look at the lib/pq source code you will find that application_name is supported.

    This style connection works as desired:

    connstring := fmt.Sprintf("user='%s' password='%s' dbname='%s' host='%s' application_name='%s'", user, password, dbname, host, application_name)
    db, err := sql.Open("postgres", connstring)
    
    打赏 评论

相关推荐 更多相似问题