Skip to content

Database analysis

Three analyzers read a database you already have a probe for. Each one needs the Engineering tier or above. They connect with the probe’s own host, port, database, credential and TLS setting (and, for SQL Server, the probe’s named instance), so a probe that can log in is usually all the setup there is. The two schema analyzers also need the probe to name a database. See the overview for how an analysis is created, refreshed and gated.

AnalyzerProtocolsWhat you get
Schema (ERD)MySQL, PostgreSQL, SQL ServerAn entity relationship diagram of one schema, with a profile of the data in each table
SchemaMongoDBThe fields, types and indexes of each collection, inferred from a sample of documents
KeyspaceRedisServer version and memory, keys per database and a histogram of key types

All three are read-only. The probes they generate for you are saved and never sent on their own.

The analyzer reads the catalog of the database named on the probe and draws it. It needs that database set: without one the analysis comes back Inconclusive with the finding No database selected.

It reads tables, columns with their types and nullability, primary keys, indexes and foreign keys from the server’s own catalog (information_schema on MySQL, the PostgreSQL system catalogs, the sys views on SQL Server). Only the schema the connection lands in is read. The row count on each table comes from the same catalog, so on MySQL and PostgreSQL it is the server’s estimate rather than an exact COUNT(*). On PostgreSQL a table that has never been analyzed or vacuumed has no estimate and shows no count.

ERD canvas: tables laid out by their foreign keys, key columns shown, one table expanded

Tables are laid out from their foreign keys, so a table that others reference sits to the left of the tables that reference it. A foreign key is drawn from the child table to its parent, with a crow’s foot on the child end. Selecting either end labels the edge with the columns it joins.

Each table card shows its name and row count. A primary key column carries a green dot and a foreign key column a blue one, nullable columns are set in italics and a column that data profiling labels as personal data carries a violet stripe. By default a card shows its key columns only. All columns in the toolbar switches every card to the full list. +N more at the foot of a card expands just that one table.

The toolbar also has Filter tables (it matches table and column names and dims everything else), zoom controls, Fit and Export. Export offers four formats:

  • PNG image and SVG vector of the diagram
  • SQL (DDL) with the tables, indexes and foreign keys
  • PlantUML source

Click a table to open its detail panel, which lists each column with its type, key and nullable flags and the profile figures described below, plus the table’s indexes and up to five sample values per column.

After the structure, the analyzer reads up to the first 200 rows of each table (as the server returns them, with no ordering) and profiles every column in that sample:

  • Null %: the share of sampled rows where the column is null
  • Distinct: how many different non-null values the sample holds, which undercounts on a table larger than the sample
  • Samples: up to five distinct values
  • a personal-data label when at least 90 percent of the sampled values (and at least four of them) look like an email address, an IPv4 address, a US social security number, a payment card number that passes the Luhn check or a phone number

Binary, large-object, JSON, XML and spatial columns are skipped. The label is decided from the values alone and never from the column name. Profiling is best effort: if the sample query for one table fails, that table stays unprofiled and the analysis is not marked as failed.

The sampled values are stored in the analysis and in its snapshot history, which means personal data the profiler found is stored there too. A workspace shared through a folder or a repository carries those values to everyone who opens it.

Right-click a table or a column to create a probe pre-filled with this analysis’s connection and a statement for that table. The probe lands in the analysis’s bundle and opens in a tab.

Menu itemStatement
Query rowsSELECT * FROM t (the probe caps the result at 1,000 rows)
Count rowsSELECT COUNT(*) FROM t
Insert a rowINSERT INTO t (...) VALUES ({{column}}, ...) with one variable per column
Update rowsUPDATE t SET <first non-key column> = {{column}} WHERE <key> = {{key}}
Delete rowsDELETE FROM t WHERE <key> = {{key}}
Filter by this columnSELECT * FROM t WHERE c = {{val}}
List distinct valuesSELECT DISTINCT c FROM t
Count by valueSELECT c, COUNT(*) AS n FROM t GROUP BY c ORDER BY n DESC
Find null valuesSELECT * FROM t WHERE c IS NULL

Identifiers are quoted for the dialect. A table with no primary key gets WHERE 1 = 0 on update and delete with a comment asking for a condition, so a generated statement can never change every row by accident. Insert, update and delete take their columns from the current snapshot.

Generate assertions from this table on the same menu builds a chain that pins this one table’s column types and row count. See Drift and generated tests.

FindingSeverityWhen
No database selectedErrorThe probe names no database (the analysis is Inconclusive)
Could not read the schemaErrorThe connection or a catalog query failed; the detail carries the server’s message

A schema that was read without trouble has no findings and its status is OK.

MongoDB has no catalog of fields, so the schema is inferred. For every collection in the probe’s database the analyzer counts the documents, draws a random sample of 100 with $sample and reads the indexes. It needs the database set on the probe, in the same way as the SQL analyzer.

Each document in the sample is flattened into dotted paths (address.city). Every path gets the types it was seen with, its presence (the share of sampled documents that contain it) and up to three sample values. Extended JSON types such as objectId, date, long and decimal are reported by name. An array is reported as array and its elements are not walked.

MongoDB schema: one card per collection with inferred fields, presence bars and indexes

Each collection is a card with its name, a sampled N badge, the document count and a Fields table of paths, types, presence and samples, followed by its Indexes. A collection that has a $jsonSchema validator carries a Validated badge. Click the badge to show the validator document under the card. Filter collections narrows the cards by collection name or field path.

The analyzer authenticates against the authentication database the probe names (admin when it names none). If the user lives in another database, set Authentication database under Analyzer options.

Because the sample is random, two refreshes of an unchanged collection can report slightly different presence figures and samples, which shows up as structure changes in drift.

The wand button on a card (or a right-click on it) creates a MongoDB probe for that collection, pre-filled with this analysis’s connection:

  • Find documents: a find with an empty filter, limited to 50 documents
  • Count documents: a count with an empty filter
  • Insert a document: an insert whose document has one {{variable}} per top-level field the sample found
  • Aggregate (sample): an aggregation of $sample with a size of 10

Right-click a field for Find by this field, a find filtered on that path with a variable for the value.

FindingSeverityWhen
No database selectedErrorThe probe names no database (the analysis is Inconclusive)
Could not sample the schemaErrorThe connection or a command failed

The keyspace analyzer authenticates when the probe carries a credential (with a user name when the credential has one), then reads INFO. From that it reports the server Version, the Mode (standalone, cluster or sentinel), Memory in use and, per database, the number of keys, the number with an expiry and the average TTL.

For the database that holds the most keys it then walks the keys with SCAN and asks each one for its TYPE, stopping after 1,000 keys. The result is the Key types histogram, with a line underneath saying whether the counts cover every key or a sample of 1,000. On a cluster the analyzer reads only the node the probe connects to.

Redis keyspace: server facts, keys per database and the key type histogram

The keyspace analyzer encrypts the connection when the probe uses TLS but does not verify the server certificate, whatever the probe’s TLS mode says. Use the TLS posture analyzer to check the certificate.

FindingSeverityWhen
Authentication failedErrorThe server rejected the credential; the detail quotes its reply
Could not read the keyspaceErrorThe connection or a command failed
The keyspace is emptyWarningThe server answered but no database holds a key (the analysis is Inconclusive)

There is no probe authoring from a keyspace. Its snapshot still feeds drift and a generated drift test.