Run SQL

Last modified 01 Sep 2026 13:19 UTC

The run-sql command executes SQL scripts on the midPoint database.

Database schema changes are performed using SQL scripts that are bundled with the distribution and stored in doc/config/sql/native/*.sql folder. User selects the scripts to run using the following options:

  • --create executes scripts that create the database schema from scratch.

  • --upgrade upgrades an existing database schema.

    • You can combine this with --mode set to either REPOSITORY or AUDIT to upgrade repository or audit schema selectively.

The run-sql command can be also used to execute custom scripts using the --scripts option, which accepts a path to an SQL script file.

The script set specified using the --scripts option does not need to be located in doc/config/sql/native/. Any SQL script accessible by the midPoint deployment can be executed.

The --result option prints the results of executed SQL statements (including query output) to the standard output (SYSOUT). This option is particularly useful when executing custom SQL scripts using the --scripts option, as it allows users to inspect query results directly from the command line.

Ninja by default uses repository/audit configuration from midpoint-home/config.xml to connect to database. This behaviour can be changed via --jdbc-url, --jdbc-username and --jdbc-password options. With these options, ninja will switch to raw mode, create custom JDBC connection and execute scripts on it.

If you do not want to provide the password directly on the command line, use the --jdbc-ask-password option. Ninja will prompt you to enter the password interactively, preventing it from being displayed in the command history or process list.

Example runs custom-upgrade-database.sql script on JDBC connection specified by url/username/password
./bin/ninja.sh run-sql \
  --jdbc-url jdbc:postgresql://localhost:5432/postgres \
  --jdbc-username postgres \
  --jdbc-password postgres \
  --scripts ./custom-upgrade-database.sql
This example runs upgrade scripts for repository on database defined in midpoint-home/config.xml
./bin/ninja.sh run-sql \
  --mode repository \
  --upgrade
Following example runs upgrade scripts for audit on database defined in midpoint-home/config.xml
./bin/ninja.sh run-sql \
  --mode audit \
  --upgrade
This example runs custom defined scripts for repository on database defined in midpoint-home/config.xml
./bin/ninja.sh run-sql \
  --mode repository \
  --scripts ./upgrade/new-distribution/doc/config/sql/native/postgres-upgrade.sql
Was this page helpful?
YES NO
Thanks for your feedback