PostgreSQL | ターミナルコマンド集
DB 初期化
initdb --encoding=UTF-8 --no-locale --username={user name} --pgdata={database directory}
DB 作成
createdb --encoding=UTF-8 --username=root --owner=root --port=5432 {database name}
DB 起動
pg_ctl start --pgdata={database directory} --log={log file}
pg_ctl が root で実行されないようにする。設定ファイルを使用するため、postgres が所有している状態で root 権限により pg_ctl start を実行すると、権限が付与される可能性がある。
iDEFENSE が指摘した権限昇格攻撃である。もちろん postmaster は失敗するが、慣れていないシステム管理者を保護するため、より早く失敗させる必要がある。
選択された修正は、すべての場合で pg_ctl の root 使用を無効にすることである。
DB 終了
pg_ctl stop --pgdata={database directory} -m fast
DB 接続
psql --host=127.0.0.1 --port=5432 --username={user name} --dbname={database name} --password
テーブル一覧確認
\dt
終了
\q