Home > Net >  How to write a go connection string for pgx.pool to a remote RDS?
How to write a go connection string for pgx.pool to a remote RDS?

Time:10-08

I have no trouble connecting go pgxpool to a postgresql database in a docker container but can't figure out how to write a connection URL string for a linode postgresql RDS. Specifically, what is the first part of the URL "postgres://"? I can't find any example for a connection URL other than a local db and no code examples for a DSN connection.

Can somebody please help me out with either a connection URL or DSN for these details?

Here is my current connection string which returns "host is invalid". ssl_mode is also invalid.

config, err := pgxpool.ParseConfig("user=linpostgres, password=secret, host=lin-9930-2356-pgsql-primary.servers.linodedb.net, port=5432 dbname=mydb, pool_max_conns=10")

This psq connect string times out: psql --username=linpostgres --host=lin-9930-2356-pgsql-primary.servers.linodedb.net port=5432 --password

CodePudding user response:

You can check the code official GitHub repository code here: link

// See Config for definitions of these arguments.
//
//  # Example DSN 
//  user=jack password=secret host=pg.example.com port=5432 dbname=mydb sslmode=verify-ca pool_max_conns=10
//
//  # Example URL
//  postgres://jack:[email protected]:5432/mydb?sslmode=verify-ca&pool_max_conns=10

so your connection string should be

postgres://jack:[email protected]:5432/mydb?sslmode=verify-ca&pool_max_conns=10

hope this helps

  • Related