最近データベースはMySQLを使う事が多かったのですが、PostgreSQLを久しぶりに色々触ってみています。
調べたいことがあれば、日本PostgreSQLユーザー会のドキュメント を見れば事足りる事が多いかと思います。
その上で、メモがてらに記録しておきます。最後に pgbench の実行結果だけ記載しています。
構成ファイル
initdb で作成された dataディレクトリ(/var/lib/pgsql/data/)内に配置されている。
- postgresql.conf(パラメータ設定ファイル)
- pg_hba.conf(ホストベース認証設定)
- pg_ident.conf(ident認証用の構成ファイル)
データベースへのアクセス
psql をユーザー指定した場合とユーザー指定しなかった場合(スーパーユーザ)のコンソールの違い
$ psql drupal -U drupal psql (8.4.18) "help" でヘルプを表示します. drupal=> drupal=> \q $ $ psql drupal psql (8.4.18) "help" でヘルプを表示します. drupal=# drupal=# \q $
バージョン確認
psql でバージョン確認
$ cat /etc/redhat-release CentOS release 6.4 (Final) $ $ cat PG_VERSION 8.4 $ $ psql --version psql (PostgreSQL) 8.4.18 コマンドライン編集機能のサポートが組み込まれています。 $ $ psql psql (8.4.18) "help" でヘルプを表示します. postgres=# select version(); version ------------------------------------------------------------------------------------------------------------------ PostgreSQL 8.4.18 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), 64-bit (1 行) postgres=#
ログの出力先
postgresql.conf でのログ仕様
log_directory = 'pg_log' log_filename = 'postgresql-%a.log' log_truncate_on_rotation = on log_rotation_age = 1d log_rotation_size = 0
上記載の場合、data ディレクトリ配下に、pg_log ディレクトリがあります。
$ pwd /var/lib/pgsql/data $ ls -1st pg_log/ 合計 20 0 postgresql-Sun.log 4 postgresql-Sat.log 0 postgresql-Fri.log 4 postgresql-Thu.log 12 postgresql-Wed.log $
pgbench
今回は、yum でインストールします。
# yum install postgresql-contrib
使い方は「pgbenchの使いこなし」に記載されています。
$ createdb test $ pgbench -i test NOTICE: テーブル"pgbench_branches"は存在しません。省略します NOTICE: テーブル"pgbench_tellers"は存在しません。省略します NOTICE: テーブル"pgbench_accounts"は存在しません。省略します NOTICE: テーブル"pgbench_history"は存在しません。省略します creating tables... 10000 tuples done. 20000 tuples done. 30000 tuples done. 40000 tuples done. 50000 tuples done. 60000 tuples done. 70000 tuples done. 80000 tuples done. 90000 tuples done. 100000 tuples done. set primary key... NOTICE: ALTER TABLE / ADD PRIMARY KEYはテーブル"pgbench_branches"に暗黙的なインデックス"pgbench_branches_pkey"を 作成します NOTICE: ALTER TABLE / ADD PRIMARY KEYはテーブル"pgbench_tellers"に暗黙的なインデックス"pgbench_tellers_pkey"を作 成します NOTICE: ALTER TABLE / ADD PRIMARY KEYはテーブル"pgbench_accounts"に暗黙的なインデックス"pgbench_accounts_pkey"を 作成します vacuum...done. $ $ pgbench -c 10 -t 1000 test starting vacuum...end. transaction type: TPC-B (sort of) scaling factor: 1 query mode: simple number of clients: 10 number of transactions per client: 1000 number of transactions actually processed: 10000/10000 tps = 105.200402 (including connections establishing) tps = 105.244772 (excluding connections establishing) $
上記は、私の検証環境(仮想マシン)での試験結果です。