RegisterDriver registers a Postgres driver that uses the alloydbconn.Dialer
configured with the provided options. The choice of name is entirely up to
the caller and may be used to distinguish between multiple registrations of
differently configured Dialers. The driver uses pgx/v4 internally.
RegisterDriver returns a cleanup function that should be called one the
database connection is no longer needed.
Example
packagemainimport("database/sql""log""time""cloud.google.com/go/alloydbconn/driver/pgxv4")funcmain(){// Note that sslmode=disable is required it does not mean that the connection// is unencrypted. All connections via the proxy are completely encrypted.pgxv4.RegisterDriver("alloydb")db,err:=sql.Open("alloydb","host=project:region:instance user=postgres dbname=postgres password=password sslmode=disable",)iferr!=nil{log.Fatal(err)}deferdb.Close()varnowtime.Timeiferr:=db.QueryRow("SELECT NOW()").Scan(&now);err!=nil{log.Fatal(err)}log.Println(now)}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[[["\u003cp\u003eThe latest version of the AlloyDB driver for pgx v4 is 1.15.0, with multiple previous versions available, starting from 0.1.1.\u003c/p\u003e\n"],["\u003cp\u003eThis package, \u003ccode\u003epgxv4\u003c/code\u003e, provides a driver that enables the use of pgx v4 with the \u003ccode\u003edatabase/sql\u003c/code\u003e package for AlloyDB connections.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRegisterDriver\u003c/code\u003e function configures and registers a Postgres driver that uses \u003ccode\u003ealloydbconn.Dialer\u003c/code\u003e, allowing for custom names and the ability to distinguish between different configurations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eRegisterDriver\u003c/code\u003e returns a cleanup function that is important to call when the connection is no longer needed.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example code demonstrates how to use \u003ccode\u003eRegisterDriver\u003c/code\u003e to open a database connection with \u003ccode\u003esslmode=disable\u003c/code\u003e, noting that connections through the proxy are fully encrypted.\u003c/p\u003e\n"]]],[],null,[]]