How to migrate the metabase from SQLite to SQL Server with qmeta#
Querona keeps its own metadata - virtual databases, logins, roles, connections, credentials, jobs and their history - in the metabase. An installation can start on a SQLite metabase, a single file on the Querona server, and migrate to a SQL Server metabase later, for example to run Querona as a two-node cluster, which requires SQL Server.
The migration is done with qmeta, a command-line tool that the installer puts in the bin folder of the
Querona installation - the destination folder chosen during installation, C:\Program Files\YouNeedIT\Querona by
default. Every build ships its own qmeta: the tool carries the metabase schema of its build and works only with a
metabase at that schema version, so the qmeta to run is always the one of the installed build. It has three
commands:
statuschecks a metabase against the installed build and reports what a migration depends on: the schema version, the master key, the stored secrets, the initial passwords and the Hive metastore (see Check the metabase). It changes nothing.migratecopies a SQLite metabase into an empty SQL Server database, keeping every row and every id, and switches the server to the new metabase.deploycreates a new, empty metabase in an empty SQL Server database without the installer.
qmeta without arguments lists the commands; qmeta <command> --help lists a command’s options. On a console
the verdict of a command is green, a line that needs acting on but blocks nothing is yellow and prefixed
Warning:, and what refuses a command or would refuse a migration is red and prefixed Error:. The text is the
same when the output goes to a file or a pipe, where no colors are used; setting the NO_COLOR environment variable
turns them off on a console too. Errors go to the standard error and everything else to the standard output, so
redirect both to keep a whole report, for example qmeta status ... > report.txt 2>&1.
Note
Switching the metabase engine in the installer does not migrate the metabase: it creates a new, empty one. Use
qmeta migrate to keep your metadata.
How the metabase schema is versioned#
The metabase schema is built and changed by numbered migrations that ship inside every Querona build. A migration
number is YYDDDHHMM: the two-digit year and the day of the year it was written, then the hour and minute it
was written - 262901854 stands for the 290th day of 2026 at 18:54. Older migrations carry a four-digit
sequence within the day instead of the time - 262830000 is the first migration of the 283rd day of 2026 - and
numbers of both kinds sort together by date. The installer applies, in ascending order,
every migration of the build that the metabase has not seen yet, and records each one in the journal table
VersionInfo with its number, its description and the time it was applied. A metabase is therefore at the schema
version of a build when its journal holds every migration number that build carries.
qmeta carries the same migrations as the Querona build it was installed with, and it compares them with the
journal of the metabase it is given:
A migration of the build that the journal does not hold is reported as missing: the metabase is behind the build.
migraterefuses, because it would copy rows into tables or columns that the migration shapes differently; upgrade with the installer first.A journal entry with a number above the build’s highest migration is reported as newer than this build: the metabase was used by a later build.
migraterefuses, because this build does not know that schema; run theqmetaof that later build.A journal entry with a number below the build’s highest migration that the build does not carry - typically left by a development build, or by a migration that was later consolidated - is reported as a warning.
migratecopies the rows but not that journal entry, so the new metabase records exactly the migrations of the build.A journal description that differs from the build’s description of the same number is reported as a warning only; the number is what identifies a migration.
An empty journal - a metabase whose first deployment never completed - is reported as an error; such a metabase has to be created again.
Example of a migration from the journal’s point of view#
The numbers below are illustrative. A server was installed from a build whose newest migration was 262520000, and
its SQLite metabase has been in use since. The build to be installed now carries migrations up to 262830000.
Running the new build’s
qmeta statusagainst the SQLite metabase before the upgrade reports that the metabase lacks migrations of this build - how many, from262570000to262830000- that this build needs schema version262830000, and that the upgrade with the installer comes first;migratewould refuse.The installer upgrades Querona. It applies
262570000through262830000to the SQLite metabase and journals each of them;qmeta statusnow reportsThe metabase is at this build's schema version, 262830000.qmeta migrate --dry-runfinds no problem, andqmeta migratewith--update-instance-configcopies the rows into the empty SQL Server database, whose schemaqmetacreated with the same migrations, and switches the server to it. The new journal holds the same numbers as the old one.Had the SQLite metabase been used in the meantime by a newer build - say one carrying
262900000-qmeta statuswould report that the metabase holds a migration newer than this build,262900000, while this build’s schema version is262830000, andmigratewould refuse; theqmetaof that newer build is the one to run.
Prerequisites#
The SQLite metabase is at the schema version of the installed build. Upgrade Querona with the installer first, then run the
qmetaof the upgraded installation.Every Querona service using the metabase is stopped.
qmetadoes not check this; rows written while it runs are not copied.A database administrator has created an empty database on the target SQL Server with a case-insensitive collation, and the login
qmetaconnects with isdb_ownerof that database:CREATE DATABASE QueronaMeta COLLATE SQL_Latin1_General_CP1_CI_AS;
Run
qmetaon the Querona server whose metabase you are migrating. Its master key file,master-key.dpapi1in the configuration folder, opens the credentials stored in the metabase only on this machine.
Tip
A connection-string argument never has to carry a password in the open: @env:NAME takes the connection string
from the environment variable NAME, and @path from a file, so that nothing appears in the process list or
the command history. See Keeping passwords out of files. A SQLite metabase needs no connection string at all:
the path of its file is enough. In PowerShell, quote an argument that starts with @ - "@target.txt",
"@env:QMETA_TARGET" - which PowerShell would otherwise read as splatting; the quotes do no harm in cmd.exe.
Check the metabase#
qmeta status --database C:\ProgramData\Querona\qmeta.db --instance-config "C:\ProgramData\Querona\conf\instance.config"
A SQLite metabase is named by the path of its file, or by a connection string such as
"Data Source=C:\ProgramData\Querona\qmeta.db"; a SQL Server metabase by a connection string. A value that is
neither a connection string nor an existing file, a file that is not a SQLite database, or a SQLite file that does not
exist is refused with the name of the option it was given with. --target and --engine-connection take only a
SQL Server connection string: a file given there by mistake is refused with a reminder to write @ before it. A
refusal never shows a connection string, which may hold a password.
The report answers the questions a migration depends on and says what to do. A line reported as an error (red) is
what migrate would refuse the metabase for; a warning (yellow) is worth acting on but does not block the migration.
For a SQLite metabase the last line is the verdict: ready to migrate - the schema allows migrate, whose dry run then
checks every row - or not ready. A SQL Server metabase gets no verdict, because migrate reads only SQLite. The
command exits with 0 whenever it produced the report.
whether the metabase is at the schema version this build needs; otherwise which migrations of the build it lacks (upgrade with the installer first) or which newer ones it holds (run that build’s
qmeta), with the version this build needs;whether this server’s key file opens the master key stored in the metabase - with
--instance-config, which names the server’s configuration - and a warning when it would keepmigrate --update-instance-configfrom switching the server;how many stored secrets the Querona service has not yet moved under the master key;
which logins still have the default password: the administrator’s is changed in the Admin Portal, while the Spark reverse account’s is managed by Querona and changes only with a new metabase (a new installation or
qmeta deploy);whether Spark keeps its Hive metastore in an embedded Derby database (see the warning under Migrate the metabase).
Migrate the metabase#
Run a dry run. It checks every row against the SQL Server schema and leaves the target database empty:
qmeta migrate --source C:\ProgramData\Querona\qmeta.db --target "@target.txt" --dry-run
target.txtholds the connection string of thedb_ownerlogin. It must name the database, for exampleServer=sql01;Database=QueronaMeta;Integrated Security=true;Encrypt=true.Correct what the dry run refuses (see What qmeta refuses), with the Querona service started on the SQLite metabase or with
sqlite3, and repeat the dry run until it passes.Run the migration and switch the server to the new metabase:
qmeta migrate --source C:\ProgramData\Querona\qmeta.db --target "@target.txt" --instance-config "C:\ProgramData\Querona\conf\instance.config" --update-instance-config --engine-connection "@engine.txt"
engine.txtholds the connection string the Querona service will use - not thedb_ownerlogin’s - and names the same database. Before it copies any data,qmetachecks that this connection reaches the new metabase - the same server and database, however the server is spelled - and refuses the migration when it does not. With SQL Server authentication it signs in exactly as the service will, which also proves the service’s right to read the metabase. With integrated security, or a Microsoft Entra method that signs in as the service’s own identity, it checks the server and database with your own sign-in and reminds you to give the service’s identity a login, a user in the database, and thedb_datareaderanddb_datawriterroles, as the installer does.qmetacopies the server’s master key file andinstance.configbefore it changes them; the copies are left beside the originals, namedqmeta-<time>-<file name>.bak. Without--update-instance-configit prints the two settings to change instead.Start the Querona service.
The SQLite file is not changed and stays where it is. To go back, stop the service, restore the instance.config
copy and start the service again.
Warning
When the report says that Spark keeps its Hive metastore in an embedded Derby database, Spark keeps working after
the migration. The next installer run on a server whose metabase is on SQL Server, however, points the metastore
at the SparkMetastore database, and the tables registered in Derby are no longer seen. Querona has no tool
that carries a metastore from Derby to SQL Server: before you upgrade Querona again, list the databases and
tables registered in Derby (SHOW DATABASES and SHOW TABLES in Spark), and re-create them in the
SparkMetastore database after the upgrade. The data files are not touched by either step.
What qmeta changes and what it keeps#
Every row is copied with its ids. Date and time values keep the clock value they were written with; a
datetimecolumn keeps it to 1/300 of a second, as SQL Server does for any value.The identifier generators continue above every id the SQLite metabase has handed out, deleted ones included.
A row that refers to a row deleted earlier is left out when SQL Server would have deleted it with its parent (for example the usage statistics of a dropped table), and the report lists it. An owner that refers to a dropped login is cleared, as dropping the login means.
Migration history entries of migrations this build does not include are not copied.
Stored passwords and keys are copied as they are;
qmetanever decrypts them.
What qmeta refuses#
A migration that would change data silently is refused, with the table, the row key and the column of every problem:
a reference to a row that does not exist;
a
NULLin a column that does not accept it;text or binary data longer than its column;
a character that a non-Unicode column cannot hold, for example
Łin a column stored in code page 1252;two names that differ only in letter case or trailing spaces where they must be unique;
a date before 1753 in a
datetimecolumn, or a date and time in a form Querona does not write;a table or column the build’s schema does not have.
A refused or failed run removes everything it created, so the target database is empty again and the command can be run
once more. If qmeta itself is stopped during a migration, drop and re-create the target database before running it
again.
One failure keeps what it created: when the data was committed but instance.config could not be switched - the
file is locked, for example - the migrated metabase stays in the target database. The report says so and names the two
settings to set by hand in instance.config; do not run the migration again, because the target is no longer empty.
Create a new metabase without the installer#
qmeta deploy --target "@target.txt" --instance-config "C:\ProgramData\Querona\conf\instance.config" --admin-login qadmin
deploy creates the schema, renames the administrator to the login given and asks for its password at the console
twice, the second time to confirm it (the keystrokes are not echoed), and gives the Spark reverse account a new
password. It asks only once every check that needs no password has passed, so a run that is refused does not ask. Ports, the certificate, Spark
directories and the Hive metastore keep their initial values, and the service account has no access to the database
yet: set them in the portal or with an installer run.
When nobody can answer the prompt, the password is piped into qmeta on the standard input instead; see the next
section. A password is never read from a file or from the command line.
Keeping passwords out of files#
Two secrets can be involved in a run: the administrator password that deploy sets, and a password inside a
connection string when the target uses SQL Server authentication. Neither needs a file:
The administrator password is typed at the prompt, or piped on the standard input when the run is unattended; then
qmetasays on the standard error that it reads the standard input, so a run whose input never ends shows why it waits. The piped text must be UTF-8, which PowerShell 7 sends to a native command. In Windows PowerShell 5.1, set$OutputEncoding = [Text.UTF8Encoding]::new($false)first: its default sends every character outside ASCII as?. A byte-order mark at the start is not part of the password, and text that is not UTF-8 is refused.A connection string is given as
@env:NAME, taken from an environment variable the shell sets for the duration of the session, or as@pathfrom a file. With integrated security, as in the examples above, the connection string holds no password at all, which is the recommended form.
From PowerShell, with the administrator password read into a SecureString and the connection strings in
environment variables of the session:
$password = Read-Host -AsSecureString "Administrator password"
$env:QMETA_TARGET = "Server=sql01;Database=QueronaMeta;Integrated Security=true;Encrypt=true"
[Net.NetworkCredential]::new('', $password).Password |
qmeta deploy --target "@env:QMETA_TARGET" --instance-config "C:\ProgramData\Querona\conf\instance.config" --admin-login qadmin
Remove-Item Env:\QMETA_TARGET
The SecureString is decrypted only for the pipe, in the memory of the shell. An automation that keeps its secrets
in a vault does the same with the value the vault returns, for example (Get-Secret QmetaAdmin -AsPlainText) |
qmeta deploy ... with the SecretManagement module, or $env:QMETA_ADMIN_PASSWORD | qmeta deploy ... when the
pipeline injects the secret as an environment variable. Nothing is written to disk in any of these forms.
Exit codes#
Code |
Meaning |
|---|---|
0 |
The command completed successfully. For |
1 |
The command was refused; the report says why, and nothing was changed. |
2 |
The command line could not be parsed. |
3 |
An unexpected failure; anything the command had created was removed where possible. The exception is a migration
whose data was committed but whose |