Moodle external database enrolment from a student information system

Syncing course enrolments from an SIS or HR database view into Moodle, with required fields, role mapping, course creation and safe unenrolment handling.

On this page

Moodle external database enrolment from a student information system: when it fits

Choose external database enrolment when the registrar or learning team already keeps authoritative course rosters in a student information system (SIS) or HR database, and those rosters must match Moodle every term without anyone re-keying them. The external database enrolment plugin (enrol_database) reads a database view that you publish from the source system. On each sync run it enrols users into courses, updates their roles and removes enrolments that have disappeared from the view. Depending on configuration it can also create courses from rows in the same view. The plugin does not decide who belongs in a course. That decision stays in the SIS, and Moodle only copies it. Before committing, confirm with your SIS administrator that the view can be exposed read-only to the Moodle database connection and that it returns one row per user per course with stable identifiers.

Compare this with the alternatives before you build. A flat file feed suits legacy systems that can only export files, but it adds file permissions and monitoring work. Web services suit cases where Moodle must receive changes in near real time or where the source system pushes updates, and they require service accounts, token scope and error handling on both sides. Database enrolment is usually the simplest option when the source can expose a stable view and a scheduled pull is acceptable. Note what the plugin does not do on its own: it does not provision accounts (users must already exist in Moodle through an authentication plugin or another process), it does not validate that a course should exist, and it does not protect you from a broken view that returns zero rows, which can unenrol a whole cohort in one run.

Confirm the Moodle version you will run before you design the view, because course creation fields and sync behaviour have changed between releases. The Moodle 4.5 release notes state that external database course creation can now include start and end dates, so check whether your target version supports the dates your SIS holds. Also agree who owns the view, who can change its columns and how a failed or empty sync is detected and reported. A short illustrative scenario helps: if a registrar renames a column in the view during term start, the sync may stop matching users and enrolments silently, so the view contract needs change control from the start.

Configuration options and when each fits

The connection settings decide what Moodle can read and how far its access reaches. Most teams point the plugin at a database view that exposes only the columns the sync needs, not at the SIS base tables. A view lets the source team change internal structures without breaking Moodle, and it keeps personal fields that enrolment does not need out of reach. Connection settings cover the database type, host, database name, user, password, the remote table or view name, and the character encoding. Confirm each setting name on the enrolment plugin page of your Moodle version before you rely on it.

  • Read-only service account: Create an account that can only select from the view. Moodle does not need write access to the SIS.
  • Database type and driver: Match the type to the engine the SIS actually runs. The available types come from the plugin's settings page, and the PHP extension for that engine must be installed on the Moodle web and cron servers.
  • Encoding and quoting: Set the encoding to match the source data. Mismatched encodings often show up as names that look correct in the source but arrive garbled in Moodle.
  • Network path: The Moodle server must reach the database port through the firewall and any network segmentation between the two systems.
  • Credential storage: The database password is stored in Moodle's configuration, so restrict who can view the plugin settings.

Before the first sync, check that a test query from the Moodle server returns the expected rows from the view.

How to set up the database view and sync

This sequence moves the SIS feed from an agreed contract to a verified, scheduled enrolment sync. Each step ends with a check so the team knows the data, the account and the plugin behave before real enrolments change.

  1. Agree the view contract with the SIS owner

    The Moodle lead and the SIS or HR data owner agree in writing which view or table Moodle will read, the column names, data types, allowed values for role and status, and how a withdrawn or graduated student appears. Agree who owns the view, how changes are announced and who approves a schema change. Done means both parties sign off a short contract document that lists every column Moodle depends on, with one example row per enrolment type. Check the contract against a sample extract before anything else is built, so mismatches surface while changes are still cheap.

  2. Create a read-only database account

    The database administrator creates a dedicated account for Moodle that can only select from the agreed view, with no rights on base tables, no write permissions and no access to other schemas. The account password is stored in the server's secrets process and not in the Moodle admin screens or version control. Confirm the account works by connecting with the database client from the Moodle web server and running a select on the view. Then attempt an insert or update with the same account and confirm it is refused. Both checks must pass before continuing.

  3. Enable and configure the enrolment plugin

    The Moodle administrator enables the External database enrolment plugin from the site administration plugin screen and enters the database type, host, database name, the read-only account and the view name. Map the remote fields for the user identifier, course identifier, role and status to the names agreed in the contract, and set the course creation options if courses come from the same table. Save the settings and run the connection test built into the plugin. Done means the test reports a successful connection and returns the expected column names. If the test fails, check the database driver, the network path from the web server and the account's grants before changing the mapping.

  4. Run a dry test against a copy of production data

    The Moodle lead restores a recent copy of the SIS data into a non-production database, points a staging Moodle site at that copy, and runs the enrolment sync manually. Record the counts of users, enrolments and unenrolments before and after the run, and review a sample of courses and roles by hand. Pay particular attention to students who withdrew, staff who changed role and courses that are missing from the view. Repeat the run to confirm it produces the same result, which shows the sync is idempotent. Sign-off is a written test log that the SIS owner and the course administrator both accept.

  5. Decide how unenrolments are handled

    Before turning on production sync, the team sets the policy for students and staff who disappear from the view. Options include suspending the enrolment, removing it, or only removing enrolments the plugin created itself. Removing enrolments can delete a student's grades and access, so most teams start with suspension and review manual enrolments separately. Test a withdrawal in staging and confirm the learner loses course access while the record and grades remain. Write the decision into the runbook so course administrators know what they will see after each run.

  6. Schedule the sync task and set alerts

    The Moodle administrator schedules the external database enrolment sync as a scheduled task under the site's cron configuration and sets the frequency the SIS owner agreed to. Confirm the server's cron job runs as the expected system user and that the task appears in the scheduled task log after its first run. Add monitoring that alerts the Moodle team when a run fails, returns zero rows where rows are expected, or takes unusually long. Done means a test run in production-like conditions completes on schedule and the alert fires when a deliberately broken connection is simulated in staging.

  7. Verify enrolments, roles and course records

    After the first production run, the course administrator checks a defined sample of learners, teachers and courses against the SIS extract. Verify that each enrolment exists with the correct role, that status values produce the expected suspended or active state, and that new course records carry the names, identifiers and start and end dates supplied by the view. Review the enrolment and task logs for errors. Record the results and keep the sample list so it can be repeated after each upgrade, plugin change or schema change in the SIS.

Securing the database connection and enrolment changes

The external database enrolment plugin gives a Moodle site a direct read path into your student information system, so the connection and the enrolment changes it triggers deserve the same controls as any other system holding personal data. The cards below cover the database account, the network path, secret handling, the scope of the view and the monitoring that catches a bad sync before students lose course access.

Read-only service account

Create a dedicated database account for Moodle that holds only SELECT on the enrolment view. It should have no write, delete or schema privileges, and no access to other tables. Confirm this by logging in as the account and attempting an insert against the view and a select against a base table; both should fail. Keep the account separate from any account your reporting or integration teams use, so revoking one does not break the other.

Network path and TLS

Restrict the database port so only the Moodle web and cron servers can reach it, using firewall rules or a private network segment. Require TLS on the connection and confirm the certificate chain is trusted by the Moodle servers, not just accepted by default. Ask your database team to show the server listens on encrypted connections and that plaintext connections are refused for this account.

Credential storage

Keep the database password out of web-visible files and out of version control. Store it in a file readable only by the web server and cron user, or in your secrets manager if your Moodle hosting injects it at runtime. Set a rotation date, and check that the plugin settings screen does not echo the password back in a form that administrators or logs can read.

Minimal columns in the view

Build the enrolment view to expose only the fields the sync needs: a stable user identifier, the course identifier, the role code and the enrolment status. Leave out national identifiers, dates of birth, health or disciplinary fields and free-text notes. Ask the data owner to sign off the column list, and re-check it when the SIS schema changes, since new columns can appear in a view that selects all fields.

Bulk unenrolment alerts

Unenrolments are the change most likely to cause harm when a source table is empty, truncated or mis-joined. Set a threshold for how many enrolments a single run may remove, and have the run stop or raise an alert when it is exceeded. Confirm who receives the alert, how quickly they are expected to respond, and whether a held run can be released without a manual database edit.

Sync logs and review

Turn on the Moodle log and task output for the enrolment sync, and keep it for a period agreed with your records and security teams. Compare a sample of course memberships against the SIS each term. Test the controls before go-live by removing a test enrolment in the source view and confirming the expected log entry and alert appear.

How the sync treats removed students and courses

The external database enrolment plugin in Moodle does not read the whole view as a fresh list on each run. It compares the rows it sees with the enrolments it previously created from that source, and when a student or course membership is no longer present, the plugin can remove the enrolment. The exact behaviour depends on the remove action settings for unenrolment and course handling, so confirm each setting in the plugin configuration of your version before go-live, and test it with one course rather than assuming the default is safe. Role changes work differently: when the role field in the view changes for an existing enrolment, the plugin updates the role on the next run, so a teacher moved to a student role loses teaching permissions at the next sync, not at the end of the term.

Renames and deletions of courses need separate handling. The plugin matches courses on the course identifier field you map, not on the full name, so renaming a course in the SIS view usually updates the existing Moodle course only if the short name or identifier is unchanged. If the identifier changes, the plugin may create a new empty course and leave the old one holding grades and submissions. Ask your SIS team whether course codes are stable across years, and decide in advance whether a removed course should be hidden, archived or deleted in Moodle. Deletion is irreversible without a backup, so treat it as a manual step.

The practical risk is mass unenrolment from a bad or empty view. If the view fails, is filtered by a wrong term code, or returns no rows because of a permissions change on the database user, every synced enrolment can be removed in one run and students lose access to courses in the middle of an assessment window. Guard against this before go-live by testing with a copy of the view, adding a check that the row count is within an expected range before removal, keeping the database account read-only and restricted to the view, and confirming with Moodle's logs and task output that a run reports the counts it intends to remove. Agree a manual review step for large removals, and rehearse restoring enrolments from a recent backup so the recovery path is known, not assumed.

How SIS data flows into Moodle enrolments

The flow starts in the student information system, where a read-only database account reads a view that exposes only the enrolment fields Moodle needs. The external database enrolment sync task in Moodle reads that view on its schedule, applies the role and course mapping, and writes enrolments and course records into the Moodle database. The trust boundary sits between the SIS network and Moodle, so check that the account cannot write to the SIS, that only the agreed columns are exposed, and that the sync log shows what changed on each run.

Enrolment data moves one way from the SIS view into Moodle across a trust boundary.

Limits to confirm in your environment

External database enrolment depends on details that sit with the SIS owner and the Moodle version you run, not with Moodle alone. The cards below list the limits to confirm before you write the sync, so that the mapping, performance and data rules are agreed in writing rather than discovered in production.

Supported database engines and drivers

The external database enrolment plugin connects to a database that Moodle can reach through a supported driver, and the SIS may run an engine your Moodle build or PHP extension set does not support cleanly. Confirm the engine and version the SIS runs, the PHP database driver available on your web servers, and whether the SIS vendor provides a read-only view or replica for integration. Check this against the Moodle version you plan to run, since the database engine versions required by Moodle 5.1 and 5.3 differ.

Moodle 5.1 minimum
PostgreSQL 15
Moodle 5.1 requirements

View performance on large rosters

Each sync run reads the external table or view, so a view that joins several SIS tables can become slow when enrolment volumes peak at the start of a term. Ask the SIS owner for expected row counts per term, whether the view is indexed on the course and student keys, and whether a materialized copy is available. Run a timed query against production-sized data before you set the sync schedule, and confirm which account the sync uses and what read rights it needs.

Multi-role users

A person can be a student in one course, a teacher in another and a course creator or staff observer elsewhere, and the SIS may store these as separate rows or as one row with a role code. Confirm whether the view returns one row per user, course and role, and how the SIS represents dual roles such as a teaching assistant who is also enrolled as a student. Decide with the SIS owner which row wins when two roles conflict, because the mapping you choose controls which capabilities each user receives.

Term-based course naming

Course short names and IDs usually come from the SIS course code and the academic term, and a naming rule that changes between terms can cause the plugin to create duplicate courses or fail to match existing ones. Agree the exact format for the course short name, full name and idnumber, and confirm how the SIS handles cross-listed sections and retired course codes. Ask who approves a new term's course codes before the first sync run that creates courses for that term.

Start and end dates from the SIS

Moodle 4.5 allows course creation from the external database to include start and end dates, so term dates can flow from the SIS instead of being set by hand. Confirm which SIS fields hold the term start and end, whether they are stored in the same time zone as your Moodle site, and whether the SIS publishes dates for every course type, including short courses and non-credit programmes. Agree who owns a date change after creation, since a later SIS edit may or may not overwrite a date an administrator has changed in Moodle.

Moodle 4.5 release notes

Questions teams ask before syncing enrolments from an SIS

What drives the cost of an external database enrolment project?

The cost depends mostly on how much work sits in the database view and the mapping rules, not on the Moodle plugin itself. The main components are view design with the SIS or registry team, mapping of statuses and roles to Moodle enrolment and role rules, course creation logic, and testing against real term data. One-time work covers design, build and cutover testing. Recurring work covers monitoring the sync, handling new programme codes each term and reviewing changes to the source schema. Ask any quote to split these components so you can see who does each one and what you will maintain afterwards.

How long does an SIS enrolment sync take to build and test?

No duration is fixed in advance because it depends on the number of data sources, how clean the SIS data is and how many term cycles you need to test. The schedule is usually set by the first full term you must test against, since enrolment changes at the start and end of terms create the most edge cases. Ask for a written timeline with separate milestones for view agreement, a build against a copy of live data, a parallel run and cutover, so you can see where the dependencies on the SIS and registry teams sit.

What must the SIS and registry teams provide before work starts?

They need to provide a stable database view or table with agreed column names, data types and a unique key for each enrolment, plus read-only database access for a service account. They should also confirm which statuses mean active, withdrawn or completed, how course codes map to Moodle course shortnames, and who owns changes to the view. Without a documented change process, a column rename in the source can silently stop enrolments from syncing, so agree a notice period for schema changes before build.

Can an internal team run an external database enrolment sync without a partner?

Yes, if the team has a Moodle administrator who can configure plugins, someone who can write and review SQL against the source database, and a named owner for the sync after go-live. The hard parts are rarely the Moodle settings. They are agreeing the data contract with the SIS team, writing safe unenrolment rules and testing with real term data. Teams that lack one of these skills often choose a fixed-scope engagement for the design and test phases, then run the sync internally with a runbook.

How do you handle unenrolments safely?

The safest approach is to unenrol only when a record is clearly withdrawn in the source, not when it is simply missing from one run. A missing row can come from a failed query, a timing issue or a bad view change, and an automatic unenrolment would then remove students from live courses. Set a clear rule for which statuses trigger removal, keep a log of every change, and consider a threshold that stops the run if the number of removals is unusually high. Test this with a copy of real term data before enabling it on production courses.

How often should the enrolment sync run?

Choose the frequency from the business need, the load on the SIS database and how quickly changes must reach Moodle. Many teams run the sync on a schedule through Moodle cron and use a more frequent run during registration or add/drop periods. Confirm with the database owner how often they can be queried, and check that the Moodle cron job runs reliably, since a stalled cron will stop all scheduled syncs without an obvious error on the page.

How are the database credentials for the sync protected?

Use a dedicated read-only database account with access limited to the agreed view or table, and no access to other schemas. Store the password in a way your security team accepts, rotate it on a schedule and record who holds it. Restrict the network path between the Moodle server and the SIS database to the required host and port, and review the account's permissions after each SIS upgrade. Ask your security team to review the design before the sync goes live.

What should be tested before the sync goes live?

Test with a copy of real term data rather than sample data, because the edge cases such as late registrations, transfers, cross-listed courses and withdrawals appear only in full data. Check that new courses are created with the right shortnames, dates and categories, that roles map correctly, that unenrolments behave as designed and that re-running the sync produces no duplicate enrolments. Keep a record of test results so the sign-off can be reviewed later by audit or compliance teams.

How DeployOpen works on this

DeployOpen plans and implements Moodle external database enrolment from a student information system inside your own infrastructure, starting with a written scope that names the source view, role mapping and unenrolment rules. The build is tested against a copy of your data, documented, and handed over so your team can run the sync day to day.

How we scope

  • Review the SIS or HR view with your data owners before any build starts
  • Agree in writing which fields, roles, course rules and sync schedule are in scope
  • Confirm the Moodle version, database engine and hosting so the plan matches your environment
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work begins

How we build

  • Configure the external database enrolment plugin against a read-only database account
  • Map SIS roles to Moodle roles and test each mapping with sample enrolments
  • Set up course creation from the external table, including start and end dates where your release supports them
  • Test suspension and removal rules on a staging copy so unenrolments cannot erase course data

How we hand over

  • Deliver configuration records, field mappings, role tables and the sync schedule as documentation
  • Provide a runbook covering failed syncs, log review, and how to pause the sync safely
  • Walk your administrators through a test cycle and record the results for your audit trail
  • Confirm with your SIS team how view changes will be communicated before go-live

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers
  • Plan retesting of the sync after each Moodle upgrade and after changes to the SIS view
  • Agree response and escalation terms in the retainer, confirmed in writing before work starts
  • Ask for a quote built from the written scope, covering one-time build work and recurring support separately

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.