Browsing database tables: the DB explorer's table list and row preview
Describes Database Explorer 0.4.0.
The DB explorer lets you look inside your site’s Postgres database from the admin: every table, how big it is, and the rows it holds. It only reads. Nothing on these pages changes data.
Where to find it
In the admin sidebar, open DB, or go to /admin/db. Under it are two entries: Overview (the table list) and Activity (the live feed, which has a guide of its own).
The module is off until someone switches it on under Admin › Modules. To see it you need the DB permission. Owner and Admin have it; a custom role gets it from the roles matrix.
Give that permission with care. The explorer shows every row of every table in the database, including tables of other modules and of the host app. Think of it as handing someone direct database access.
The DB explorer: every table, read only.
The overview
Four cards sit at the top:
- Tables: how many tables the explorer can show (Application tables).
- Rows: the rows in all of them added up, from Postgres’s own statistics, so it can be slightly off.
- Tables Size: the space the tables and their indexes take.
- Database Size: the size of the whole database.
Below them is the table list. Each row shows the table as schema.table, its row count and its Size. Click the name, or the eye button at the end of the row, to open the table.
- Search tables narrows the list as you type: it matches the schema or the table name.
- Prev and Next move between pages of 20 tables. The line beside them says which page you are on and how many tables match.
- When nothing matches, the list says No tables found.
The page refreshes itself a couple of seconds after a watched table changes, so the counts stay current while you look.
A table whose schema or name contains anything other than letters, digits and underscores cannot be opened here. Such tables are left out, and a line under the list says how many were left out.
Looking at a table’s rows
Opening a table shows its name, its approximate row count and its size at the top, then its rows, 20 at a time.
One table's rows.
- The total above the rows is exact. For a table with more than 100,000 rows it shows the estimate Postgres keeps instead, worded about … rows total (estimate).
- Show … per page: 10, 20, 50, 100 or 200 rows per page. Changing it keeps you near the rows you were looking at.
- The arrow buttons go to the First page, Previous page, Next page and Last page. Between them is Page … of ….
- On a table with more than one page, a thin scrollbar on the right shows page numbers as you move along it.
- Rows are in the order of the table’s
uuidcolumn, else itsidcolumn, else the order Postgres stores them in. There is no way to sort by another column. - An empty value shows as null. A long value is cut off at the edge of its column.
- No rows found. means the table is empty.
Live updates
While the page is open, it updates on its own when rows are added, changed or removed. A notice says what happened (for example 3 rows added or Data updated), and the rows that are new or changed on the page flash green for a few seconds.
The first time anyone opens a table, the explorer starts watching it for changes. If it can’t do that right away (the table is busy), a yellow box says Live updates are not available for this table right now. The rows are still correct as of the moment the page loaded; reload to try again.
If the table is deleted while you have it open, you are sent back to the list with the message Table … not found.
Live Activity at the top right opens the activity feed already filtered to this table.
Hidden values
Values that look like secrets are never shown. A cell becomes •••••• when its column name contains words such as password, secret, token, api_key, credential or salt, starts with hashed_ or encrypted_, or ends with _hash. The same goes for such keys inside JSON values, and for the value of a settings-style row whose key or name looks like a secret. The real value never reaches your browser, and there is no button to reveal it.
The rule is by name only. A secret kept in a column with an ordinary name is shown as it is.
What it doesn’t do
- It doesn’t edit, add or delete rows, or change tables. It only reads.
- It doesn’t run queries you type, and the row preview has no search box or column sorting.
- It can’t open tables whose schema or name has characters other than letters, digits and underscores.
For developers
Watching a table installs a small Postgres trigger on it. Switching the module off removes every trigger it installed. If a table was locked at that moment, its trigger stays and is logged; PhoenixKitDb.remove_all_triggers() removes the leftovers. Installing or removing a trigger waits at most 2 seconds for the table lock, set with config :phoenix_kit_db, ddl_lock_timeout_ms: 2000.