Bỏ qua để đến nội dung
Playbook: databases Create, inspect, back up, import and drop MariaDB/MySQL, PostgreSQL (with pgvector) and MongoDB databases, users and roles, and Qdrant collections, from an AI agent with jobs_create.

Playbook: databases

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

Goal: a database and user on a server, for a site, an app or an external client.

Token: operate to create, inspect and tune. Drops need full + data:delete, and imports need full + backups:restore. Server: the engine must be installed. Check servers_inventory {id, kind: "db_engine" | "pg_engine" | "mongo_engine"}. To install one, use extension.install {id: "mariadb" | "mysql" | "postgres" | "mongodb" | "pgvector"} (full; the mongodb extension needs Pro) or servers_provision with the component.

  • db_list {server} (core tool) lists databases live.
  • servers_inventory {id, kind: "databases"} and {kind: "db_users"} return the cached lists.
  • MariaDB/MySQL: db.status, db.info {name}, db.tables {name}, db.user-list, db.user-detail {user, host?}.
  • PostgreSQL: pg.status, pg.db-list, pg.detail {name}, pg.tables, pg.vector-status.
  • PostgreSQL roles: pg.role-list → {roles:[{name, system, databases:[{db, access, primary}]}]}.
  • MongoDB: mongo.status, mongo.db-list, mongo.detail {name}, mongo.collections, mongo.user-list → {users:[{user, db, roles, primary}]}.
  • Qdrant: qdrant.status → {installed, running, container, version, api_key_set, collections:[{name, points, vector_size, distance, size_bytes}]}.
EngineJob kind and bodyNotes
MariaDB / MySQLdb.create {name, user?, pass?, host?}With user but no pass, a 20-character password is generated. host is localhost (the default) or % (any host).
MariaDB / MySQL user onlydb.user-create {user, db?, pass?, host?} → db.user-grant {user, db, host?}Grant on an existing database.
PostgreSQLpg.db-create {name, user?}Names: lowercase letters, digits and _, starting with a letter.
PostgreSQL + pgvectorpg.vector-enable {db}Needs the pgvector extension installed.
PostgreSQL rolepg.role-create {name, pass?, db?, access?: "owner" | "readwrite" | "readonly"} → pg.role-grant {name, db, access}A plain LOGIN role; presets only on databases MZPanel manages. postgres, public and pg_* are reserved. Agent 0.2.164+.
MongoDBmongo.db-create {name, user?}
MongoDB usermongo.user-create {user, db, role?: "readWrite" | "read" | "dbOwner", pass?}The user authenticates against db. Never admin, local or config. Agent 0.2.164+.
Qdrant collectionqdrant.collection-create {name, size, distance?: "Cosine" | "Dot" | "Euclid" | "Manhattan", container?}size = the embedding dimension. Qdrant must already run (marketplace app).
For a Docker app (Pro)app.db-attach {name: <app>, engine: "mariadb" | "postgres", db?}Creates the database and wires the app’s env. The password appears only in the live output (REST stream), and the job is never queued.

Then poll jobs_get and verify with db_list {server}, or with servers_inventory_refresh {id, kind: "databases"} followed by servers_inventory.

Passwords: a password you set in pass is masked in the job’s stored arguments and the audit log (for db.user-*, pg.role-* and mongo.user-* it is sealed to the box and never stored). Generated passwords show up only in the live job output, so read them from the REST stream or set your own. Never write them into chat logs.

NeedJob kind
Change a user’s passworddb.user-passwd {user, pass?, host?} · pg.role-passwd {name, pass?} · mongo.user-passwd {user, db, pass?}
Revoke a grantdb.user-revoke {user, db, host?} · pg.role-revoke {name, db}
Change a Mongo user’s rolemongo.user-role {user, db, role}
Export / dump (MariaDB)db.export {name, gzip?} · list dumps: db.backup-list {name}
Export (MongoDB)mongo.export {name}
Export (PostgreSQL)pg.export {db} → {ok, path, bytes} (a pg_dump -Fc file in /var/lib/mz/db-dumps)
Optimize tablesdb.optimize (operate) · Postgres pg.vacuum {name, analyze?}
Tune the serverdb.tune-get / db.tune-plan → db.tune-apply {key, value} · Postgres pg.tune
Remote access (Postgres)pg.expose {ip} / pg.unexpose {ip} · pg.exposed lists the allowlist
Remote access (MariaDB)db.net-status, then db.config-set {bind: "local" | "remote", port?}

Destructive operations (confirm with the human first)

Section titled “Destructive operations (confirm with the human first)”
NeedJob kindToken
Import a dump into a database (overwrites it)db.import {name, file, external?} · mongo.import {name, file} · pg.import {db, file} (file in /var/lib/mz/db-imports or /var/lib/mz/db-dumps; one transaction)full + backups:restore
Drop a databasedb.drop {name, dropUser?} · pg.db-drop · mongo.db-dropfull + data:delete
Drop a userdb.user-drop · pg.role-drop {name} · mongo.user-drop {user, db}full + data:delete
Delete a Qdrant collection (all points)qdrant.collection-delete {name}full + data:delete
Delete a dumpdb.backup-deletefull + data:delete

Before an import or drop, take a dump (db.export) or a backup (see Backups and restore).

phpMyAdmin, pgAdmin and mongo-express login links (db.pma, db.pma-admin and the admin-UI sessions) and the Qdrant API key reveal (qdrant.api-key) are dashboard-only. System accounts are refused on the box: protected_role (postgres, superusers), protected_db / protected_user (Mongo admin), owns_database / primary_user (drop the database instead). Tell the user to open the database from the server’s Databases page.