dougai3418 2017-07-01 22:48
浏览 145

无法通过Golang连接到Postgres数据库

I am using Golang to connect to a Postgres DB instance.

When the code below is executed from an Amazon EC2 instance, the error is not nil after sql.open().

db, err := sql.Open("postgres", "postgres://username:mypassword@xxxxxx.xxxxxxxxxx.xx-xxxx-x.xxx.xxxxxxxxx.xxx/postgres?sslmode=disable")

    if err != nil {
        check(err)
        panic(err)
    }

    err = db.Ping()

    if err != nil {
        check(err)
        panic(err)
    }

However, when I run db.Ping() it doesn't do anything. The code after db.ping() doesn't seem to be executed. After a while I get getsockopt: connection timed out in the terminal window.

What could be the problem? Also even when I use the wrong password, the error is still not nil.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败