【转自谭峰】PostgreSQL9.5:新增参数设置神器:pg_file_setting
来源于:
http://francs3.blog.163.com/blog/static/405767272015711115245190/ 9.5 版本新增 pg_file_settings 视图,可谓参数设置的神器,为啥这么说呢? 因为 postgresql.conf 参数值调整后,有些 reload 后就生效了,有些需要重启服务才生效,如果你设置的参数值是非法的, pg_ctl reload 命令也不报错,这时很让人尴尬,reload 后还得连到数据库里去 show 参数值,确认参数值是否生效,9.5 版本新增 pg_file_settings 视图,让这项工作容易很多。 一 关于 pg_file_settings 视图 --pg_file_settings 视图 postgres=# d pg_file_settings View "pg_catalog.pg_file_settings" Column | Type | Modifiers ------------+---------+----------- sourcefile | text | sourceline | integer | seqno | integer | name | text | setting | text | applied | boolean | error | te postgres=# select * from pg_file_settings limit 3; sourcefile | sourceline | seqno | name | setting | applied | error ----------------------------------------+------------+-------+------------------+---------+---------+------- /database/pg95/pg_root/postgresql.conf | 59 | 1 | listen_addresses | * | t | /database/pg95/pg_root/postgresql.conf | 63 | 2 | port | 1931 | t | /database/pg95/pg_root/postgresql.conf | 64 | 3 | max_connections | 100 | t | (3 rows) 备注:sourcefile: 配置文件名称 [pg95@db2 pg_root]$ grep "log_statement =" postgresql.conf log_statement = 'ddd' # none,ddl,mod,all --reload 配置 [pg95@db2 pg_root]$ pg_ctl reload server signaled 备注: postgresql.conf 参数调整后,不管设置成功与否,pg_ctl reload 参数是不输出相关信息的,9.5 版本之前要确认参数是否成功有两种方法,一种是查看相关 pg_log,例如 --查看报错日志 [pg95@db2 pg_log]$ grep "log_statement" postgresql-2015-08-11_000000.csv 2015-08-11 10:36:36.177 CST,31634,55c83dc1.7b92,9,2015-08-10 13:59:29 CST,LOG,22023,"invalid value for parameter ""log_statement"": ""ddd""","Available values: none,all.","" 2015-08-11 10:43:25.063 CST,12,"" --另一种方式是连接到数据库中查看 [pg95@db2 pg_log]$ psql -c "show log_statement" log_statement --------------- none (1 row)备注:可见 log_statement 参数设置无效。 9.5 版本之后,可以通过 pg_file_settings 视图查看。 --查看 pg_file_settings 中的错误信息 postgres=# select * from pg_file_settings where error is not null; -[ RECORD 1 ]-------------------------------------- sourcefile | /database/pg95/pg_root/postgresql.conf sourceline | 441 seqno | 32 name | log_statement setting | ddd applied | f error | setting could not be applied备注:错误信息简单明了。 三 测试二: 设置需要重启服务才生效的参数--修改 max_connections 参数 [pg95@db2 pg_root]$ grep "max_connections =" postgresql.conf max_connections = 100 # (change requires restart) 备注: max_connections 参数默认为 100,这个参数设置后需要重启才生效,我们把它设置成 200。 [pg95@db2 pg_root]$ grep "max_connections =" postgresql.conf max_connections = 200 # (change requires restart) [pg95@db2 pg_root]$ pg_ctl reload server signaled --数据库查看 postgres=# select * from pg_file_settings where name='max_connections'; -[ RECORD 1 ]-------------------------------------- sourcefile | /database/pg95/pg_root/postgresql.conf sourceline | 64 seqno | 3 name | max_connections setting | 200 applied | f error | setting could not be applied备注:max_connections 参数的 ERROR 信息很明显了,新增这个视图将让参数设置这项工作变得容易 。 四 参考
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |