You can reach a database from anywhere you can run ezgh, with no instance, VPN or Network Gateway in
its VPC. ezgh databases connect opens a port on your computer, and anything that speaks the engine’s
protocol connects through it: psql, mysql, DBeaver, migrations and connection pools. The engine’s
TLS runs from your client to the database, and the engine still checks its user and password.
Who can connect
The IAM action databases.databases.connect controls it. It’s in DatabasesFullAccess, not in
DatabasesReadOnlyAccess or ReadOnlyAccess.
A connection made this way doesn’t pass through the database’s
allowed sources. The engine sees it come from an
address in the database’s own subnet, so users and rules that admit that subnet, such as a MySQL user
'app'@'10.0.%', match. A user scoped to another range only, such as your app’s subnet, doesn’t.
Connect from your computer
ezgh databases connect dbi_4k2m9x0a7qpeListening: 127.0.0.1:5432
Endpoint: db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com
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
curl -fsSO https://get.ezghcloud.com/databases/ca-bundle.pem
psql "host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com hostaddr=127.0.0.1 port=5432 dbname=postgres user=ezgh_admin sslmode=verify-full sslrootcert=ca-bundle.pem"It listens until you stop it with Ctrl-C. The port is the database’s own unless you pass --port, for
example when a local server already uses 5432; --address listens on another local address, and the
printed command uses it. Every connection your client opens is a connection to the database, and counts
toward its limit.
In a second terminal, download the CA bundle and run the client command it printed:
psql "host=db-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com hostaddr=127.0.0.1 port=5432 dbname=postgres user=ezgh_admin sslmode=verify-full sslrootcert=ca-bundle.pem"host is the database’s endpoint and hostaddr the local port’s address, so verify-full checks the
certificate against the database’s real name. Drivers built on libpq take the same parameters.
mysql --host=127.0.0.1 --port=3306 --user=ezgh_admin --password --ssl-mode=VERIFY_CA --ssl-ca=ca-bundle.pemmysql --host=127.0.0.1 --port=3306 --user=ezgh_admin --password --ssl-mode=VERIFY_CA --ssl-ca=ca-bundle.pemWhy MySQL clients use VERIFY_CA
The mysql and mariadb command-line clients check the certificate’s name against the address they dial,
here 127.0.0.1, and can’t be given another name. VERIFY_IDENTITY (or the mariadb client’s
--ssl-verify-server-cert) can’t pass on a local port, so use VERIFY_CA: it checks that the
certificate chains to the EZGH CA bundle. The mariadb client has no mode that checks the chain without
the name, so use MySQL’s own mysql client (MySQL 8.0 or later) with MariaDB too. Where MariaDB’s client
is installed as mysql, it refuses --ssl-mode.
Drivers that take a server name check the endpoint’s name through the local port: in Go’s
go-sql-driver/mysql, a tls.Config with the bundle as RootCAs and the endpoint as ServerName.
From inside the VPC, connect to the endpoint with VERIFY_IDENTITY as in
Connecting.
When a connection ends
A connection through ezgh databases connect ends when:
- the database fails over, including during maintenance, or a blue/green deployment switches over;
- it has been idle for 30 minutes;
- it has been open for 8 hours;
- the database is deleted.
ezgh prints why on its standard error. After a failover, a switchover or a limit it keeps listening, so
a client can reconnect through the same local port; once the database is deleted, or you no longer have
access to it, ezgh stops. Connection pools that replace a failed
connection carry on, as they do after a failover inside the VPC.
Query in the console
Open the database in the console and choose Query. It opens in a new browser tab. Enter a database name, a user and its password, and choose Connect. Then type a statement and choose Run (Ctrl+Enter or ⌘+Enter).
- Statements run one at a time on one connection, so
BEGIN,SETand temporary tables carry over from one statement to the next until you disconnect. - A result shows up to 1,000 rows or 4 MiB. A longer result says it was cut short.
- Cancel stops the statement that’s running.
- Errors are shown as the engine sent them.
The same IAM action, databases.databases.connect, controls Query.
Limits
| Limit | Value |
|---|---|
Open connections per database, from ezgh databases connect and Query together |
20 |
| Idle time before a connection is closed | 30 minutes |
| Longest connection | 8 hours |
| Rows in one Query result | 1,000 (or 4 MiB) |
Opening a connection past the limit is refused with quota_exceeded; try again once one closes.