Friday, 26 March 2021

[DB2 LUW] gathering statistcs

The runstat command is used to gather statistics on tables and indexes in DB2 LUW. However, it is no standard SQL command, not even an IBM extension. It is an IBM specific to be run on their CLI. However, one can still issue from any SQL client it encapsulated in the ADMIN_SYS procedure. For details, check the IBM documentation

Example

call sysproc.admin_cmd('runstats on table MY_SCHEMA.SOME_TABLE use profile');

Monday, 12 October 2020

[DB2] Reorganising table partitions in a loop ends with SQLSTATE 24501

Setup

You write a SQLPL procedure/function to reorganise table partitions and loop through the partitions having read the metadata in a cursor.

Problem

After the first pass, execution terminate in an exception with SQLSTATE 24501. If you catch the exception to propagate the error to a log table - e. g., the error message you get from the diagnostics stack might be like:

SQL0501N The cursor specified in a FETCH statement or CLOSE statement is not open or a cursor variable in a cursor scalar function reference is not open. SQLSTATE=24501

Cause

DB2 closes the loop cursor with the execution of the reorg statement no matter if you specify HOLD in the cursor definition.

Solution

If you place the actual reorg statement into a different function/procedure and define that as autonomous (transaction), the cursor remains open.

Note

Some say, that it is not recommended doing that in a loop. They argue that it takes long time for big tables. This certainly is true however, there is no real other choice. One can reorganise the table as a whole which will end up with more or less the same time needed as it is the same amount of data being reorganised. Apparently, reorganising partition by partition takes less resources to do.

Saturday, 29 August 2020

[QGIS] Batch reprojecting

If you need to put together data from different sources, chances are high that they are not using the same coordinate system, the same projection. Thus, you need to reproject affected layers. For a multitude of layers done one by one this is tedious and error prone work. QGIS, however, provides batch functionality to do so:

 

I believe, that the layer id is the name concatenated with a hex form of a UUID (https://en.wikipedia.org/wiki/Universally_unique_identifier#Format). Therefore, I just cut the last 37 characters from the layer id to obtain the pure layer name. In some QGIS documentation there is stated a layer_name variable, but I could not find that in my version, thus the substring hassle: '/home/thiemo/Downloads/auswandern/sverige/SCID_v4.0_EPSG4326/' || substr(@INPUT, 1, length(@INPUT) - 37) || '.shp'

 

 

 

[git] Create a local branch from another branch

From the active branch git checkout -b <LOCAL_BRANCH> From a donator branch git checkout -b <LOCAL_BRANCH> <DONATING_BRANCH...