Deleting all the old versions that are created before a given date in all the catalogs OR a specific catalog
******************************************************************************


Description: 

In a WPC/GDS DB2 database, you can purge all the old versions that are created before a given date in all the catalogs by using db2_delete_versions_by_date.sh.

You can use db2_delete_versions_by_ctg_date.sh to purge all the old versions that are created before a given date in a specific catalog.

You can use db2_estimate_versions_by_date.sh and db2_estimate_versions_by_ctg_date.sh to get an estimate on how many rows will get deleted by the delete scripts.

These scripts work for all versions of WPC 5.3.x

Execution Environment:

Shell script that invokes DB2 CLI and SQL in bash shell

Usage for db2_estimate_versions_by_date.sh:

db2_estimate_versions_by_date.sh --cmpid=<CompanyID> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for db2_estimate_versions_by_ctg_date.sh:

db2_estimate_versions_by_ctg_date.sh --cmpid=<CompanyID> --ctgid=<CatalogId> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for db2_delete_versions_by_date.sh:
 
db2_delete_versions_by_date.sh --cmpid=<CompanyID> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for db2_delete_versions_by_ctg_date.sh:

db2_delete_versions_by_ctg_date.sh --cmpid=<CompanyID> --ctgid=<CatalogId> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Options:
 
cmpid: Company ID. You can get this from CMP table using simple sql "select * from cmp".

date: To select old versions that are created before given date. Date must be in format YYYY-MM-DD

dbuser: Name of the database user. This is value of db_userName parameter in $TOP/etc/default/common.properties file.

dbpassword: Password of the database user. This is value of db_password parameter in $TOP/etc/default/common.properties file.

dbname: Name of the database. This can be found in db_url parameter value in $TOP/etc/default/common.properties file.

ctgid: Catalog or Container ID. You can get this from CTG table using simple sql "select * from ctg"


Example: 

./db2_delete_versions_by_date.sh --cmpid=40001 --date=2005-09-30 --dbuser=wpc1 --dbpassword=wpc1 --dbname=wpcdb | tee delete_old_versions.out

./db2_delete_versions_by_date.sh --cmpid=40001 --ctgid=804 --date=2005-09-30 --dbuser=wpc1 --dbpassword=wpc1 --dbname=wpcdb | tee delete_old_versions.out

Procedure:

1  Stop the WPC application on which you are going to run this script. 
   Make sure that there are no jobs running when you stop the application.
   Stop the application on all the nodes if it is clustered environment.
2. Take a physical or logical backup of the database before running the script
3. Run db2_delete_versions_by_date.sh script from $TOP/src/maintenance/ directory
4. Re-start the WPC application after completion of the script execution.
5. After the script is run, it is recommended to run DB2 REORG TABLE and INDEX


Notes:

Amount of time taken to finish running the script depends on the size of catalogs and the number of old versions in One or all catalogs according to respective script. 

These scripts will not delete the rows that belong to latest version of any catalog.

Logs for the scripts are written to $TOP/logs/default/ of format del_version*.

