Skip to content

Connecting

Connect to a database's endpoint over TLS, verified against the EZGH CA bundle, with client timeouts, keepalives and DNS settings that reconnect quickly.

Updated View as Markdown
ezgh databases connection dbi_4k2m9x0a7qpe
Endpoint:   db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com
Port:       5432
User:       ezgh_admin
Password:   ezgh secrets read sec_a1b2c3d4e5f6 --project 0199a3c2-6c2f-7e51-8a4b-3d9f7c2e5a81 --field password --format raw
CA bundle:  https://get.ezghcloud.com/databases/ca-bundle.pem

It prints the engine’s own client command too. The console shows the same on the database’s Connectivity tab.

  • Endpoint: the database’s DNS name. It stays the same through failovers, maintenance and blue/green switchovers.
  • Port: 5432 for PostgreSQL, 3306 for Percona Server and MariaDB.
  • User: ezgh_admin. Its password is in the database’s admin Secret, fields username and password. ezgh doesn’t read it for you: the ezgh secrets read command above does. ezgh databases rotate-admin-password writes a new password as a new version of the Secret; new connections need it, and open ones carry on. For your apps, create users with a preset on one logical database. To use the password on an instance without handling it, see Read a secret on an instance.

Connect from an address in the database’s allowed sources, inside its VPC. From anywhere else, connect without entering your VPC.

TLS

Connections must use TLS. The database’s certificate is for its endpoint, and chains to the EZGH CA bundle at https://get.ezghcloud.com/databases/ca-bundle.pem. Verify the server’s certificate and its name against the bundle:

curl -fsSO https://get.ezghcloud.com/databases/ca-bundle.pem
psql "host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com port=5432 dbname=postgres user=ezgh_admin sslmode=verify-full sslrootcert=ca-bundle.pem"

Drivers built on libpq take the same sslmode=verify-full and sslrootcert. The PostgreSQL JDBC driver takes them as URL parameters.

mysql --host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com --port=3306 --user=ezgh_admin --password --ssl-mode=VERIFY_IDENTITY --ssl-ca=ca-bundle.pem

In MySQL Connector/J, sslMode=VERIFY_IDENTITY with the bundle as the trusted CA. In Go’s go-sql-driver/mysql, a tls.Config with the bundle as RootCAs and the endpoint as ServerName.

mariadb --host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com --port=3306 --user=ezgh_admin --password --ssl-verify-server-cert --ssl-ca=ca-bundle.pem

MariaDB Connector/J takes sslMode=verify-full and serverSslCert=ca-bundle.pem.

Timeouts and keepalives

After a failover or maintenance, open connections end and clients reconnect to the same endpoint. Set connection timeouts and TCP keepalives in your clients:

PostgreSQL (libpq connection parameters):

Setting Example Meaning
connect_timeout 5 Seconds to wait for a connection.
keepalives 1 Send TCP keepalives.
keepalives_idle 30 Seconds idle before the first keepalive.
keepalives_interval 10 Seconds between unanswered keepalives.
keepalives_count 3 Unanswered keepalives before the connection is closed.
tcp_user_timeout 30000 Milliseconds sent data may stay unacknowledged before the connection is closed.
host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com port=5432 dbname=postgres user=ezgh_admin
sslmode=verify-full sslrootcert=ca-bundle.pem connect_timeout=5 keepalives=1 keepalives_idle=30
keepalives_interval=10 keepalives_count=3 tcp_user_timeout=30000

Percona Server and MariaDB: set your connector’s connect timeout and socket (read) timeout, for example Connector/J’s connectTimeout=5000 and socketTimeout, or go-sql-driver/mysql’s timeout=5s and readTimeout. Set the socket timeout above your longest query.

Connection pools should test or replace connections that fail, and retry a transaction that failed because its connection ended.

DNS

The endpoint is a DNS name for a private address in your VPC. Its record has a 5-second TTL. Set clients to cache it for no longer:

  • Java: a JVM caches names for 30 seconds by default. Set networkaddress.cache.ttl=5, in the JDK’s conf/security/java.security or with java.security.Security.setProperty("networkaddress.cache.ttl", "5") before the first connection.
  • Your own caches: a resolver cache on the instance, or a connection string with an address in place of the endpoint, has the same effect. Use the endpoint, and honor its TTL.

Instances resolve the endpoint through public DNS, so an app’s instance needs a path to the internet to look it up, for example through a Network Gateway or a public IPv4 address. The connection itself stays inside the VPC.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close