# MongoDB and SQL Server

> Source: https://www.allsweb.com/sixpanel/docs/mongodb-and-sql-server
> Markdown for agents: https://www.allsweb.com/sixpanel/docs/mongodb-and-sql-server.md
> Publisher: AllsWeb (www.allsweb.com)

Part of: SixPanel documentation

**What this page is for:** give your websites a **MongoDB** or a **Microsoft SQL Server**
database, installed and looked after from the panel — install it, see how it is doing,
its databases and users, its memory, its log, restart or repair it, and remove it.

Open **Server**, the **Software** tab, and **MongoDB** or **SQL Server**.

**The rule that does not move:** each engine is reachable from **this server only**
(`127.0.0.1`). Its port is never opened to the internet, nor is its container reached by
the container's own address from another machine (the rule is in
[Docker and apps](https://www.allsweb.com/sixpanel/docs/docker-and-apps)); an app on another computer reaches it through an
SSH tunnel (see [Connect from an app](#connect-from-an-app)). One
engine serves every website that has a database on it: a restart, a memory change or a
removal is felt by all of them, and each confirm on its page says so.

**You need**

- **Docker**, installed from **Software → Docker**. Neither engine is in your
  operating system's own packages, so each runs from its maker's own image in a container
  of its own. Until Docker is there, the engine's page says so and links to it.
- For **MongoDB**: an Intel or AMD processor with AVX, or an ARM processor of ARMv8.2 or
  newer (MongoDB's own requirement — a Raspberry Pi 4 is too old); 512 MB of free memory;
  2 GB of free disk.
- For **SQL Server**: an **Intel or AMD** server (x86-64 — see
  [Why not on an ARM server](#why-not-on-an-arm-server)), at least **2 GB of free memory**,
  2 processor cores, 6 GB of free disk on an ext4 or XFS disk. These are Microsoft's own
  minimums; the page says which one your server is short of, with the numbers.
- The owner's login to install, change or remove anything here. A temporary login can read
  the page; the read-only demo shows it but changes nothing.

---

## MongoDB

MongoDB is installed from **MongoDB's official image** (Docker Hub `mongo`, MongoDB
Community **9.0.4** — the version is pinned by SixPanel, so every server runs the one the
release was tested with).

Press **Install**. The panel downloads the image (about 385 MB), makes its folders and an
account of its own for it, starts it and makes its root user. The progress is in the job's
log. When it is done the page shows:

- whether it is running, its version, how long it has been up, and the **memory** it uses
  now against its ceiling;
- its **data cache** (WiredTiger's), the connections open now, how many databases there
  are and how much they hold;
- every **database** with its size and the website it belongs to, and every **user** with
  what it may do.

How it is set up, so you do not have to:

- **Passwords are on.** Every website's user reaches its own database only (read and
  write, and its indexes). The root user's password is generated at install and kept in a
  file only root can read: `/var/lib/sixpanel/mongodb/root.json`. The panel never shows it
  — read it in the server's **Terminal** with `sudo cat /var/lib/sixpanel/mongodb/root.json`.
- **Its own account.** MongoDB runs as `sixpanel-mongodb`, not as any website's account,
  and its data is in `/var/lib/sixpanel/mongodb`, a folder only root can enter.
- **Sized for your server.** Its memory ceiling is an eighth of the server's memory
  (768 MB to 4 GB, and never more than half of it), its data cache is MongoDB's own formula
  applied to that ceiling, and it may use half the processor cores — the shops on this
  server always keep the rest.
- **Quiet.** MongoDB's diagnostic capture (which nobody here sends to MongoDB) and the
  shell's telemetry are switched off.

A database for a website is made on **that website's Database page** (see
[Give a website a database](#give-a-website-a-database)). MongoDB makes the database itself
when the app first writes to it, so a new one shows "made when the app first writes to it"
until then — the website's user can already use it.

## SQL Server

SQL Server is installed from **Microsoft's own image** (`mcr.microsoft.com/mssql/server`,
**SQL Server 2025, CU9 with its security update GDR1** — pinned by SixPanel).

### Install SQL Server

The SQL Server page shows the install form while SQL Server is not installed:

1. **Choose the edition.**
   - **Express** — free, and licensed for production. A database can be up to 50 GB, and
     SQL Server keeps up to 1.4 GB of data in memory and uses up to four cores. This is the
     default, and the right choice for a website.
   - **Developer** — free, with every feature of SQL Server, but **not licensed for
     production use**: for building and testing only. The page says so beside the choice.
2. **Read Microsoft's licence terms** — the page links them — and tick **I have read and
   accept Microsoft's licence terms for SQL Server**. **Install** stays off until you tick
   it. SixPanel never accepts Microsoft's terms for you, and neither does Tia: the panel
   records who accepted them and when, and the page shows it afterwards.
3. Press **Install SQL Server**. About 634 MB is downloaded; the first start sets SQL
   Server up, which takes a minute or two.

How it is set up:

- **The `sa` password** is generated at install and moved off the one SQL Server's first
  setup used, at once — the live password is only in `/var/lib/sixpanel/mssql/root.json`
  (root only, never shown by the panel).
- **Memory:** SQL Server itself is held to 2 GB (Microsoft's minimum), its container to
  512 MB more. You can give it more on its page; Express keeps at most 1.4 GB of data in
  memory whatever it is given.
- **Its own user id.** Microsoft's image runs as user id 10001; SixPanel reserves that id
  on the server as `sixpanel-mssql`, so no other account can ever get it.
- **Quiet:** SQL Server Agent is off, and Microsoft's usage and diagnostic data collection
  is switched off with SQL Server's own setting.
- Each database a website gets uses the **simple recovery model** (its log does not grow
  until the disk is full) and stays open between queries.

### Why not on an ARM server

Microsoft makes SQL Server for Linux for **64-bit Intel and AMD processors (x86-64)
only**. On an ARM server (arm64 — AWS Graviton, Ampere, Oracle Ampere A1 and others) the
SQL Server card says so and offers no Install button. MongoDB, PostgreSQL and MariaDB all
run on ARM.

## Give a website a database

A website's databases are added on **the website's Database page**: choose the engine
(MariaDB, and PostgreSQL, MongoDB or SQL Server once each is installed), and the panel
makes the database, its own user and a password for it. That page shows the connection
details — host `127.0.0.1`, the port, the database, the user, and a connection URL — and
the password behind **Show**.

What a website's user may do: on MongoDB, read and write its own database and manage its
indexes; on SQL Server, own its own database (`db_owner` of that database and nothing
else). A read-only user is a choice there too.

## Connect from an app

**On this server**, an app connects to `127.0.0.1` — MongoDB on port **27017**, SQL Server
on port **1433**:

- MongoDB: `mongodb://<user>:<password>@127.0.0.1:27017/<database>?authSource=<database>`
- SQL Server: `sqlserver://127.0.0.1:1433;database=<database>;user=<user>;password=<password>;encrypt=true;trustServerCertificate=true`
  (.NET: `Server=127.0.0.1,1433;Database=…;User Id=…;Password=…;Encrypt=True;TrustServerCertificate=True`).
  SQL Server's certificate is its own, so a client trusts it explicitly; the connection
  never leaves the server.

Node.js reaches both with their usual drivers (`mongodb`, `mssql`/`tedious`). A PHP website
needs the `mongodb` extension for MongoDB (**Software → PHP**, the extension packages of its
version). PHP's SQL Server driver is Microsoft's own and is not in your operating system's
packages, so SixPanel does not install it.

**From your own computer** (MongoDB Compass, SQL Server Management Studio, Azure Data
Studio), open an SSH tunnel and connect to `127.0.0.1` on your side:

    ssh -N -L 27017:127.0.0.1:27017 <you>@<your server's IP>
    ssh -N -L 1433:127.0.0.1:1433 <you>@<your server's IP>

Use the server's IP address, not a domain that Cloudflare proxies — Cloudflare carries web
traffic only. The engine's page shows the same line under **Connect**, the root password's
file and the data folder.

## Memory

The **Memory** card shows the engine's ceiling — the most it may use; it takes much less
while it is quiet — and the size SixPanel picks for this server. Type another size within
the range the card gives and press **Save**: the container is made again with it (every
website that uses the engine loses it for a few seconds; the data stays where it is).
**Use SixPanel's size** goes back to the size it picks.

## Restart, Repair and the log

- **Logs** shows the newest lines of the engine's own log.
- **Restart** gives the engine a minute to write what it holds, stops it and starts it
  again.
- **Repair** puts its container back exactly as SixPanel runs it — the image this SixPanel
  release pins (when it is the same version line), the memory ceiling, `127.0.0.1` only —
  makes sure its folders and account are right, and checks its root user. The data is not
  touched. When a SixPanel update pins a newer image of the same version, the page says so
  and Repair moves the engine to it.

If the page says the engine is **not running**, open **Logs** to see why, and press
**Repair**.

## Remove a database no website owns

A database that belongs to no website (made outside SixPanel, or left by a website that was
deleted) has a **Remove** button. Type the database's name to confirm. A copy is kept on the
server first, for 7 days (a root-only file in `/var/lib/sixpanel/<engine>/kept/`; the job's
log says where it is and how to put it back) — untick it and removing cannot be undone. A
website's own database is never removed here: remove it on that website's Database page.

## Remove MongoDB or SQL Server

The **Remove** card at the bottom of the engine's page removes its container and its image.
It is refused while any website still has a database on the engine — the card names them.

**The data is kept** unless you tick **Also delete its data** and type the engine's name
(`mongodb` or `mssql`): every database, its users and the root password file stay in
`/var/lib/sixpanel/<engine>`, and installing the engine again brings them all back. Tick it
only when you want the disk back and nothing in it any more.

## Backups

A website's databases on MongoDB and SQL Server go into its backups with the rest of the
website: MongoDB as a `mongodump` archive, SQL Server as a `BACKUP DATABASE` file, each
gzipped. Restoring one replaces the database, and what it held is kept first (7 days) —
a restore that stops half way is never the end of the old data.

## What Tia can do

Tia reads both engines — their state, memory, databases and users — and can restart,
repair or resize them, install MongoDB, remove a database no website owns (she asks you
first), and remove an engine with its data kept. She never sees a password, never installs
SQL Server (that accepts Microsoft's licence terms, which only you can do) and never deletes
an engine's data.

## If it went wrong

- **"Install Docker first"** — install Docker on **Software → Docker**, then come
  back.
- **"needs 2 GB of free memory"** (SQL Server) — the server is busy with what it already
  runs. Free some memory or use a larger server; the numbers are on the card.
- **"port … is already taken by another program"** — something else on the server listens
  on 27017 or 1433 (a MongoDB or SQL Server installed by hand). Stop it, then install.
- **The engine is not running** — **Logs**, then **Repair**.
- **"SQL Server did not answer within 5 minutes"** — the sentence ends with the last answer
  SixPanel had from it, which says why (still starting, a refused sign-in). If SQL Server's
  own tool refuses the way SixPanel asks it, the install stops at once and says so in that
  tool's words, instead of waiting: press **Install** again once SixPanel is updated — the
  data it set up so far is kept and the install carries on from it.
- **"the root password SixPanel keeps for it is missing or does not match"** — the data from
  an earlier install is there, but its `root.json` is not. Put that file back, or remove the
  engine with **Also delete its data** and install it again.
