Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Backup DBM config and create instance

1
2
3
4
5
db2cfexp /tmp/backupconfig.txt backup
db2 stop dbm force
db2idrop db2
db2icrt db2
db2cfimp /tmp/backupconfig.txt
https://snipt.net/embed/9892ea5e67088ffc4ba5d902a65dac69/
https://snipt.net/raw/9892ea5e67088ffc4ba5d902a65dac69/
9892ea5e67088ffc4ba5d902a65dac69
text
Text only
6
2016-11-16T00:27:02
True
False
False
/api/public/snipt/24672/
backup-dbm-config-and-create-instance
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>db2cfexp /tmp/backupconfig.txt backup </span><span id="L-2"><a name="L-2"></a>db2 stop dbm force </span><span id="L-3"><a name="L-3"></a>db2idrop db2 </span><span id="L-4"><a name="L-4"></a>db2icrt db2 </span><span id="L-5"><a name="L-5"></a>db2cfimp /tmp/backupconfig.txt </span></pre></div> </td></tr></table>
db2

Text only

Truncate table

alter table schema.table_name activate not logged initially with empty table
https://snipt.net/embed/54704efad51b676b61f781f5e1700cf1/
https://snipt.net/raw/54704efad51b676b61f781f5e1700cf1/
54704efad51b676b61f781f5e1700cf1
text
Text only
2
2016-11-11T03:24:10
True
False
False
/api/public/snipt/24671/
truncate-table
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>alter table schema.table_name activate not logged initially with empty table </span></pre></div> </td></tr></table>
db2

Text only

Simple DB2 trace

1
2
3
4
5
Prefix select with "explain plan with snapshot for":
db2 "explain plan with snapshot for SELECT id,name,address from person where age between 30 and 35"

Export execution plan to file:
db2exfmt -d DBNAME -u USERNAME PASSWORD -1 -o /tmp/explain_plan.txt
https://snipt.net/embed/52edda953dcce733f1883d8c36157120/
https://snipt.net/raw/52edda953dcce733f1883d8c36157120/
52edda953dcce733f1883d8c36157120
text
Text only
5
2016-12-02T15:32:03
True
False
False
/api/public/snipt/24670/
simple-db2-trace
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>Prefix select with &quot;explain plan with snapshot for&quot;: </span><span id="L-2"><a name="L-2"></a>db2 &quot;explain plan with snapshot for SELECT id,name,address from person where age between 30 and 35&quot; </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>Export execution plan to file: </span><span id="L-5"><a name="L-5"></a>db2exfmt -d DBNAME -u USERNAME PASSWORD -1 -o /tmp/explain_plan.txt </span></pre></div> </td></tr></table>
db2

Text only

Get database size

1
2
3
db2 connect to DBNAME
db2 "CALL GET_DBSIZE_INFO(?, ?, ?, 0)"
db2 connect reset
https://snipt.net/embed/8450e0722ee2f4a5900faa04312d25c0/
https://snipt.net/raw/8450e0722ee2f4a5900faa04312d25c0/
8450e0722ee2f4a5900faa04312d25c0
text
Text only
3
2016-11-30T05:12:07
True
False
False
/api/public/snipt/24669/
get-database-size
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>db2 connect to DBNAME </span><span id="L-2"><a name="L-2"></a>db2 &quot;CALL GET_DBSIZE_INFO(?, ?, ?, 0)&quot; </span><span id="L-3"><a name="L-3"></a>db2 connect reset </span></pre></div> </td></tr></table>
db2

Text only

Get tablespace total, free and % free pages

select substr(tablespace_name,1,15) ts_name,free_pages,total_pages,free_pages*100/total_pages free_perc,case when (free_pages*100/total_pages<5) then ' <- critical' when (free_pages*100/total_pages<10) then ' <- warning' else '' end status from table(snapshot_tbs_cfg(' ',-1)) as tbssz where tablespace_type=0 order by free_perc asc
https://snipt.net/embed/9d345c74fda1463075c1baf42400616a/
https://snipt.net/raw/9d345c74fda1463075c1baf42400616a/
9d345c74fda1463075c1baf42400616a
text
Text only
1
2016-12-04T02:34:14
True
False
False
/api/public/snipt/24668/
get-tablespace-total-free-and-free-pages
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>select substr(tablespace_name,1,15) ts_name,free_pages,total_pages,free_pages*100/total_pages free_perc,case when (free_pages*100/total_pages&lt;5) then &#39; &lt;- critical&#39; when (free_pages*100/total_pages&lt;10) then &#39; &lt;- warning&#39; else &#39;&#39; end status from table(snapshot_tbs_cfg(&#39; &#39;,-1)) as tbssz where tablespace_type=0 order by free_perc asc </span></pre></div> </td></tr></table>
db2

SQL

DB2 Restore Diffrent Name and Log Path

db2 restore db OLD_DB_NAME from BACKUP_PATH into NEW_DB_NAME newlogpath NEW_LOG_PATH with 2 buffers buffer 1024 without prompting
https://snipt.net/embed/bb1ee6824c1806e8de19807600b7a159/
https://snipt.net/raw/bb1ee6824c1806e8de19807600b7a159/
bb1ee6824c1806e8de19807600b7a159
sql
SQL
1
2016-12-04T12:19:52
True
False
False
/api/public/snipt/12315/
db2-restore-diffrent-name-and-log-path
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">db2</span> <span class="n">restore</span> <span class="n">db</span> <span class="n">OLD_DB_NAME</span> <span class="k">from</span> <span class="n">BACKUP_PATH</span> <span class="k">into</span> <span class="n">NEW_DB_NAME</span> <span class="n">newlogpath</span> <span class="n">NEW_LOG_PATH</span> <span class="k">with</span> <span class="mi">2</span> <span class="n">buffers</span> <span class="n">buffer</span> <span class="mi">1024</span> <span class="k">without</span> <span class="n">prompting</span> </span></pre></div> </td></tr></table>
db2

SQL

DB2 Reorg Table

1
2
3
db2 connect to <db_name>
db2 reorg table <table_name>
db2 terminate
https://snipt.net/embed/9690fe65aeb058851ffe3006208e297c/
https://snipt.net/raw/9690fe65aeb058851ffe3006208e297c/
9690fe65aeb058851ffe3006208e297c
sql
SQL
4
2016-12-04T12:19:57
True
False
False
/api/public/snipt/10520/
db2-reorg-table
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">db2</span> <span class="k">connect</span> <span class="k">to</span> <span class="o">&lt;</span><span class="n">db_name</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">db2</span> <span class="n">reorg</span> <span class="k">table</span> <span class="o">&lt;</span><span class="k">table_name</span><span class="o">&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="n">db2</span> <span class="k">terminate</span> </span></pre></div> </td></tr></table>
db2

SQL

DB2 Drop FK

ALTER TABLE <name>
      DROP FOREIGN KEY <foreign_key_name>
https://snipt.net/embed/fdfbe0eef3c88775fb3ff69cb3dd6014/
https://snipt.net/raw/fdfbe0eef3c88775fb3ff69cb3dd6014/
fdfbe0eef3c88775fb3ff69cb3dd6014
sql
SQL
2
2016-12-05T09:24:09
True
False
False
/api/public/snipt/10308/
db2-drop-fk
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">ALTER</span> <span class="k">TABLE</span> <span class="o">&lt;</span><span class="n">name</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">DROP</span> <span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="o">&lt;</span><span class="n">foreign_key_name</span><span class="o">&gt;</span> </span></pre></div> </td></tr></table>
db2, sql
Copyrighted, illegal, or inappropriate content? Email [email protected].