Postgresql参数配置文件及参数生效方法

PostgreSQL数据库的配置文件的位置在实例目录下,文件名为 postgresql.conf 。

修改配置参数的时候,需要手工修改 postgresql.conf 文件里边的配置参数。
大部分配置参数是被注释掉的,文件内初始值就是默认值。

使用 show all 命令可以看到所有参数值,例如:

test=# show all;
                name                 |                         setting                          |                                                          description 
                                                         
-------------------------------------+----------------------------------------------------------+----------------------------------------------------------------------
---------------------------------------------------------
 allow_system_table_mods             | off                                                      | Allows modifications of the structure of system tables.
 application_name                    | psql                                                     | Sets the application name to be reported in statistics and logs.
 archive_command                     | (disabled)                                               | Sets the shell command that will be called to archive a WAL file.
 archive_mode                        | off                                                      | Allows archiving of WAL files using archive_command.
 archive_timeout                     | 0                                                        | Forces a switch to the next xlog file if a new file has not been star
ted within N seconds.
 array_nulls                         | on                                                       | Enable input of NULL elements in arrays.
 authentication_timeout              | 1min                                                     | Sets the maximum allowed time to complete client authentication.
 autovacuum                          | on                                                       | Starts the autovacuum subprocess.
 autovacuum_analyze_scale_factor     | 0.1                                                      | Number of tuple inserts, updates, or deletes prior to analyze as a fr
action of reltuples.

下面语句也可以查看所有有效参数值和当前值,也可以看到生效时机:

select * from pg_settings;

关于 pg_settings 的官方文档:
https://www.postgresql.org/docs/9.3/view-pg-settings.html

全部生效时机如下所示:

test=# select distinct context from pg_settings;
  context   
------------
 backend
 user
 internal
 postmaster
 superuser
 sighup
(6 rows)

上述6种生效时机的具体含义如下:

***internal***
    These settings cannot be changed directly; they reflect internally determined values. Some of them may be adjustable by rebuilding the server with different configuration options, or by changing options supplied to initdb.
***postmaster***
    These settings can only be applied when the server starts, so any change requires restarting the server. Values for these settings are typically stored in the postgresql.conf file, or passed on the command line when starting the server. Of course, settings with any of the lower context types can also be set at server start time.
***sighup***
    Changes to these settings can be made in postgresql.conf without restarting the server. Send a SIGHUP signal to the postmaster to cause it to re-read postgresql.conf and apply the changes. The postmaster will also forward the SIGHUP signal to its child processes so that they all pick up the new value.
***backend***
    Changes to these settings can be made in postgresql.conf without restarting the server; they can also be set for a particular session in the connection request packet (for example, via libpq's PGOPTIONS environment variable). However, these settings never change in a session after it is started. If you change them in postgresql.conf, send a SIGHUP signal to the postmaster to cause it to re-read postgresql.conf. The new values will only affect subsequently-launched sessions.
***superuser***
    These settings can be set from postgresql.conf, or within a session via the SET command; but only superusers can change them via SET. Changes in postgresql.conf will affect existing sessions only if no session-local value has been established with SET.
***user***
    These settings can be set from postgresql.conf, or within a session via the SET command. Any user is allowed to change his session-local value. Changes in postgresql.conf will affect existing sessions only if no session-local value has been established with SET.

参数值修改之后,需要让参数生效。让参数生效的方法的官方文档链接:
https://www.postgresql.org/docs/9.3/config-setting.html
下面这段话:

The configuration file is reread whenever ***the main server process receives a SIGHUP signal***; this is most easily done by ***running pg_ctl reload*** from the command-line or by calling the ***SQL function pg_reload_conf()***. The main server process also propagates this signal to all currently running server processes so that existing sessions also get the new value. Alternatively, you can send the signal to a single server process directly. Some parameters can only be set at server start; any changes to their entries in the configuration file will be ignored until the server is restarted. Invalid parameter settings in the configuration file are likewise ignored (but logged) during SIGHUP processing.

说明有三种方式可以让参数生效:

1. 发送 SIGHUP 信号给主服务进程;
2. 运行 pg_ctl reload 命令;
3. 调用函数 select pg_reload_conf();
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PostgreSQL是一个功能强大的开源关系型数据库管理系统,它可以在多种操作系统上运行。要配置PostgreSQL,你需要进行以下步骤: 1. 安装PostgreSQL:首先,你需要从PostgreSQL官方网站(https://www.postgresql.org/)下载适合你操作系统的安装包,并按照指示进行安装。 2. 创建数据库集群:在安装完成后,你需要创建一个数据库集群。在终端中执行以下命令(Windows用户可以使用pgAdmin等图形界面工具): ``` initdb -D /path/to/data/directory ``` 这将在指定的路径下创建一个数据库集群。 3. 启动PostgreSQL服务器:执行以下命令来启动PostgreSQL服务器: ``` pg_ctl -D /path/to/data/directory start ``` 这将启动一个后台进程来运行PostgreSQL服务器。 4. 创建数据库和用户:使用以下命令登录到PostgreSQL控制台: ``` psql -U postgres ``` 然后,你可以执行以下命令来创建数据库和用户: ``` CREATE DATABASE dbname; CREATE USER username WITH ENCRYPTED PASSWORD 'password'; GRANT ALL PRIVILEGES ON DATABASE dbname TO username; ``` 将 `dbname` 替换为你想创建的数据库名称,`username` 替换为你想创建的用户名,`password` 替换为用户密码。 5. 修改配置文件PostgreSQL配置文件位于数据目录下的 `postgresql.conf` 文件中。你可以使用任何文本编辑器打开该文件,并通过修改参数配置数据库的行为。 6. 重启数据库:在修改配置文件后,你需要重新启动PostgreSQL服务器以使更改生效。执行以下命令: ``` pg_ctl -D /path/to/data/directory restart ``` 这将重新启动PostgreSQL服务器。 这些是配置PostgreSQL的基本步骤。你可以根据自己的需求进一步修改和调整配置。如果需要更详细的帮助,请参考PostgreSQL官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值