Database Connections
A connection tells Kvery how to reach one of your databases. Queries always run against a connection, so this is usually the first thing you set up in a new group.
Creating a connection
A new connection is created from the query form: in the Database connection field choose Add new connection and fill in the connection details. The Databases page (in the sidebar) lists the connections that the group's queries use, each with an Edit button.
Every connection has these fields:
- Production — a switch that marks a connection to a live database. The editor of every query that uses such a connection shows the warning "Be careful, the database is in "Production"!" at the top.
- Name — an optional name of the connection. The Database connection list
of the query form and the Databases page show it; a connection without a name
is shown by its details (
[MySQL] user@host:port/database, or the agent URL and the agent's connection name). - Database type — one of MySQL, PostgreSQL, or MSSQL. (MariaDB uses the MySQL type.) See Supported databases.
- Database name — the schema/database to connect to. On app.kvery.io it may
not set a host (
host=,hostaddr=orunix_socket=).
Below them, choose how Kvery reaches the database:
- Database — Kvery connects to the database server itself, as described on this page.
- Agent — Kvery sends the statements to the Kvery Agent, a small service you run next to a database that Kvery cannot reach directly. See Agent connections.
A Database connection needs:
- Host — the database server's hostname or IP address. On app.kvery.io a
direct connection needs a host that resolves to public addresses only: a host
that is — or whose name resolves to — any address that is not public (loopback,
private, link-local, carrier-grade NAT, reserved or multicast, such as
127.0.0.1,10.x.x.x,192.168.x.xor100.64.x.x, also in an IPv6 form that carries such an IPv4 address) is refused with the message "This database host is not allowed: it is an internal address of the server's network". A host name that cannot be resolved is refused too, with the message "The host name could not be resolved". Reach a database on a private network through an SSH tunnel or an agent. - Port — the port the database listens on. On app.kvery.io it may contain digits only. A port or a database name that breaks these rules is refused with "This connection is not allowed: the port may only contain digits, and the database name may not set a host (host, hostaddr or unix_socket)."; a saved connection that breaks them does not run.
- Username and Password — the credentials Kvery should authenticate with.
The Create query page and the edit page of a connection show Server IP: at
the top: the address of the Kvery server. Allow this address in the firewall of
your database server (or of the SSH server), and list it in the ip_whitelist of a
Kvery Agent.
Create a dedicated database user for Kvery with only the permissions your queries
need. For read-only reporting, grant SELECT only.
Testing a connection
Check connection in the query form connects with the details you entered. A new connection has to pass this check: on the Create query page the rest of the form (description, tags and settings) appears only after a successful check, and in the settings of a query in the editor a successful check saves the query. Saving a connection on its edit page checks it the same way first. A failed check reports:
- "Connection failed: …" with the error message of the database (a password you entered is masked in it);
- "Connection failed: the SSH tunnel could not be opened. …" with the reason (see SSH tunnel);
- "Fill in the following field(s) to test the connection: …" with the empty required fields (Database type, Host, Port, Database name);
- a refused host, port or database name (see above).
This lets you catch firewall, credential, or host issues immediately. An agent connection is checked through the agent (see Checking the connection).
Securing a connection
SSL
For a PostgreSQL connection, upload the client SSL certificate, key and root certificate to encrypt traffic between Kvery and your database. This is recommended whenever the database is reachable over a public network. MySQL, MariaDB and SQL Server connections do not use these files: encrypt them with an SSH tunnel.
Tick SSL? in the connection form and choose the files in SSL Cert,
SSL Key and SSL Root Cert. A file may have the extension .pem, .crt,
.key, .cer, .der, .p12, .pfx, .ca-bundle or .crl, or none, and may be
up to 5 MB.
SSH tunnel
If your database is not directly reachable, route the connection through an SSH bastion host. Kvery establishes a tunnel to the bastion and connects to the database through it. Each run opens the tunnel on a free local port of the Kvery server; the tunnel is reused only within that request and closed when the request ends.
Tick SSH? in the connection form and fill in SSH Host, SSH Port (22 by
default), SSH Username, and SSH Password or an SSH Key file (the
private key, up to 5 MB, with the extension .pem, .key, .pub or .ppk, or
none); with a key the password is not used. In Host and Port enter the database as the
SSH server reaches it, for example 127.0.0.1 and 3306 for a MySQL database
that runs on the SSH server itself.
On app.kvery.io the SSH host must resolve to public addresses only: an internal address is refused with "This SSH host is not allowed: it is an internal address of the server's network. Use a public address for the SSH server.", and a name that cannot be resolved with "The host name could not be resolved. Check the host name.". The database host of a connection through a tunnel is not checked.
Kvery accepts the host key of an SSH server at the first connection and remembers it. When the server later presents a different key, the tunnel is not opened ("The SSH server presented a different host key than at an earlier connection, so ssh did not log in. …"); after an intended change of the key, ask the Kvery administrators to remove the old key. Other reasons the check reports include a rejected user name, password or key ("The SSH server rejected the user name, the password or the key.") and a tunnel that did not accept connections.
Editing and removing connections
You can edit a connection's details at any time; existing queries that use it pick up the change automatically. The edit page never shows the stored passwords and the Agent Secret Key, and saving stores what the form holds: enter the passwords (or the Agent Secret Key) again every time you save, and choose the SSL certificate files and the SSH key again when the connection uses them. A connection has no delete action of its own: it is removed together with the last query that uses it, or with its group when no query uses it. A connection that no query uses any more because its query switched to another connection stays until the group is deleted.
Connections and permissions
Because connections contain credentials, only the owner and the editors of the group create, check and edit them; the Databases item of the sidebar appears only for them. See Members and permissions.