Skip to content

Databases and optimizer ​

This page explains how MoorCP stores account databases (MariaDB and PostgreSQL), how to move them to a separate database server, and the tools that keep databases fast. It is written for admins and technicians.

Open Servers › (server) › Settings › Databases.

Database engines ​

EngineAvailabilityWeb manager
MariaDBInstalled on every hosting server.phpMyAdmin
PostgreSQL 16Optional per server.AdminNeo

Database and user names always start with <account>_, for example jane_shop. The package's database quota counts MariaDB and PostgreSQL together.

Setting up PostgreSQL ​

PostgreSQL is set up per server, in one of these ways:

  • when adding the server, add the --pgsql option to the agent installer command;
  • on a running server, call the API POST /v1/servers/{id}/pgsql/setup.

The setup installs PostgreSQL 16 with SCRAM authentication and postgresql-contrib (extensions such as pgcrypto, uuid-ossp, pg_trgm, hstore, citext, and unaccent), revokes public access to other databases, and installs the PHP pgsql extension for every PHP version. The server's websites are then applied again so PHP loads pgsql and pdo_pgsql.

The setup is safe to repeat. An existing PostgreSQL cluster keeps its authentication settings. On servers set up before postgresql-contrib was added, run the setup again to install it.

PostgreSQL from cPanel

Importing a cPanel account (migration wave or cPanel archive restore) also imports its PostgreSQL databases, users, and grants. The target server must have PostgreSQL set up first; otherwise only that step fails and the rest of the import continues. PostgreSQL databases count toward the package's database quota in the pre-migration check. Extensions outside postgresql-contrib, such as PostGIS, must be installed by the admin first. See Importing from cPanel.

phpMyAdmin and AdminNeo ​

Both are installed from Settings › Apps & tools with the Install / update button. The server's hostname certificate must already be issued.

ToolAddressExtra requirement
phpMyAdminhttps://srv1.example.com/pma/-
AdminNeohttps://srv1.example.com/adminneo/PostgreSQL is set up.

Clients and staff open them with a one-time link from the panel or billing, without a login form. AdminNeo uses a temporary role that can only open that account's databases, with a session of at most 4 hours.

Local database or external endpoint ​

Each hosting server has a database profile for MariaDB and one for PostgreSQL. Account databases can live in:

  • Local: on the hosting server itself. This is the default.
  • External endpoint: another database server, a VPS, or a managed service, reached over a private or public IP.

An external endpoint separates database load and storage from the web server.

Setting up an external endpoint ​

  1. On the engine card (MariaDB or PostgreSQL), click Configure.
  2. Choose External endpoint.
  3. Fill in the address:
    • Private address: for one data center or VPC. Faster and not exposed to the internet;
    • Public address: used when the private address is empty or the public network is chosen.
  4. Choose Connect through: Private network (recommended) or Public network.
  5. Fill in the port, Admin user, and Admin password. The password is stored encrypted in the panel. Leave it empty to use the stored password.
  6. Choose the TLS mode. For Verify, paste the CA certificate (PEM).
  7. If accounts already have databases, tick Move existing account databases and users to the new location.
  8. Click Test connection.
  9. If it succeeds, click Save and apply.

Privileges the admin user needs:

EnginePrivileges
MariaDBALL PRIVILEGES ON *.* ... WITH GRANT OPTION
PostgreSQLSUPERUSER, or CREATEROLE + CREATEDB on managed services

TLS modes ​

ModeBehavior
PreferredEncrypts when the database server offers it.
RequiredAlways encrypted, certificate not verified.
VerifyEncrypted, certificate checked against the CA you provide.
DisabledNo encryption. Only for private networks.

WARNING

Database traffic over the public internet without TLS can be read by others. Use TLS or a private network.

Connection test ​

Test connection checks from the hosting server itself:

  1. the network path to the endpoint;
  2. TLS;
  3. admin privileges, by creating and dropping a test database and user;
  4. the hosting server's address as the database server sees it (This server as seen by the DB).

Allow address number 4 in the database server's firewall. Nothing is saved during the connection test.

Moving existing databases ​

The endpoint cannot be changed while accounts still have databases in the old location, unless the move option is ticked. If only the address or credentials change for the same database server, nothing is moved.

With the move option, the agent:

  1. copies every account database to the new endpoint;
  2. recreates users with their password hashes and privileges, so old passwords keep working;
  3. locks the users in the old location, so applications do not quietly keep writing to the old copy;
  4. changes DB_HOST in WordPress wp-config.php files that still point to localhost to the new host;
  5. reports the databases, users, and files changed.

The result is shown in the window, for example "2 database(s) and 3 user(s) copied". Click Run in background if you do not want to wait.

Applications other than WordPress

Other applications that store the database host in their configuration must be repointed manually. The host in use is shown on the client's Databases page.

Old data is not deleted

Data in the old location stays until you delete it yourself. If the move fails, nothing is moved and the server keeps using the old location.

When databases are moved from a managed PostgreSQL service with a non-superuser admin, password hashes cannot be read. Users are created with random passwords and the report asks for the passwords to be reset from the panel.

To go back to local, choose Local in the same window.

What adjusts along with it ​

  • The client's Databases page shows the endpoint's host and port.
  • phpMyAdmin and AdminNeo are still opened from the hosting server, then connect to the endpoint.
  • One-click WordPress and Softaculous use the endpoint host.
  • Backup, restore, moving accounts between servers, export, and import run over the endpoint connection.

Limitations:

  • MySQL Governor only applies to local MariaDB.
  • The slow query log of an external endpoint cannot be read from the hosting server.

Remote database access ​

Clients can let applications or tools on other computers connect to their MariaDB databases, like Remote MySQL in cPanel.

Allowing it ​

Remote access works when both are true:

  • the account's package has the Remote database feature. See Packages;
  • the Remote database access control on the account is not turned off. It is on by default. Turn it off in Accounts › (account) › Access controls to block one account. See Accounts.

The client then adds allowed hosts in Databases › Remote database access in the client panel, at most 20 per account:

EntryExample
IPv4 address203.0.113.7
CIDR, /8 to /32203.0.113.0/24
Netmask203.0.113.0/255.255.255.0
Wildcard octet203.0.113.%
Any address%. The client panel asks for confirmation.

IPv6 hosts are not supported for remote MariaDB yet.

What happens on the server ​

  • Every database user of the account is copied to each allowed host with the same password, connection limit, lock state, and privileges (all or read-only). Custom privileges are not copied. The copies stay in sync when users, passwords, or privileges change, and the client panel only shows the original users.
  • When firewalld runs, port 3306/tcp is opened only for the hosts of all accounts on the server, without a firewalld reload. Host % opens 3306 to everyone. Rules an admin added earlier are never removed.
  • When firewalld is not running, the port is not filtered, and only the MariaDB user hosts limit access. When firewalld is turned on from the panel, the rules are added again.
  • When the package or access control no longer allows remote access, the copies and firewall rules are removed. The client's host list stays saved and applies again once access is allowed.

The client panel shows a warning when MariaDB on the server does not accept network connections (skip_networking, or bind_address set to loopback). Change bind_address in the my.cnf editor if needed.

External endpoint

For accounts on an external endpoint, the connection address is the endpoint's public host. Open port 3306 on the database server itself. The hosting server's firewall is not used.

MariaDB tuning ​

The MariaDB tuning card gives recommendations from live server statistics, similar to MySQLTuner. The card shows the version, uptime, and server RAM.

What it checks: the InnoDB buffer pool and hit rate, peak connections, per-user connection limits, on-disk temporary tables, table cache, thread cache, query cache, slow query log, and failed connections. The RAM calculation leaves room for web and PHP on the same server.

Each recommendation has a level:

LevelMeaningTicked automatically
ImportantCan cause refused connections or memory pressure.Yes
RecommendedShould be applied.Yes
TipOptional.No
informationInformation only, with no value to apply.-

Applying recommendations ​

  1. Click Re-analyze to read the latest statistics.
  2. Tick the recommendations you want to apply.
  3. Tick Restart MariaDB now if needed. This is required and ticked automatically for values marked needs restart, for example innodb_log_file_size.
  4. Click Apply selected, then confirm.

Values are written to /etc/my.cnf.d/99-moorcp.cnf. Without a restart, values are applied live when possible. Every apply is validated by mariadbd and then health-checked. If MariaDB is unhealthy, the previous file is restored automatically.

Managed parameters: max_connections, max_user_connections, innodb_buffer_pool_size, innodb_log_file_size, max_allowed_packet, tmp_table_size, max_heap_table_size, wait_timeout, table_open_cache, thread_cache_size, query_cache_type, query_cache_size, slow_query_log, and long_query_time.

Restarting MariaDB

A restart drops all database connections for a few seconds. Websites can briefly show connection errors. Do it in quiet hours.

On an external endpoint, all recommendations are advice only and the my.cnf editor is not shown.

my.cnf editor ​

For options not covered by tuning, use the my.cnf editor card. The options are stored in /etc/my.cnf.d/zz-moorcp-custom.cnf and loaded last, so they override the panel's settings.

  1. Write options under a [mysqld] or [mariadb] section. Example:

    ini
    [mysqld]
    innodb_flush_log_at_trx_commit = 2
  2. Click Preview changes to see the diff.

  3. Click Validate, save and restart, then confirm.

If mariadbd rejects an option, the error message points to the wrong line and your text stays in the editor. If MariaDB does not come back up, the previous file is restored automatically.

Not allowed:

  • sections other than [mysqld], [mariadb], [mariadbd], and [server];
  • !include;
  • file and directory paths (*_file, *_dir, *_path), datadir, tmpdir, secure_file_priv;
  • plugins, init_file, init_connect;
  • user, socket, port, skip-grant-tables, skip-networking, log_bin, local_infile, and SSL file options.

Version history and rollback for this editor are in Service configuration, target "MariaDB: my.cnf editor".

Running queries ​

Settings › Databases also has a Running queries (all accounts) card: a live list of MariaDB and PostgreSQL connections per account, refreshed every 5 seconds, with Stop to cancel a query or close a connection. With a shared external endpoint, each server only lists and stops connections of its own accounts. Per-account database load over time is shown in Resource usage. See Resource usage › Database load.

Slow queries ​

The Slow queries (all accounts) table shows the slowest queries on the server, from the MariaDB slow query log.

  • Queries are grouped by database and query shape.
  • Literal values are replaced with ?, so customer data is not shown.
  • Columns: query, database, user, count, total/max time, average rows examined, and last seen.
  • Period: the last 24 hours or 7 days.

TIP

Turn on slow_query_log through the tuning recommendations if this table is empty. Queries that read many rows usually need an index on the columns in WHERE or JOIN.

Table maintenance per account ​

The Database optimizer card is in the account's Databases tab (admin) and on the client panel's Databases page.

Table maintenance ​

Choose an action for one database:

ActionMariaDBPostgreSQL
CheckChecks the tables.Dead row report per table.
AnalyzeUpdates statistics.ANALYZE
OptimizeRebuilds tables (InnoDB: recreate + analyze).VACUUM (ANALYZE)
RepairRepairs tables. Tables are locked briefly.REINDEX DATABASE

The result is a status per table. Every action is recorded in the audit log.

WARNING

Optimize and Repair can lock tables. Run them outside busy hours.

Tables that need attention ​

The Tables that need attention card flags tables that:

  • have no primary key;
  • have no index at all (1,000 rows or more);
  • still use MyISAM;
  • have a lot of wasted space or dead rows.

The card also shows the slow queries of that account only.

MySQL Governor (CloudLinux) ​

On CloudLinux servers, MySQL Governor limits MariaDB usage per account. Accounts that exceed their limits are put into their own LVE. The MySQL Governor card is in the CloudLinux tab of the server's details.

Installing ​

  1. Read Before you install:
    • MariaDB packages are replaced with the CloudLinux build of the same version, and MariaDB restarts;
    • all databases are dumped first to /var/backups/moorcp on the server.
  2. Leave Start in monitoring mode (off) ticked.
  3. Click Install MySQL Governor, then confirm.

Only admins can install it. The install takes a few minutes. If it fails, the card shows the log and the database backup location, with a Retry install button.

Modes ​

ModeBehavior
offOnly monitors and records usage. Nothing is restricted.
abusersAccounts that exceed their limits are restricted to their LVE.

TIP

Start in off mode. Move to abusers once the limits look right against real usage.

Limits ​

Click Edit on Default limits or on an account's row. Fill in:

  • CPU (%; 100 = one core);
  • Read (MB/s) and Write (MB/s);
  • Slow SELECT limit (seconds): only applies when stopping slow queries is on.

The panel fills the current-period limits. The short, mid, and long limits are derived automatically with CloudLinux coefficients.

Other per-account actions: Ignore, Watch, Use default, and Unrestrict. Unrestrict all releases every account that is currently restricted.

Stopping slow SELECT queries ​

Turn on Stop slow SELECT queries to stop SELECT queries that run longer than the account's limit. Governor checks periodically, so a query can run a little longer than its limit. Queries other than SELECT are not stopped. Turning this feature on or off restarts db_governor.

Database user map ​

Governor maps MariaDB users <account>_* to accounts. The map is updated automatically every 10 minutes. Click Sync user map to update it now, for example after creating a new database user.

INFO

Long queries that were already running before the account was restricted are not moved into the LVE. Use slow query stopping for cases like that.

See also ​

MoorCP Shared, a shared hosting panel for server fleets.