Coverity Connect PostgreSQL databases use cross reference tables to link data between tables. Over time, duplicate cross-reference link entries are created within the cross reference table. The database cross-reference deduplication tool deletes duplicate cross reference entries in PostgreSQL cross-reference tables. Performing database cross-reference deduplication during a database migration can reduce cross-reference table size by as much as 80%, thereby improving Coverity commit performance because there is less data to load.
A database migration involves moving data from one database to another. Deduplication is the process of removing redundant data within a database. Performing a database cross-reference deduplication during a PostgreSQL migration reduces the amount of data that needs to be transferred, and optimizes storage space on the target system. Depending on database size, load, and available resources, a database deduplication and migration might take hours or days. Once a cross reference deduplication starts, you can not disable it.
The default migration schedule runs at 2 AM local time every day for one hour until the migration is complete. The migration pauses after one hour and restarts the next day at 2 AM, continuing from where it paused. You can configure this behavior as described in "Scheduling cross-reference deduplication."
Performing a migration consumes 5-10% of the memory during the migration.
Database migration does not impact Coverity Connect functionality. Connect continues to work properly while the database is partially migrated. When a migration restarts, it resumes from where it stopped.
Also, all new commits load data to new tables.
Procedure: configuring and performing a database cross-reference deduplication
To perform a database cross-reference deduplication:
- Back up your PostgreSQL database.
- Configure the
cim.propertiesfile to schedule and enable cross-reference deduplication. - Monitor the deduplication progress.
- Validate that the deduplication was successful by checking cross references.
Click on any files in the
Files in Latest Snapshotview. On the source code which appears in the lower pane, check the cross-references; they should work within the file and across multiple files. - When the migration completes, compare the original database size
old_xref_countwith the deduplicated database withnew_xref_count. See "Monitoring a database cross-reference deduplication." - If everything passes validation, repeat this procedure for the production database.
Enabling cross-reference deduplication
To enable cross-reference deduplication, add the following property to the
cim.properties file. Once you have configured these parameters
and enabled cross-reference deduplication, the deduplication will begin at the next
scheduled time.
-
To enable cross-reference deduplication, add the following parameter, where
trueenables cross-reference deduplication andfalsedisables cross-reference deduplication:xrefs.enable_linksets=trueNote: Database cross-reference deduplication is disabled by defaultImportant: You cannot reverse a database cross-reference deduplication once it has started. You must let the tool complete all deduplications.
xrefs.enable_linksets=true is the main parameter which decides
whether to trigger the migration job or not. Nore that once is enabled there is no
going back.
Scheduling cross-reference deduplication
The default migration schedule runs at 2 AM local time every day for 1 hour until the migration is complete. The migration pauses after one hour and restarts the next day at 2 AM, continuing from where it paused.
To override the default schedule, add the following properties to the
cim.properties file. Once you have configured these parameters
and enabled cross-reference deduplication, the deduplication will begin at the next
scheduled time.
-
Use the
xrefs.migration_scheduleparameter to schedule the database migration. This parameter uses the Spring CRON syntax.xrefs.migration_schedule=<CRON>Note:The Spring CRON syntax contains a 'Seconds' field:
xrefs.migration_schedule=* * * * * *From left to right: Seconds, Minutes, Hours, Day of month, Month, Day of week
For example, to override the default setting and run continuously until completed, add the following parameter:
xrefs.migration_schedule=0 * * * * *To schedule a database migration at 12:30 AM every day, add the following parameter:
xrefs.migration_schedule=* 30 0 * * * -
To change the duration of each batch migration, add the following parameter:
xrefs.migration_max_batch_duration=<duration>where the
<duration>value is in milliseconds. You can set the the duration to any value.For example, to set the batch duration to one hour:
xrefs.migration_max_batch_duration=3600000For example, to set the batch duration to six hours (6 hrs x 60 mins x 60 secs x 1000 ms = 21600000):
xrefs.migration_max_batch_duration=21600000
xrefs.migration_schedule and
xrefs.migration_max_batch_duration parameters, cross reference
deduplication will automatically use the default schedule and trigger at 2 AM each
day for one hour.Examples
Thie following examples enable, schedule, and set the job duration of cross reference deduplication.
-
If you need the job to go slower, maybe avoid any system load or to run during the night, you can schedule it any hour, or increase the maximum duration, etc.
For example, to enable and schedule a job to run at 12 AM, and run for 6 hours:
xrefs.enable_linksets=true xrefs.migration_schedule=0 0 0 * * * xrefs.migration_max_batch_duration=21600000 -
The following
migration_scheduleparameter continues the job one minute after each pause. This means that after a job reaches its maximum duration, it gets paused, then is restarted in the next minute. The maximum duration is set to 2 hours.xrefs.enable_linksets=true xrefs.migration_schedule=0 * * * * * xrefs.migration_max_batch_duration=7200000
Monitoring a database cross-reference deduplication
You can monitor the progress of a cross-reference deduplication. Refer to the
xref_migration_state table; it provides information such
as:
- Status
- Total old rows
- Processed rows
- New rows
- Elapsed time
The xref_migration_state table, described below, is updated
periodically as defined by the xrefs.migration_max_batch_duration
parameter, or each hour if not set.
cim.log file:Starting Xref migration jobFinished Xref migration job, all data has been migratedStopping Xref migration job, an exception occurredStopping Xref migration job, time limit reached
The following table defines the xref_migration_state table fields
and values.
| Column | Data Type | Description | Examples |
|---|---|---|---|
| id | int8 | Primary key. | 1 |
| jobruns | int8 | Job run counter tracks the number of times a deduplication starts or restarts. This value begins at zero and increments when the deduplication first starts as well as each time the deduplication restarts after a pause. | 1 |
| batch_size | int8 | The default batch is 100k rows. The batch size can decrease based on memory usage. | 100k |
| time_in_s | bigint | Total deduplication time in seconds. This value is updated every hour. | 600s |
| start_dttm | timestamp | Deduplication start date and time. | 2025-02-05 11:28:00.092 |
| end_dttm | timestamp | Deduplication end date and time. | 2025-02-05 11:38:00.092 |
| migration_status | int8 |
Note: PostgreSQL autovacuum errors do not
affect or stop a cross reference migration. Autovacuum is an
independent PostgreSQL daemon job. Ignore PostgreSQL autovacuum
errors as relates to migration.
|
Completed |
| old_xref_count | bigint |
Total number cross reference rows in the old tables. ( |
50000 |
| processed_xref_count | bigint |
Total number of duplicate rows removed from the old tables. By default, this value is updated every hour. |
50000 (Do not worry if this value is different than old_xref_count) |
| new_xref_count | text | Total number of cross reference rows in the new tables (updated at the end). |
|
| timer_stats | text | Individual timings for each sub-program in the migration. |
|
| error | text | Describes any error that might have occurred. |
Verify and review the deduplicated database
After the deduplication successfully completes, verify that duplicated data was removed and valid data remains within the database. You can compare the new database sizes with the sizes recorded before you began the deduplication.
Run the deduplication on the production database
If you ran the first pass of the deduplication on a test database and the deduplication was successful, you can now run the deduplication on the production database.