Contenu connexe Similaire à 使いこなそうGUC (20) 使いこなそうGUC2. GUC
● Grand Unified Configuration(ソースの中にしか出てこない
言葉かもしれない)
● PostgreSQLの設定はどうやって変更する?
● postgresql.confを書き換えたり
● SETコマンドとか
● いつ反映される?
● 再起動?
● リロード?
● 参考:
● src/include/misc/guc.h
3. とりあえずSELECT * FROM pg_settings;
● 8.3.7での実行例
● 以降、context列とsource列の説明です
=> SELECT * FROM pg_settings;
-[ RECORD 1 ]-------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------
name | add_missing_from
setting | off
unit | <Null>
category | Version and Platform Compatibility / Previous PostgreSQL Versions
short_desc | Automatically adds missing table references to FROM clauses.
extra_desc | <Null>
context | user
vartype | bool
source | default
min_val | <Null>
max_val | <Null>
...
4. context(1)
● いつ変更が反映されるのか
● internal
● 内部的な設定値。変更不可(server_version等)
● postmaster
● postmaster起動時
● postgresql.conf又はコマンドラインオプション
● sighup
● kill -HUP(pg_ctl reload等)で読み込む
5. context(2)
● backend
● バックエンド起動時(=接続時)のパラメータ
● なので接続毎に異なる値を持つ
● クライアントの環境変数や接続文字列
● superuser
● スーパーユーザがsetコマンドで変更可能
● user
● どのユーザでもsetコマンドで変更可能
6. source(1)
● 現在の値はどこで設定されたものか
● default
● environment variable
● postmasterの環境変数
● PGDATESTYLE,PGPORT,PGCLIENTENCODING
● 普通使いません
● configuration file
● postgresql.conf
7. source(2)
● command line
● postmasterのコマンドライン引数
● postgres -D data --add_missing_from=on
● pg_ctl start -D data -o “--add_missing_from=on”
● database
● ALTER DATABASE dbname SET foo to bar;
● user
● ALTER USER username SET foo to bar;
8. source(3)
● client
● 環境変数PGOPTIONS,PGCLIENTENCODINGや接続文字列
等
● PGOPTIONS=”-c add_missing_from=on” psql
● pg_connect(“options='--add_missing_from=on'”)
● session
● SETコマンド
9. 8.4のpg_settings
● vartypeにenumが追加された
● sourcefile, sourcelineが追加された
=# SELECT * from pg_settings where name = 'log_statement';
-[ RECORD 1 ]-----------------------------------
name | log_statement
setting | none
unit | <Null>
category | Reporting and Logging / What to Log
short_desc | Sets the type of statements logged.
extra_desc | <Null>
context | superuser
vartype | enum
source | default
min_val | <Null>
max_val | <Null>
enumvals | {none,ddl,mod,all}
boot_val | none
reset_val | none
sourcefile | /usr/home/ishida/pgsql/8.4.0/data/postgresql.conf
sourceline | 500
10. case study(1)
● 動作中のアプリのSQLのログを取りたい
● contextはsuperuser
● でもSETコマンドではそのセッションしか変更できない
● postgresql.confを変更するのは面倒
● ALTER DATABASE又はALTER USERを使ってみれば?
11. 間違ったGUCの使い方
● http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks
#Any_other_session_variables