truncate table. Error Msg = sqlcode -668 sqlerrmc=7 - db2

I am trying to run this DB2 query on DBEAVER:
TRUNCATE table departments immediate
but I got this error:
DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016, SQLERRMC=7;DB2INST1.DEPARTMENTS, DRIVER=4.19.49
(it is happening just when I run it on DBEVAER (external channel) on local it's run well.
help someone?

The sqlcode -668 with sqlerrmc=7 (this 7 is the "reason code") means:
SQL0668N Operation not allowed for reason code "" on
table
"".
and the reason code 7 means:
The table is in the reorg pending state. This can occur after an
ALTER TABLE statement containing a REORG-recommended operation.
If your userid has the correct permissions, then try:
reorg table db2inst1.departments
if you have command-line access to Db2, or from jdbc application like DBeaver call admin_cmd ('reorg table db2inst1.departments').
But the reorg will fail if your account lacks permissions, or if the syntax is not allowed on your Db2-server version, and in that case you must ask a DBA to do the work for you, or a become user db2inst1 and run the reorg.
When the reorg completes without errors, retry the truncate table.

Related

SQL Error [42P07]: ERROR: relation "table1" already exist

Running a query to create a table, in the framework DBeaver v22, the error returns from a random table, every time I run the SQL script and it hits a query to create a table.
The script has a few thousands of lines, lots of drops and creates tables and. the very same error happens randomly when a CREATE query gets executed.
At the time I created this thread, I executed the script and it returned error in the creation of table1.
But It could have been any other. It doesn`t seem to be an error in he syntax/grammar of my SQL, but somehow in the engine of DBeaver 22.2. Because the error returns in a random table as per script execution.
SQL Error [42P07]: ERROR: relation "table1" already exist
Even though I added the following query to DROP TABLE, right before the one to CREATE table, the error still returns, when the query to create gets executed.
DROP TABLE IF EXISTS sandbox.table1;
CREATE TABLE sandbox.table1 as ();
I wonder if it takes a long time to drop the table so that, the create command line returns error
Is that possible to be the cause ?
Do I need a timer to wait for RDBMS fully drop the table?
SQL Error [42P07]: ERROR: relation "table1" already exist
Accessing further logs I`ve identified the root cause was permission error.
As It couldn't delete then creating table caused the error
org.jkiss.dbeaver.model
Error
Wed Dec 07 11:38:44 BRT 2022
SQL Error [42501]: ERROR: permission denied for relation table1

Db2 doesn't allow to update table, throws an error saying that operation is incomplete

I'm getting an error when trying to update a table. The SQL statement is:
UPDATE dda_accounts SET TYPE_SK = TYPE_SK - 10 WHERE TYPE_SK > 9;
The error I get is:
SQL Error [57007]: Operation not allowed for reason code "7" on table
"BANK_0002_TEST.DDA_ACCOUNTS".. SQLCODE=-668, SQLSTATE=57007, DRIVER=4.27.25
SQLSTATE 57007 says that there's something incomplete after an ALTER TABLE was executed.
I found this resolution, but it's not clear if it can be fixed or the only way to recover the table is using a backup.
Running a select statement works, only the update fails. What is the way to fix this table?
You need to REORG the table to recover, see this page for details.
When you get an error like this, lookup the SQL066N code with the reason code "7".
This shows:
The table is in the reorg pending state. This can occur after an ALTER
TABLE tatement containing a REORG-recommended operation.
Be aware the the previous alter table (that put the table into this state of reorg needed) might have happened quite some time ago, possibly without your knowledge.
If you lack the authorisation to perform reorg table inplace "BANK_0002_TEST.DDA_ACCOUNTS" , then contact your DBA for assistance. The DBA may choose to also reorg indexes at the same time, and to perform runstats (docs) on the table following completion of the reorg, and to check whether anything else needs rebinding.

How to set table to LOGGED in postgresql 9.2?

I'm using PostgreSQL 9.2. I created a bunch of UNLOGGED tables, loaded data into there, and created primary keys. Now I'd like to set them back to LOGGED status.
I tried the command:
ALTER TABLE table_name SET LOGGED;
However, I get this error:
ERROR: syntax error at or near "LOGGED"
What is the proper syntax for this?

REORG command in db2

So I have been altering a table in QMF. After 3 alters I believe the table has gone into a pending reorg state so that I cannot alter it additionally. Am I correct in this assumption? If so what implications does this have and to get around it can I simply reorganize the table and continue altering it? If so, what does the syntax look like for reorganizing a table? I tried
REORG TABLE PIDJBIP.TABLE_NAME_T
and receive the error:
an unexpected token "PIDJBIP" was found following "REORG TABLE".
Expected tokens may include: "JOIN". SQL state = 42601.
I haven't gotten much help out of the IBM pages regarding this subject.
REORG is not an SQL statement, so it cannot be issued using a SQL interface (such as QMF). You will need to run it using the DB2 Command Line Processor.
Alternatively, you might use the administrative stored procedure, which you could call via QMF:
call sysproc.admin_cmd('reorg table PIDJBIP.TABLE_NAME_T')

DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68

I am getting this error when I ran:
alter table tablename add column columnname varchar(1) default 'N';
DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68
How to solve it?
The alter statement wants to get an X lock on this row in SYSIBM.SYSTABLES. There is an open transaction that has this row/index value in an incompatible lock state. This lock that caused the timeout could even be from an open cursor that reads this row with an RS or RR isolation level.
Terminate any other SQL currently trying to query SYSTABLES and any utilities that may be trying to update SYSTABLES like reorg and runstats then try the alter again.
See DB2 Info center (I picked the one for DB2 10, most likely this error code is the same in other versions, but doublecheck!).
Seems there is a transaction open on your table, that prevents your alter command from execution.
after you have Altered a table you need to Reorg: reade up on it here:
Run the runstats script, which is a DB2 script, at regular intervals and set the script to gather RUNSTATS WITH DISTRIBUTION AND DETAILED INDEXES ALL.
In addition to running the runstats scripts regularly, you can perform the following tasks to avoid the problem:
Use REOPT ONCE or REOPT ALWAYS with the command-line interface (CLI ) packages to change the query optimization behavior.
In the DB2 database, change the table to make it volatile. Volatile tables indicate to the DB2 optimizer that the table cardinality can change significantly at run time (from empty to large and vice versa). Therefore, DB2 uses an index to access a table rather than a table scan.