DavidYahalom.com is an IT knowledgebase dedicated to the world of databses and RDBMS systems by David Yahalom. Here you'll find articles, views, news, tips and in-depth analysis about Oracle, DB2 LUW, Sql Server and MySql. I hope you'll enjoy your stay.
1st
JUL
Truncate in DB2, DB2 CLP tricks, simple DB2 tracing
Posted by David Yahalom under DB2 LUW
Truncate table in DB2
One of the things I really missed when going DB2 from Oracle is the truncate table command.
In Oracle you have the option to quickly truncate a table using the truncate table command. This is a really good feature as the difference between doing truncate or a DML delete is huge in terms of performance.
You have to remember that when doing a truncate you are actually doing a non-logged delete of the table which is much less I/O intensive then a regular DML delete. This is most useful if you want to truncate a table during work hours without increasing server load.
However, apparently, DB2 does have a truncate feature, the command is just not as straightforward as writing truncate table in Oracle.
To truncate a table in DB2, simply write:
alter table schema.table_name activate not logged initially with empty table
From what I was able to read, this will delete the table content without doing any kind of logging which will go much easier on your server’s I/O.
Change the DB2 CLP prompt
Working with multiple servers or databases in DB2 can be dangerous if you are using the command line interface and forget which session is connected to which server.
So, in order to save yourself allot of future headaches and lost sleep hours while trying to mount restore tapes you can issue the following command which will change the DB2 CLP prompt to a meaningful (user@database):
db2set DB2_CLPPROMPT=(%da@%d):
You can get creative and also use the following environment variables in building your custom DB2 prompt:
%d = Currently connected database name %i = Attached instance name %ia = Authorization ID of the current instance %n = Newline (for a two line prompt) %da = Authorization ID of the current database
Nifty DB2 CLP commands you usually forget:
history
Lists the last 20 commands entered and prefixes each with a number. The maximum number of commands kept in memory can be customized with the DB2 registry variable DB2_CLP_HISTSIZE.
runcmd command_number_n [/sourcode] Re executes command number n from the list given by the history command. If n is not specified (or n = -1), the previous command is invoked. [sourcecode language="sql"] edit command_number_n [/sourcode] Edits the command number n using an editor defined by the DB2 registry variable DB2_CLP_EDITOR. If not set, this uses the vi editor on Linux/UNIX and Notepad on Windows. [sourcecode language="sql"] Exclamation mark (!) [/sourcode] This is the escape character that lets you issue operating system commands from within the CLP interactive mode How to monitor locks: [sourcecode language="sql"] 1) db2 update monitor switches using LOCK on 2) db2 get snapshot for locks on opal_d > /tmp/locks.txt 3) db2 reset monitor all
Do a simple DB2 trace
DB2 has several ways to do an SQL query trace. This method is using the explain plan with snapshotsql prefix:
1) Create a text file with the query you want to trace. For example, create a file named c:\query1.sql and paste your query inside.
2) Add the following text before the SELECT operator:
explain plan with snapshot for
So that your query will look something like this:
explain plan with snapshot for SELECT count(*) from syscat.tables;
3) Run the following command:
db2 -tvf c:query1.sql
This will prepare the execution plan and save it in the explain tables within the system catalog.
4) Run the following command which will output the execution plan to a txt file:
db2exfmt -d database_name -u username password -1 -o c:explain_plan.txt
Category Cloud
ASM DB2 LUW ETL General IT Grid Control Hardware ITIL Linux Monitoring MySQL Oracle RAC Security Solaris SQL Server Storage Uncategorized Unix Windows
Recent Posts
- What will happen to ASM when the disk path changes in Linux?
- The relation between an Oracle instance and memory in Windows
- Blog has been renamed!
- Cloud Oracle Storage: how to make ASM even better, the NAS way.
- ORA-600: Oracle process has no purpose in life!
Active polls
Categories
- ASM (2)
- DB2 LUW (11)
- ETL (2)
- General IT (7)
- Grid Control (1)
- Hardware (4)
- ITIL (1)
- Linux (3)
- Monitoring (1)
- MySQL (1)
- Oracle (32)
- RAC (5)
- Security (3)
- Solaris (3)
- SQL Server (1)
- Storage (1)
- Uncategorized (1)
- Unix (2)
- Windows (2)
Archives
- September 2009
- February 2009
- January 2009
- November 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- October 2007
- September 2007
- July 2007
- June 2007
- April 2007
- March 2007
- February 2007
- January 2007
- March 2006
Blogroll
DavidYahalom.com - Oracle, Databases, SQL, news, views, articles and in-depth analysis is powered by Wordpress. Designed by Free WordPress Themes.
