HHeLiBeXの日記 正道編

日々の記憶の記録とメモ‥

identity column定義を削除する

大昔に、DB2でidentity columnを定義するという記事を書いた。

これを使って生成したテーブルがあるのだが、とある事情により、自動採番ではない形に変更する必要が生じた。

うーん‥どうやって削除するんだ、これ?‥と悩み探して20分ほど。

以下のページに助けられました。

ALTER TABLE hoge ALTER COLUMN hoge_id DROP IDENTITY

‥これだけだった・・・

ちなみに、本家のドキュメントは以下。

DB2のトランザクションログ領域が足りない場合の対処

プライベートでデータを蓄積しているDB2サーバーで、巨大なインデックスを作ろうとしたら、トランザクションログがいっぱいというエラーが発生しました。

db2inst1@ubuntu14.04:~$ db2 "CREATE INDEX idx_hoge_hogehoge ON hoge(hogehoge)"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0964C  The transaction log for the database is full.  SQLSTATE=57011
db2inst1@ubuntu14.04:~$

なので、以下のサイトを参考に、設定を変更して、再実行し、無事に成功しました。

以下はその対応内容のログです。

まずは現状を確認します。

db2inst1@ubuntu14.04:~$ db2 get db cfg for HOGEHOGE | grep LOG
Catalog cache size (4KB)              (CATALOGCACHE_SZ) = 300
Log buffer size (4KB)                        (LOGBUFSZ) = 256
Log file size (4KB)                         (LOGFILSIZ) = 1024
Number of primary log files                (LOGPRIMARY) = 13
Number of secondary log files               (LOGSECOND) = 4
Changed path to log files                  (NEWLOGPATH) =
Path to log files                                       = /home/db2inst1/db2inst1/NODE0000/SQL00002/SQLOGDIR/
Overflow log path                     (OVERFLOWLOGPATH) =
Mirror log path                         (MIRRORLOGPATH) =
Block log on disk full                (BLK_LOG_DSK_FUL) = NO
Block non logged operations            (BLOCKNONLOGGED) = NO
Percent max primary log space by transaction  (MAX_LOG) = 0
Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0
Log retain for recovery enabled             (LOGRETAIN) = OFF
First log archive method                 (LOGARCHMETH1) = OFF
Options for logarchmeth1                  (LOGARCHOPT1) =
Second log archive method                (LOGARCHMETH2) = OFF
Options for logarchmeth2                  (LOGARCHOPT2) =
Log pages during index build            (LOGINDEXBUILD) = OFF
db2inst1@ubuntu14.04:~$ 

3~5行目が関連する設定項目ですね。

まずは、即時反映できるという「LOGSECOND」を弄ってみます。

db2inst1@ubuntu14.04:~$ db2 update db cfg for HOGEHOGE using LOGSECOND 4000 IMMEDIATE
SQL5130N  The value specified for the configuration parameter "logsecond" is
not in the valid range of "0" to "254".
db2inst1@ubuntu14.04:~$ 

「LOGSECOND」の値に制限があるようです。

db2inst1@ubuntu14.04:~$ db2 update db cfg for HOGEHOGE using LOGSECOND 254 IMMEDIATE
SQL5153N  The update cannot be completed because the following relationship
would be violated: "logprimary + logsecond <= 256".
db2inst1@ubuntu14.04:~$ 

更に「LOGPRIMARY + LOGSECOND」の値にも制限があるようです。

結局、インスタンスを再起動する前提で、以下のように設定しました(元に戻しやすいように、それぞれ元の値の8倍)。

db2inst1@ubuntu14.04:~$ db2 update db cfg for HOGEHOGE using LOGFILSIZ 8192
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, all
applications must disconnect from this database before the changes become
effective.
db2inst1@ubuntu14.04:~$ db2 update db cfg for HOGEHOGE using LOGPRIMARY 104
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, all
applications must disconnect from this database before the changes become
effective.
db2inst1@ubuntu14.04:~$ db2 update db cfg for HOGEHOGE using LOGSECOND 32
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
db2inst1@ubuntu14.04:~$ db2stop
SQL1025N  The database manager was not stopped because databases are still active.
db2inst1@ubuntu14.04:~$ db2stop force
SQL1064N  DB2STOP processing was successful.
db2inst1@ubuntu14.04:~$ db2start
SQL1063N  DB2START processing was successful.
db2inst1@ubuntu14.04:~$ db2 "CREATE INDEX idx_hoge_hogehoge ON hoge(hogehoge)"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL1224N  The database manager is not able to accept new requests, has
terminated all requests in progress, or has terminated the specified request
because of an error or a forced interrupt.  SQLSTATE=55032
db2inst1@ubuntu14.04:~$ db2 "CREATE INDEX idx_hoge_hogehoge ON hoge(hogehoge)"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL1024N  A database connection does not exist.  SQLSTATE=08003
db2inst1@ubuntu14.04:~$ db2 connect to HOGEHOGE

   Database Connection Information

Database server        = DB2/LINUXX8664 9.7.5
SQL authorization ID   = DB2INST1
Local database alias   = HOGEHOGE

db2inst1@ubuntu14.04:~$ db2 "CREATE INDEX idx_hoge_hogehoge ON hoge(hogehoge)"
echo 2020/02/07 08:07 ; date
DB20000I  The SQL command completed successfully.
db2inst1@ubuntu14.04:~$ 

無事に作成できました。

hostnameの変更

CentOSにおけるホスト名、永続的に変更しようと思うと、バージョンによってやり方が異なるので簡単にまとめておくメモ。

CentOS 5/6

ホスト名は「/etc/sysconfig/network」ファイルに書いてあるので、hostnameコマンドで変更しても永続的には変更されません。

# vi /etc/sysconfig/network
HOSTNAME=<new-hostname>
# sync;sync;sync;shutdown -r now

「service network restarrt」で反映されると書いてあるサイトを山ほど見つけたのだけど、ダメだよね?その認識で合ってるよね?

中には「/etc/hosts」も編集すると書いてあるサイトもあって、なんかもう‥

CentOS 7/8

hostnamectlコマンドを使います。

# hostnamectl set-hostname <new-hostname>

これで即時反映されます。

logwatchをアンインストールせずにメール通知を止める

logwatchを使ってログの集計情報をメールで飛ばすということをやってきたけど、毎日毎日何通も来るのでだんだんウザくなって読まなくなってしまった。

そんなわけで、アンインストールするのもアレだったので、とりあえずメール通知を止めようということになった。

まずCentOS 6の環境で設定。

[hhelibex@centos6 ~]$ logwatch --version
Logwatch 7.3.6 (released 05/19/07)
[hhelibex@centos6 ~]$ cat /etc/logwatch/conf/logwatch.conf
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)
Detail = High
Archives = Yes
Save = /tmp/logwatch
[hhelibex@centos6 ~]$ 

これで様子を見てみると、無事に指定したファイルに結果が保存された。よしよし。

次はCentOS 7の環境。

[hhelibex@centos7 ~]$ logwatch --version
Logwatch 7.4.0 (released 03/01/11)
[hhelibex@centos7 ~]$ 

・・なのだが、CentOS 6環境と同じように設定してもダメで、相変わらずメールが飛んでくる・・ そこで「/usr/share/logwatch/default.conf/logwatch.conf」を見てみると、v7.3.6(CentOS 6)では存在した「Save」パラメータがv7.4.0(CentOS 7)では無くなっている。

なぬ!?と思って「logwatch --help」してみる。

[hhelibex@centos6 ~]$ logwatch --help

Usage: /usr/sbin/logwatch [--detail <level>] [--logfile <name>]
   [--print] [--mailto <addr>] [--archives] [--range <range>] [--debug <level>]
   [--save <filename>] [--help] [--version] [--service <name>]
   [--numeric] [--output <output_type>]
   [--splithosts] [--multiemail] [--no-oldfiles-log]

--detail <level>: Report Detail Level - High, Med, Low or any #.
--logfile <name>: *Name of a logfile definition to report on.
--logdir <name>: Name of default directory where logs are stored.
--service <name>: *Name of a service definition to report on.
--print: Display report to stdout.
--mailto <addr>: Mail report to <addr>.
--archives: Use archived log files too.
--save <filename>: Save to <filename>.
--range <range>: Date range: Yesterday, Today, All, Help
                             where help will describe additional options
--numeric: Display addresses numerically rather than symbolically and numerically
           (saves  a  nameserver address-to-name lookup).
--debug <level>: Debug Level - High, Med, Low or any #.
--splithosts: Create a report for each host in syslog.
--multiemail: Send each host report in a separate email.  Ignored if
              not using --splithosts.
--output <output type>: Report Format - mail, html or unformatted#.
--encode: Use base64 encoding on output mail.
--no-oldfiles-log: Suppress the logwatch log, which informs about the
                   old files in logwatch tmpdir.
--version: Displays current version.
--help: This message.
* = Switch can be specified multiple times...

[hhelibex@centos6 ~]$
[hhelibex@centos7 ~]$ logwatch --help

Usage: /usr/sbin/logwatch [--detail <level>] [--logfile <name>] [--output <output_type>]
   [--format <format_type>] [--encode <enconding>] [--numeric] [--no-oldfiles-log]
   [--mailto <addr>] [--archives] [--range <range>] [--debug <level>]
   [--filename <filename>] [--help|--usage] [--version] [--service <name>]
   [--hostformat <host_format type>] [--hostlimit <host1,host2>] [--html_wrap <num_characters>]

--detail <level>: Report Detail Level - High, Med, Low or any #.
--logfile <name>: *Name of a logfile definition to report on.
--logdir <name>: Name of default directory where logs are stored.
--service <name>: *Name of a service definition to report on.
--output <output type>: Report Output - stdout [default], mail, file.
--format <formatting>: Report Format - text [default], html.
--encode <encoding>: Enconding to use - none [default], base64.
--no-oldfiles-log: Suppress the logwatch log, which informs about the
                   old files in logwatch tmpdir.
--mailto <addr>: Mail report to <addr>.
--archives: Use archived log files too.
--filename <filename>: Used to specify they filename to save to. --filename <filename> [Forces output to file].
--range <range>: Date range: Yesterday, Today, All, Help
                             where help will describe additional options
--numeric: Display addresses numerically rather than symbolically and numerically
           (saves  a  nameserver address-to-name lookup).
--debug <level>: Debug Level - High, Med, Low or any #.
--hostformat: Host Based Report Options - none [default], split, splitmail.
--hostlimit: Limit report to hostname - host1,host2.
--hostname: overwrites hostname
--html_wrap <num_characters>: Default is 80.
--version: Displays current version.
--help: This message.
--usage: Same as --help.
* = Switch can be specified multiple times...

[hhelibex@centos7 ~]$

unified diffも取ってみる。

--- centos6
+++ centos7
@@ -1,31 +1,33 @@
-Usage: /usr/sbin/logwatch [--detail <level>] [--logfile <name>]
-   [--print] [--mailto <addr>] [--archives] [--range <range>] [--debug <level>]
-   [--save <filename>] [--help] [--version] [--service <name>]
-   [--numeric] [--output <output_type>]
-   [--splithosts] [--multiemail] [--no-oldfiles-log]
+Usage: /usr/sbin/logwatch [--detail <level>] [--logfile <name>] [--output <output_type>]
+   [--format <format_type>] [--encode <enconding>] [--numeric] [--no-oldfiles-log]
+   [--mailto <addr>] [--archives] [--range <range>] [--debug <level>]
+   [--filename <filename>] [--help|--usage] [--version] [--service <name>]
+   [--hostformat <host_format type>] [--hostlimit <host1,host2>] [--html_wrap <num_characters>]
--detail <level>: Report Detail Level - High, Med, Low or any #.
--logfile <name>: *Name of a logfile definition to report on.
--logdir <name>: Name of default directory where logs are stored.
--service <name>: *Name of a service definition to report on.
---print: Display report to stdout.
+--output <output type>: Report Output - stdout [default], mail, file.
+--format <formatting>: Report Format - text [default], html.
+--encode <encoding>: Enconding to use - none [default], base64.
+--no-oldfiles-log: Suppress the logwatch log, which informs about the
+                   old files in logwatch tmpdir.
--mailto <addr>: Mail report to <addr>.
--archives: Use archived log files too.
---save <filename>: Save to <filename>.
+--filename <filename>: Used to specify they filename to save to. --filename <filename> [Forces output to file].
--range <range>: Date range: Yesterday, Today, All, Help
                              where help will describe additional options
--numeric: Display addresses numerically rather than symbolically and numerically
            (saves  a  nameserver address-to-name lookup).
--debug <level>: Debug Level - High, Med, Low or any #.
---splithosts: Create a report for each host in syslog.
---multiemail: Send each host report in a separate email.  Ignored if
-              not using --splithosts.
---output <output type>: Report Format - mail, html or unformatted#.
---encode: Use base64 encoding on output mail.
---no-oldfiles-log: Suppress the logwatch log, which informs about the
-                   old files in logwatch tmpdir.
+--hostformat: Host Based Report Options - none [default], split, splitmail.
+--hostlimit: Limit report to hostname - host1,host2.
+--hostname: overwrites hostname
+--html_wrap <num_characters>: Default is 80.
--version: Displays current version.
--help: This message.
+--usage: Same as --help.
* = Switch can be specified multiple times...

・・おいおい、変わりすぎでしょう。

まぁ、とりあえず「Output = file」「Filename = /tmp/logwatch」とすれば良さそう・・・ダメだった・・なぜにメールが飛ぶ!?・・

ということで、今度はcronの設定を疑ってみる。

[hhelibex@centos7 ~]$ cat /etc/cron.daily/0logwatch
#!/bin/sh

#Set logwatch location
LOGWATCH_SCRIPT="/usr/sbin/logwatch"
#Add options to this line. Most options should be defined in /etc/logwatch/conf/logwatch.conf,
#but some are only for the nightly cronrun such as --output mail and should be set here.
#Other options to consider might be "--format html" or "--encode base64", man logwatch for more details.
OPTIONS="--output mail"

#Call logwatch
$LOGWATCH_SCRIPT $OPTIONS

exit 0
[hhelibex@centos7 ~]$ 

・・ちょっと待て!!設定ファイルを無視して強制的にメール送信かよ!!

(疲れたので中略)

結局、辿り着いた答えは以下だった。

[hhelibex@centos7 ~]$ cat /etc/logwatch/conf/logwatch.conf
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)
Detail = High
Archives = Yes
mailer = "cat > /tmp/logwatch"
[hhelibex@centos7 ~]$ 

ちなみに余談だけど、CentOS 6環境のcron設定も覗いてみると・・・

[hhelibex@centos6 ~]$ cat /etc/cron.daily/0logwatch
#!/bin/bash

DailyReport=`grep -e "^[[:space:]]*DailyReport[[:space:]]*=[[:space:]]*" /usr/share/logwatch/default.conf/logwatch.conf | head -n1 | sed -e "s|^\s*DailyReport\s*=\s*||"`

if [ "$DailyReport" != "No" ] && [ "$DailyReport" != "no" ]
then
    logwatch
fi
[hhelibex@centos6 ~]$ 

・・「/etc/logwatch/conf/logwatch.conf」で「DailyReport」を設定しても無視ですか・・orz

hostnamectlとsystemctlでの情報表示

今まで、パラメータを渡して実行することしかしなかったので、パラメータなしで実行すると情報が出てくるっていうのをつい最近になって知りました(汗)。

hostnamectlコマンドは、ホスト名やOS名等々が表示される。

[hhelibex@centos7 ~]$ hostnamectl
   Static hostname: centos7
   Pretty hostname: CentOS7
         Icon name: computer-vm
           Chassis: vm
        Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
           Boot ID: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1062.9.1.el7.x86_64
      Architecture: x86-64
[hhelibex@centos7 ~]$ 

systemctlコマンドは、操作できるUNITの一覧などを参照することができる。

[hhelibex@centos7 ~]$ systemctl
UNIT                                                                                     LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount                                                        loaded active running   Arbitrary Executable File Formats File System Automount Point
 :
sys-subsystem-net-devices-eth0.device                                                    loaded active plugged   Virtio network device
sys-subsystem-net-devices-eth1.device                                                    loaded active plugged   Virtio network device
-.mount                                                                                  loaded active mounted   /
boot.mount                                                                               loaded active mounted   /boot
 :
postfix.service                                                                          loaded active running   Postfix Mail Transport Agent
postgresql.service                                                                       loaded active running   PostgreSQL database server
 :
sshd.service                                                                             loaded active running   OpenSSH server daemon
 :
network.target                                                                           loaded active active    Network
 :
systemd-tmpfiles-clean.timer                                                             loaded active waiting   Daily Cleanup of Temporary Directories

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

101 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[hhelibex@centos7 ~]$ 

ふと叩いてみた結果として気付いたんだけど、何がきっかけで知識を得られるか分からない。

findコマンドで特定のユーザ/グループのファイル/ディレクトリを探す

ある時、特定のユーザ/グループのファイル/ディレクトリをchownしたい要件が出てきた。 開発環境で、最初は「apache/apache」で動かしていたhttpd、だんだんとめんどくさくなって、httpdのUser/Groupを変えたいけど、ファイルの所有者が‥という感じ。

まぁ探す手段はあるんだろうと思いながら、findコマンドのヘルプを見てみる。

$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
$ find --version
find (GNU findutils) 4.5.11
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
有効になっている機能: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
$ find --help
使用法: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

デフォルトのパスはカレントディレクトリです。デフォルトの評価式 (expression) は -print です。評価式は演算子、オプション、テストおよびアクションで構成さ
れます。

演算子 (優先順位は降順です。特に指定がない場合は -and が暗黙的に使用されます):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
-depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
--version -xautofs -xdev -ignore_readdir_race -noignore_readdir_race

テスト (N は +N、-N または Nで指定します): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
-readable -writable -executable
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls]
-context CONTEXT


アクション: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
-fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
-exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
-execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

バグを発見した場合は findutils バグ報告ページ http://savannah.gnu.org/ を
使用して報告 (および修正の進捗を追跡) してください。Web を利用できない場合
は <bug-findutils@gnu.org> に E-mail を送ってください。

覚えていた定型的なものを使っていただけなんだなと改めて思う。

今回は、テスト「-user NAME」と「-group NAME」を使えばよさげ。

例えば以下のような感じになるだろう。

# find / -user apache -group apache -exec chown hhelibex.hhelibex {} \; -o -user apache -exec chown hhelibex {} \; -o -gro
up apache -exec chown .hhelibex {} \;

ユーザ/グループが両方ともapacheであるケースを忘れてはいけないことに注意。

2020年の行動指針(努力目標)

今更感ですが、明けましておめでとうございます。

昨年どころか、ここ数年というもの、いろいろとあって、何も進展しておらずにただただ日々の諸々に追われるだけの毎日になっている気がしています。

この流れを断ち切るべく、また続々と現れる若い力に飲み込まれないために、何ができるだろうかと考えてみました。

実のところ、このブログ自体をどうしていこうかなというのも思うところありなのですが、いったんリセットして、コンテンツは何らかの形で継承できるようにとか、ゆっくりですが、考えているところです。

とりあえず、2020年は「何かを知ったら何かを書こう」というのを行動指針(努力目標)にしていきたいなと思っています。

例えば「コマンドのオプションを1つ知ったからブログ記事を一つ書こう」とか、そんな軽いノリにしようかと思っています。

整理しないと取り留めなくなってしまうという恐れもあるのですが、書かなければ記憶の中だけにとどまっていずれ忘れ去ってしまうので、「学習ログ」という意味合いでよいかな、と考えて、とりあえず数をこなしていきたいなと思います。

本年もどうぞよろしくお願いします。