DbSchemaCLI
DbSchemaCLI is the command-line client of DbSchema: a program that you control by typing commands in a terminal, instead of using menus. It connects to databases through JDBC drivers, the files that let a Java program talk to a database. It runs SQL and Groovy on one database or on several at once. It also runs script files, for example in a scheduled task that the operating system starts at a set time. And it hosts the Floating License Server for teams.
DbSchemaCLI comes with every DbSchema installation. On Windows, it is DbSchemaCLI.exe in the DbSchema folder.
The examples on this page connect to a PostgreSQL database shopdb, with the schema shop. Change these names to those of your own database.
Start DbSchemaCLI
- Open a terminal, a window where you type commands.
- Run DbSchemaCLI, such as
"C:\Program Files\DbSchema\DbSchemaCLI.exe"on Windows. - Type
helpto list every command.
Not Connected > help
Define connections in 'C:\Users\you\.DbSchema\config\cli\init.sql' file.:
...
Connectivity Commands
register driver <rdbms> <className> <url> Register JDBC Driver. ...
download driver <db_name> Download JDBC driver from repository for a given database. ...
connection <alias> -d <dbms> (-h <host> | -url <jdbcUrl>) [-P <port>] [-D <db>] [-u <user>] [-p <password>] ... Create a database connection. ...
connection group <alias> <con1>,<con2>... Create a group of connections. ...
connect [-q] <con1>,<group1>,... [exclude <con3>,...] Connect to the defined connection or connection group. ...
show connections Shows currently connected databases.
check network <url> Check whether a URL is reachable with the configured proxy and certificate trust. ...
...
All other commands will be executed in the database.
Not Connected > is the prompt: DbSchemaCLI prints it, and you type the command after it.
The prompt shows the connection that you work with, or Not Connected.
Type exit to quit.
In the command descriptions, replace a word in < > with your own value, such as a host name.
A part in [ ] is optional, and | separates two choices. Do not type the brackets.
Each line of DbSchemaCLI output starts with information such as the time and the label 「STDOUT」. For example: 12:03:46.467 I {main} 「STDOUT」: Selected 3 rows.
The examples on this page omit this information.
Define a connection
A connection has a name and the details that DbSchemaCLI needs to reach the database.
The connection command takes the name first, then options:
connection <name> -d <dbms> -h <host> [-P <port>] [-D <database>] [-u <user>] [-p <password>]
| Option | Meaning |
|---|---|
-d, --dbms | The database type, as DbSchema names it, such as PostgreSQL, MySql, SqlServer, Oracle or Sqlite. Required. |
-h, --host | The computer where the database runs. Required, unless you give -url. |
-P, --port | The network port number of the database. |
-D, --db | The database. |
-u, --user | The user. |
-p, --password | The password. |
-url, --url | A full JDBC URL, instead of the host, port and database. |
The options are case-sensitive: -P is the port, and -p is the password.
Not Connected > connection shop -d PostgreSQL -h 127.0.0.1 -P 55432 -D shopdb -u postgres -p <password>
Ok
A JDBC URL combines the host, the port and the database name into a single address:
Not Connected > connection shop2 -d PostgreSQL -url jdbc:postgresql://127.0.0.1:55432/shopdb -u postgres -p <password>
Ok
The connection command only stores the details. connect opens the connection and tests it.
If the JDBC driver of the database is missing, the connection command downloads it.
A connection that you define this way is available only until you close DbSchemaCLI.
Connections saved in DbSchema are also available in DbSchemaCLI, with the same names.
show connections lists all of them under Available.
Connect and run SQL
- Type
connectand the connection name. - Type a query. A query ends with
;, and it can span several lines.
Not Connected > connect shop
Connected
shop > select customer_id, first_name, last_name from shop.customers order by customer_id limit 3;
customer_id | first_name | last_name
-------------+-------------+-----------
1 | Leo | Dubois
2 | Ioana | Garcia
3 | Liam | Miller
Selected 3 rows.
show connections lists the connection in use, under Connected, and every connection that you can connect to.
Keep connections in init.sql
DbSchemaCLI runs the file init.sql each time it starts.
Add your connection commands to this file to make the connections available every time you start DbSchemaCLI.
The first line of help gives the path of the file, such as C:\Users\you\.DbSchema\config\cli\init.sql on Windows.
DbSchemaCLI creates the file the first time it starts.
connection shop -d PostgreSQL -h 127.0.0.1 -P 55432 -D shopdb -u postgres -p <password>
connection shop2 -d PostgreSQL -h 10.0.0.12 -P 5432 -D shopdb -u postgres -p <password>
The file holds the passwords as plain text, without encryption. Make sure that only you can read it.
Run SQL on several databases at once
Type several connection names after connect, with commas between them.
Each query then runs in every database.
DbSchemaCLI shows the result of each database below its connection name.
Not Connected > connect shop,shop2
Connected 2
shop,shop2 > select count(*) as customers from shop.customers;
shop
customers
----------
200
Selected 1 rows.
shop2
customers
----------
200
Selected 1 rows.
Run Groovy
Groovy is a programming language similar to Java.
With Groovy, you can process the result of a query one row at a time, and print the information that you need.
Start a Groovy block with groovy. End the block with / on a line of its own.
Inside the Groovy block, the variable sql holds the database connection as a Groovy Sql object.
shop > groovy
sql.eachRow("select status, count(*) as n from shop.orders group by status order by status") { r ->
println "${r.status}: ${r.n}"
}
/
shop > CANCELLED: 130
DELIVERED: 748
NEW: 128
PAID: 247
SHIPPED: 247
Ok
DbSchemaCLI prints the connection prompt before the output of the block. While several connections are active, the block runs once for each of them.
Run a script file
A script file holds commands, such as SQL queries and groovy blocks.
Run a script from DbSchemaCLI
execute runs a script file:
shop > execute C:/scripts/top-customers.sql
Run a script when DbSchemaCLI starts
Give the full path of the file when you start DbSchemaCLI. DbSchemaCLI runs the commands of the file and then quits, so you can run it from a scheduled task.
"C:\Program Files\DbSchema\DbSchemaCLI.exe" C:/scripts/report.sql
Here report.sql defines its connection, runs a query and a Groovy block:
connection shop -d PostgreSQL -h 127.0.0.1 -P 55432 -D shopdb -u postgres -p <password>
connect shop
select status, count(*) as orders from shop.orders group by status order by status;
groovy
sql.eachRow("select count(*) as n from shop.customers") { r ->
println "Customers: ${r.n}"
}
/
The output ends with the result of the Groovy block:
shop > Customers: 200
Ok
Groovy files and their arguments
DbSchemaCLI also runs a .groovy file, with execute or when it starts.
Put the Groovy code that reads the database in a groovy block of a .sql file, as report.sql shows.
In a .groovy file, sql holds a DbSchema connection, not a Groovy Sql object. For this reason, eachRow does not work there.
You can pass arguments to a .groovy file by writing them after the file path when you start DbSchemaCLI.
In DbSchemaCLI.exe C:/scripts/check.groovy 2026-11, the script finds 2026-11 in args[0], its first argument.
A .sql file takes no arguments.
Change the DbSchemaCLI settings
DbSchemaCLI uses the settings from DbSchema. In DbSchema, choose Edit → Settings, then Command Line (DbSchemaCLI) in the tree. Its four pages are Execution, Mail Server, Scheduled Jobs (Cron) and Spool Output.
Inside DbSchemaCLI, vset changes a setting until you close DbSchemaCLI:
Not Connected > vset cli.settings.ignore_errors=false
Property Set
Check the network
A driver download or a connection can fail because of the network.
check network shows the proxy and the certificate trust settings.
The certificate trust settings decide which secure servers DbSchemaCLI trusts.
check network then uses these settings to request the URL.
Not Connected > check network https://dbschema.com
Network settings in use:
Proxy: detected from the operating system and the JVM settings
TLS trust: the JVM trust store, the operating system trust store
Reached [https://dbschema.com]: 200
The response code 200 means that the web request succeeded. Firewall, proxy and SSH explains how to change these settings.
Host the Floating License Server
A floating license lets a team share a number of DbSchema seats.
A team with a floating license can run the license server inside DbSchemaCLI.
Licensing shows the commands, register and license server.
Common problems
"Missing required option: d"
The connection command is missing the required option -d, the database type.
Write the details as options, as Define a connection shows.
"The connection needs the database host with -h, or the JDBC URL with -url."
Add the host with -h, or give the whole JDBC URL with -url.
"No DBMS is named ..."
DbSchemaCLI does not know the database type that follows -d.
Use the name that DbSchema gives the database, such as PostgreSQL or SqlServer.
You can write it in uppercase or lowercase letters.
A Groovy file run with execute fails on sql.eachRow
When DbSchemaCLI runs a .groovy file, the variable sql holds a DbSchema connection rather than a Groovy Sql object.
Calling eachRow fails with the error "No signature of method: eachRow". Other Groovy Sql methods fail too.
Put the Groovy code in a groovy block that ends with /, inside a .sql file, as report.sql above shows.
DbSchemaCLI says it cannot find the script file
Give the full path of the file, such as C:/scripts/report.sql.
On Windows, DbSchemaCLI.exe may not find a file that you give by its name only.