Posts

Showing posts from September, 2023

db2: to get role name and grantee

 db2 "select substr(rolename,1,18) as rolename, substr(grantee,1,18) as grantee from syscat.roleauth order by rolename, grantee with ur" Example: TIBCO              ESBGCPDB2PRDUSER   UC4                UC4GCPDB2PRDUSER  

DB2: to export a table

 $ db2 "select count(*) from wcs.XGCPMWSTOREINVENTORY" 1 -----------     3604155   1 record(s) selected. [prd1ins1@db2prd601  prd1ins1] $ db2 -v "export to /usr/opt/app/dbdump/prd1ins1/XGCPMWSTOREINVENTORY_prod.del of del lobs to /usr/opt/app/dbdump/prd1ins1 select * from wcs.XGCPMWSTOREINVENTORY" export to /usr/opt/app/dbdump/prd1ins1/XGCPMWSTOREINVENTORY_prod.del of del lobs to /usr/opt/app/dbdump/prd1ins1 select * from wcs.XGCPMWSTOREINVENTORY SQL3104N  The Export utility is beginning to export data to file "/usr/opt/app/dbdump/prd1ins1/XGCPMWSTOREINVENTORY_prod.del". SQL3105N  The Export utility has finished exporting "3604155" rows. Number of rows exported: 3604155

DB2: To run script and spool output

 db2 -td -vf pcr.sql | tee pcr.txt -vf is verbose output To run script with @ (special character) -  At the top of the script , set schema wcs@ set schema wcs@ -  At end of the script, replace last semicolon (;) with @ END@ Now Run the script using the command below: $ db2 -td@ -vf pcr.sql | tee pcr.txt

Postgres: To get list of tables in a schema

 select table_name from information_schema.tables where table_schema='ctlgadmin';   table_schema name is in lowercase. 

DB2: Check when stats was run on a table

  SELECT STATS_TIME AS RUNSTATS_DATE     , SUBSTR(TABSCHEMA,1,20) AS SCHEMA     , SUBSTR(TABNAME,1,60) AS TABLE     , (DAYS(CURRENT_TIMESTAMP) - DAYS(STATS_TIME)) AS AGE_IN_DAYS FROM SYSCAT.TABLES WHERE TABSCHEMA = 'WCS'     AND TABNAME IN ('USERREG', 'ADDRESS') WITH UR; SELECT STATS_TIME AS RUNSTATS_DATE     , SUBSTR(TABSCHEMA,1,20) AS SCHEMA     , SUBSTR(TABNAME,1,60) AS TABLE     , (DAYS(CURRENT_TIMESTAMP) - DAYS(STATS_TIME)) AS AGE_IN_DAYS FROM SYSCAT.TABLES WHERE TABSCHEMA = 'WCS'     AND TABNAME IN ('USERREG') WITH UR;