SQLSTATE=23514 : Facing error on Set integrity - db2

Can someone suggest me what is the problem, why I am not able to enable integrity, although no constraint found with name of CATEGORY.
create function FCOK_ACCOUNT_CATEGORY_C2(xmlrecord XML) returns integer language sql contains sql no external action deterministic return xmlcast(xmlquery('$d/row/c2' passing xmlrecord as "d") as integer);
reorg table FCOK_ACCOUNT_TEST inplace
db2pd -db admindb –reorg
Database Member 0 -- Database ADMINDB -- Active -- Up 10 days 03:14:17 -- Date 2021-07-26-19.28.05.648688
Table Reorg Information:
Address TbspaceID TableID PartID MasterTbs MasterTab TableName Type IndexID TempSpaceID
0x0A001F00174DF588 4 21566 n/a n/a n/a FCOK_ACCOUNT Offline 0 4
0x0A001F0027981508 3 26880 n/a n/a n/a FCOK_ACCOUNT_TEST Online 0 3
Table Reorg Stats:
Address TableName Start End PhaseStart MaxPhase Phase CurCount MaxCount Status Completion
0x0A001F00174DF588 FCOK_ACCOUNT 07/16/2021 18:38:46 07/16/2021 18:43:15 07/16/2021 18:39:40 3 IdxRecreat 0 0 Done 0
0x0A001F0027981508 FCOK_ACCOUNT_TEST 07/26/2021 18:13:16 07/26/2021 18:14:38 n/a n/a n/a 0 0 Done 0
bash-4.2$
set integrity for FCOK_ACCOUNT_TEST off;
ALTER TABLE FCOK_ACCOUNT_TEST ADD CATEGORY INTEGER generated always as (FCOK_ACCOUNT_CATEGORY_C2(XMLRECORD))
set integrity for FCOK_ACCOUNT_TEST immediate checked;
db2 "set integrity for DB2ADMIN.FCOK_ACCOUNT_TEST immediate checked"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL3603N Integrity processing through the SET INTEGRITY statement has found
an integrity violation involving a constraint, a unique index, a generated
column, or an index over an XML column. The associated object is identified by
"DB2ADMIN.FCOK_ACCOUNT_TEST.CATEGORY". SQLSTATE=23514
bash-4.2$
bash-4.2$ db2 "select TYPE, ENFORCED from SYSCAT.TABCONST where CONSTNAME='CATEGORY'"
TYPE ENFORCED
0 record(s) selected.
bash-4.2$ db2 "select COLSEQ,COLNAME from SYSCAT.KEYCOLUSE where CONSTNAME='CATEGORY'"
COLSEQ COLNAME
0 record(s) selected.
bash-4.2$ db2 "reorg table db2admin.FCOK_ACCOUNT_TEST inplace"
SQL0668N Operation not allowed for reason code "1" on table
"DB2ADMIN.FCOK_ACCOUNT_TEST". SQLSTATE=57016

Related

Restore database db2 get error SQLSTATE=57019

After install IBM data server, i have one administrator user. I log this user into win 10.
db2 => create database sss (successful)
db2 => connect to sss
db2 => restore database sss from d:\
Drive D: has backup file. I also used create database sss to make database before. When i backup, i let backup file in drive D:. But i get error :
SQL2523W Warning! Restoring to an existing database that is different from
the database on the backup image, but have matching names. The target database
will be overwritten by the backup version. The Roll-forward recovery logs
associated with the target database will be deleted.
Do you want to continue ? (y/n) y
SQL1051N The path "E:" does not exist or is not valid. SQLSTATE=57019
What is Drive E:. I never used that drive E:
My test.clp :
UPDATE COMMAND OPTIONS USING S ON Z ON SSS_NODE0000.out V ON;
SET CLIENT ATTACH_MEMBER 0;
SET CLIENT CONNECT_MEMBER 0;
RESTORE DATABASE SSS
-- USER <username>
-- USING '<password>'
FROM 'd:\'
TAKEN AT 20210603080520
-- ON 'E:'
-- DBPATH ON '<target-directory>'
INTO SSS
-- NEWLOGPATH 'E:\DB2\NODE0000\SQL00002\LOGSTREAM0000\'
-- WITH <num-buff> BUFFERS
-- BUFFER <buffer-size>
-- REPLACE HISTORY FILE
-- REPLACE EXISTING
REDIRECT
-- PARALLELISM <n>
WITHOUT ROLLING FORWARD
-- WITHOUT PROMPTING
;
-- ** storage group definition
-- ** Default storage group ID = 0
-- ** Number of storage groups = 1
-- ** Storage group name = IBMSTOGROUP
-- ** Storage group ID = 0
-- ** Data tag = None
-- -- SET STOGROUP PATHS FOR IBMSTOGROUP
-- ON 'E:'
-- ;
-- ** table space definition
-- ** Tablespace name = SYSCATSPACE
-- ** Tablespace ID = 0
-- ** Tablespace Type = Database managed
space
-- ** Tablespace Content Type = All permanent
data. Regular table space.
-- ** Tablespace Page size (bytes) = 4096
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage = Yes
-- ** Storage group ID = 0
-- ** Source storage group ID = -1
-- ** Data tag = None
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 32768
-- ** Number of usable pages = 32764
-- ** High water mark (pages) = 31016
-- ** Tablespace name = TEMPSPACE1
-- ** Tablespace ID = 1
-- ** Tablespace Type = System managed
space
-- ** Tablespace Content Type = System Temporary
data
-- ** Tablespace Page size (bytes) = 4096
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = Yes
-- ** Total number of pages = 1
-- ** Tablespace name = USERSPACE1
-- ** Tablespace ID = 2
-- ** Tablespace Type = Database managed
space
-- ** Tablespace Content Type = All permanent
data. Large table space.
-- ** Tablespace Page size (bytes) = 4096
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = Yes
-- ** Storage group ID = 0
-- ** Source storage group ID = -1
-- ** Data tag = -1
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 8192
-- ** Number of usable pages = 8160
-- ** High water mark (pages) = 544
-- ** Tablespace name = SYSTOOLSPACE
-- ** Tablespace ID = 3
-- ** Tablespace Type = Database managed
space
-- ** Tablespace Content Type = All permanent
data. Large table space.
-- ** Tablespace Page size (bytes) = 4096
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage = Yes
-- ** Storage group ID = 0
-- ** Source storage group ID = -1
-- ** Data tag = -1
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 8192
-- ** Number of usable pages = 8188
-- ** High water mark (pages) = 152
-- ** start redirected restore
RESTORE DATABASE SSS CONTINUE;
-- ** end of file
D:>db2 -tvf d:\test.clp
UPDATE COMMAND OPTIONS USING S ON Z ON SSS_NODE0000.out V ON
DB20000I The UPDATE COMMAND OPTIONS command completed successfully.
SET CLIENT ATTACH_MEMBER 0
DB20000I The SET CLIENT command completed successfully.
SET CLIENT CONNECT_MEMBER 0
DB20000I The SET CLIENT command completed successfully.
RESTORE DATABASE SSS FROM 'd:' TAKEN AT 20210603080520 INTO SSS REDIRECT WITHOUT ROLLING FORWARD
SQL2523W Warning! Restoring to an existing database that is different from
the database on the backup image, but have matching names. The target database
will be overwritten by the backup version. The Roll-forward recovery logs
associated with the target database will be deleted.
Do you want to continue ? (y/n) y
SQL1277W A redirected restore operation is being performed. During a table
space restore, only table spaces being restored can have their paths
reconfigured. During a database restore, storage group storage paths and DMS
table space containers can be reconfigured.
DB20000I The RESTORE DATABASE command completed successfully.
RESTORE DATABASE SSS CONTINUE
SQL1051N The path "E:" does not exist or is not valid. SQLSTATE=57019

Presto To Postgres Not able to query

I have made the connections from presto to postgresql. Describing of table is working but not select query.
Its giving the below error:
select rul_name from fms.fmref_schema.ru_tbl;
Query 20200521_122033_00164_rmrsd, FAILED, 1 node
Splits: 17 total, 0 done (0.00%)
0:00 [0 rows, 0B] [0 rows/s, 0B/s]
Query 20200521_122033_00164_rmrsd failed: com.facebook.presto.plugin.jdbc.JdbcSplit cannot be cast to com.facebook.presto.plugin.jdbc.JdbcSplit

Kill Db2 select statement after the declared time

In Db2 LUW 9.7, how to implement a query timeout?
When performing queries, is there is a 'timeout' parameter that I can declare/implement somehow that will make a given query abort after a certain time?
So far, I can only consider the potentially unsafe practice of killing the process that performs the select query in Unix.
This question is not about programming, it is about administration.
A query will never "kill itself". But there are tools available which (after suitable configuration) will limit the resources that a query can consume at run time, and will cause the query to return an error (if desired) if such resources are exceeded.
You should never kill a process that is owned by a Db2-instance, doing that carries risk that you trash your database.
To control the resources (time, memory, CPU, disk, etc...) that a query can use, it is possible on V9.7 to use Workload-Manager. This requires configuration and experience to properly use it.
IBM also offered a Query-Patroller tool before IBM introduced the Workload Manager (WLM). This was a different solution than WLM. I think Query Patroller was also available in V9.7. It has since been replaced by WLM.
In principle there are two ways to achieve what you need, depending on whether you have the control over the application or the database.
From application end one can use SQL_ATTR_QUERY_TIMEOUT keyword with CLI/ODBC or setQueryTimeout with JDBC (there should be an equivalent for other interfaces). I will attach CLI example at the end.
If you have only control over database then one could consider creating a threshold with ACTIVITYTOTALTIME that would automatically interrupt long running queries.
If you are concerned with Db2 CLP client, then interrupting execution with ctrl+c will propagate interrupt to the database, i.e. you should no longer see statement as executing inside the database. If you however break it more "forcefully" e.g. run kill against db2bp process associated with the shell, statement will continue executing for some time, but it will be eventually interrupted (one will see AgentBreathingPoint Warning in db2diag.log, when Db2 engine periodically checks whether client is still around and it happens to be gone).
Db2 CLI example:
I will use
db2cli executable - CLI to run Db2 CLI commands
"bad query" that is expected to run for a long time:
select t1.*, t2.* from sysibm.syscolumns t1, sysibm.syscolumns t2, sysibm.syscolumns t3, sysibm.syscolumns t4, sysibm.syscolumns t5 order by t5.name desc, t4.name asc fetch first 10 rows only
set the timeout to 10 seconds
code:
SQLAllocEnv 1
SQLAllocConnect 1 1
SQLConnect 1 SAMPLE sql_nts db2v115 sql_nts **** sql_nts
SQLAllocStmt 1 1
SQLSetStmtAttr 1 SQL_ATTR_QUERY_TIMEOUT 10
SQLPrepare 1 "select t1.*, t2.* from sysibm.syscolumns t1, sysibm.syscolumns t2, sysibm.syscolumns t3, sysibm.syscolumns t4, sysibm.syscolumns t5 order by t5.name desc, t4.name asc fetch first 10 rows only" sql_nts
SQLExecute 1
SQLFetch 1
SQLError 1 1 1
it is SQLFetch 1 that will fail, full output including SQLCODEs below:
$ db2cli
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
> SQLAllocEnv 1
SQLAllocConnect 1 1
SQLConnect 1 SAMPLE sql_nts db2v115 sql_nts *** sql_nts
SQLAllocStmt 1 1
SQLSetStmtAttr 1 SQL_ATTR_QUERY_TIMEOUT 10
SQLAllocEnv: rc = 0 (SQL_SUCCESS)
CLI henv = 1, Test Driver henv = 1
> SQLAllocConnect: rc = 0 (SQL_SUCCESS)
CLI hdbc = 1, Test Driver hdbc = 1
> SQLConnect: rc = 0 (SQL_SUCCESS)
> SQLAllocStmt: rc = 0 (SQL_SUCCESS)
CLI hstmt = 1, Test Driver hstmt = 1
> SQLSetStmtAttr: rc = 0 (SQL_SUCCESS)
> SQLPrepare 1 "select t1.*, t2.* from sysibm.syscolumns t1, sysibm.syscolumns t2, sysibm.syscolumns t3, sysibm.syscolumns t4, sysibm.syscolumns t5 order by t5.name desc, t4.name asc fetch first 10 rows only" sql_nts
SQLPrepare: rc = 0 (SQL_SUCCESS)
> SQLExecute 1
SQLExecute: rc = 0 (SQL_SUCCESS)
> SQLFetch 1
SQLFetch: rc = -1 (SQL_ERROR)
> SQLError 1 1 1
SQLError: rc = 0 (SQL_SUCCESS)
SQLError: SQLState : S1008
fNativeError : -952
szErrorMsg : [IBM][CLI Driver][DB2/6000] SQL0952N Processing was cancelled due to an interrupt. SQLSTATE=57014
cbErrorMsg : 100
ODBC/CLI: QueryTimeout
JDBC: The commandTimeout property.
Common IBM Data Server Driver for JDBC and SQLJ properties for all supported database products
if I kill the process that performs the select query in Unix then the query should also be aborted
Yes.
create a threshold on ACTIVITYTOTALTIME or UOWTOTALTIME and set action on stop execution
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0050563.html

DB2 REORG command is not able to start

I am trying to reorg a table in DB2 as the number of alters on a table has exceeded more than 3 times.
DB2 CALL SYSPROC.ADMIN_CMD('REORG TABLE WASADMIN.EXCHANGERATES');
It is not giving any response and looks like it is hanged . I checked the status by running the command .
db2pd -db UB602 -reorgs
but there is no active Reorg process .
Database Member 0 -- Database UB602 -- Active -- Up 0 days 02:14:45 -- Date 2018-11-26-19.34.15.256000
Table Reorg Information:
Address TbspaceID TableID PartID MasterTbs MasterTab TableName Type IndexID TempSpaceID
Table Reorg Stats:
Address TableName Start End PhaseStart MaxPhase Phase CurCount MaxCount Status Completion
What could have gone wrong?
Edit:
I checked the logs but nothing is printed. but when I am pressing ctrl+c to terminate . I get some message in the logs .
2018-11-26-20.19.53.459000+330 I1F1191 LEVEL: Event
PID : 5176 TID : 4928 PROC : db2syscs.exe
INSTANCE: DB2_01 NODE : 000 DB : UB602
APPHDL : 0-1186 APPID: *LOCAL.DB2_01.181126124159
AUTHID : DB2ADMIN HOSTNAME: BLR2DEVLP0434
EDUID : 4928 EDUNAME: db2agent (UB602) 0
FUNCTION: DB2 UDB, RAS/PD component, pdLogInternal, probe:120
START : New Diagnostic Log file
DATA #1 : Build Level, 232 bytes
Instance "DB2_01" uses "64" bits and DB2 code release "SQL11010"
with level identifier "0201010F".
Informational tokens are "DB2 v11.1.0.1527", "s1606081100", "DYN1606081100WIN64", Fix Pack "0".
DATA #2 : System Info, 1760 bytes
System: WIN32_NT BLR2DEVLP0434 10.0 AMD64 Family 6, model 78, stepping 3
CPU: total:4 online:4 Cores per socket:2 Threading degree per core:2 SIMD:Y
CPU binding: not in use
Physical Memory(MB): total:16049 free:6448 available:6448
Virtual Memory(MB): total:28849 free:19248
Swap Memory(MB): total:12800 free:12800
Information in this record is only valid at the time when this file was
created (see this record's time stamp)
2018-11-26-20.19.53.469000+330 I1195F968 LEVEL: Info
PID : 5176 TID : 4928 PROC : db2syscs.exe
INSTANCE: DB2_01 NODE : 000 DB : UB602
APPHDL : 0-1186 APPID: *LOCAL.DB2_01.181126124159
AUTHID : DB2ADMIN HOSTNAME: BLR2DEVLP0434
EDUID : 4928 EDUNAME: db2agent (UB602) 0
FUNCTION: DB2 UDB, relation data serv, sqlrr_rds_common_post, probe:1700
MESSAGE : Severe TERMINATE err at nest lvl 1, in SQL from rtn SYSPROC.ADMIN_CMD
DATA #1 : SQLCA, PD_DB2_TYPE_SQLCA, 136 bytes
sqlcaid : SQLCA sqlcabc: 136 sqlcode: -952 sqlerrml: 0
sqlerrmc:
sqlerrp : SQLRL04B
sqlerrd : (1) 0x80100003 (2) 0x00000003 (3) 0x00000000
(4) 0x00000000 (5) 0x00000000 (6) 0x00000000
sqlwarn : (1) (2) (3) (4) (5) (6)
(7) (8) (9) (10) (11)
sqlstate: 57014
To perform an offline reorg, you have to ensure that nothing is using the table before the reorg command starts to run.
If an offline reorg is not possible, check if an inplace reorg can work instead.
If there are other reasons preventing the action, consult the db2diag.log file for more details. In your question it shows only sqlcode -952 which tells us that you cancelled the job with the control-C.
You can check if there are any row-locks or table-locks on the target table by using one of many different methods. You can use dsmtop or db2top, or dsm, or a command line (db2 get snapshot for locks and then parsing the output for your table name), or by using the MON_GET_LOCKS table function or equivalents.
The documentation states "
Be sure to complete all database operations and release all locks
before you invoke REORG TABLE. This step can be done by issuing a
COMMIT after you close all cursors opened WITH HOLD, or by issuing a
ROLLBACK. After you reorganize a table, use RUNSTATS to update the
table statistics, and REBIND to rebind the packages that use this
table. The reorganize utility implicitly closes all the cursors. "

PostgreSQL's table oid is not found in database

I have a question about PostgreSQL's table oid.
I create a table. oid is 24622
(-rw------- 1 postgres postgres 8192 Nov 29 17:45 24622)
and I found also modified files at the same time.
(-rw------- 1 postgres postgres 73728 Nov 29 17:45 12741)
(-rw------- 1 postgres postgres 32768 Nov 29 17:45 12744)
(-rw------- 1 postgres postgres 65536 Nov 29 17:45 12764)
(-rw------- 1 postgres postgres 57344 Nov 29 17:45 12767)
but those tables are not found in same database, no one is found.
ksh2=# select oid,relname from pg_class where oid = '12741';
oid | relname
-----+---------
(0 rows)
How can I find those tables???
(I also change schema, and try to find, but no one is found)
Thank you.
A filename doesn't necessarily correspond with oid:
Note that while a table's filenode often matches its OID, this is not
necessarily the case; some operations, like TRUNCATE, REINDEX, CLUSTER
and some forms of ALTER TABLE, can change the filenode while
preserving the OID.
The filename is stored in the relfilenode column:
Name of the on-disk file of this relation; zero means this is a
"mapped" relation whose disk file name is determined by low-level
state
So try searching for the relfilenode:
select name, relkind from pg_class where relfilenode = 12741;
The relkind column tells you what type of object the file represents:
r = ordinary table
i = index
S = sequence
v = view
c = composite type
t = TOAST table
f = foreign table