snapshotReference
command
The snapshotReference
command captures the current state of the referenceURL database, which is the source database.
The snapshot
command has two modes:
- When run without options, it gathers the current state of the database and shows a text-based version of the schema to STDOUT.
- When run with the
--snapshotFormat=JSON
option, it creates a JSON file that represents the current state of the referenceURL database. Alternatively, you can have a YAML-based output by using the--snapshotFormat=yaml
attribute.
Uses
The snapshotReference
command is typically used when you want to see changes in your source database or keep a record of your current database state.
The snapshot can be used in the diff command or diffChangeLog command.
Note: It is best practice to use the --snapshotFormat=JSON
option for the diff
and diffChangeLog
commands. Otherwise, you will get only a text report of your source database. This text report cannot be used for comparison in the future.
It can also be used to compare:
- A previous database state to an online database.
- A previous database state to another snapshot.
Note: Running a diff command by using at least one snapshot.json
file is faster than using a diff
command with two online databases. However, keep in mind that a snapshot will no longer reflect the current state of the database if the database is changed with the update
command or if it is changed manually.
Running the snapshotReference
command
To run the snapshotReference
command, you need to specify your driver, class path, and URL in your liquibase.properties
file. For more information, see Creating and configuring a liquibase.properties file. You can also specify these properties in your command line.
Then run the snapshotReference
command:
liquibase snapshotReference
Note: To create a JSON file, add the --snapshotFormat=json
attribute while running the command:
liquibase --outputFile=mySnapshot.json snapshotReference --snapshotFormat=json
Note: Enter the name of the output file that you want to use in place of mySnapshot.json
. Additionally, include --snapshotFormat=json
to create a file in a JSON format.
snapshotReference
global attributes
Attributes | Definition | Requirement |
---|---|---|
--changeLogFile
|
The root changelog | Required |
--username
|
The database username | Required |
--password
|
The database password | Required |
--url
|
The JDBC database connection | Required |
|
Specifies the file path to where the snapshot JSON or YAML will be written | Optional |
* If not specified, a JSON or YAML output goes to STDOUT.
snapshotReference
command attributes
Attributes | Definition | Requirement |
---|---|---|
--snapshotFormat
|
Creates a JSON or YAML file that represents the current state of the database. | Optional |
Using the snapshot
in the diff
and diffChangeLog
commands
You can use the JSON format snapshot file in the diff
and diffChangeLog
commands. One of the typical workflows is the following:
- Make sure your local environment is up-to-date by getting the latest changelog from source control.
- Configure your
liquibase.properties
file to point to a local development database and run theupdate
command to ensure your target database matches the changelog file. -
Take a snapshot of the local development database by running the
snapshotReference
command:
liquibase --outputFile=mySnapshot.json snapshotReference --snapshotFormat=json
- Manually change the local development database if needed.
- Append changes to the changelog by running the
diffChangeLog
command:
liquibase --url=jdbc:oracle:thin://localhost:9090/mem:test --referenceUrl=offline:mysql?snapshot=mySnapshot.json diffChangeLog
Note: If you want to see changes without appending them to the changelog file, add --changeLogFile=mydiffchangelog.xml
to the diffChangeLog
command:
liquibase --url=jdbc:oracle:thin://localhost:9090/mem:test --referenceUrl=offline:mysql?snapshot=mySnapshot.json --changeLogFile=mydiffchangelog.xml diffChangeLog
Note: The format for the referenceUrl is the following: offline:<db_type>?snapshot=<path/to/snapshot.json>
. Use the name of your database type from the list of the supported databases in place of <db_type>
and the path relative to where the command is running in place of <path/to/snapshot.json>
: "offline:<db_type>?snapshot=<path/to/snapshot.json>"
.
- Review the changelog file to ensure that it matches your expectations of the manual changes that were made.
- Mark the manual changes as deployed in the local development database by running the changelogSync command:
liquibase changeLogSync
- Commit the changes to the source control.

When running the snapshotReference
command with the --snapshotFormat
attribute, the output can be as follows:
Liquibase Pro 3.8.7 by Datical licensed to Liquibase Pro Customer until Tue Sep 22 19:00:00 CDT 2020
Liquibase command 'snapshotReference' was executed successfully.
When running the snapshotReference
command without indicating the --snapshotFormat
, you receive the following output:
Liquibase Pro 3.8.7 by Datical licensed to Liquibase Pro Customer until Tue Sep 22 19:00:00 CDT 2020
Database snapshot for jdbc:oracle:thin:@localhost:1521:ORCL
-----------------------------------------------------------------
Database type: Oracle
Database version: Oracle Database 11g Release 11.1.0.0.0 - Production
Database user: SCHEMA2
Included types:
com.datical.liquibase.ext.appdba.synonym.Synonym
com.datical.liquibase.ext.storedlogic.checkconstraint.CheckConstraint
com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackage
com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackageBody
com.datical.liquibase.ext.storedlogic.function.Function
com.datical.liquibase.ext.storedlogic.trigger.Trigger
liquibase.structure.core.Catalog
liquibase.structure.core.Column
liquibase.structure.core.ForeignKey
liquibase.structure.core.Index
liquibase.structure.core.PrimaryKey
liquibase.structure.core.Schema
liquibase.structure.core.Sequence
liquibase.structure.core.StoredProcedure
liquibase.structure.core.Table
liquibase.structure.core.UniqueConstraint
liquibase.structure.core.View
Catalog: SCHEMA2
The snapshotReference
command produces a JSON file that contains all your objects and places the file in the same directory as your changelog.

{
"snapshot": {
"created": "2020-07-22T08:45:07.624",
"database": {
"productVersion": "11.5",
"shortName": "postgresql",
"majorVersion": "11",
"minorVersion": "5",
"user": "daticaluser1",
"productName": "PostgreSQL",
"url": "jdbc:postgresql://localhost:5433/goku"
},
"objects": {
"liquibase.structure.core.Catalog": [
{
"catalog": {
"default": true,
"name": "goku",
"snapshotId": "bb2c100"
}
}]
,
"liquibase.structure.core.Column": [
{
"column": {
"name": "comments",
"nullable": true,
"order": "9!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c110",
"snapshotId": "bb2c119",
"type": {
"characterOctetLength": "255!{java.lang.Integer}",
"columnSize": "255!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "description",
"nullable": true,
"order": "8!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c110",
"snapshotId": "bb2c118",
"type": {
"characterOctetLength": "255!{java.lang.Integer}",
"columnSize": "255!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "exectype",
"nullable": false,
"order": "6!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c110",
"snapshotId": "bb2c116",
"type": {
"characterOctetLength": "10!{java.lang.Integer}",
"columnSize": "10!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "id",
"nullable": false,
"order": "1!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c125",
"snapshotId": "bb2c127",
"type": {
"characterOctetLength": "10!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "4!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "int4"
}
}
},
{
"column": {
"name": "id",
"nullable": true,
"order": "1!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c132",
"snapshotId": "bb2c133",
"type": {
"characterOctetLength": "10!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "4!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "int4"
}
}
},
{
"column": {
"name": "locked",
"nullable": false,
"order": "2!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c125",
"snapshotId": "bb2c128",
"type": {
"characterOctetLength": "1!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "-7!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "bool"
}
}
},
{
"column": {
"name": "lockedby",
"nullable": true,
"order": "4!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c125",
"snapshotId": "bb2c130",
"type": {
"characterOctetLength": "255!{java.lang.Integer}",
"columnSize": "255!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "lockgranted",
"nullable": true,
"order": "3!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c125",
"snapshotId": "bb2c129",
"type": {
"characterOctetLength": "29!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "93!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "timestamp"
}
}
},
{
"column": {
"name": "md5sum",
"nullable": true,
"order": "7!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c110",
"snapshotId": "bb2c117",
"type": {
"characterOctetLength": "35!{java.lang.Integer}",
"columnSize": "35!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "name",
"nullable": true,
"order": "2!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c132",
"snapshotId": "bb2c134",
"type": {
"characterOctetLength": "50!{java.lang.Integer}",
"columnSize": "50!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "supplier_id",
"nullable": true,
"order": "1!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c104",
"snapshotId": "bb2c105",
"type": {
"characterOctetLength": "4!{java.lang.Integer}",
"columnSize": "4!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "2!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "numeric"
}
}
},
{
"column": {
"name": "supplier_id",
"nullable": true,
"order": "1!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c107",
"snapshotId": "bb2c108",
"type": {
"characterOctetLength": "4!{java.lang.Integer}",
"columnSize": "4!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "2!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "numeric"
}
}
},
{
"column": {
"name": "supplier_name",
"nullable": true,
"order": "2!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c104",
"snapshotId": "bb2c106",
"type": {
"characterOctetLength": "50!{java.lang.Integer}",
"columnSize": "50!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "supplier_name",
"nullable": true,
"order": "2!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c107",
"snapshotId": "bb2c109",
"type": {
"characterOctetLength": "50!{java.lang.Integer}",
"columnSize": "50!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "supplier_name",
"nullable": true,
"order": "1!{java.lang.Integer}",
"relation": "liquibase.structure.core.View#bb2c102",
"snapshotId": "bb2c103",
"type": {
"characterOctetLength": "50!{java.lang.Integer}",
"columnSize": "50!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
},
{
"column": {
"name": "tag",
"nullable": true,
"order": "10!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#bb2c110",
"snapshotId": "bb2c120",
"type": {
"characterOctetLength": "255!{java.lang.Integer}",
"columnSize": "255!{java.lang.Integer}",
"columnSizeUnit": "BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}",
"dataTypeId": "12!{java.lang.Integer}",
"radix": "10!{java.lang.Integer}",
"typeName": "varchar"
}
}
}]
,
"liquibase.structure.core.Index": [
{
"index": {
"columns": [
"liquibase.structure.core.Column#bb2c127"]
,
"name": "databasechangeloglock_pkey",
"snapshotId": "bb2c126",
"table": "liquibase.structure.core.Table#bb2c125",
"unique": true
}
}]
,
"liquibase.structure.core.PrimaryKey": [
{
"primaryKey": {
"backingIndex": "liquibase.structure.core.Index#bb2c126",
"columns": [
"liquibase.structure.core.Column#bb2c127"]
,
"name": "databasechangeloglock_pkey",
"snapshotId": "bb2c131",
"table": "liquibase.structure.core.Table#bb2c125"
}
}]
,
"liquibase.structure.core.Schema": [
{
"schema": {
"catalog": "liquibase.structure.core.Catalog#bb2c100",
"default": true,
"name": "public",
"snapshotId": "bb2c101"
}
}]
,
"liquibase.structure.core.Table": [
{
"table": {
"columns": [
"liquibase.structure.core.Column#bb2c116",
"liquibase.structure.core.Column#bb2c117",
"liquibase.structure.core.Column#bb2c118",
"liquibase.structure.core.Column#bb2c119",
"liquibase.structure.core.Column#bb2c120",
,
"default_tablespace": false,
"name": "databasechangelog",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c110"
}
},
{
"table": {
"columns": [
"liquibase.structure.core.Column#bb2c127",
"liquibase.structure.core.Column#bb2c128",
"liquibase.structure.core.Column#bb2c129",
"liquibase.structure.core.Column#bb2c130"]
,
"default_tablespace": false,
"indexes": [
"liquibase.structure.core.Index#bb2c126"]
,
"name": "databasechangeloglock",
"primaryKey": "liquibase.structure.core.PrimaryKey#bb2c131",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c125"
}
},
{
"table": {
"columns": [
"liquibase.structure.core.Column#bb2c105",
"liquibase.structure.core.Column#bb2c106"]
,
"default_tablespace": false,
"name": "testcp",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c104"
}
},
{
"table": {
"columns": [
"liquibase.structure.core.Column#bb2c108",
"liquibase.structure.core.Column#bb2c109"]
,
"default_tablespace": false,
"name": "testtable1",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c107"
}
},
{
"table": {
"columns": [
"liquibase.structure.core.Column#bb2c133",
"liquibase.structure.core.Column#bb2c134"]
,
"default_tablespace": false,
"name": "vacuumtest",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c132"
}
}]
,
"liquibase.structure.core.View": [
{
"view": {
"columns": [
"liquibase.structure.core.Column#bb2c103"]
,
"definition": " SELECT testtable1.supplier_name\n FROM testtable1\n ORDER BY testtable1.supplier_name DESC;",
"name": "testview1",
"schema": "liquibase.structure.core.Schema#bb2c101",
"snapshotId": "bb2c102"
}
}]
},
"snapshotControl": {
"snapshotControl": {
"includedType": [
"com.datical.liquibase.ext.appdba.synonym.Synonym",
"com.datical.liquibase.ext.storedlogic.checkconstraint.CheckConstraint",
"com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackage",
"com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackageBody",
"com.datical.liquibase.ext.storedlogic.function.Function",
"com.datical.liquibase.ext.storedlogic.trigger.Trigger",
"liquibase.structure.core.Catalog",
"liquibase.structure.core.Column",
"liquibase.structure.core.ForeignKey",
"liquibase.structure.core.Index",
"liquibase.structure.core.PrimaryKey",
"liquibase.structure.core.Schema",
"liquibase.structure.core.Sequence",
"liquibase.structure.core.StoredProcedure",
"liquibase.structure.core.Table",
"liquibase.structure.core.UniqueConstraint",
"liquibase.structure.core.View"]
}
}
}
}
Liquibase Community snapshotReference
categories:
- Catalog
- Column
- Foreign Key
- Index
- Primary Key
- Schema
- Sequence
- Unique Constraints
- View
Liquibase Pro snapshotReference
categories:
- Package
- Package Body
- Procedures
- Function
- Trigger
- Synonyms
- Check Constraints