Postgresql服务器配置-设置参数

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB PostgreSQL 版,企业版 4核16GB
推荐场景:
HTAP混合负载
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介: Postgresql服务器配置-设置参数 1、Parameter Names and Values 每个参数都有一个值。所有参数名称都不区分大小写。每个参数值都采用五种类型之一: 布尔、字符串、整数、浮点或枚举 (枚举) Boolean:值可以是off, true, false, yes, no, 1, 0 (区分大小写)或其中一个值的任何明确前缀。

Postgresql服务配置-设置参数

1、Parameter Names and Values

每个参数都有一个值。所有参数名称都不区分大小写。每个参数值都采用五种类型之一: 布尔、字符串、整数、浮点或枚举 (枚举)

  • Boolean:值可以是off, true, false, yes, no, 1, 0 (区分大小写)或其中一个值的任何明确前缀。
  • String:通常用单引号括起来,数字和标识符可以忽略单引号
  • Numeric:允许整数和浮点型
  • Numeric with Unit:带单位的数字,某些数字参数具有隐式单位,为方便起见, 可以使用显式指定的单位给出设置, 例如时间值的 "120 ms", 它们将转换为参数的实际单位。请注意, 该值必须以字符串 (带引号) 的形式写入才能使用此功能。单位名称区分大小写, 数值和单位之间可以有空白。
  • Enumerated:枚举不区分大小写。

2、Parameter Interaction via the Configuration File

通过参数文件配置

  • 通过更改文件postgresql.conf配置参数
  • 通过这种方式设置的参数,提供的是默认值
  • pg_ctl reload可使服务器重新读取配置文件
  • pg_file_settings查看参数文件配置的参数
查看参数在参数文件中的配置
postgres=# select * from pg_FILE_settings where name='max_connections';
sourcefile | sourceline | seqno | name | setting | applied | error 
-----------------------------------------+------------+-------+-----------------+---------+---------+-------
/opt/postgres/data/postgresql.conf | 66 | 3 | max_connections | 100 | f | 
/opt/postgres/data/postgresql.auto.conf | 9 | 30 | max_connections | 200 | t | 
(2 rows)

3、Parameter Interaction via SQL

pg提供三种SQL命令用于配置参数

  • alter system命令更改全局(global/cluster)配置
  • alter database命令针对每个数据库更改设置,覆盖全局设置
  • alter role命令允许配置特定用户的参数值,覆盖全局和数据库设置

    注意:alter database和alter role仅对新的会话生效,且有些参数无法修改,使之永久生效,只能修改动态参数
postgres=# alter database postgres set max_connections=300;
ERROR: parameter "max_connections" cannot be changed without restarting the server
  • pg_settings查看当前参数配置

    注意:通过查询系统表pg_settings,可以了解更改配置后使参数生效是通过重新载入配置文件还是重启数据库服务。如果context显示postmaster需要重启数据库服务,执行pg_ctl restart;如果context显示sighup,重新加载pg_ctl即执行pg_ctl reload命令。
查看当前参数值
postgres=# select name,setting,unit,context,sourcefile from pg_settings where name='max_connections';
name | setting | unit | context | sourcefile 
-----------------+---------+------+------------+-----------------------------------------
max_connections | 200 | | postmaster | /opt/postgres/data/postgresql.auto.conf
(1 row)
查看是否需要重启
postgres=# select name,context from pg_settings where name in ('max_connections','log_connections','log_temp_files');
name | context 
-----------------+-------------------
log_connections | superuser-backend
log_temp_files | superuser
max_connections | postmaster
(3 rows)
context内容参考:
https://www.postgresql.org/docs/10/view-pg-settings.html
There are several possible values of context. In order of decreasing difficulty of changing the setting, they are:
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.
superuser-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), but only if the connecting user is a superuser. 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.
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); any user can make such a change for their session. 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 their session-local value. Changes in postgresql.conf will affect existing sessions only if no session-local value has been established with SET.
  • pg_settings视图可以查看和修改(只能修改会话级别的值)
    In addition, the system view pg_settings can be used to view and change session-local values
  • 客户端连接后可以使用show和set命令设置当前会话的参数值,不影响其他会话。show调用内部函数current_setting,set调用内部函数set_config(setting_name, new_value, is_local)
查看参数大小
postgres=# show shared_buffers;
shared_buffers 
----------------
128MB
(1 row)
or
postgres=# SELECT name,setting,unit,current_setting(name) FROM pg_settings WHERE name='shared_buffers';
name | setting | unit | current_setting 
----------------+---------+------+-----------------
shared_buffers | 16384 | 8kB | 128MB
(1 row)

注意:set命令只能由superuser执行

4、Parameter Interaction via the Shell

除了在数据库或角色级别设置全局默认值或附加重写外, 还可以通过 shell 工具将设置传递给 PostgreSQL。服务器和客户端库都通过 shell 接受参数值。

  • 在服务器启动过程中, 可以通过-c 命令行参数将参数设置传递给 postgres
postgres -c log_connections=yes -c log_destination='syslog'
  • 通过 libpq 启动客户端会话时, 可以使用 PGOPOPS 环境变量指定参数设置。以这种方式建立的设置构成会话生存期的默认值, 但不会影响其他会话。由于历史原因, POSTGRES 的格式类似于启动 postgres 命令时使用的格式;具体而言, 必须指定-c 标志。例如,
env PGOPTIONS="-c geqo=off -c statement_timeout=5min" psql

5、Managing Configuration File Contents

PostgreSQL 提供了几个功能, 用于将复杂的 poostgresql. conf 文件分解为子文件。在管理具有相关但不相同的配置的多台服务器时, 这些功能特别有用。
除了单个参数设置外, postgresql. conf 文件还可以包含指令, 这些指令指定要读取和处理的另一个文件, 就像此时将其插入到配置文件中一样。此功能允许将配置文件划分为物理上独立的部分。如:

include 'filename'

文件名没有绝对路径时, 则将其视为相对于包含引用配置文件的目录

也可以指定整个目录。如:

include_dir 'directory'

目录名称没有绝对路径时,则将其视为相对于包含引用配置文件的目录。

在指定的目录中, 将只包括名称以后缀. conf 结尾的非目录文件。的开始的文件名。字符也会被忽略, 以防止错误, 因为此类文件隐藏在某些平台上。包含目录中的多个文件按文件名顺序处理

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
11天前
|
弹性计算 网络协议 安全
阿里云服务器ECS自定义购买方式各选项参数选择与注意事项参考
在我们通过自定义购买的方式购买阿里云服务器器ECS时,会有多个选项,有的新手用户可能并不是很清楚这些选项是什么,选择或设置时需要注意什么,本文将从付费类型、地域与可用区、网络及实例、镜像、存储、带宽和安全组、管理设置以及高级选项等多个方面,为您详细介绍如何选择与配置阿里云ECS实例,以供参考。
阿里云服务器ECS自定义购买方式各选项参数选择与注意事项参考
|
5天前
|
存储 安全 网络安全
服务器设置了端口映射之后外网还是访问不了服务器
服务器设置了端口映射之后外网还是访问不了服务器
|
9天前
|
存储 机器学习/深度学习 弹性计算
阿里云ECS计算型c8i服务器测评_网络PPS_云盘IOPS性能参数
阿里云ECS计算型c8i实例采用Intel Xeon Emerald Rapids或Sapphire Rapids CPU,主频2.7 GHz起,支持CIPU架构,提供强大计算、存储、网络和安全性能。适用于机器学习、数据分析等场景。实例规格从2核到192核,内存比例1:2,支持ESSD云盘,网络带宽高达100 Gbit/s,具备IPv4/IPv6,vTPM和内存加密功能。详细规格参数表包括不同实例的vCPU、内存、网络带宽、IOPS等信息,最高可达100万PPS和100万IOPS。
|
9天前
|
存储 弹性计算 网络协议
阿里云服务器ECS计算型c7实例详解_网络PPS_云盘IOPS性能参数
阿里云ECS计算型c7实例,基于三代神龙架构,采用Intel Ice Lake CPU,2.7 GHz基频,3.5 GHz全核睿频,提供高性能计算、存储和网络能力。支持vTPM和Enclave特性,适用于高网络负载、游戏、数据分析等场景。实例规格从2核4GB至128核256GB,最大网络收发包可达2400万PPS。详细规格及性能参数见官方页面。
|
11天前
|
存储 关系型数据库 Serverless
PolarDB产品使用问题之开启Serverless功能后如何设置资源的扩缩范围
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
|
2天前
|
XML 关系型数据库 MySQL
支付系统----微信支付19---集成MyBatis-plus,数据库驱动对应的依赖版本设置问题,5没版本没有cj这个依赖,mysql驱动默认的是版本8,这里是一个父类,数据库都有,写个父类,继承就行
支付系统----微信支付19---集成MyBatis-plus,数据库驱动对应的依赖版本设置问题,5没版本没有cj这个依赖,mysql驱动默认的是版本8,这里是一个父类,数据库都有,写个父类,继承就行
|
4天前
|
前端开发 JavaScript Java
文本----简单编写文章的方法(中),后端接口的编写,自己编写好页面就上传到自己的服务器上,使用富文本编辑器进行编辑,想写好一个项目,先分析一下需求,再理一下实现思路,再搞几层,配好参数校验,lomb
文本----简单编写文章的方法(中),后端接口的编写,自己编写好页面就上传到自己的服务器上,使用富文本编辑器进行编辑,想写好一个项目,先分析一下需求,再理一下实现思路,再搞几层,配好参数校验,lomb
|
4天前
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
6天前
|
NoSQL 算法 Linux
【内附完整redis配置文件】linux服务器命令设置redis最大限制内存大小,设置redis内存回收机制,redis有哪些回收机制
【内附完整redis配置文件】linux服务器命令设置redis最大限制内存大小,设置redis内存回收机制,redis有哪些回收机制
10 0
|
7天前
|
消息中间件 Serverless 网络性能优化
消息队列 MQ产品使用合集之客户端和服务器之间的保活心跳检测间隔是怎么设置的
消息队列(MQ)是一种用于异步通信和解耦的应用程序间消息传递的服务,广泛应用于分布式系统中。针对不同的MQ产品,如阿里云的RocketMQ、RabbitMQ等,它们在实现上述场景时可能会有不同的特性和优势,比如RocketMQ强调高吞吐量、低延迟和高可用性,适合大规模分布式系统;而RabbitMQ则以其灵活的路由规则和丰富的协议支持受到青睐。下面是一些常见的消息队列MQ产品的使用场景合集,这些场景涵盖了多种行业和业务需求。