VACUUM は、不要タプルが使用する領域を回収します。 PostgreSQLの通常動作では、削除されたタプルや更新によって不要となったタプルは、テーブルから物理的には削除されません。 これらのタプルはVACUUMが完了するまで存在し続けます。 そのため、特に更新頻度が多いテーブルでは、VACUUMを定期的に実行する必要があります。
[docker] docker-compose
アプリケーションのコンテナの他に、データベースなどのコンテナが必要な場合などに使用される
$ sudo docker-compose version
docker-compose version 1.16.1, build 6d1ac21
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
### docker composeでアプリケーション実行環境を立ち上げる手順
1. コンテナを立ち上げるのに必要なイメージを用意(dockerfile)
2. 各コンテナを起動する際の設定をdocker-compose.ymlに定義
3. docker-compose.ymlに置いてあるディレクトリ上でdocker
– コンテナ間に通信したい場合に、サービス名で通信できる
記述例
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
redis:
image: redis
volumes:
logvolume01: {}
うおおおおおおおおおお
なんとなくわかってきた
[docker] tmpfsを使ってみる
tmpfsはメモリ領域をコンテナにマウントする
コンテナやホストが停止すると、保持していたデータは解放されtmpfsマウントが取り除かれる
$ sudo docker run -itd –name tmpfs-c1 –mount type=tmpfs,destination=/cache busybox
$ sudo docker inspect tmpfs-c1
“Mounts”: [
{
“Type”: “tmpfs”,
“Source”: “”,
“Destination”: “/cache”,
“Mode”: “”,
“RW”: true,
“Propagation”: “”
}
],
$ sudo docker run -itd –name tmpfs-c1 –mount type=tmpfs,destination=/cache,tmpfs-size=500000000,tmpfs-mode=700 busybox
ファイルモードや容量などを指定できる
なるほど、あんまり使わなそうだな…
[docker] Bind Mount
Bind MountはPC上の任意のディレクトリをコンテナにマウントする
-v <ホスト上のディレクトリ>:<コンテナ上のディレクトリ>
$ touch test-file
$ ls -la
total 8
drwxr-xr-x 2 vagrant vagrant 4096 Mar 19 00:57 .
drwxrwxr-x 3 vagrant vagrant 4096 Mar 18 23:07 ..
-rw-rw-r– 1 vagrant vagrant 0 Mar 19 00:57 test-file
$ sudo docker run -itd –name bind-c1 -v “$(pwd)”:/bind_dir busybox
$ sudo docker exec bind-c1 ls -la /bind_dir
total 8
drwxr-xr-x 2 1000 1000 4096 Mar 19 00:57 .
drwxr-xr-x 1 root root 4096 Mar 19 01:12 ..
-rw-rw-r– 1 1000 1000 0 Mar 19 00:57 test-file
$ touch test-file2
$ sudo docker exec bind-c1 ls -la /bind_dir
total 8
drwxr-xr-x 2 1000 1000 4096 Mar 19 01:13 .
drwxr-xr-x 1 root root 4096 Mar 19 01:12 ..
-rw-rw-r– 1 1000 1000 0 Mar 19 00:57 test-file
-rw-rw-r– 1 1000 1000 0 Mar 19 01:13 test-file2
### -mountを指定したコンテナの起動
$ sudo docker run -itd –name bind-c2 –mount type=bind,source=”$(pwd)”,target=/bind_dir busybox
54deefdb625241544cc84326df8055e38c32a8d3e6b2a97c1d0db2bb260c693f
$ sudo docker exec bind-c2 ls -l /bind_dir
total 0
-rw-rw-r– 1 1000 1000 0 Mar 19 00:57 test-file
-rw-rw-r– 1 1000 1000 0 Mar 19 01:13 test-file2
※–mountオプションの方が読みやすい。また、間違えたディレクトリのバインドを防ぐ意味でも–mountの方が安全
### バインドマウントの設定確認
$ sudo docker inspect bind-c1
“Mounts”: [
{
“Type”: “bind”,
“Source”: “/home/vagrant/dev/docker/test/app”,
“Destination”: “/bind_dir”,
“Mode”: “”,
“RW”: true,
“Propagation”: “rprivate”
}
],
なるほど、bindの概念はvolumeと一緒でわりかし簡単だな
[docker] volumeを作成
### volumeの作成方法
$ sudo docker volume ls
$ sudo docker volume create my-vol
$ sudo docker volume inspect my-vol
[
{
“CreatedAt”: “2022-03-18T23:05:02Z”,
“Driver”: “local”,
“Labels”: {},
“Mountpoint”: “/var/lib/docker/volumes/my-vol/_data”,
“Name”: “my-vol”,
“Options”: {},
“Scope”: “local”
}
]
$ sudo docker volume rm my-vol
### volumeのマウント方法
$ sudo docker run -itd –name c1 -v vol1:/app busybox
$ sudo docker volume ls
$ sudo docker inspect c1
"Mounts": [
{
"Type": "volume",
"Name": "vol1",
"Source": "/var/lib/docker/volumes/vol1/_data",
"Destination": "/app",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],
$ sudo docker exec -it c1 /bin/sh
/ # df
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 40593612 36988012 3589216 91% /
tmpfs 65536 0 65536 0% /dev
tmpfs 2013052 0 2013052 0% /sys/fs/cgroup
shm 65536 0 65536 0% /dev/shm
/dev/sda1 40593612 36988012 3589216 91% /app
/dev/sda1 40593612 36988012 3589216 91% /etc/resolv.conf
/dev/sda1 40593612 36988012 3589216 91% /etc/hostname
/dev/sda1 40593612 36988012 3589216 91% /etc/hosts
tmpfs 2013052 0 2013052 0% /proc/acpi
tmpfs 65536 0 65536 0% /proc/kcore
tmpfs 65536 0 65536 0% /proc/keys
tmpfs 65536 0 65536 0% /proc/timer_list
tmpfs 65536 0 65536 0% /proc/sched_debug
tmpfs 2013052 0 2013052 0% /proc/scsi
tmpfs 2013052 0 2013052 0% /sys/firmware
/ # cd /app
/app # touch hogehoge
/app # exit
$ sudo docker run -itd –name c2 –mount source=vol1,target=/app busybox
$ sudo docker exec -it c2 /bin/sh
/ # ls -la /app/
total 8
drwxr-xr-x 2 root root 4096 Mar 18 23:16 .
drwxr-xr-x 1 root root 4096 Mar 18 23:18 ..
-rw-r–r– 1 root root 0 Mar 18 23:16 hogehoge
おおおお、マウントされてる…
### 既に存在するディレクトリへのvolumeのマウントについて
$ sudo docker run -itd –name c3 –mount source=vol2,destination=/var busybox
$ sudo docker inspect c3
“Mounts”: [
{
“Type”: “volume”,
“Name”: “vol2”,
“Source”: “/var/lib/docker/volumes/vol2/_data”,
“Destination”: “/var”,
“Driver”: “local”,
“Mode”: “z”,
“RW”: true,
“Propagation”: “”
}
],
$ sudo docker exec -it c3 /bin/sh
/ # ls -la /var/
–mount で読み取り専用(readonly)
-vフラグで読み取り専用
volumeのマウントタイプはDockerホスト上のDockerが管理する領域に自動的にディレクトリが作成されコンテナにマウントされる
なるほど、dockerの管理領域にディレクトリを作成するのがvolumeね。
Git基礎: リモートリポジトリ
リモートリポジトリを使う手順
1. 空のリモートリポジトリを作る
2. ローカルリポジトリの内容をリモートリポジトリに送る
3. ローカルリポジトリで作業して内容を更新する
2, 3を繰り返す
### リモートリポジトリを上流リポジトリとする
$ git init
$ git remote add origin https://github.com/hpscript/git101.git
$ git remote -v
$ git push origin master
### リモート追跡ブランチ
$ git branch -r
$ git branch -r -v
### クローン
$ git clone https://github.com/hpscript/git101.git
### リモートの更新を取得
$ git fetch リモート リモートブランチ
### リモートの更新をローカルに反映
git checkout ローカルブランチ
git merge –ff-only リモート追跡ブランチ
$ git checkout master
$ git merge –ff-only origin/master
### リモートブランチとローカルブランチを対応づけ
git branch -u
git branch -u origin/master
うーん、なんだかなー
Git基礎: タグ
Gitのタグの種類
– 軽量タグ
– 注釈付きタグ
– 署名タグ
### 軽量タグをつける
git tag タグ名
git tag タグ名 コミット
$ git tag v1.0
$ git tag
v1.0
prog.sh
#!/bin/sh echo "Your age?"; read age echo "Your age is $age."
$ git add .
$ git commit -m “first commit”
$ git tag v1.0
$ git tag
$ git show
### 注釈付きタグ
git tag -a タグ名
git tag -a タグ名 コミット
$ git add -u
$ git tag -a v3.0 -m “version3.0”
$ git show
### タグのついたコミットをチェックアウトする
git checkout タグ
$ git tag v1.1
$ git branch
master
* v1fix
### タグを削除する
git tag -d タグ
$ git tag -d v2.0
ニャルほどー
git基礎: ブランチ
ブランチとは履歴の枝分かれ
変更をmasterブランチに取り込むことをマージ
program.txt
春の大運動会 * 開会式 * 閉会式
$ git add program.txt
$ git commit -m “プログラム作成開始”
### ブランチを作る
git branch ブランチ名
$ git add -u
※バージョン管理されていて、変更があったすべてのファイルがaddされる
$ git commit -m “玉関係の競技追加”
$ git branch proc
$ git branch
$ git branch -v
* master 69c78cb 玉関係の競技追加
proc 69c78cb 玉関係の競技追加
git branchに-vオプションを与えると、ブランチの先頭があるコミット情報も表示される
$ git add -u
$ git commit -m “走る競技追加”
$ git branch -v
* master 66006b7 走る競技追加
proc 69c78cb 玉関係の競技追加
### ブランチ切り替え
git checkout ブランチ
$ git checkout proc
$ git branch
$ cat program.txt
春の大運動会
* 開会式
* 玉入れ
* 大玉転がし
* 閉会式
$ git checkout master
$ git branch
$ cat program.txt
春の大運動会
* 開会式
* 玉入れ
* 大玉転がし
* 二人三脚
* 徒競走
* 閉会式
$ git log –all –graph
$ git log –all –graph –oneline
* df1adc9 (proc) 選手宣誓追加
| * 66006b7 (HEAD -> master) 走る競技追加
|/
* 69c78cb 玉関係の競技追加
* 38d5fe3 プログラム作成開始
### ブランチのマージ
$ git merge proc
$ cat program.txt
春の大運動会
* 開会式
* 選手宣誓
* 玉入れ
* 大玉転がし
* 二人三脚
* 徒競走
* 閉会式
$ git ls-files -s
100644 9dc5b70af547cf38876fd39e696ca12944609018 1 program.txt
100644 8dcdb3703137b61fd6286001320d39045e9ab679 2 program.txt
100644 1203c826d8f52af84d75362c8a59f69fa399a473 3 program.txt
### ブランチを削除
git branch -d ブランチ
$ git checkout master
$ git branch -d proc
なるほどー ブランチの概念はわかったわ
git基本コマンド2
git diff: ファイルの差分, 最後にstageした後に何を変更したかの確認によく使う
git diff –staged, git diff HEAD
$ git diff
diff –git a/hello.txt b/hello.txt
index 05a682b..4a49d86 100644
— a/hello.txt
+++ b/hello.txt
@@ -1 +1,2 @@
-Hello!
\ No newline at end of file
+Hello!
+I am a student.
### 履歴の中で違いを見る
git diff コミット1 コミット2
git diff コミット1 コミット2 — ファイル
$ git diff 7aad1 HEAD
$ git diff HEAD^ HEAD
$ git diff HEAD~1 HEAD
$ git diff @^^ @
headは@とも書ける
### コミット情報の表示
git show: 直近のコミットがどんなものだったかを表示する
$ git show
### 一度ステージした内容を変更
ファイルに変更を追加してgit add -uなどとする
### ステージの内容を見る
$ git ls-files
詳細を見る場合は-sオプションをつける
$ git ls-files -s
$ git show a5842752b
### ステージしたことを無かったことにする
git reset
git reset –file
git reset –hard # ツリーの状態をHEADの上に戻す
$ git reset –hard
変更したものが、HEADの状態に戻る
### ステージした後の変更をなしにする
git checkout — file
$ git checkout — hello.txt
$ cat hello.txt
### ファイル名を変える
git mv 元のファイル 新しいファイル
### ファイルを管理下から外す
git rm ファイル
ステージだけから取り除き、作業ツリーにあるものは残したい場合 –cachedをつける
git rm –cached file
git rm -r –cached dir
### 昔のファイルをリポジトリから取り出す
$ git checkout HEAD~3 –hello.txt
チェックアウトせずに昔のファイルを見る
$ git show HEAD~3:hello.txt
$ git checkout HEAD~3 — hello.txt
$ git show HEAD~3:hello.txt
### 作業ツリーの内容をHEADの状態にする
$ git reset –hard
$ ls
### 最近の履歴を無かったものにする
$ git reset –hard コミット
$ git reset a82684a02
$ git log
### 直近のコミットをやり直す
$ git commit –amend
### gitにファイルを無視させる
.gitignoreを使う
*.log !test.log
$ git commit -m “8th commit”
使いながら覚えないとどうにもならんな これ…
git基本コマンド1
$ git help
$ git help help
### git config
Gitの設定ファイルにある変数の値を設定
/etc/gitconfig : マシン全体に対する設定 –sytemオプションを使う
~/.gitconfig: ユーザごとの設定 –globalオプション
.git/config: プロジェクトごとの設定
$ git config –global -l
user.email=hoge@gmail.com
user.name=Hpscript
### バージョン管理を始める
$ git init
Initialized empty Git repository in /home/vagrant/dev/git/.git/
### ファイルやディレクトリを管理下に入れる
$ touch README.txt
$ git add README.text
### コミットしてリポジトリに入れる
既にステージにある場合は git add -uを使う
$ git commit -m “first commit”
$ git add -u
$ git commit -m “second commit”
### 履歴を見る
$ git log
$ git log –oneline
7aad1d5 (HEAD -> master) second commit
8a0580a first commit
### ファイルを追加
hello.txt
$ git add .
### どのファイルを新たにステージしたか見る
$ git status
※ファイルを追加した場合、new file, 編集した場合はmodified
$ git add -u
$ git status
※stageされてない場合は untracked fileと表示される
うむ、基礎操作から結構大変だな