diff --git a/CN/antora.yml b/CN/antora.yml index fb9f27c3..0f42c9d5 100644 --- a/CN/antora.yml +++ b/CN/antora.yml @@ -1,7 +1,7 @@ name: ivorysql-doc -title: IvorySQL -version: v4.5 -start_page: v4.5/welcome.adoc +title: 文档中心 +version: master +start_page: master/welcome.adoc asciidoc: attributes: source-language: asciidoc@ diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index 55ea5b11..38288d03 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -1,38 +1,49 @@ -* xref:v4.5/welcome.adoc[欢迎] -* xref:v4.5/1.adoc[发行说明] -* xref:v4.5/2.adoc[关于IvorySQL] -* IvorySQL入门 -** xref:v4.5/3.adoc[快速开始] -** xref:v4.5/4.adoc[日常监控] -** xref:v4.5/5.adoc[日常维护] -* IvorySQL高级 -** xref:v4.5/6.adoc[安装指南] -** xref:v4.5/7.adoc[集群搭建] -** xref:v4.5/8.adoc[开发者指南] -** xref:v4.5/9.adoc[运维管理指南] -** xref:v4.5/10.adoc[迁移指南] -* IvorySQL生态 -** xref:v4.5/11.adoc[PostGIS] -** xref:v4.5/12.adoc[pgvector] -* IvorySQL架构设计 -** 查询处理 -*** xref:v4.5/31.adoc[双parser] -** 兼容框架 -*** xref:v4.5/30.adoc[initdb过程] -* Oracle兼容功能列表 -** xref:v4.5/14.adoc[1、框架设计] -** xref:v4.5/15.adoc[2、GUC框架] -** xref:v4.5/16.adoc[3、大小写转换] -** xref:v4.5/17.adoc[4、双模式设计] -** xref:v4.5/18.adoc[5、兼容Oracle like] -** xref:v4.5/19.adoc[6、兼容Oracle匿名块] -** xref:v4.5/20.adoc[7、兼容Oracle函数与存储过程] -** xref:v4.5/21.adoc[8、内置数据类型与内置函数] -** xref:v4.5/22.adoc[9、新增Oracle兼容模式的端口与IP] -** xref:v4.5/26.adoc[10、XML函数] -** xref:v4.5/27.adoc[11、兼容Oracle sequence] -** xref:v4.5/28.adoc[12、包] -** xref:v4.5/29.adoc[13、不可见列] -* xref:v4.5/32.adoc[社区贡献指南] -* xref:v4.5/24.adoc[工具参考] -* xref:v4.5/25.adoc[FAQ] \ No newline at end of file +* IvorySQL +** xref:master/welcome.adoc[欢迎] +** xref:master/1.adoc[发行说明] +** xref:master/2.adoc[关于IvorySQL] +** IvorySQL入门 +*** xref:master/3.1.adoc[快速开始] +*** xref:master/3.2.adoc[日常监控] +*** xref:master/3.3.adoc[日常维护] +** IvorySQL高级 +*** xref:master/4.1.adoc[安装指南] +*** xref:master/4.2.adoc[集群搭建] +*** xref:master/4.3.adoc[开发者指南] +*** xref:master/4.4.adoc[运维管理指南] +*** xref:master/4.5.adoc[迁移指南] +** IvorySQL生态 +*** xref:master/5.1.adoc[PostGIS] +*** xref:master/5.2.adoc[pgvector] +** IvorySQL架构设计 +*** 查询处理 +**** xref:master/6.1.1.adoc[双parser] +*** 兼容框架 +**** xref:master/6.2.1.adoc[initdb过程] +*** 兼容特性 +**** xref:master/6.3.1.adoc[like] +**** xref:master/6.3.3.adoc[RowID] +**** xref:master/6.3.2.adoc[OUT 参数] +**** xref:master/6.4.adoc[国标GB18030] +** Oracle兼容功能列表 +*** xref:master/7.1.adoc[1、框架设计] +*** xref:master/7.2.adoc[2、GUC框架] +*** xref:master/7.3.adoc[3、大小写转换] +*** xref:master/7.4.adoc[4、双模式设计] +*** xref:master/7.5.adoc[5、兼容Oracle like] +*** xref:master/7.6.adoc[6、兼容Oracle匿名块] +*** xref:master/7.7.adoc[7、兼容Oracle函数与存储过程] +*** xref:master/7.8.adoc[8、内置数据类型与内置函数] +*** xref:master/7.9.adoc[9、新增Oracle兼容模式的端口与IP] +*** xref:master/7.10.adoc[10、XML函数] +*** xref:master/7.11.adoc[11、兼容Oracle sequence] +*** xref:master/7.12.adoc[12、包] +*** xref:master/7.13.adoc[13、不可见列] +*** xref:master/7.14.adoc[14、RowID] +*** xref:master/7.15.adoc[15、OUT 参数] +** xref:master/8.adoc[社区贡献指南] +** xref:master/9.adoc[工具参考] +** xref:master/10.adoc[FAQ] +* PostgreSQL +** xref:master/100.adoc[PG参数参考手册] +** xref:master/110.adoc[PG函数参考手册] diff --git a/CN/modules/ROOT/pages/v4.5/1.adoc b/CN/modules/ROOT/pages/master/1.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/1.adoc rename to CN/modules/ROOT/pages/master/1.adoc diff --git a/CN/modules/ROOT/pages/v4.5/25.adoc b/CN/modules/ROOT/pages/master/10.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/25.adoc rename to CN/modules/ROOT/pages/master/10.adoc diff --git a/CN/modules/ROOT/pages/master/100.adoc b/CN/modules/ROOT/pages/master/100.adoc new file mode 100644 index 00000000..8636e483 --- /dev/null +++ b/CN/modules/ROOT/pages/master/100.adoc @@ -0,0 +1,5854 @@ +:sectnums: +:sectnumlevels: 16 + +== PostgreSQL 参数参考手册 + +本文参考来源: https://www.postgresql.org/docs/13/runtime-config.html[https://www.postgresql.org/docs/13/runtime-config.html] + + +本文档贡献单位及贡献者: + +瀚高基础软件股份有限公司:徐云鹤、张波、咸士杰、类延良 + +中国开源软件推进联盟PostgreSQL分会:魏波 + + +本文档错误反馈方式: + +请在 https://github.com/IvorySQL/ivorysql_docs/issues[https://github.com/IvorySQL/ivorysql_docs/issues]提交issue。 + +文档下载: link:../postgresql.pdf[PostgreSQL参考手册] + +=== Resource Usage / Disk + +==== temp_file_limit + +[cols="136,387"] +|=== +h| 参数名称 h| temp_file_limit +| 参数值数据类型 | integer +| 默认值 | -1,表示不限制 +| 取值范围 | -1到2147483647 +| 参数单位 | 如果指定的值不带单位,则以KB为单位 +| 参数含义 | 指定一个进程可以占用的最大的磁盘空间。该磁盘空间可以用于temporary files(sort及hash使用)或者持有cursor的storage file。试图超过该限制的transaction会被取消。 +| 是否可session级修改 | 可以,此时仅限于superuser可以在session级修改 +| 修改后何时生效 | 非session级修改Reload即可生效;Session级修改时会立即在session级生效 + +|=== + + +=== Replication + +==== track_commit_timestamp + +[cols="136,387"] +|=== +h| 参数名称 h| track_commit_timestamp +| 参数值数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 记录transaction的提交时间。注意:只有当这个参数是on时,函数pg_xact_commit_timestamp(xid)、pg_last_committed_xact()才能获得已提交事务的时间值。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +=== Version and Platform Compatibility / Other Platforms and Clients + +==== transform_null_equals + +[cols="136,387"] +|=== +h| 参数名称 h| transform_null_equals +| 参数值数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数值为on时,PG会将expr=NULL(或者NULL=expr)视为expr IS NULL.本参数仅仅影响=NULL这个形式,不会影响其他形式(如in) +| 是否可session级修改 | 可以,superuser和普通用户均可以在session级修改 +| 修改后何时生效 | Reload即可生效Session级修改时会立即在session级生效 + +|=== + + +=== Resource Usage / Kernel Resources + +==== max_files_per_process + +[cols="136,387"] +|=== +h| 参数名称 h| max_files_per_process +| 参数值数据类型 | integer +| 默认值 | 1000 +| 取值范围 | 64到2147483647 +| 参数单位 | +| 参数含义 | 本参数用于设置每个server subprocess允许同时打开的files的最大数量。如果遇到 "Too many open files"的提示,请尝试减少本参数值。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + +=== Process Title + +==== cluster_name + +[cols="136,387"] +|=== +h| 参数名称 h| cluster_name +| 参数值数据类型 | string +| 默认值 | 空值 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于设置PGCluster的名字,可以用操作系统命令ps -ef\| grep postgres查看该名字。该名字会出现在所有server process的开头位置,另外,对于standby连接来说,该名字还是默认的application name. +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 +|=== + + +==== update_process_title + +[cols="136,387"] +|=== +h| 参数名称 h| update_process_title +| 参数值数据类型 | Bool +| 默认值 | on(除windows之外的平台);off(Windows平台) +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 每当服务器接收到一个新的 SQL 命令时都更新process title +| 是否可session级修改 | 是,此时仅限于superuser可以在session级修改 +| 修改后何时生效 | Reload即可生效Session级修改时会立即在session级生效 + +|=== + + +=== Replication / Master Server + +==== synchronous_standby_names + +[cols="136,387"] +|=== +h| 参数名称 h| synchronous_standby_names +| 参数值数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 本参数为primary角色库参数。本参数值区分大小写。本参数指定了支持同步复制的standby server清单。standby server的name是standby连接信息中的application_name,在物理复制standby中,standby server的name是在primary_conninfo中设置的,如果cluster_name配置参数的配置过了,那么standby server的name默认是cluster_name参数值,否则是walreceiver对于逻辑复制,可以在subscription中设置连接信息,默认值是subscription name本参数使用如下语法指定了一系列的standby servers的列表:[FIRST] num_sync ( standby_name [, ...] )ANY num_sync ( standby_name [, ...] )standby_name [, ...] + +num_sync代表同步standby的个数举例,FIRST 3 (s1, s2, s3, s4)的含义:s1, s2, s3这三个standby是同步standbys4这个standby是潜在的同步standby(potential synchronous standbys)如果当前同步standby不论什么原因断开,它的位置会立即被next-highest-priority standby取代。关键字FIRST是可选的。FIRST 3 (s1, s2, s3, s4)中,优先级由大到小为s1>s2>s3>s4 + +举例, ANY 3 (s1, s2, s3, s4) 的含义:s1, s2, s3, s4这四个standby 中的任意3个standby server应用wal变化之后,primary端的事务才能提交请务必注意:FIRST 和ANY关键字是大小写敏感的。如果这两个关键字被用于standby server的name,那么standby_name需要用双引号引起来。在PostgreSQL 9.6之前版本中使用的第三种语法已经受到支持。该语法与"FIRST 1"是相同作用。比如, FIRST 1 (s1, s2) 和 s1, s2 有相同的含义:要么s1要么s2被选为同步standby + +*表示匹配任何standby name + +没有机制来确保standby name的唯一性。在重复发生时,匹配到的standby 会被视为更高的优先级。尽管确切地说哪个是不确定的注意:每个standby_name应该是有效地SQL 标识符,除非是*。如果需要,你可以使用双引号。但是请注意:standby_names与standby application_name 比较时,是不区分大小写的,不论有无双引号。 + +如果synchronous_standby_names参数不指定值,同步复制不会启用。即使同步复制被启用,通过设置synchronous_commit配置参数为local或者off,单个事务可以被配置为不等待standby端的wal被应用。 + +本参数可以在postgresql.conf文件或者在the server command line设置 + + + + +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可生效。 + + +|=== + + +==== vacuum_defer_cleanup_age + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_defer_cleanup_age +| 参数值数据类型 | integer +| 默认值 | 0 +| 取值范围 | 0到1000000 +| 参数单位 | +| 参数含义 +a| 该参数指定了在primary库上vacuum和HOT updates 会延迟清理dead row versions的事务的数量。默认值是零个事务,零个事务的含义是dead row versions会尽可能快的被removed掉。尽可能快是指dead row versions不会被任何open transaction可见。你可以在hot standby环境中的primary端为此参数设置为非零值,这允许standby端的query运行更长的时间以便完成,而不会遇到过早的dead row versions cleanup而导致冲突。由于本参数值是根据在primary上发生的写入事务的数量来衡量的,因此,很难预测会为standby query增加多长时间。 + +本参数可以在postgresql.conf文件或者在the server command line设置 + +你可以考虑在standby 端使用hot_standby_feedback配置参数作为vacuum_defer_cleanup_age的替代。本参数不会防止那些已经达到age(由old_snapshot_threshold配置参数指定)的dead rows的清理。 + +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可生效。 + + +|=== + + + +=== Replication / Subscribers + +==== max_logical_replication_workers + +[cols="136,387"] +|=== +h| 参数名称 h| max_logical_replication_workers +| 参数值数据类型 | integer +| 默认值 | 4 +| 取值范围 | 0到262143 +| 参数单位 | +| 参数含义 | 本参数设置Logical replication workers进程的最大数量,此处的worker进程包括两种:apply workers 和table synchronization workers。Logical replication workers进程的数量从max_worker_processes配置参数定义的池中获取。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + +==== max_sync_workers_per_subscription + +[cols="136,387"] +|=== +h| 参数名称 h| max_sync_workers_per_subscription +| 参数值数据类型 | integer +| 默认值 | 2 +| 取值范围 | 0到262143 +| 参数单位 | +| 参数含义 | 指定了每个subscription中synchronization workers的最大数量。本参数控制在subscription初始化 或者 新表加入时的initial data copy的并行度。目前,每个table只能指定一个synchronization workersynchronization workers从max_logical_replication_workers配置参数定义的池中取得。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效。 + +|=== + + +=== Write-Ahead Log / Archive Recovery + +==== restore_command + +[cols="136,387"] +|=== +h| 参数名称 h| restore_command +| 参数值数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 恢复时指定archive wal的位置 restore_command = 'cp /mnt/server/archivedir/%f "%p"' restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows restore_command对应的命令执行成功之后,restore_command返回零, + + %f代表archived wal文件名 %p代表copy destination path name %r代表含有最后一个有效的resart point的file的文件名 %%代表一个%字符(当需要写入%字符的情况下使用) + +本参数需要在pg instance启动之前进行设置。 + +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + +==== archive_cleanup_command + +[cols="136,387"] +|=== +h| 参数名称 h| archive_cleanup_command +| 参数值数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 本参数定义了在每个restart point时所执行的shell命令。 + + archive_cleanup_command参数的目的是提供一个清理不再被standby server所需要的老的archived wal file的机制。 + + %r代表最后一个有效的restart point的wal file。该wal file是最早一个必须保留的文件,以便允许restore操作可以被restart。注意: restart point 是一个 point ,该point用于standby server重启recovery操作。因此,所有早于%r的文件可以被安全的清理掉。本信息可以用来truncate掉archive wal file,以便满足从当前restore可以restart的最小需求。 pg_archivecleanup实用命令常被用在单个standby配置的archive_cleanup_command参数中 archive_cleanup_command = 'pg_archivecleanup /mnt/server/archivedir %r' + + %%代表一个%字符(当需要写入%字符的情况下使用)如果命令返回非零值,一个警告日志消息会被写入。一个例外是:当命令被一个signal终止或者shell中有错误时,一个fatal error会被抛出。 + +本参数可以在postgresql.conf设置,也可以在server command line设置。 + +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可生效。 + + +|=== + + +==== recovery_end_command + + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_end_command +| 参数值数据类型 | String +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于定义在recovery结束时候的需要执行的shell命令。如果命令返回非零值,一个警告日志消息会被写入,然后数据库会继续启动。一个例外是:当命令被一个signal终止或者shell中错误时,数据库不会继续启动。%r代表最后一个有效的restart point的wal file +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效。 + +|=== + + +=== Error Handling + +==== exit_on_error + +[cols="136,387"] +|=== +h| 参数名称 h| exit_on_error +| 参数值数据类型 | Bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 +a| 当设置为on时,任何error均会导致session被终止。默认情况下,本参数值为off,只有FATAL error才会终止session。 postgres=# set exit_on_error=on; SET postgres=# show exit_on_error ; -[RECORD 1]-+--- exit_on_error \| on + + postgres=# begin; BEGIN postgres=*# select \* form t1; FATAL: syntax error at or near "form" LINE 1: select \* form t1; ^ server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Succeeded.postgres=# + +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效Session级别修改可以立即生效。 +|=== + + +==== restart_after_crash + +[cols="136,387"] +|=== +h| 参数名称 h| restart_after_crash +| 参数值数据类型 | bool +| 默认值 | on +| 取值范围 | +| 参数单位 | +| 参数含义 | 当设置为on时,PostgreSQL会在backend crash之后重新初始化(即:restart)。在某些情况下,比如PostgreSQL被Clusterware调用时,需要禁用PostgreSQL的restart(将该参数值设置为off)以便clusterware获得PostreSQL的控制权并采取适当的操作。 +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可生效 + + +|=== + + +==== data_sync_retry + +[cols="136,387"] +|=== +h| 参数名称 h| data_sync_retry +| 参数值数据类型 | bool +| 默认值 | off +| 取值范围 | off 和on +| 参数单位 | +| 参数含义 | 如果设置为off(默认值),当PostgreSQL flush数据到文件系统上遇到failure时,PostgreSQL会抛出一个panic级别的error。这会导致数据库服务crash掉。本参数只能在数据库服务启动之前设置。在某些操作系统中,当回写(write-back)失败之后,kernel的page cache中的数据状态是未知的(unknown).在一些情况下,它可能会被完全忘记,设置为尝试是不安全的,在实际上数据已经丢失的情况下,第二次尝试可能会报告成功,在这些场景中,避免数据损失的唯一方法是解决掉硬件问题之后从wal中恢复。当设置为on时,PostgreSQL会报告一个error并会继续运行,data flushing操作会在稍后的checkpoint中尝试。注意:仅在调查操作系统对buffered data的处理以防回写失败的情况下,才将其设置为on。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + +=== Write-Ahead Log / Archiving + +==== archive_mode + +[cols="136,387"] +|=== +h| 参数名称 h| archive_mode +| 参数值数据类型 | enum +| 默认值 | off +| 取值范围 | off,on,always +| 参数单位 | +| 参数含义 | 指定归档模式。on表示启用归档模式,当wal_level配置参数值为minimal时, archive_mode 不能设置为on。当本参数值设置为always时,standby 实例会为收到的每个wal segments调用归档命令,也就是standby实例上也会进行wal的归档操作。本参数仅仅能在pg启动时设置 +| 是否可session级修改 | 否 +| 修改后何时生效 +a| 重启PG instance生效。 + + +|=== + + + + +==== archive_command + +[cols="136,387"] +|=== +h| 参数名称 h| archive_command +| 参数值数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 定义对wal进行归档的命令。当archive_mode配置参数启用并且archive_command配置参数是空字符串时,wal archiving暂时被禁用,但是pg会继续积累wal segment文件。archive_command参数值设置为/bin/true会禁用归档,但这样会导致wal文件归档中断,归档中断是无法进行归档恢复的,请注意这一点。使用举例如下: archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' # Unix archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows + +退出码是零代表本命令正常运行。本参数可以在postgresql.conf或者server command line设置。 + +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可生效 + + +|=== + + +==== archive_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| archive_timeout +| 参数值数据类型 | integer +| 默认值 | 0 +| 取值范围 | 0到1073741823 +| 参数单位 | 若是不指定单位,那默认的单位是秒 +| 参数含义 | 强制进行wal segments归档的时长。使用本参数归档出来的wal segment与正常的wal segment是相同的大小。因此,本参数值设置太小会对存储空间有浪费。本参数可以在postgresql.conf或者server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +=== Resource Usage / Background Writer + +==== bgwriter_delay + +[cols="136,387"] +|=== +h| 参数名称 h| bgwriter_delay +| 参数值数据类型 | integer +| 默认值 | 200 +| 取值范围 | 10到10000 +| 参数单位 | 若是不指定单位,那默认的单位是毫秒(ms) +| 参数含义 | 在每一轮循环中,background writer都会为一定数量的脏缓冲区发出写操作,然后background writer进行睡眠,睡眠的时间为bgwriter_delay参数值,然后再唤醒,然后重复。设置bgwriter_delay为不是10的倍数的值可能与将其设置为10的下一个更高的倍数具有相同的结果。本参数可以在postgresql.conf或者server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== bgwriter_lru_maxpages + +[cols="136,387"] +|=== +h| 参数名称 h| bgwriter_lru_maxpages +| 参数值数据类型 | integer +| 默认值 | 100 +| 取值范围 | 0到1073741823 +| 参数单位 | +| 参数含义 | 每轮bgwriter进程写入LRU Page的最大数量。本参数设置为零会禁用background writing行为,但是background writer进程依然会存在。本参数可以在postgresql.conf或者server command line设置 +| 是否可session级修改 | 否 +| 修改后何时生效 +a| Reload即可 + + +|=== + + +==== bgwriter_lru_multiplier + +[cols="136,387"] +|=== +h| 参数名称 h| bgwriter_lru_multiplier +| 参数值数据类型 | real +| 默认值 | 2.0 +| 取值范围 | 0到10 +| 参数单位 | +| 参数含义 | 每轮写dirty buffer的数量基于服务器进程(即:backend process)在最近几轮中所需要的新buffer数量。最近的平均需要量乘以本参数值就是下一轮需要的新buffers数量的估计值。Dirty buffers会一直写入,直到有那么多干净的、可重用的buffers为止。因此,本参数值为1.0表示准确预计了需要的buffers数量。较大的本参数值提供了一些缓冲,以防需求激增,而较小的本参数值会有意将写dirty buffers操作留给服务器进程(即:backend process)完成。本参数可以在postgresql.conf或者server command line设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== bgwriter_flush_after + +[cols="136,387"] +|=== +h| 参数名称 h| bgwriter_flush_after +| 参数值数据类型 | integer +| 默认值 | Linux平台下是64,也就是512KB;其他平台下是0 +| 取值范围 | 源码中BLCKSZ 符号常量为8KB时,取值范围是0到256;源码中BLCKSZ 符号常量不为8KB时,等比例计算即可。 +| 参数单位 | 8KB +| 参数含义 | 当background writer写入的数据量超过本参数值之后,尝试强制操作系统发送这些写入的数据到底层存储中。这么做会限制kernel中page cache的dirty data的数量,减少在checkpoint末尾发生fsync时发生卡顿的可能性。本参数可以在postgresql.conf或者server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +=== Statistics / Monitoring + +==== log_statement_stats + +[cols="62,207"] +|=== +h| 参数名称 h| log_statement_stats +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在本参数设置为on的情况下,pg会向运行日志中写入系统性能统计信息。本参数on时,其他参数(log_parser_stats 、log_planner_stats、log_executor_stats)必须设置为off在本参数设置为on的情况下,当前台发出SQL语句时(如下以psql中执行select \* from pg_database为例子),在pg的运行日志中,会有如下的输出: 2021-03-31 09:55:21.621 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,6,"",2021-03-31 09:51:32 CST,3/0,0,LOG,00000,"QUERY STATISTICS","! system usage stats: ! 0.000657 s user, 0.000000 s system, 0.000657 s elapsed ! [0.003464 s user, 0.001403 s system total] ! 6288 kB max resident size ! 0/8 [0/24] filesystem blocks in/out ! 0/128 [0/1295] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent! 0/0 [11/2] voluntary/involuntary context switches",,,,,"select \*from pg_database;",,,"psql","client backend" +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效,仅仅superuser能修改本参数 + +|=== + + + +==== log_parser_stats + +[cols="58,211"] +|=== +h| 参数名称 h| log_parser_stats +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在本参数设置为on的情况下,pg会向运行日志中写入解析统计信息。在本参数设置为on的情况下,log_statement_stats配置参数无法设置为on,设置为on时会有如下的错误: postgres=# alter system set log_statement_stats='on'; ERROR: invalid value for parameter "log_statement_stats": 1 DETAIL: Cannot enable "log_statement_stats" when "log_parser_stats", "log_planner_stats", or "log_executor_stats" is true. postgres=#在本参数设置为on的情况下,当前台发出SQL语句时(如下以psql中执行select \* from pg_database为例子),在pg的运行日志中,会有如下的输出: 2021-03-31 10:16:25.962 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,41,"",2021-03-31 09:51:32 CST,3/3486,0,LOG,00000,"PARSER STATISTICS","! system usage stats: ! 0.000019 s user, 0.000000 s system, 0.000019 s elapsed ! [0.015481 s user, 0.001403 s system total] ! 7720 kB max resident size ! 0/0 [0/56] filesystem blocks in/out ! 0/0 [0/1673] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent ! 0/0 [39/6] voluntary/involuntary context switches",,,,,"select \* from pg_database;",,,"psql","client backend" 2021-03-31 10:16:25.962 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,42,"",2021-03-31 09:51:32 CST,3/3486,0,LOG,00000,"statement: select \* from pg_database;",,,,,,,,,"psql","client backend" 2021-03-31 10:16:25.962 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,43,"",2021-03-31 09:51:32 CST,3/3486,0,LOG,00000,"PARSE ANALYSIS STATISTICS","! system usage stats: ! 0.000031 s user, 0.000000 s system, 0.000030 s elapsed ! [0.015565 s user, 0.001403 s system total] ! 7720 kB max resident size ! 0/0 [0/56] filesystem blocks in/out ! 0/0 [0/1673] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent ! 0/0 [39/6] voluntary/involuntary context switches",,,,,"select \* from pg_database;",,,"psql","client backend" 2021-03-31 10:16:25.962 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,44,"",2021-03-31 09:51:32 CST,3/3486,0,LOG,00000,"REWRITER STATISTICS","! system usage stats: ! 0.000003 s user, 0.000000 s system, 0.000003 s elapsed ! [0.015582 s user, 0.001403 s system total] ! 7720 kB max resident size ! 0/0 [0/56] filesystem blocks in/out ! 0/0 [0/1673] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent! 0/0 [39/6] voluntary/involuntary context switches",,,,,"select \* from pg_database;",,,"psql","client backend" +| 是否可session级修改 | 是,但是不能在log_statement_stats=on时设置本参数为on +| 修改后何时生效 | Session级修改立即生效非session级修改reload生效,仅仅superuser能修改本参数 + +|=== + + + +==== log_planner_stats + +[cols="58,211"] +|=== +h| 参数名称 h| log_planner_stats +| 参数值数据类型 | boolean +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在本参数设置为on的情况下,pg会向运行日志中写入规划器统计信息。在本参数设置为on的情况下,log_statement_stats配置参数无法设置为on,设置为on时会有如下的错误: postgres=# alter system set log_statement_stats='on'; ERROR: invalid value for parameter "log_statement_stats": 1 DETAIL: Cannot enable "log_statement_stats" when "log_parser_stats", "log_planner_stats", or "log_executor_stats" is true. postgres=#在本参数设置为on的情况下,当前台发出SQL语句时(如下以psql中执行select \* from pg_database为例子),在pg的运行日志中,会有如下的输出: 2021-03-31 10:24:39.323 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,63,"",2021-03-31 09:51:32 CST,3/3491,0,LOG,00000,"PLANNER STATISTICS","! system usage stats: ! 0.000041 s user, 0.000006 s system, 0.000045 s elapsed ! [0.017384 s user, 0.002173 s system total] ! 7740 kB max resident size ! 0/0 [0/80] filesystem blocks in/out ! 0/0 [0/1674] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent! 0/0 [55/10] voluntary/involuntary context switches",,,,,"select \* from pg_database;",,,"psql","client backend" +| 是否可session级修改 | 是,但是不能在log_statement_stats=on时设置本参数为on +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效,仅仅superuser能修改本参数 + +|=== + + + +==== log_executor_stats + +[cols="58,211"] +|=== +h| 参数名称 h| log_executor_stats +| 参数值数据类型 | Bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在本参数设置为on的情况下,pg会向运行日志中写入执行器统计信息。在本参数设置为on的情况下,log_statement_stats配置参数无法设置为on,设置为on时会有如下的错误: postgres=# alter system set log_statement_stats='on'; ERROR: invalid value for parameter "log_statement_stats": 1 DETAIL: Cannot enable "log_statement_stats" when "log_parser_stats", "log_planner_stats", or "log_executor_stats" is true. postgres=#在本参数设置为on的情况下,当前台发出SQL语句时(如下以psql中执行select \* from pg_database为例子),在pg的运行日志中,会有如下的输出: 2021-03-31 10:27:59.858 CST,"pg131","postgres",8896,"[local]",6063d5a4.22c0,71,"",2021-03-31 09:51:32 CST,3/3496,0,LOG,00000,"EXECUTOR STATISTICS","! system usage stats: ! 0.000031 s user, 0.000000 s system, 0.000030 s elapsed ! [0.018581 s user, 0.003320 s system total] ! 7744 kB max resident size ! 0/0 [0/104] filesystem blocks in/out ! 0/0 [0/1676] page faults/reclaims, 0 [0] swaps ! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent! 0/0 [71/14] voluntary/involuntary context switches",,,,,"select \* from pg_database;",,,"psql","client backend" +| 是否可session级修改 | 是,但是不能在log_statement_stats=on时设置本参数为on +| 修改后何时生效 | Session级修改立即生效非session级修改reload生效,仅仅superuser能修改本参数 + +|=== + + + +=== Client Connection Defaults / Shared Library Preloading + +==== jit_provider + +[cols="136,387"] +|=== +h| 参数名称 h| jit_provider +| 数据类型 | string +| 默认值 | llvmjit +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了jit provider library的名称,本参数仅仅可以在pg启动时设置。若是指定了不存在的library,则jit不可用,但是不会有报错抛出。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== local_preload_libraries + +[cols="136,387"] +|=== +h| 参数名称 h| local_preload_libraries +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定在连接启动时被预加载的一个或多个共享库。多个库名称以逗号分隔,其中每个库名的解释与load命令相同。库名之间的空格会被忽略,若是需要在库名中包括空格或者逗号,请用双引号将库名引起来。参数值仅仅在连接开始时生效,后续更改无效。如果找不到指定的库,则连接会将失败(即:连接将无法登陆到数据库中)。本参数任何user都可以设置。因此,被加载的共享库仅仅限于在$libdir/plugins目录下。数据库管理员有责任确保该目录下的共享库的安全性。本参数的参数值可以明确指定目录,比如$libdir/plugins/mylib,或者仅仅指定library名称,比如mylib,mylib的作用等同于$libdir/plugins/mylib本参数的目的是允许非授权用户加载debugging或者performance-measurement 库到特定session中,而无需load命令。为此,可以在客户端上使用设置了本参数的PGOPTIONS环境变量或者使用alter role set +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效非session级修改reload生效 + +|=== + + + +==== session_preload_libraries + +[cols="136,387"] +|=== +h| 参数名称 h| session_preload_libraries +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了在连接启动时被预加载的一个或者多个共享库。多个库名称以逗号分隔,其中每个库名的解释与load命令相同。库名之间的空格会被忽略,若是需要在库名中包括空格或者逗号,请用双引号将库名引起来。参数值仅仅在连接开始时生效,后续更改无效。如果找不到指定的库,则连接会将失败(即:连接将无法登陆到数据库中)。本参数的目的是允许加载debugging或者performance-measurement 库到特定session中,而无需load命令。比如,使用alter role set 语句设置本参数可以将auto_explain针对所有session生效。与shared_preload_libraries不同,在会话开始时(而不是在首次使用时)加载库没有太大的性能优势。但是,使用连接池时有一些优点。 +| 是否可session级修改 | 可以,只有superuser可以改变本参数值 +| 修改后何时生效 | Session级修改立即生效非session级修改reload生效,reload之后,仅仅对新启动的session生效。 + +|=== + + + +==== shared_preload_libraries + +[cols="136,387"] +|=== +h| 参数名称 h| shared_preload_libraries +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了在PostgreSQL数据库启动时被预加载的一个或者多个共享库。多个库名称以逗号分隔,其中每个库名的解释与load命令相同。库名之间的空格会被忽略,若是需要在库名中包括空格或者逗号,请用双引号将库名引起来。该参数只能在PostgreSQL数据库启动时设置,若是找不到指定的库,PostgreSQL数据库启动会失败。设置了本参数之后,新的backend process的启动时间会略有延长,即使这个backedn process不用这个共享库。因此,本参数推荐用于哪些在绝大多数session中使用的共享库。另外,由于本参数需要重启PostgreSQL数据库生效,因此,若是用于短期的debugging目的,请使用session_preload_libraries参数。请注意,在Windows主机上,在服务器启动时预加载库不会减少启动每个新服务器进程所需的时间。每个服务器进程将重新加载所有预加载库。但是,对于需要在postmaster启动时执行操作的库,本参数在windows主机上是很有用的。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +=== Lock Management + +==== deadlock_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| deadlock_timeout +| 数据类型 | string +| 默认值 | 1000 +| 取值范围 | 1到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 在检查是否存在deadlock条件之前,等待一个lock的时间长度。死锁检查是相对昂贵的,因此,pg不会在每次等待lock时都运行死锁检测。PostgreSQL会乐观的认为死锁在生产应用程序中并不常见,只需要等待一段时间后再检查死锁。这是您在实践中想要设置的最小值,在负载很重的pg中,可能需要提高本参数值。在理想情况下,本参数值应该超过典型的transaction 时间,以提高在PostgreSQL决定检查死锁之前将释放锁的几率。仅仅superuser可以修改本参数值。在log_lock_waits参数启用的情况下,deadlock_timeout参数值也决定了一个有关lock wait的 log message被写入运行日志之前的等待时间。如果你正在尝试调查锁定延迟(locking delays),你可能希望设置比正常deadlock_timeout参数值更短的时间。 +| 是否可session级修改 | 是(仅仅superuser可修改) +| 修改后何时生效 | Session级修改立即生效(仅仅superuser);非session级别修改Reload即可生效 + +|=== + + + + +==== max_locks_per_transaction + +[cols="136,387"] +|=== +h| 参数名称 h| max_locks_per_transaction +| 数据类型 | integer +| 默认值 | 64 +| 取值范围 | 10到2147483647 +| 参数单位 | +| 参数含义 +a| 共享锁表(shared lock table)追踪max_locks_per_transaction \* (max_connections + max_prepared_transactions) 个lock objects,因此,一次只能锁定这么多不同的对象。本参数控制分配给每个事务的object lock的平均数量。单个事务可以锁定更多的对象,只要所有事务的锁都在锁表(lock table)中. 本参数值不是可以锁定的行数;可以锁定的行数是无限的。max_locks_per_transaction的默认值是64在历史上是被证明足够的,但是如果在多个事务中有涉及多个不同的表的SQL语句(比如一个有多个子表的父表的SQL语句),则可能提高该数值。本参数只能在PostgreSQL数据库启动时设置。当存在standby server时,standby server上的本参数值要大于或者等于master server上的本参数值,否则,查询语句在standby server上是不被允许的。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== max_pred_locks_per_transaction + +[cols="136,387"] +|=== +h| 参数名称 h| max_pred_locks_per_transaction +| 数据类型 | Integer +| 默认值 | 64 +| 取值范围 | 10到2147483647 +| 参数单位 | +| 参数含义 | 共享谓词锁表(shared predicate lock table)追踪max_pred_locks_per_transaction \* (max_connections + max_prepared_transactions) 个lock objects,因此,一次只能锁定这么多不同的对象。本参数控制分配给每个事务的object lock的平均数量。单个事务可以锁定更多的对象,只要所有事务的锁都在锁表(lock table)中. 本参数值不是可以锁定的行数;可以锁定的行数是无限的。本参数默认值64在测试环境中是足够的,但是如果你的client在单个串行化事务中用到了多个不同的table,你可能需要加大本参数值。本参数只能在PostgreSQL数据库启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== max_pred_locks_per_relation + +[cols="136,387"] +|=== +h| 参数名称 h| max_pred_locks_per_relation +| 数据类型 | Integer +| 默认值 | -2 +| 取值范围 | -2147483648到2147483647 +| 参数单位 | +| 参数含义 | 本参数控制在将锁提升为覆盖整个relation之前,单个relation中能有多少pages或者tuples能被predicate-locked 。本参数值大于等于零时表示绝对限制,本参数值为负值时表示max_pred_locks_per_transaction/本参数值的绝对值。本参数可以在postgresql.conf设置也可以在server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload生效 + +|=== + + +==== max_pred_locks_per_page + +[cols="136,387"] +|=== +h| 参数名称 h| max_pred_locks_per_page +| 数据类型 | integer +| 默认值 | 2 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 本参数控制在将锁提升为覆盖整个page之前,单个page中能有多少tuples能被predicate-locked。本参数可以在postgresql.conf设置也可以在server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload生效 + +|=== + + + + +=== Resource Usage / Cost-Based Vacuum Delay + +==== vacuum_cost_delay + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_cost_delay +| 数据类型 | Real +| 默认值 | 0,零代表禁用了基于成本的vacuum delay特性。 +| 取值范围 | 0到100 +| 参数单位 | 毫秒 +| 参数含义 | vacuum_cost_limit参数值是一个累积vacuum io操作的成本值,当vacuum操作达到vacuum_cost_limit参数值之后,vacuum操作会停下来休眠一段时间,该段时间是vacuum_cost_delay参数值指定的,然后,PostgreSQL会重置计数器并继续vacuum操作。本参数的参数值建议尽量小,大值是没有帮助的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session修改会立即生效;非session级修改reload即可生效。 + +|=== + + + + + +==== vacuum_cost_page_hit + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_cost_page_hit +| 数据类型 | Integer +| 默认值 | 1 +| 取值范围 | 0到10000 +| 参数单位 | +| 参数含义 | 对shared buffer中发现的一个buffer进行vacuum的估计成本,本成本代表:锁定buffer pool的成本+查找shared hash table的成本+扫描page中内容的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session修改会立即生效;非session级修改reload即可生效。 + +|=== + + + +==== vacuum_cost_page_miss + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_cost_page_miss +| 数据类型 | Integer +| 默认值 | 10 +| 取值范围 | 0到10000 +| 参数单位 | +| 参数含义 | 对不在shared buffer中的一个buffer(只能从disk读取)进行vacuum的估计成本,本成本代表:锁定buffer pool的成本+查找shared hash table的成本+从disk中读取该block到buffer的成本+扫描page中内容的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session修改会立即生效;非session级修改reload即可生效。 + +|=== + + + +==== vacuum_cost_page_dirty + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_cost_page_dirty +| 数据类型 | Integer +| 默认值 | 20 +| 取值范围 | 0到10000 +| 参数单位 | +| 参数含义 | Vacuum改变一个之前是干净的block的估计成本。本成本代表:额外的io操作以便将dirty block刷新到disk中。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session修改会立即生效;非session级修改reload即可生效。 + +|=== + + + + +==== vacuum_cost_limit + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_cost_limit +| 数据类型 | Integer +| 默认值 | 200 +| 取值范围 | 1到10000 +| 参数单位 | +| 参数含义 | 本参数值是一个累积vacuum io操作的成本值,当vacuum操作达到本参数值之后,vacuum操作会停下来休眠一段时间。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session修改会立即生效;非session级修改reload即可生效。 + +|=== + + + +=== Replication / Sending Servers + +==== max_wal_senders + +[cols="136,387"] +|=== +h| 参数名称 h| max_wal_senders +| 数据类型 | Integer +| 默认值 | 10 +| 取值范围 | 0到262143,0表示复制被禁用 +| 参数单位 | +| 参数含义 | 同时运行wal sender process的最大数量。运行wal sender process的场景包括流复制和以streaming模式进行base backup(译者注:其实还包括逻辑复制使用逻辑复制槽的场景,但是在PostgreSQL文档中并没有写明这一点)。本参数仅能在PostgreSQL启动时进行设置。配置参数waL_level必须设置为replica或者更高的值以便允许来自standby server的连接。在流复制环境中,在流复制备库上的该参数值至少要等于或者大于流复制主库上的该参数值,否则在备库上的query是不允许的。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instanc生效 + +|=== + + + +==== max_replication_slots + +[cols="136,387"] +|=== +h| 参数名称 h| max_replication_slots +| 数据类型 | Integer +| 默认值 | 10 +| 取值范围 | 0到262143 +| 参数单位 | +| 参数含义 +a| 设置PostgreSQL能支持的复制槽的最大数量,本参数仅能在PostgreSQL启动时进行设置。当本参数值小于当前已经存在的replicat slot时,会导致PG instance无法启动。配置参数waL_level必须设置为replica或者更高的值以便允许replication slot被用到。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instanc生效 + +|=== + + +==== wal_keep_size + +[cols="136,387"] +|=== +h| 参数名称 h| wal_keep_size +| 数据类型 | Integer +| 默认值 | 0,0表示PostgreSQL不会为流复制环境保留额外的wal segments, +| 取值范围 | 0到2147483647 +| 参数单位 | MB,若是设置时不带单位,则默认为MB +| 参数含义 | 指定在pg_wal目录中保留的wal segment file的最小大小,以便流复制环境中的standby server 从主库中fetch wal file。如果连接到发送服务器的standby server超过本参数值的大小,发送服务器可能会删除掉standby server仍然需要的wal segments,此时,复制连接会终止,下游的连接最终也会因此失败,若是wal进行了归档,standby server可以从归档中进行fetch segments,以便恢复流复制。本参数值仅仅设置保留在pg_wal中的wal segments的最小大小。系统可能需要保留更多的wal segments以便进行wal 归档或者从检查点中恢复。本参数值仅仅在postgresql.conf中进行设置或者在server command line中进行设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== max_slot_wal_keep_size + +[cols="136,387"] +|=== +h| 参数名称 h| max_slot_wal_keep_size +| 数据类型 | Integer +| 默认值 | -1,-1表示复制槽保留不限数量的wal files。 +| 取值范围 | -1到2147483647 +| 参数单位 | MB +| 参数含义 | 用来指定复制槽保留pg_wal目录中wal file的最大大小。当一个复制槽的restart_lsn落后于current_lsn超过本参数值时,使用了复制槽的standby server不能再继续流复制,因为已经删除掉了需要的wal files +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== wal_sender_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| wal_sender_timeout +| 数据类型 | Integer +| 默认值 | 60000 +| 取值范围 | 0到2147483647,0代表禁用timeout机制。 +| 参数单位 | 毫秒,若是指定时不带单位,默认为为毫秒数 +| 参数含义 | 当处于inactive状态多长时间(多长时间由本参数指定)之后,终止掉复制连接。这对于发送服务器检测standby crash或者网络中断很有用。当主备节点分布于不同的地理位置时,不同地理位置的节点使用不同的本参数值会带来管理上的灵活性。对于低延迟网络连接,较小的本参数值有助于快速的连接故障检测;对于地理位置较远的高延迟网络连接,较高的本参数值有助于判断standby server的健康状况。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效,允许非superuser修改本参数值非session级修改reload生效。 + +|=== + + + +=== Connections and Authentication / Authentication + +==== authentication_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| authentication_timeout +| 数据类型 | Integer +| 默认值 | 60 +| 取值范围 | 1到600 +| 参数单位 | 秒,如果指定本参数值时不带单位,默认为秒 +| 参数含义 | 允许完成连接认证的最长时间。如果客户端没有在本参数值指定的时间内完成连接认证,PostgreSQL数据库会关闭此次连接。本参数用于防止大量的客户端无限制的占用连接。本参数仅仅可以在postgresql.conf设置或者在server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + + + + + + + +==== password_encryption + +[cols="136,387"] +|=== +h| 参数名称 h| password_encryption +| 数据类型 | enum +| 默认值 | md5 +| 取值范围 | md5和scram-sha-256,写on也可以,on与md5有相同的作用。 +| 参数单位 | +| 参数含义 | 本参数决定了create role或者alter role语句中指定的密码的加密算法。请注意,老的客户端版本不支持SCRAM-SHA-256密码加密算法,具体请见下面的描述。有两个关键的标准去确定是否支持SCRAM密码加密算法。 正在运行PostgreSQL 10及其更高版本 你用来连接到PostgreSQL数据库的驱动有SCRAM兼容性。PostgreSQL社区已经提供了一个驱动清单(https://wiki.postgresql.org/wiki/List_of_drivers#Drivers)如果您的系统满足上述两个标准,您可以使用SCRAM密码加密算法。请注意:要把现有的环境从md5升级到scram-sha-256,可以在确保所有在用的客户端已经足以支持SCRAM之后,在postgresql.conf中设置password_encryption = 'scram-sha-256',然后让所有用户设置新口令并且在pg_hba.conf中将认证方法说明改为scram-sha-256。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效 + +|=== + + + + +==== krb_server_keyfile + +[cols="136,387"] +|=== +h| 参数名称 h| krb_server_keyfile +| 数据类型 | string +| 默认值 | FILE:/krb5.keytab,注意,sysconfdir代表sysconfdir目录,该目录可以用pg_config --sysconfdir操作系统命令获得。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置服务器Kerberos key file的位置。如果本参数设置为空字符串(empty string),PostgreSQL会忽略这个空字符串,此时系统默认值会被使用。本参数值在postgresql.conf或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== krb_caseins_users + +[cols="136,387"] +|=== +h| 参数名称 h| krb_caseins_users +| 数据类型 | bool +| 默认值 | off,off代表大小写敏感 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于控制GSSAPI user names是否被视为大小写不敏感,本参数值仅能在postgresql.conf或者server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== db_user_namespace + +[cols="136,387"] +|=== +h| 参数名称 h| db_user_namespace +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 +a| 若本参数值设置为on,那么创建的用户名的格式是username@dbname,当client传递username时,@符以及database name会被附加到username的末尾,并且PostgreSQL数据库查询用户是查找username@dbname这个格式的用户。当你在SQL环境中使用username@dbname这个格式的用户名时,请使用引号引起来username@dbname。当本参数值设置为on时,你依然可以建立普通的全局users,在客户端指定username时加上@即可,当PostgreSQL查找username之前,@符号会被去掉。 + +本参数会导致客户端和服务器端的用户名称表示方法不同。认证始终检查服务器端的username。因此,认证方法必须被配置为服务器端的username。因为md5密码加密算法在客户端和服务器端均使用username作为salt,因此,md5密码加密算法不能与本参数值一起使用。 + +本参数值仅能在postgresql.conf或者server command line中设置。请注意,本特性的目的是在一个完整的解决方案找到之前作为临时措施,到那时,本参数会被remove掉。 + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +=== Statistics / Query and Index Statistics Collector + +==== track_activities + +[cols="136,387"] +|=== +h| 参数名称 h| track_activities +| 数据类型 | boolean +| 默认值 | on +| 取值范围 | on 和off +| 参数单位 | +| 参数含义 | 当设置为on时,当每个session中执行SQL语句或者命令时,PostgreSQL会收集信息(包括命令执行的时间信息)。收集的信息仅仅对superuser和执行命令所在session的owner可见。 +| 是否可session级修改 | 是,仅限于superuser可进行session级修改 +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效 + +|=== + + + +==== track_activity_query_size + +[cols="136,387"] +|=== +h| 参数名称 h| track_activity_query_size +| 数据类型 | Integer +| 默认值 | 1024 +| 取值范围 | 100到1048576 +| 参数单位 | Byte,当指定本参数不带单位时,默认是Bytes +| 参数含义 | 为每个active的session保留当前执行命令的文本的大小,该文本对应pg_stat_activity.query列。本参数仅仅能在PostgreSQL start时设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + +==== track_counts + +[cols="136,387"] +|=== +h| 参数名称 h| track_counts +| 数据类型 | Bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当设置为on时,针对database activity收集统计信息。Autovacuum进程需要这些收集的信息。 +| 是否可session级修改 | 是,仅限于superuser可进行session级修改 +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效 + +|=== + + + + +==== track_io_timing + +[cols="136,387"] +|=== +h| 参数名称 h| track_io_timing +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 是否为database中的 io call/activity启用计时(即:io操作消耗了多少时间)。io计时信息体现在如下方面: pg_stat_database中 explain 带buffer时的输出中 pg_stat_statements中当设置为on时,PostgreSQL会重复查询操作系统的当前时间,这个可能会导致在某些平台下有大量开销。您可以使用pg_test_timing工具(该工具在bin目录下)来衡量系统的计时开销。仅superuser可以更改本参数值 +| 是否可session级修改 | 是,仅限于superuser可进行session级修改 +| 修改后何时生效 | Session级修改立即生效非session级修改reload生效 + +|=== + + + +==== track_functions + +[cols="136,387"] +|=== +h| 参数名称 h| track_functions +| 数据类型 | enum +| 默认值 | none,none的含义是禁用本功能 +| 取值范围 | none,pl,all +| 参数单位 | +| 参数含义 | 启用追踪函数调用计数和消耗的时间。参数值pl的含义是仅仅对procedural-language函数进行追踪,参数值all的含义是追踪SQL和C语言函数。仅superuser可以更改本参数值 +| 是否可session级修改 | 是,仅限于superuser可进行session级修改 +| 修改后何时生效 | Session级修改立即生效;非session级修改reload生效 + +|=== + + + + +==== stats_temp_directory + +[cols="136,387"] +|=== +h| 参数名称 h| stats_temp_directory +| 数据类型 | string +| 默认值 | pg_stat_tmp +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值用于指定存储临时统计信息的目录。本参数值可以是绝对路径,也可以是相对于data directory的相对路径本参数值指定为基于RAM的文件系统会减少物理IO并提升性能。本参数仅能在postgresql.conf中设置或者在server command line设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload生效 + +|=== + + + + +=== File Locations + +==== data_directory + +[cols="136,387"] +|=== +h| 参数名称 h| data_directory +| 数据类型 | string +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值表示PostgreSQL的数据目录的位置 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== config_file + +[cols="136,387"] +|=== +h| 参数名称 h| config_file +| 数据类型 | string +| 默认值 | 在数据目录中 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了postgresql.conf的位置本参数值仅仅可以在postgres command line设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== hba_file + +[cols="136,387"] +|=== +h| 参数名称 h| hba_file +| 数据类型 | string +| 默认值 | 在数据目录中 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了pg_hba.conf的位置;本参数值仅仅可以在PostgreSQL启动时设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== ident_file + +[cols="136,387"] +|=== +h| 参数名称 h| ident_file +| 数据类型 | string +| 默认值 | 在数据目录中 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值指定了pg_ident.conf的位置本参数值仅仅可以在PostgreSQL启动时设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + +==== external_pid_file + +[cols="136,387"] +|=== +h| 参数名称 h| external_pid_file +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 指定了将postmaster的pid写入哪个文件本参数值仅仅可以在PostgreSQL启动时设置。 postgres=# alter system set external_pid_file='/home/pg131/postmasterpid.txt'; ALTER SYSTEM postgres=# exit [pg131@VM-0-8-centos ~]$ pg_ctl restart waiting for server to shut down.... done server stopped waiting for server to start....2021-04-09 10:09:21.776 CST [5977] LOG: redirecting log output to logging collector process 2021-04-09 10:09:21.776 CST [5977] HINT: Future log output will appear in directory "log". done server started [pg131@VM-0-8-centos ~]$ cd [pg131@VM-0-8-centos ~]$ ll total 136260 -rw-rw-r-- 1 pg131 pg131 0 Mar 10 20:47 12345aa drwxrwxr-x 2 pg131 pg131 4096 Apr 9 10:09 archive drwx------ 20 pg131 pg131 4096 Apr 9 10:09 data -rw-rw-r-- 1 pg131 pg131 72 Mar 23 10:34 para.sql drwxrwxr-x 6 pg131 pg131 4096 Dec 20 14:32 postgresql-13.1 -rw-r--r-- 1 pg131 pg131 139499520 Dec 20 14:07 postgresql-13.1.tar -rw-r--r-- 1 pg131 pg131 5 Apr 9 10:09 postmasterpid.txt drwxrwxr-x 7 pg131 pg131 4096 Dec 20 14:45 soft drwx------ 3 pg131 pg131 4096 Dec 20 16:04 ts1 [pg131@VM-0-8-centos ~]$ cat postmasterpid.txt 5977 [pg131@VM-0-8-centos ~]$ pg_ctl status pg_ctl: server is running (PID: 5977) /home/pg131/soft/bin/postgres[pg131@VM-0-8-centos ~]$ +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +=== Reporting and Logging / When to Log + +==== log_min_messages + +[cols="136,387"] +|=== +h| 参数名称 h| log_min_messages +| 数据类型 | enum +| 默认值 | warning +| 取值范围 | debug5,debug4,debug3,debug2,debug1,info,notice,warning,error,log,fatal,panic +| 参数单位 | +| 参数含义 | 控制哪种message level写入系统日志。取值范围见上。在上面的取值范围中,前一个取值包括其后的取值。在上面的取值范围中,级别越在后边,写入系统日志中的messages就越少。注意: 本参数的参数值log的级别与client_min_messages配置参数的参数值log的级别不同。仅允许superuser可以修改本参数值。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效;其他级别修改reload生效 + +|=== + + + +==== log_min_error_statement + +[cols="136,387"] +|=== +h| 参数名称 h| log_min_error_statement +| 数据类型 | enum +| 默认值 | error,表示那些导致了errors、log messages、fatal errors、panics的SQL语句会被记录到日志中。 +| 取值范围 | debug5,debug4,debug3,debug2,debug1,info,notice,warning,error,log,fatal,panic +| 参数单位 | +| 参数含义 | 控制导致何种级别错误的SQL语句内容被记录到日志中。为了关闭对错误SQL语句的记录,请设置被参数值为panic仅允许superuser可以修改本参数值。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== log_min_duration_statement + +[cols="136,387"] +|=== +h| 参数名称 h| log_min_duration_statement +| 数据类型 | integer +| 默认值 | -1,-1表示禁用本功能。 +| 取值范围 | -1到2147483647 +| 参数单位 | 毫秒,若是不指定单位的话。 +| 参数含义 | 所有运行超过本参数值的SQL语句会打印到系统日志中。本参数对追踪未优化的SQL语句有很大帮助。本参数值为零表示打印所有的SQL语句。仅允许superuser可以修改本参数值。本参数会覆盖log_min_duration_sample参数,这意味持续时间超过本参数值的SQL语句将不进行采样,而是始终记录下来。对于使用扩展查询协议的客户端,Parse、Bind、Execute阶段会被各自独立记录下来。本参数与log_statement参数合用时,由于log_statement参数起作用而记录到log中的SQL文本不会被重复记录。在不使用syslog时,推荐使用log_line_prefix参数,以便记录PID或者Session ID。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + + +==== log_min_duration_sample + +[cols="136,387"] +|=== +h| 参数名称 h| log_min_duration_sample +| 数据类型 | Integer +| 默认值 | -1,-1表示禁用本功能。 +| 取值范围 | -1到2147483647,参数值为零时,记录所有语句的sample +| 参数单位 | 毫秒 +| 参数含义 | 举例说明,如果本参数值设置为100ms,那么运行时间超过100ms的SQL语句会被考虑进行采样。仅允许superuser可以修改本参数值。当流量太大而无法记录所有查询时,启用此参数会很有帮助。本参数的优先级比log_min_duration_statement参数优先级要低。这意味着持续时间超过log_min_duration_statement参数值的SQL语句不受采样限制,并且总是被记录下来。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +==== log_statement_sample_rate + +[cols="136,387"] +|=== +h| 参数名称 h| log_statement_sample_rate +| 数据类型 | Real +| 默认值 | 1 +| 取值范围 | 0到1 +| 参数单位 | +| 参数含义 | 确定将记录的持续时间超过log_min_duration_sample参数值的的语句的比率。例如0.5意味着统计上每两个给定语句中就有一个被记录的机会。默认值为1.0,意味着记录所有采样语句。本参数值设置为0表示禁用sampled statement-duration logging。仅允许superuser可以修改本参数值。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +==== log_transaction_sample_rate + +[cols="136,387"] +|=== +h| 参数名称 h| log_transaction_sample_rate +| 数据类型 | Real +| 默认值 | 0,参数值为0表示不记录任何其他事务的语句 +| 取值范围 | 0到1,参数值为1表示记录所有事物的所有语句 +| 参数单位 | +| 参数含义 | 设置除其他原因记录的语句之外,所有记录语句的事务的百分比,本参数适用于每个新事务,而不考虑其语句的持续时间。采样是随机的,例如0.1意味着在统计上,每十个交易中有一个机会记录任何给定的事务。本参数值有助于构建一个事务的采样。仅允许superuser可以修改本参数值。另外请注意:与所有statement-logging选项一样,本参数会显著增加系统负载。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +=== Checkpoints + +==== checkpoint_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| checkpoint_timeout +| 数据类型 | Integer +| 默认值 | 300 +| 取值范围 | 30到86400 +| 参数单位 | 秒 +| 参数含义 | 设置两次automatic WAL checkpoints的时间间隔。增加本参数值会导致进行crash recovery的时间长度增大。本参数值仅能在postgresql.conf设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== checkpoint_completion_target + +[cols="136,387"] +|=== +h| 参数名称 h| checkpoint_completion_target +| 数据类型 | Real +| 默认值 | 0.5 +| 取值范围 | 0到1 +| 参数单位 | +| 参数含义 | 指定了checkpoint 完成的目标,即:checkpoint需要在checkpoint_timeout\* checkpoint_completion_target的时间长度内完成。本参数值仅能在postgresql.conf设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== checkpoint_flush_after + +[cols="136,387"] +|=== +h| 参数名称 h| checkpoint_flush_after +| 数据类型 | Integer +| 默认值 | 32,注意:linux平台下本参数默认值为32,Windows平台下本参数默认值为0 +| 取值范围 | 0到256,如果BLCKSZ符号常量值不是8KB,请根据比例进行修改。 +| 参数单位 | 8KB,若是指定参数值时不带单位,默认是BLCKSZ bytes,在不修改BLCKSZ符号常量值的情况下,该符号常量值为8KB。 +| 参数含义 | 每当在执行检查点时写入的数据量超过本参数值时,会尝试强制操作系统向底层存储发出这些写入操作。这样会限制kernel page cache中dirty data的总量,减少了在checkpoint的末尾发出fsync命令时,或者当操作系统在后台以更大的批写入数据时,PostgreSQL暂停的可能性。这通常会大大减少事务延迟,但也有一些情况,特别是在工作负载大于shared_buffers,但小于操作系统page cache的情况下,性能可能会降低。本参数值仅可以在postgresql.conf中设置或者在server command line进行设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== checkpoint_warning + +[cols="136,387"] +|=== +h| 参数名称 h| checkpoint_warning +| 数据类型 | integer +| 默认值 | 30 +| 取值范围 | 0到2147483647,0会禁用warning。 +| 参数单位 | 秒。若是指定本参数值不带单位,默认是秒 +| 参数含义 | 如果由于填充WAL段文件而导致的检查点发生的时间间隔比本参数值更小(这表明应该加大max_wal_size配置参数值),则向服务器日志写入一条消息。当checkpoint_timeout参数值小于checkpoint_warning参数值时,warning不会产生。本参数值仅可以在postgresql.conf中设置或者在server command line进行设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + + + + + +==== max_wal_size + +[cols="136,387"] +|=== +h| 参数名称 h| max_wal_size +| 数据类型 | Integer +| 默认值 | 1024 +| 取值范围 | 2到2147483647 +| 参数单位 | MB +| 参数含义 | 触发automatic checkpoints的最大wal 大小。这是软限制,wal size可以在如下情况下超过本参数值的限制:重负载,失败的archive_command命令,以及高的wal_keep_size参数值设置。增加本参数值会导致进行crash recovery的时间长度增大。本参数值仅能在postgresql.conf设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== min_wal_size + +[cols="136,387"] +|=== +h| 参数名称 h| min_wal_size +| 数据类型 | Integer +| 默认值 | 80 +| 取值范围 | 2到2147483647 +| 参数单位 | MB +| 参数含义 | 只要WAL Disk的使用低于本参数值,旧的wal文件总是在checkpoint发生时被循环使用,而不是删除wal文件。这可以用来确保保留足够的WAL空间来处理WAL使用中的峰值,例如在运行大型批处理作业时。此参数只能在postgresql.conf文件文件或在server command line上。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +=== dynamic_library_path + +[cols="136,387"] +|=== +h| 参数名称 h| dynamic_library_path +| 数据类型 | string +| 默认值 | $libdir, $libdir代表的绝对路径请见pg_config --pkglibdir命令的输出 +| 取值范围 | +| 参数单位 | +| 参数含义 | 如果需要打开可动态加载的模块,并且create function 或LOAD命令中指定的文件名没有目录组件(即名称不包含斜杠),系统将在该路径中搜索所需的文件。本参数值必须是由冒号分隔(针对Linux平台)或者分号分隔(针对Windows平台)的绝对路径列表。如果本参数值以特殊字符串$libdir开头,那么编译后的PostgreSQL package library directory会取代$libdir, PostgreSQL package library directory请见pg_config --pkglibdir命令的结果。若是本参数值被设置为空字符串,表示自动path search功能会被关闭。superuser可以在运行时更改此参数,但这样做的设置只会持续到客户端连接结束,因此应将此方法保留用于开发目的。 +| 是否可session级修改 | 是,此时仅限于superuser在session级别修改。 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +=== gin_fuzzy_search_limit + +[cols="136,387"] +|=== +h| 参数名称 h| gin_fuzzy_search_limit +| 数据类型 | integer +| 默认值 | 0,0表示无限制 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | GIN索引扫描返回的结果集大小的软上限。开发GIN索引的主要目的是在PostgreSQL中创建对高度可伸缩的全文搜索的支持,而且通常情况下,全文搜索会返回非常大的结果集。此外,当查询包含非常频繁的单词时,这种情况经常发生,因此大的结果集甚至没有用处。因为从磁盘读取许多元组并对它们进行排序可能需要花费大量时间,这对于生产来说是不可接受的。(请注意,索引搜索本身非常快。)为了便于此类查询的受控执行,GIN对返回的行数有一个可配置的软上限,这就是gin_fuzzy_search_limit配置参数。默认设置为0(表示无限制)。如果设置了非零限制,则返回的集是随机选择的整个结果集的子集。"软"意味着返回结果的实际数量可能与指定的限制有所不同,这取决于查询和系统随机数生成器的质量。从经验来看,以千为单位的本参数值(例如,5000-20000)工作正常。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload生效 + +|=== + + + +=== tcp_keepalives_count + +[cols="136,387"] +|=== +h| 参数名称 h| tcp_keepalives_count +| 数据类型 | +| 默认值 | 0,0表示取操作系统的默认值, +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 指定在服务器与客户端的连接被视为已断开之前可以被丢弃的TCP keepalive messages.在一个基于Unix-domain socket的session中,本参数会被忽略,此时本参数值被视为零。本参数在Windows操作系统上不被支持,因此,在Windows操作系统上,本参数值必须为0。本参数仅仅支持符合如下条件的操作系统:那些支持TCP_KEEPCNT或者等价socket option的操作系统。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +=== tcp_keepalives_idle + +[cols="136,387"] +|=== +h| 参数名称 h| tcp_keepalives_idle +| 数据类型 | integer +| 默认值 | 0,0表示取操作系统的默认值 +| 取值范围 | 0到2147483647 +| 参数单位 | 秒 +| 参数含义 | 指定在没有网络活动的情况下,经过多长时间之后,操作系统应该向Client端发送TCP keepalive message.本参数仅仅支持符合如下条件的操作系统:那些支持TCP_KEEPIDLE或者等价socket option的操作系统。因此,在Windows以及其他操作系统中,本参数值必须为0,在一个基于Unix-domain socket的session中,本参数会被忽略,此时本参数值被视为0。在Windows操作系统上,本参数值为0时,本参数值将会被视为2小时,因为,Windows不提供读取系统默认值的方法。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +=== tcp_keepalives_interval + +[cols="136,387"] +|=== +h| 参数名称 h| tcp_keepalives_interval +| 数据类型 | Integer +| 默认值 | 0,0表示取操作系统的默认值 +| 取值范围 | 0到2147483647 +| 参数单位 | 秒 +| 参数含义 | 指定TCP keepalive message重传的时间间隔。本参数仅仅支持符合如下条件的操作系统:那些支持TCP_KEEPINTVL或者等价socket option的操作系统。因此,在Windows以及其他操作系统中,本参数值必须为零,在一个基于Unix-domain socket的session中,本参数会被忽略,此时本参数值被视为零。在Windows操作系统上,本参数值为零时,本参数值将会被视为1秒,因为,Windows不提供读取系统默认值的方法。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +=== tcp_user_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| tcp_user_timeout +| 数据类型 | Integer +| 默认值 | 0,0表示取操作系统的默认值 +| 取值范围 | 0到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 指定在强制关闭TCP连接之前,传输的数据可能保持未确认状态的时间长度本参数仅仅支持符合如下条件的操作系统:那些支持TCP_USER_TIMEOUT或者等价socket option的操作系统。因此,在其他操作系统中,本参数值必须为零,在一个基于Unix-domain socket的session中,本参数会被忽略,此时本参数值被视为零。在Windows操作系统上,本参数不受支持,此时本参数值必须设置为零。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + + +=== Query Tuning / Genetic Query Optimizer + +==== geqo + +[cols="136,387"] +|=== +h| 参数名称 h| geqo +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 +a| 启用或者禁用genetic query optimization,生产环境中不应该将本参数设置为off。配置参数geqo_threshold提供了对GEQO更细粒度的控制。遗传查询优化器(GEQO)是一种使用启发式搜索进行查询计划的算法。这减少了用于复杂查询(那些包含许多关系的查询)的计划时间,但所产生的计划的成本有时不如普通穷举搜索算法所找到的计划。 + + +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== geqo_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_threshold +| 数据类型 | integer +| 默认值 | 12 +| 取值范围 | 2到2147483647 +| 参数单位 | +| 参数含义 | 本参数是启用geqo的阈值,即:当from之后的关系数量至少有本参数值指定的个数时,才启用geqo。注意一个FULL OUTER JOIN只被计为一个FROM项。对于简单的SQL语句,通常最好使用常规的穷举搜索planner,但是对于具有许多表的查询,穷举搜索花费的时间太长,通常比执行次优计划的代价要长,因此,本阈值是管理geqo的一种方法。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== geqo_effort + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_effort +| 数据类型 | Integer +| 默认值 | 5 +| 取值范围 | 1到10 +| 参数单位 | +| 参数含义 | 控制GEQO中计划时间和查询计划质量之间的权衡。此变量必须是1到10之间的整数。默认值为5。较大的值会增加生成查询计划所花费的时间,但也会增加选择高效查询计划的可能性。本参数实际上并不直接做任何事情;它只用于计算影响geqo行为的其他变量的默认值。如果愿意,可以手动设置其他参数。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== geqo_pool_size + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_pool_size +| 数据类型 | Integer +| 默认值 | 0,0表示PostgreSQL会根据SQL语句中表的数量以及geqo_effort参数值选择一个合适的值。 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 控制GEQO使用的pool size,即:遗传群体中的个体数,至少是2,有用的值通常是100到1000. 参数值为0表示PostgreSQL会根据SQL语句中表的数量以及geqo_effort参数值选择一个合适的值。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== geqo_generations + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_generations +| 数据类型 | Integer +| 默认值 | 0 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 控制GEQO使用的generations,即算法的迭代次数。它必须至少是一个,并且有用的值通常是100到1000。如果设置为零(默认设置),则PostgreSQL会根据geqo_pool_size选择合适的值。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== geqo_selection_bias + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_selection_bias +| 数据类型 | real +| 默认值 | 2 +| 取值范围 | 1.5到2 +| 参数单位 | +| 参数含义 | 控制GEQO使用的选择偏差。选择偏差是population内部的选择压力 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +==== geqo_seed + +[cols="136,387"] +|=== +h| 参数名称 h| geqo_seed +| 数据类型 | real +| 默认值 | 0 +| 取值范围 | 0到1 +| 参数单位 | +| 参数含义 | 控制GEQO用于通过连接顺序搜索空间选择随机路径的随机数生成器的初始值,更改该值将更改所探索的连接路径集。并可能导致找到更好或更差的最佳路径 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +=== Write-Ahead Log / Recovery Target + +==== recovery_target + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target +| 数据类型 | string +| 默认值 | 空串 +| 取值范围 | immediate +| 参数单位 | +| 参数含义 | 此参数指定恢复应在达到一致状态后尽快结束,即尽早结束。从联机备份还原时,这意味着在备份结束的时间点结束恢复。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 本参数不支持修改。 + +|=== + + + +==== recovery_target_name + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_name +| 数据类型 | string +| 默认值 | 空串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 此参数指定将继续恢复(recovery)到的命名还原点,该还原点由函数pg_create_restore_point()创建。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_time + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_time +| 数据类型 | string +| 默认值 | 空串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 此参数指定将继续恢复(recovery)到的time stamp,精确的停止点受到recovery_target_inclusive配置参数影响。此参数的值是一个时间戳,其格式与timestamp with time zone数据类型所接受的格式相同,只是您不能使用时区缩写(除非在配置文件的前面设置了timezone_abbreviations变量)。首选样式是使用UTC的数字偏移量,或者您可以编写完整的时区名称,例如,Europe/Helsinki,而不是EEST +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_xid + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_xid +| 数据类型 | string +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | 此参数指定将继续恢复(recovery)到的trasaction ID。请记住,虽然事务ID在事务开始时按顺序分配,但事务可以按不同的数字顺序完成。要恢复的事务是在指定事务之前提交的事务(也可以选择包括指定事务),精确的停止点受到recovery_target_inclusive配置参数影响。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_lsn + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_lsn +| 数据类型 | string +| 默认值 | 空串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 此参数指定将继续恢复(recovery)到的LSN,精确的停止点受到recovery_target_inclusive配置参数影响。本参数使用系统数据类型pg_lsn解析。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_inclusive + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_inclusive +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数设置为on时指定到达指定的recovery target之后停止当本参数设置为off时指定到达指定的recovery target之前停止本参数与如下参数配合使用:recovery_target_lsn、recovery_target_time、recovery_target_xid。本参数控制含有精确recovery target(恢复目标)的LSN、commit time、或者trasaction id是否被包括恢复(recovery)之内。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_timeline + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_timeline +| 数据类型 | string +| 默认值 | latest +| 取值范围 | +| 参数单位 | +| 参数含义 | 指定recovery进入一个特定的timeline,本参数值可以是一个数字的timeline id或者一个特定的值,值current的含义:recover到做base backup时的那个timeline;值latest表示recover到在archive 中找到的最新的timeline,值latest适用于standby server。您通常只需要在复杂的重新恢复情况下设置本参数,在这种情况下,您需要返回到在时间点恢复之后达到的状态。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +==== recovery_target_action + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_target_action +| 数据类型 | enum +| 默认值 | pause +| 取值范围 | pause,promote,shutdown +| 参数单位 | +| 参数含义 | 指定了一旦达到recovery target,PostgreSQL该采取的操作。默认值pause表示恢复暂停(pause),值promote表示恢复过程完成并且PostgreSQL将会启动以接受外部连接,值shutdown表示在达到recovery target之后会stop PostgreSQL。pause值的预期用途是允许对数据库执行查询,以检查此恢复目标是否是最理想的恢复点,pg_wal_replay_resume()函数表示paused state resumed,这意味着恢复走到了终点。若是recovery target不是期望的那个stopping point,那么请关闭PostgreSQL,改变recovery target到更为之后的一个target,然后重启recovery即可。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG Instance生效 + +|=== + + + +=== Query Tuning / Other Planner Options + +==== default_statistics_target + +[cols="136,387"] +|=== +h| 参数名称 h| default_statistics_target +| 数据类型 | integer +| 默认值 | 100 +| 取值范围 | 1到10000 +| 参数单位 | +| 参数含义 | 为没有通过ALTER TABLE SET STATISTICS设置column-specific target的表列设置默认统计目标。较大的本参数值会增加analyze的时间,但也会提升planner估计的质量。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== constraint_exclusion + +[cols="136,387"] +|=== +h| 参数名称 h| constraint_exclusion +| 数据类型 | enum +| 默认值 | partition +| 取值范围 | partition,on,off on表示检查所有表的约束 off表示不检查约束partition表示仅仅对继承的子表以及union all子查询检查约束。 +| 参数单位 | +| 参数含义 +a| 控制planner是否使用constraints优化查询,如果表的约束保证没有与查询匹配的行,table scan会被跳过。本参数经常与传统的继承树一起使用以提高性能,比如如下的例子: CREATE TABLE parent(key integer, ...); CREATE TABLE child1000(check (key between 1000 and 1999)) INHERITS(parent); CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent); ... SELECT \* FROM parent WHERE key = 2400;当本参数启用时,select语句就不会扫描child1000这个表。目前,默认情况下仅对经常用于通过继承树实现表分区的情况启用约束排除。为所有表启用它会带来额外的计划开销,这在简单查询中非常明显,而且对于简单查询通常不会产生任何好处。如果没有使用传统继承进行分区的表,则可能希望完全关闭它。(请注意,分区表的等效功能由单独的配置参数enable_partition_pruning控制。) + + +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== cursor_tuple_fraction + +[cols="136,387"] +|=== +h| 参数名称 h| cursor_tuple_fraction +| 数据类型 | real +| 默认值 | 0.1 +| 取值范围 | 0到1 +| 参数单位 | +| 参数含义 | 设置planner's估计,本参数设置较少的值时,会使planner倾向于对cursors使用"fast start" plan,这会快速的检索前几行,而获取所有行可能需要很长时间。较大的值更强调总的估计时间。在最大设置为1.0时,游标的规划与常规查询完全相同,只考虑总的估计时间,而不考虑第一行的交付时间。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== from_collapse_limit + +[cols="136,387"] +|=== +h| 参数名称 h| from_collapse_limit +| 数据类型 | integer +| 默认值 | 8 +| 取值范围 | 1到2147483647 +| 参数单位 | +| 参数含义 | 如果生成的FROM列表包含的项目不超过本参数值,那么planner将会把子查询合并到上面的查询中。较小的值会减少计划时间,但可能会产生较差的查询计划。设置本参数值为geqo_threshold参数值或者更大可能会触发GEQO Planner的使用,进而导致非优化的执行计划。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +==== jit + +[cols="136,387"] +|=== +h| 参数名称 h| jit +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 确定jit编译是否被PostgreSQL使用。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + +==== join_collapse_limit + +[cols="136,387"] +|=== +h| 参数名称 h| join_collapse_limit +| 数据类型 | integer +| 默认值 | 8 +| 取值范围 | 1到2147483647 +| 参数单位 | +| 参数含义 | 每当生成的items列表不超过本参数值时,planner就会将explicit join结构(FULL JOINs除外)重写为FROM items列表。较小的值会减少计划时间,但可能会产生较差的查询计划.默认情况下,此参数值设置为与from_collapse_limit参数值相同,这适用于大多数用途。将其设置为1可防止explicit join的任何重新排序。因此,查询中指定的显式连接顺序将是连接关系的实际顺序。因为查询规划器并不总是选择最佳的连接顺序,所以高级用户可以选择将此参数值临时设置为1,然后显式指定所需的连接顺序。设置本参数值为geqo_threshold参数值或者更大可能会触发GEQO Planner的使用,进而导致非优化的执行计划。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + + + + +==== parallel_leader_participation + +[cols="136,387"] +|=== +h| 参数名称 h| parallel_leader_participation +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 允许leader进程在Gather和Gather Merge node下执行查询计划,而不是等待worker进程。将此值设置为off可降低worker进程被阻塞的可能性,因为leader进程读取元组的速度不够快,但需要leader进程等待工作进程启动,然后才能生成第一个元组。Leader进程能够帮助或阻碍性能的程度取决于计划类型、worker数量和查询持续时间。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + + +==== force_parallel_mode + +[cols="136,387"] +|=== +h| 参数名称 h| force_parallel_mode +| 数据类型 | enum +| 默认值 | off +| 取值范围 | off,on,regress off表示仅仅当预期能提升性能时,才使用parallel mode on表示对被视为safe的查询语句强制使用并行查询。regress表示除了有本参数值设置为"on"的相同的所有效果之外,还有一些旨在促进自动回归测试的附加效果 +| 参数单位 | +| 参数含义 | 是否使用parallel query功能。更具体地说,将此值设置为on将在任何查询计划的顶部添加一个Gather节点,这看起来是安全的,因此查询在并行worker进程中运行,即使并行worker进程不可用或无法使用,也将禁止在并行查询上下文中禁止的操作(如启动子事务),除非planner认为这将导致查询失败,如果设置此选项时出现故障或意外结果,则查询使用的某些函数可能需要标记为PARALLEL UNSAFE(或者,可能是PARALLEL RESTRICTED)通常,来自并行worker进程的消息包含一个context line,但是设置为regress会抑制该context line,以便输出与非并行执行中的输出相同。此外,通过此设置,添加到计划中的Gather nodes将隐藏在EXPLAIN的输出中,以便当本参数值设置为off时,输出与获得的结果相匹配。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== plan_cache_mode + +[cols="136,387"] +|=== +h| 参数名称 h| plan_cache_mode +| 数据类型 | enum +| 默认值 | auto +| 取值范围 | auto,force_generic_plan,force_custom_plan +| 参数单位 | +| 参数含义 | 可以使用自定义或generic的plan执行prepared statements(explicitly prepared或implicitly generated,例如通过PL/pgSQL),针对每一次的执行,自定义plan使用特定的一组参数值被重新生成,generic plans不依赖本plan_cache_mode参数值,可以被多次的执行重复使用。此外,使用generic plans会节省 planning time,但是,如果理想的plan强烈依靠本参数,那么,generic plan可能效率低下。这些选项之间的选择通常是自动进行的,但它可以被plan_cache_mode配置参数覆盖。在执行缓存的计划时,而不是在准备计划时,会考虑本参数值 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + + +=== Version and Platform Compatibility / Previous PostgreSQL Versions + +==== array_nulls + +[cols="136,387"] +|=== +h| 参数名称 h| array_nulls +| 数据类型 | bool +| 默认值 | on,本参数值为on时表示允许输入包括NULL的数组值 +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数控制数组输入解析器是否将未加引号的NULL识别为指定NULL数组元素。8.2版本之前的PostgreSQL不支持数组中的null值,因此将null视为使用字符串值"null"指定普通数组元素。为了向后兼容需要旧行为的应用程序,可以关闭此参数。请注意,即使本参数值是off,也可以创建包含NULL的数组值 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== backslash_quote + +[cols="136,387"] +|=== +h| 参数名称 h| backslash_quote +| 数据类型 | enum +| 默认值 | safe_encoding +| 取值范围 | safe_encoding,on,off on表示始终允许\' off表示始终拒绝\'safe_encoding表示仅当客户端编码不允许在多字节字符中使用ASCII\时才允许. +| 参数单位 | +| 参数含义 | 本参数用于设置字符串的引用符是否是\'符号。SQL标准中是'',而PostgreSQL历史上也接受了\'符号,但是,使用\'会带来安全风险,这是因为,在一些客户端字符集编码中,存在多字节字符,其中最后一个字节在数字上等同于ASCII \.如果客户端没有正确的转义,那么SQL注入攻击是可能的。这种风险可以通过使PostgreSQL数据库拒绝引用符被backslash反斜杠转义的查询来防止。请注意,在标准一致性字符串文本中,无论如何,\仅仅表示\。此参数仅影响对非标准一致性文本的处理,包括转义字符串语法(E'…') +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== escape_string_warning + +[cols="136,387"] +|=== +h| 参数名称 h| escape_string_warning +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当设置为on时,表示当\出现在一个普通的字符串('…'这样的)中并且standard_conforming_strings参数值为off时,一个warning会发出。希望使用反斜杠作为转义的应用程序应该修改为使用转义字符串语法(E'…'). 因为根据SQL标准,普通字符串的默认行为现在是将反斜杠视为普通字符. 可以启用本参数来帮助定位需要更改的代码 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== lo_compat_privileges + +[cols="136,387"] +|=== +h| 参数名称 h| lo_compat_privileges +| 数据类型 | bool +| 默认值 | off +| 取值范围 | +| 参数单位 | +| 参数含义 | 对large object,为权限检查启用面向backward的兼容性模式。在PostgreSQL9.0之前,large object并不具有访问权限,因此,large object总是能被所有的user进行读和写。设置本参数值为on将会禁用新权限的检查,这会与PostgreSQL9.0之前的版本保持兼容。 +| 是否可session级修改 | 是,仅限于superuser进行修改 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== operator_precedence_warning + +[cols="136,387"] +|=== +h| 参数名称 h| operator_precedence_warning +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用此选项后,解析器将对自PostgreSQL 9.4以来由于运算符优先级的更改而可能已更改含义的任何构造发出警告。对于审核应用程序以查看优先级更改是否破坏了任何内容非常有用;但这并不意味着在生产环境中保持打开状态,因为它将警告某些完全有效、符合标准的SQL代码 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== quote_all_identifiers + +[cols="136,387"] +|=== +h| 参数名称 h| quote_all_identifiers +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 +a| 当数据库生成SQL语句时,即使标识符不是关键字,也会将标识符引用起来。这会影响explain的输出以及诸如pg_get_viewdef函数的结果,比如下面的例子: postgres=# select pg_get_viewdef('company_view'); -[RECORD 1]--+-------------------- pg_get_viewdef | SELECT company.id,+ | company.name, + | company.age + | FROM company; + + postgres=# set quote_all_identifiers=on; SET postgres=# select pg_get_viewdef('company_view'); -[RECORD 1]--+------------------------ pg_get_viewdef | SELECT "company"."id",+ | "company"."name", + | "company"."age" + | FROM "company"; + +postgres=# + +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== standard_conforming_strings + +[cols="136,387"] +|=== +h| 参数名称 h| standard_conforming_strings +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数控制普通字符串文本('…')是否按SQL标准中的指定按字面含义处理反斜杠.从PostgreSQL9.1开始,默认值为on。此参数的存在也可以被视为表示支持转义字符串语法(E'…')如果应用程序希望反斜杠被视为转义字符,则应使用转义字符串语法 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +==== synchronize_seqscans + +[cols="136,387"] +|=== +h| 参数名称 h| synchronize_seqscans +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 这允许对大表的顺序扫描彼此同步,以便并发扫描在大约相同的时间读取相同的块,从而共享I/O工作负载。启用本参数后,扫描可能从表的中间开始,然后"环绕"结尾以覆盖所有行,以便与正在进行的扫描活动同步。这可能导致没有ORDERBY子句的查询返回的行顺序发生不可预知的更改。将此参数设置为off可确保与PostgreSQL 8.3之前的行为,即顺序扫描始终从表的开头开始 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效,其他级别修改reload生效 + +|=== + + + +=== Connections and Authentication / Connection Settings + +==== listen_addresses + +[cols="136,387"] +|=== +h| 参数名称 h| listen_addresses +| 数据类型 | string +| 默认值 | localhost +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置数据库服务器监听的hostname或者IP地址,监听多个hostname或者IP地址时,请用逗号隔开。 \*号表示监听所有可用的IP地址, 0:0:0:0监听代表所有IPV4的地址, ::代表监听所有IPV6的地址。当本参数值为空时,PostgreSQL不会监听任何的IP,此时,只有Unix-domain sockets才可以用于连接到数据库中。本参数控制哪些IP地址上接受连接尝试,这可以帮助防止在不安全的IP地址上重复出现恶意连接请求。该参数只能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== port + +[cols="136,387"] +|=== +h| 参数名称 h| port +| 数据类型 | integer +| 默认值 | 5432 +| 取值范围 | 1到65535 +| 参数单位 | +| 参数含义 | PostgreSQL监听的TCP端口。请注意,PostgreSQL监听的所有IP地址都使用相同的端口号,本参数只能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== max_connections + +[cols="136,387"] +|=== +h| 参数名称 h| max_connections +| 数据类型 | integer +| 默认值 | 100 +| 取值范围 | 1到262143 +| 参数单位 | +| 参数含义 | 本参数值指定了PostgreSQL数据库的最大连接数。本参数只能在PostgreSQL启动时设置。在流复制备库上,必须将本参数值设置为与主库相同或者比主库参数值大,否则,备用服务器将不允许查询操作。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== superuser_reserved_connections + +[cols="136,387"] +|=== +h| 参数名称 h| superuser_reserved_connections +| 数据类型 | integer +| 默认值 | 3 +| 取值范围 | 0到262143 +| 参数单位 | +| 参数含义 | 为superusers保留的connection "slots"的数量,当PostgreSQL的活跃的并发连接的数量等于max_connections参数值减去superuser_reserved_connections参数值之后,仅仅可以面向superuser建立新的连接,并且,replication connection也是建立不了的。本参数只能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== unix_socket_directories + +[cols="136,387"] +|=== +h| 参数名称 h| unix_socket_directories +| 数据类型 | string +| 默认值 | 在Linux中默认值为/tmp;在Windows中默认值为空 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了PostgreSQL监听客户端连接的Unix-domain socket(s)目录,多个目录可以用逗号隔开,两个目录之间的空格会被忽略,如果你想在目录名中包括逗号或者空格,请使用双引号引起来。本参数值为空时表示不监听任何的Unix-domain socket(s)目录,这意味着只有TCP/IP sockets可以被用来连接到PostgreSQL中。本参数只能在PostgreSQL启动时设置。在本参数值指定的目录下,会有名为s.PGSQL.nnnn的socket file,nnnn是PostgreSQL使用的端口号,在该目录下,还有一个名为.s.PGSQL.nnnn.lock的文件。这两个文件请不要手工删除。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== unix_socket_group + +[cols="136,387"] +|=== +h| 参数名称 h| unix_socket_group +| 数据类型 | string +| 默认值 | 空字符串,空字符串表示使用启动PostgreSQL 的user的默认组。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置Unix-domain socket(s).的owning group(请注意:socket的owning user总是启动PostgreSQL的user)。本参数与unix_socket_permissions结合使用可以将其作为Unix-domain connections的额外访问控制机制。本参数只能在PostgreSQL启动时设置。本参数不支持在Windows上使用,在Windows上,本参数取任何值都会被忽略。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== unix_socket_permissions + +[cols="136,387"] +|=== +h| 参数名称 h| unix_socket_permissions +| 数据类型 | integer +| 默认值 | 0777,0777表示任何人都可以连接 +| 取值范围 | 0到511 +| 参数单位 | +| 参数含义 | 本参数用于设置Unix-domain socket(s)的访问权限。Unix-domain socket使用通常的Unix文件系统权限集。参数值预计是被chmod和umask系统调用接受的数字模式。(要使用惯用的八进制格式,数字必须以0(零)开头。)合理的参数值是0770(仅用户和组,另请参见unix_socket_group)和0700(仅用户)。请注意,对于Unix-domain socket,仅写许可权是重要的,因此设置或撤消读或执行许可权没有意义。本参数只能在PostgreSQL启动时设置。在完全忽略socket permissions的操作系统上(特别是自solaris10起的Solaris),此参数是不相关的。在此类操作系统上,可以通过将unix目录指向一个搜索权限仅限于所需访问用户的目录来实现类似的效果。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + + +==== bonjour + +[cols="136,387"] +|=== +h| 参数名称 h| bonjour +| 数据类型 | boolean +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 本参数控制是否通过Bonjour机制通告PostgreSQL的存在。本参数只能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + + + +==== bonjour_name + +[cols="136,387"] +|=== +h| 参数名称 h| bonjour_name +| 数据类型 | string +| 默认值 | 空字符串。空字符串表示使用计算机名 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于设置Bonjour service name。当PostgreSQL软件没有编译Bonjour support时,本参数会被忽略。本参数只能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效。 + +|=== + + + +=== Resource Usage / Asynchronous Behavior + +==== effective_io_concurrency + +[cols="136,387"] +|=== +h| 参数名称 h| effective_io_concurrency +| 数据类型 | integer +| 默认值 | 1 +| 取值范围 | 0到1000,0表示禁止发布异步I/O请求 +| 参数单位 | +| 参数含义 | 有效利用disk子系统的并发disk io的数量。目前,本参数仅仅影响bitmap heap scans。对于HDD(机械硬盘),本参数的起始值应该是PostgreSQL database用到的、组成raid 0 条带或者raid 1镜像的单独 disk drive的个数。但是,如果PostgreSQL数据库经常忙于并发会话中发出的多个查询,则较低的值可能足以使磁盘阵列保持繁忙。高于使磁盘保持忙碌的本参数值只会导致额外的CPU开销,固态盘(SSD)以及其他基于内存的存储可以经常处理很多并发请求,因此,此时最佳的值可能是几百。异步IO请求取决于一个有效的posix_fadvise函数,该函数在有些操作系统上是缺少的。在该函数缺少时,设置本参数为非零值会导致错误发生。在有些操作系统上(比如Solaris),本函数存在但是并没有实际的执行任何操作。在受到支持的操作系统上,本参数值的默认值为1,否则为零。本参数值可以被tablespace级别的同名参数值所覆盖。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + + +==== maintenance_io_concurrency + +[cols="136,387"] +|=== +h| 参数名称 h| maintenance_io_concurrency +| 数据类型 | integer +| 默认值 | 10 +| 取值范围 | 0到1000 +| 参数单位 | +| 参数含义 | 本参数类似于effective_io_concurrency参数,但本参数用于代表许多客户端会话执行的维护工作。在受到支持的操作系统上,本参数值的默认值为10,否则为零。本参数值可以被tablespace级别的同名参数值所覆盖。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + + +==== max_worker_processes + +[cols="136,387"] +|=== +h| 参数名称 h| max_worker_processes +| 数据类型 | integer +| 默认值 | 8 +| 取值范围 | 0到262143 +| 参数单位 | +| 参数含义 | 本参数值指定了PostgreSQL所能支持的并发worker进程的最大数量。本参数值仅能在PostgreSQL启动时设置。当运行在standby server环境中时,在standby server上的本参数值必须大于或者等于在master server上的本参数值。否则,query是不能运行在standby server上。当改变本参数值时,请考虑调整max_parallel_workers,参数,max_parallel_maintenance_workers参数,max_parallel_workers_per_gather参数 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== max_parallel_workers_per_gather + +[cols="136,387"] +|=== +h| 参数名称 h| max_parallel_workers_per_gather +| 数据类型 | integer +| 默认值 | 2 +| 取值范围 | 0到1024,0表示禁用parallel query execution +| 参数单位 | +| 参数含义 | 本参数指定了可以被单个Gather或者Gather Merge Node启动的worker进程的最大数量。Parallel Workers进程从由max_worker_processes配置参数建立的进程池中获取,受限于max_parallel_workers配置参数。请注意,请求的workers的数量在运行时并不一定实际可用,如果这个情况发生,执行计划会以少于期望个数的workers去运行,这可能是低效的。请注意,parallel queries可能比非parallel queries消耗更多的资源,因为每个工作进程是一个完全独立的进程,其对系统的影响与附加用户会话大致相同。在为此设置选择值时,以及在配置控制资源利用率的其他设置(如work_mem)时,都应考虑到这一点。诸如work_mem之类的资源限制单独应用于每个worker,这意味着所有进程的总利用率可能比任何单个进程的正常利用率高得多。例如,一个使用4个worker的并行查询可能会使用多达5倍的CPU时间、内存、I/O带宽。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + +==== max_parallel_maintenance_workers + +[cols="136,387"] +|=== +h| 参数名称 h| max_parallel_maintenance_workers +| 数据类型 | integer +| 默认值 | 2 +| 取值范围 | 0到1024,0表示禁用由实用命令使用的parallel workers +| 参数单位 | +| 参数含义 | 可以被单个实用命令启动的parallel worker的最大数量。当前,支持parallel workers的并行实用命令有如下几种: create index 建立B-Tree时; vacuum 不带full选项时; Parallel Workers进程从由max_worker_processes配置参数建立的进程池中获取,受限于max_parallel_workers配置参数。请注意,请求的workers的数量在运行时并不一定实际可用,如果这个情况发生,执行计划会以少于期望个数的workers去运行,这可能是低效的。注意,并行实用程序命令不应该比等效的非并行操作消耗更多的内存,这种策略不同于并行查询,在并行查询中资源限制通常适用于每个worker进程。并行实用命令将资源限制maintenance_work_mem视为应用于整个实用命令的限制,而不考虑并行工作进程的数量。然而,并行实用命令仍然可能消耗更多的CPU资源和I/O带宽。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + + +==== max_parallel_workers + +[cols="136,387"] +|=== +h| 参数名称 h| max_parallel_workers +| 数据类型 | integer +| 默认值 | 8 +| 取值范围 | 0到1024 +| 参数单位 | +| 参数含义 | 本参数值指定了PostgreSQL支持的parallel操作的worker的最大数量。当增加或者减少本参数值时,请考虑同时调整max_parallel_maintenance_workers 配置参数和 max_parallel_workers_per_gather配置参数。请注意:当本参数值高于max_worker_processes参数值时不会有任何作用。因为,因为parallel workers是从max_worker_processes配置参数所建立的工作进程池中获取的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + + +==== backend_flush_after + +[cols="136,387"] +|=== +h| 参数名称 h| backend_flush_after +| 数据类型 | integer +| 默认值 | 0,0表示禁用强制writeback +| 取值范围 | 0到256 +| 参数单位 | 8KB +| 参数含义 | 每当单个backend进程写入的数据超过本参数值时,尝试强制操作系统向底层存储发出这些写入操作。这样做将限制内核page cache中脏数据的数量,减少在检查点结束时发出fsync时,或者当操作系统在后台以更大的批写入数据时暂停的可能性。这通常会大大减少事务延迟,但也有一些情况,特别是在工作负载大于共享缓冲区,但小于操作系统page cache的情况下,性能可能会降低。此参数可能在某些平台下无效。如果指定该值时没有单位,则将其作为块,即源码中的符号常量BLCKSZ个字节,通常为8KB。如果BLCKSZ不是8KB,则最大值与之成比例缩放。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级别修改立即生效非session级修改reload生效 + +|=== + + + +==== old_snapshot_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| old_snapshot_threshold +| 数据类型 | intger +| 默认值 | -1,-1代表禁用本特性,表示snapshot age 是无限制的。 +| 取值范围 | -1到86400 +| 参数单位 | 分钟 +| 参数含义 | 设置在使用snapshot时可以使用查询快照而不会出现"snapshot too old"错误的最短时间。处于dead状态的且超过本参数值的数据可以被vacuum掉。这有助于防止snapshot长期使用时出现表膨胀。为了防止由于清除快照可见的数据而产生不正确的结果,当快照早于本参数值并且快照用于读取自创建快照以来已修改的页面时,将生成一个错误。对生产环境有用的值可能从几个小时到几天不等。只允许使用较小的值(如0或1min),因为它们有时可能对测试有用。虽然允许高达60d的设置,但请注意,在许多工作负载中,在更短的时间内可能会出现极端膨胀或事务ID环绕(transaction ID wraparound)。启用本特性后,relation末尾释放的空间将无法释放给操作系统,因为这可能会删除检测"snapshot too old"条件所需的信息。分配给relation的所有空间都与该relation保持关联,以便仅在该relation中重用,除非显式释放(例如,使用VACUUM FULL)。此参数并不试图保证在任何特定情况下都会生成错误。事实上,如果正确的结果可以从一个已经物化的结果集中生成,则即使引用表中的底层行已被vacuum,也不会生成错误。某些表不能安全地提前vacuum,因此不受此设置的影响,例如系统目录(system catalogs)。对于这样的表,此设置既不会减少膨胀,也不会在扫描时产生"snapshot too old"错误的可能性。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +=== Replication / Standby Servers + +==== primary_conninfo + +[cols="136,387"] +|=== +h| 参数名称 h| primary_conninfo +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数值指定了连接到sending server的连接字符串(连接信息).在本连接字符串中缺少的option,PostgreSQL会到环境变量中取寻找。若是环境变量中也没有,那么就用默认值。连接字符串应该指定如下信息: Sending Server的主机名或者IP地址、 Sending Server的端口号(若是跟standby server端口号不同) Username(该用户在sending-server端有合适的权限) Password:请注意,密码可以在primary_conninfo中提供,也可以在standby server上的~/.pgpass文件中提供(此时,是用replication作为database name)。请不要在primary_conninfo中指定database的名字本参数仅能在postgresql.conf文件或者server command line中设置。当在wal receiver process正在运行的情况下修改本参数值,wal receiver process会被发信号通知关闭然后再以新参数值去启动,除非primary_conninfo配置参数为空字符串。当PostgreSQL没有处于standby mode的情况下,本参数无效。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== primary_slot_name + +[cols="136,387"] +|=== +h| 参数名称 h| primary_slot_name +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数指定了当要连接到sending-server端时,要使用的sending-server端的已经存在的replication slot,用来控制sending-server端的wal removal。本参数仅能在postgresql.conf文件或者server command line中设置。当在wal receiver process正在运行的情况下修改本参数值,wal receiver process会被发信号通知关闭然后再以新参数值去启动,本参数在如下情况下没有作用:PostgreSQL没有处于standby mode或者primary_conninfo参数值没有设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== promote_trigger_file + +[cols="136,387"] +|=== +h| 参数名称 h| promote_trigger_file +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数值指定了一个trigger file,该文件用于standby server结束recovery状态进行角色提升。本参数值没有设置时,你可以使用pg_ctl promote或者使用函数pg_promote()进行角色提升。本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== hot_standby + +[cols="136,387"] +|=== +h| 参数名称 h| hot_standby +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数控制standby server是否允许运行只读查询语句。本参数仅能在server start时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== max_standby_archive_delay + +[cols="136,387"] +|=== +h| 参数名称 h| max_standby_archive_delay +| 数据类型 | integer +| 默认值 | 30000 +| 取值范围 | -1到2147483647,-1表示允许standby server一直在等待直到冲突的query执行完毕。 +| 参数单位 | 毫秒 +| 参数含义 +a| 本参数为备库参数,本参数在sending-server端会被忽略。当hot standby在被启用的状态下,本参数决定了standby server在取消掉standby中运行的且与WAL日志应用有冲突的查询语句之前的等待时间。本参数适用于从wal 归档读取wal data的情况。当不指定单位时,本参数的单位是毫秒。本参数仅能在postgresql.conf文件或者server command line中设置。 + + + +本参数值与查询语句在取消之前可以运行的最长时间不同。相反,本参数值是:一旦standby server从sending-server收到wal data,所允许的应用wal data的最长时间。因此,如果一个查询在一个wal segment之前导致了显著的延迟,那么在standby server再次赶上之前,后续冲突查询的容忍时间(宽限时间)将少得多。 + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + +==== max_standby_streaming_delay + +[cols="136,387"] +|=== +h| 参数名称 h| max_standby_streaming_delay +| 数据类型 | integer +| 默认值 | 30000 +| 取值范围 | -1到2147483647,-1表示允许standby server一直在等待直到冲突的query执行完毕。 +| 参数单位 | 毫秒 +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。当hot standby在被启用的状态下,本参数决定了standby server在取消掉standby中运行的且与WAL日志应用有冲突的查询语句之前的等待时间。本参数适用于wal data通过流复制被接收的情况。当不指定单位时,本参数的单位是毫秒。本参数仅能在postgresql.conf文件或者server command line中设置。本参数值与查询语句在取消之前可以运行的最长时间不同。相反,本参数值是从主服务器接收到WAL数据后允许应用该数据的最长总时间,因此,如果一个查询导致了显著的延迟,那么在备用服务器再次赶上之前,后续冲突查询的容忍时间(宽限时间)将少得多 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_receiver_create_temp_slot + +[cols="136,387"] +|=== +h| 参数名称 h| wal_receiver_create_temp_slot +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数用于指定当永久的复制槽没有配置(复制槽配置请见配置参数primary_slot_name)的情况下,wal receiver是否在远程PG Cluster上创建一个临时的复制槽。本参数仅能在postgresql.conf文件或者server command line中设置。当wal receiver进程正在运行的同时本参数被改变时,wal receiver进程会关闭并重启以读取到新值。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== wal_receiver_status_interval + +[cols="136,387"] +|=== +h| 参数名称 h| wal_receiver_status_interval +| 数据类型 | integer +| 默认值 | 10 +| 取值范围 | 0到2147483,0表示完全禁止状态更新。 +| 参数单位 | 秒 +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数指定了备库上的wal receiver 进程向 primary库或者sending-server库发送复制进度(replication progress)的最短时间频率。备库将报告它写到的wal的位置,它flush 到disk的位置以及它应用wal的位置。本参数值是两次报告之间的最大时间间隔。每次写入(write)或刷新(flush)位置更改时都会发送更新,或者至少与本参数指定的频率相同。因此,应用的位置可能稍微落后于真实位置。本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== hot_standby_feedback + +[cols="136,387"] +|=== +h| 参数名称 h| hot_standby_feedback +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。是否允许一个hot standby的备库发送关于正在备库执行的查询的feedback给primary库或者upstream库。本参数值可以消除由于cleanup records导致的query cancels,但是会导致primary库上发生膨胀。feedback信息的发送频率不会超过配置参数wal_receiver_status_interval。当是级联复制环境时,feedback会通过upstream(即:中间节点)会最终到达primary库。Standby节点除了向upstream反馈信息外,没有其他用途。本参数不会覆盖primary端的配置参数old_snapshot_threshold的行为。Standby端上超过primary端age阈值的snapshot会变为invalid,这导致standby端上的查询被取消。这是因为配置参数old_snapshot_threshold的目的是在时间上对dead row导致膨胀提供绝对的限制,否则会因为standby的配置违反该限制。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_receiver_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| wal_receiver_timeout +| 数据类型 | integer +| 默认值 | 60000 +| 取值范围 | 0到2147483647,0代表禁用本timeout检测机制。 +| 参数单位 | 毫秒 +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。当本备端与sending-server端或者primary端的inactive状态超过本参数值时,终止掉复制连接。本参数对receiving standby server检测primary node crash或者网络故障很有用。本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_retrieve_retry_interval + +[cols="136,387"] +|=== +h| 参数名称 h| wal_retrieve_retry_interval +| 数据类型 | integer +| 默认值 | 5000 +| 取值范围 | 1到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。本参数控制standby server遇到从所有源头(streaming replication、本地pg_wal目录、WAL Archive位置)获取wal而获取不到时的等待时间。本参数对处于in recovery的节点需要控制等待新的wal data可用的时间很有用。比如,在archive recovery中,通过降低本参数值,在检测一个新wal log file时,可以使recovery更快响应。在一个wal file产生很少的PostgreSQL中,增加本参数值会减少访问wal archive的请求次数。这在那些基础设施的访问次数会被考虑在内的云环境中非常有用。本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== recovery_min_apply_delay + +[cols="136,387"] +|=== +h| 参数名称 h| recovery_min_apply_delay +| 数据类型 | integer +| 默认值 | 0,0代表无延迟。 +| 取值范围 | 0到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 本参数为备库参数,本参数在sending-server端会被忽略。默认情况下,standby server会及时的restore 来自于sending server端的WAL 记录。数据的延迟copy可能很有用,它提供了纠正数据丢失错误的机会。本参数值指定了允许你指定延迟recovery的时间长度。比如,你设置本参数值为5分钟,那么只有当standby端的系统时间比master端报告的提交时间至少晚5分钟时,standby端才会重放每个事物的提交。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +=== Query Tuning / Planner Cost Constants + +==== seq_page_cost + +[cols="136,387"] +|=== +h| 参数名称 h| seq_page_cost +| 数据类型 | real +| 默认值 | 1 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数设置了顺序读取磁盘上的page的成本。在table以及index上的表空间级别的同名本参数可以覆盖配置参数中的该参数值。增大本参数值会使索引扫描看起来相对更昂贵 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + + +==== random_page_cost + +[cols="136,387"] +|=== +h| 参数名称 h| random_page_cost +| 数据类型 | real +| 默认值 | 4 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数设置了非顺序读取磁盘上的page的成本。在table以及index上的表空间级别的同名本参数可以覆盖配置参数中的该参数值。相对于seq_page_cost减少本参数值会使PostgreSQL更倾向于使用索引扫描。随机访问机械硬盘要比四次顺序访问还要昂贵。但是,使用较低的默认值(4.0),因为大多数对磁盘的随机访问(如索引读取)都假定在cache中。默认值可以认为是将随机访问模型比顺序访问慢40倍,同时,期望90%的随机读取都是在cache中。如果您认为90%的缓存比率对于您的工作负载来说是一个不正确的假设,那么你可以增加本参数值以反映随机存储读取的真实成本。相应的,如果你的数据可能完全在cache中,比如在database大小小于服务器内存,减少本参数值是合适的。那些相对于顺序读具有低随机读成本的存储(比如固态驱动器),也可以使用较低本参数值(比如1.1) +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== cpu_tuple_cost + +[cols="136,387"] +|=== +h| 参数名称 h| cpu_tuple_cost +| 数据类型 | real +| 默认值 | 0.01 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数值设置在执行一个SQL语句时planner预计的处理每行数据的成本 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + + +==== cpu_index_tuple_cost + +[cols="136,387"] +|=== +h| 参数名称 h| cpu_index_tuple_cost +| 数据类型 | real +| 默认值 | 0.005 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数用于设置在索引扫描期间planner预计的处理每个index entry的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== cpu_operator_cost + +[cols="136,387"] +|=== +h| 参数名称 h| cpu_operator_cost +| 数据类型 | real +| 默认值 | 0.0025 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数值设置在执行一个SQL语句时planner预计的处理执行的每个operator或者function的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== parallel_setup_cost + +[cols="136,387"] +|=== +h| 参数名称 h| parallel_setup_cost +| 数据类型 | real +| 默认值 | 1000 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数值设置planner预估的启动parallel worker processes的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + + +==== parallel_tuple_cost + +[cols="136,387"] +|=== +h| 参数名称 h| parallel_tuple_cost +| 数据类型 | real +| 默认值 | 0.1 +| 取值范围 | 0到1.79769e+308 +| 参数单位 | +| 参数含义 | 本参数值设置了从一个parallel worker进程将一个tuple传输到另外一个parallel worker进程的成本。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== min_parallel_table_scan_size + +[cols="136,387"] +|=== +h| 参数名称 h| min_parallel_table_scan_size +| 数据类型 | integer +| 默认值 | 1024,默认情况下是8MB +| 取值范围 | 0到715827882 +| 参数单位 | 8KB +| 参数含义 | 本参数设置了考虑使用parallel scan的table的数据(data)的最小大小,对于并行顺序扫描,table的数据(data)的最小大小总是等于table的大小。但是当index被用到时,table的数据(data)的最小大小通常会笑。如果本参数不带单位,取的是源码中符号常量BLCKSZ的值,通常为8KB。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== min_parallel_index_scan_size + +[cols="136,387"] +|=== +h| 参数名称 h| min_parallel_index_scan_size +| 数据类型 | integer +| 默认值 | 64,默认情况下是512KB +| 取值范围 | 0到715827882 +| 参数单位 | 8KB +| 参数含义 | 本参数设置了考虑使用parallel scan的index的数据(data)的最小大小,请注意:一个并行索引扫通常不会扫过整个index。本参数是planner认为扫描实际会涉及的页数,本参数也用来决定一个特定的索引是否可以参与并行vacuum。如果本参数不带单位,取的是源码中符号常量BLCKSZ的值。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== effective_cache_size + +[cols="136,387"] +|=== +h| 参数名称 h| effective_cache_size +| 数据类型 | integer +| 默认值 | 524288 +| 取值范围 | 1到2147483647 +| 参数单位 | 8KB +| 参数含义 | 本参数设置了planner对单个SQL语句可用的disk cache的有效大小。这被纳入使用索引的成本估算中。值越大,使用索引扫描的可能性越大;值越小,使用顺序扫描的可能性越大。设置本参数时,应该同时考虑PostgreSQL的shared buffers和kernel的page cache用于PostgreSQL数据文件的部分,虽然这两个位置都可能存在一些数据。另外,还要考虑在不同表上预计的并发SQL语句数量,因为他们必须共享可用空间。本参数不影响PostgreSQL分配的shared buffers大小,也不会保留kernel的page cache。它仅用于估算目的。系统也不坚定在两次查询之间数据扔保留在磁盘cache中。如果本参数不带单位,取的是源码中符号常量BLCKSZ的值。通常为8KB。如果BLCKSZ不是8KB,则默认值按照定比例缩放。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== jit_above_cost + +[cols="136,387"] +|=== +h| 参数名称 h| jit_above_cost +| 数据类型 | real +| 默认值 | 100000 +| 取值范围 | -1到1.79769e+308。-1表示禁用JIT编译 +| 参数单位 | +| 参数含义 | 当SQL语句的查询成本高于本参数值时,JIT编译会被激活,若是JIT编译被enable的情况下。执行JIT会消耗planning time但是可以加速查询执行。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + +==== jit_inline_above_cost + +[cols="136,387"] +|=== +h| 参数名称 h| jit_inline_above_cost +| 数据类型 | real +| 默认值 | 500000 +| 取值范围 | -1到1.79769e+308,-1表示禁用inline +| 参数单位 | +| 参数含义 | 当SQL语句的查询成本高于本参数值时,JIT编译会尝试inline functions and operators。Inlining会增加planning time,但是会提升执行速度。将本参数值设置为低于jit_above_cost是没有意义的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + +==== jit_optimize_above_cost + +[cols="136,387"] +|=== +h| 参数名称 h| jit_optimize_above_cost +| 数据类型 | real +| 默认值 | 500000 +| 取值范围 | -1到1.79769e+308,-1表示禁用expensive optimizations +| 参数单位 | +| 参数含义 | 当SQL语句的查询成本高于本参数值时,JIT编译会尝试进行expensive optimizations。这种优化会增加planning time,但是会提升执行速度。将本参数值设置为低于jit_above_cost是没有意义的,将本参数值设置为高于jit_inline_above_cost也是没有益处的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session修改立即生效;其他修改Reload即可生效 + +|=== + + + + + +=== autovacuum + +==== autovacuum + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 控制PostgreSQL是否允许autovacuum launcher daemon.autovacuum进程能正常工作的前提条件是配置参数track_counts设置为启用。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。即使本参数被禁用,若是需要防止事务id wraparound,PostgreSQL会启动autovacuum进程。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== log_autovacuum_min_duration + +[cols="136,387"] +|=== +h| 参数名称 h| log_autovacuum_min_duration +| 数据类型 | integer +| 默认值 | 0,0表示记录所有autovacuum操作到PostgreSQL运行日志中 +| 取值范围 | -1到2147483647,-1表示禁止autovacuum进程执行信息打印到PostgreSQL运行日志中。 +| 参数单位 | 毫秒 +| 参数含义 +a| 当autovacuum进程运行的时间长度大于等于本参数值时,autovacuum进程执行时的每个动作会被记录到PostgreSQL运行日志中。举例,若是本参数值设置为250ms,那么所有运行时间长度大于等于250ms的automatic vacuum 和analyze操作会记录到PostgreSQL运行日志中。当本参数值被设置为-1之外的值时,若是autovacumm由于冲突所或者并发dropped relation的原因被skipped掉,一条信息会打印到PostgreSQL运行日志中。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== autovacuum_max_workers + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_max_workers +| 数据类型 | integer +| 默认值 | 3 +| 取值范围 | 1到262143 +| 参数单位 | +| 参数含义 | 本参数设置了同时可以运行的autovacuum worker进程的最大个数。本参数仅仅可以在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== autovacuum_naptime + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_naptime +| 数据类型 | integer +| 默认值 | 60 +| 取值范围 | 1·到2147483 +| 参数单位 | 秒 +| 参数含义 | 本参数指定了两次autovacuum进程运行的最小时间间隔。在每次autovacuum进程运行时,autovacuum守护进程检查数据库并针对需要的表发出vacuum和analyze命令。本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== autovacuum_vacuum_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_threshold +| 数据类型 | integer +| 默认值 | 50 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 本参数用于设置作为vacuum操作候选表的条件,即:更新或者删除掉多少条记录可以被作为vacuum操作的候选表。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== autovacuum_vacuum_insert_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_insert_threshold +| 数据类型 | integer +| 默认值 | 1000 +| 取值范围 | -1到2147483647,-1表示即使有本参数值数量的insert记录,autovacuum守护进程也不会针对该表触发vacuum操作。 +| 参数单位 | +| 参数含义 | 本参数用于设置作为vacuum操作候选表的条件,即:插入多少条记录可以触发针对该表的vacuum。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== autovacuum_analyze_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_analyze_threshold +| 数据类型 | integer +| 默认值 | 50 +| 取值范围 | 0到2147483647 +| 参数单位 | +| 参数含义 | 本参数用于设置作为analyze操作候选表的条件,即:插入、更新、删除多少条记录可以触发针对该表的analyze。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== autovacuum_vacuum_scale_factor + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_scale_factor +| 数据类型 | real +| 默认值 | 0.2,0.2表示表大小的20% +| 取值范围 | 0到100 +| 参数单位 | +| 参数含义 | 本参数设置了表大小的一个比率,当决定一个表是否触发vacuum操作时,该比率会被配置参数autovacuum_vacuum_threshold考虑在内。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== autovacuum_vacuum_insert_scale_factor + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_insert_scale_factor +| 数据类型 | real +| 默认值 | 0.2,0.2表示表大小的20% +| 取值范围 | 0到100 +| 参数单位 | +| 参数含义 | 本参数设置了表大小的一个比率,当决定一个表是否触发vacuum操作时,该比率会被配置参数autovacuum_vacuum_insert_threshold考虑在内。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== autovacuum_analyze_scale_factor + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_analyze_scale_factor +| 数据类型 | real +| 默认值 | 0.1 +| 取值范围 | 0到100 +| 参数单位 | +| 参数含义 | 本参数设置了表大小的一个比率,当决定一个表是否触发vacuum操作时,该比率会被配置参数autovacuum_analyze_threshold考虑在内。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== autovacuum_freeze_max_age + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_freeze_max_age +| 数据类型 | integer +| 默认值 | 200000000 +| 取值范围 | 100000到2000000000 +| 参数单位 | +| 参数含义 | 指定表的pg_class.relfrozenxid字段在强制执行vacuum操作以防止事务ID wraparound之前可以达到的最大年龄,请注意,即使autovacuum进程被禁用,PostgreSQL也会为了防止wraparound而启动autovacuum进程。Vacuum还允许从pg_xact子目录中删除旧文件,这就是为什么默认值是相对较低的2亿个事务的原因。此参数只能在服务器启动时设置,但是可以通过更改表存储参数来减少单个表的设置值。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== autovacuum_multixact_freeze_max_age + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_multixact_freeze_max_age +| 数据类型 | integer +| 默认值 | 400000000 +| 取值范围 | 10000到2000000000 +| 参数单位 | +| 参数含义 | 指定表的pg_class. relminmxid字段在强制执行vacuum操作以防止multixact ID wraparound之前可以达到的最大年龄,请注意,即使autovacuum进程被禁用,PostgreSQL也会为了防止wraparound而启动autovacuum进程。Vacuuming multixacts还允许从pg_multixact/members 和pg_multixact/offsets子目录中删除旧文件,这就是为什么默认值是相对较低的4亿个事务的原因。此参数只能在服务器启动时设置,但是可以通过更改表存储参数来减少单个表的设置值。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== autovacuum_vacuum_cost_delay + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_cost_delay +| 数据类型 | real +| 默认值 | 2 +| 取值范围 | -1到100,-1表示使用配置参数vacuum_cost_delay的参数值。 +| 参数单位 | 毫秒 +| 参数含义 | 本参数是在autovacuum中vacuum操作用到的cost delay值。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== autovacuum_vacuum_cost_limit + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_vacuum_cost_limit +| 数据类型 | integer +| 默认值 | -1,-1表示使用配置参数vacuum_cost_limit的参数值。 +| 取值范围 | -1到10000 +| 参数单位 | +| 参数含义 | 本参数是在autovacuum中vacuum操作用到的cost limit值。请注意,如果有多个autovacuum workers,则本参数值按比例分布在运行中的autovacuum workers之间,以便每个autovacuum worker该值的总和不超过本参数值。本参数仅能在postgresql.conf文件或者server command line中设置。本参数可以在表级设置,在表级设置的优先级高于配置参数中的优先级。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + + +=== Connections and Authentication / SSL + +==== ssl + +[cols="136,387"] +|=== +h| 参数名称 h| ssl +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 是否启用ssl连接 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_ca_file + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_ca_file +| 数据类型 | string +| 默认值 | 空字符串,空字符串表示没有CA File被加载,并且Client身份验证不会被执行。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了包括SSL server certificate authority (CA)的文件名。本参数值是相对于data directory的相对路径,本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_cert_file + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_cert_file +| 数据类型 | string +| 默认值 | server.crt +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了包括SSL server certificate的文件名。本参数值是相对于data directory的相对路径,本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_crl_file + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_crl_file +| 数据类型 | string +| 默认值 | 空字符串,空字符串表示没有CRL文件被加载。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了包括SSL server certificate revocation list (CRL)的文件名。本参数值是相对于data directory的相对路径,本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== ssl_key_file + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_key_file +| 数据类型 | string +| 默认值 | server.key +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了包括SSL server private key的文件名。本参数值是相对于data directory的相对路径,本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_ciphers + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_ciphers +| 数据类型 | string +| 默认值 | HIGH:MEDIUM:+3DES:!aNULL +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置允许被SSL连接使用的SSL ciphers suites的清单。有关此设置的语法和支持值的列表,请参阅OpenSSL package中的ciphers manual page。有使用TLS版本1.2及更低版本的连接才会受到影响。当前没有控制TLS版本1.3连接使用的密码选择的设置。默认值通常是一个合理的选择,除非您有特定的安全要求。本参数仅能在postgresql.conf文件或者server command line中设置。下面解释一下默认值的含义: HIGH:使用HIGH Group的Cipher suites(例如,AES、Camellia、3DES)MEDIUM:使用MEDIUM Group的Cipher suites(例如,RC4, SEED) +3DES:针对HIGH的OpenSSL默认排序是存在问题的,因为3DES排序高于AES128.这是错误的,因为3DES比ASE128提供了少的安全性,并且3DES更慢。在所有除了HIGH和MEDIUM的ciphers外,+3DES进行了重新排序 !aNULL:禁用掉没有经过身份验证的匿名cipher suites。此类cipher suites易于遭受中间人攻击,因此不应该使用。可用的cipher suites在不同OpenSSL版本中的细节差异很大。使用操作系统命令openssl ciphers -v 'HIGH:MEDIUM:+3DES:!aNULL'可以看到当前安装的OpenSSL库的实际细节。请注意:这个list会在运行时基于server key type被过滤 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_prefer_server_ciphers + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_prefer_server_ciphers +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 指定是否优先使用server端的SSL cipher,还是使用client端的。本参数仅能在postgresql.conf文件或者server command line中设置。更老的PostgreSQL版本没有本参数,更老的PostgreSQL版本总是优先使用client端的SSL cipher。本参数仅能在postgresql.conf文件或者server command line中设置。本参数的目的是用于向后兼容性。优先使用server端通常更好,因为更可能的是server端的配置是适当的 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_ecdh_curve + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_ecdh_curve +| 数据类型 | string +| 默认值 | prime256v1 +| 取值范围 | +| 参数单位 | +| 参数含义 | 指定要在ECDH密钥交换中使用的曲线的名称。它需要所有连接的客户端支持。它不需要与服务器的椭圆曲线密钥使用的曲线相同。本参数仅能在postgresql.conf文件或者server command line中设置。最常见曲线的OpenSSL名称是:prime256v1(NIST P-256)、secp384r1(NIST P-384)、secp521r1(NIST P-521)。可用曲线的完整列表可以通过操作系统命令openssl ecparam -list_curves显示。但并不是所有这些都可以在TLS中使用。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== ssl_min_protocol_version + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_min_protocol_version +| 数据类型 | enum +| 默认值 | TLSv1.2 +| 取值范围 | {TLSv1,TLSv1.1,TLSv1.2,TLSv1.3} +| 参数单位 | +| 参数含义 | 设置使用的SSL/TLS协议的最小版本。OpenSSLLibrary的更老的版本不支持所有的值。如果选择了不支持的设置,将引发错误。TLS 1.0之前的协议版本(即SSL version 2 和3)始终处于禁用状态。默认值是TLSv1.2,该默认值是满足本文档编写时的工业最佳实践。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_max_protocol_version + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_max_protocol_version +| 数据类型 | enum +| 默认值 | 空字符串,空字符串意味着运行任何的协议版本。 +| 取值范围 | {"",TLSv1,TLSv1.1,TLSv1.2,TLSv1.3} +| 参数单位 | +| 参数含义 | 设置使用的SSL/TLS协议的最大版本,这对测试或者有些组件使用新版本协议出现问题是有用的。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_dh_params_file + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_dh_params_file +| 数据类型 | string +| 默认值 | 空字符串,空字符串意味着使用默认DH参数编译。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 指定包含Diffie-Hellman参数的文件名,该参数用于所谓的临时DH SSL密码族。如果攻击者设法破解众所周知的编译在DH中的参数,那么使用自定义DH参数可以减少暴露。您可以使用操作系统命令openssl dhparam-out dhparams.pem 2048创建自己的DH参数文件本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== ssl_passphrase_command + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_passphrase_command +| 数据类型 | string +| 默认值 | 空字符串,空字符串表示使用内置的提示机制。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置需要获取用于解密SSL文件(如私钥)的密码短语时要调用的外部命令。命令必须将密码短语打印到标准输出,并以代码0退出。在参数值中,%p替换为提示字符串(写%%表示文本值%)。请注意提示字符串可能包含空格,因此请确保引用足够的引号。命令实际上不必提示用户输入密码短语,它可以从一个文件中读取它,从一个keychain工具中获取它,或者类似的。由用户来确定所选机制是否足够安全本参数仅能在postgresql.conf文件或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== ssl_passphrase_command_supports_reload + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_passphrase_command_supports_reload +| 数据类型 | bool +| 默认值 | off,off表示在reload时,ssl_passphrase_command配置参数会被忽略,并且在passphrase被需要时,SSL configuration不会被reload +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当一个key file需要passphrase时,本参数决定由ssl_passphrase_command配置参数设置的passphrase command在configuration reload期间是否被调用本参数仅能在postgresql.conf文件或者server command line中设置。该设置适用于需要TTY进行提示的命令,该命令在PostgreSQL运行时可能不可用。例如,如果密码短语是从文件获取的,则将本参数设置为on可能是合适的 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +=== Resource Usage / Memory + +==== shared_buffers + +[cols="136,387"] +|=== +h| 参数名称 h| shared_buffers +| 数据类型 | integer +| 默认值 | 16384,即:128MB +| 取值范围 | 16到1073741823 +| 参数单位 | 8KB,若是指定本参数值时不带单位,则取自源码中的符号常量BLCKSZ大小,默认是8KB。非默认的BLCKSZ大小会改变本参数的最小值。本参数值仅仅能在PostgreSQL启动时设置。建议将OS物理内存的25%分配给本参数值。因为PostgreSQL依赖于操作系统的cache(也就是文件系统的page cache),因此将超过40%的RAM分配给本参数值的情况不太可能比分配较小的缓冲区效果更好。较大的本参数值通常需要相应的增加max_wal_size, 以便在较长时间内分散写入大量新数据或更改数据的过程。 +| 参数含义 | +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== huge_pages + +[cols="136,387"] +|=== +h| 参数名称 h| huge_pages +| 数据类型 | enum +| 默认值 | try,try的含义是PostgreSQL会尝试使用huge pages,如果尝试失败将返回默认值。on的含义是请求huge pages失败将阻止PostgreSQL启动,off的含义是不会启用huge pages。目前,本参数值仅支持Linux和Windows平台。当在其他平台下本参数值设置为try时,本参数值会被忽略。 huge pages的使用导致了更小的page tables以及耗费在内存管理方面的更小的CPU时间,这提高了性能。在Windows平台上,huge pages被称之为large pages。开启large pages的步骤: 0.安装PostgreSQL 数据库 1.关闭windows uac控制面板--系统和安全--更改用户账户控制设置--改为'从不通知',点击确定。 2.在windows组策略编辑器,赋予运行PostgreSQL的操作系统用户'锁定内存页'的权力(Lock Pages in Memory)计算机配置\Windows 设置\安全设置\本地策略\用户权利分配\下的"锁定内存页"这个策略。 3.将windows服务中的postgresql-x64-11这个服务改为手动启动。 4.重新启动OS 5.设置postgresql.conf的配置参数huge_pages=on 6.设置postgresql.conf的配置参数shared_buffers=2048MB 7.以管理员身份打开cmd窗口,执行pg_ctl start -D e:\postgresql\11\data启动PostgreSQL 8.验证是否启用请注意:当启用large pages时,不能用Windows服务中的PostgreSQL服务启动postgresql。请注意,本参数设置仅影响main shared memory area. Linux、FreeBSD和Illumos等操作系统也可以自动使用huge pages(也称为"super" pages 或者 "large" pages)进行正常内存分配,而无需PostgreSQL的显式请求。在Linux上,这被称为"transparent huge pages"(THP)。众所周知,对于某些Linux版本的某些用户来说,该特性会导致PostgreSQL的性能下降,因此目前不鼓励使用它(与显式使用huge_pages)。 +| 取值范围 | {off,on,try} +| 参数单位 | +| 参数含义 | 控制shared_buffers是否使用huge pages。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== temp_buffers + +[cols="136,387"] +|=== +h| 参数名称 h| temp_buffers +| 数据类型 | integer +| 默认值 | 1024 +| 取值范围 | 100到1073741823 +| 参数单位 | 8KB +| 参数含义 | 设置每个session使用的temporary buffers的最大值,供临时表使用。指定本参数值时若是不带单位,以blocks为单位,取自源码中符号常量BLCKSZ,通常为8KB。若是BLCKSZ不为8KB,则本参数按照等比例变化。本参数值可以在单个session中更改,但只能在session中首次使用临时表之前更改;随后更改该值的尝试不会对该session产生任何影响。session将根据需要分配临时缓冲区,直到到达本参数值指定的限制。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== max_prepared_transactions + +[cols="136,387"] +|=== +h| 参数名称 h| max_prepared_transactions +| 数据类型 | integer +| 默认值 | 100 +| 取值范围 | 0到262143,0代表禁用prepared-transaction特性。 +| 参数单位 | 设置同时可以处于prepared状态的最大的事务个数。若是你不打算使用prepared transaction,请将本参数值设置为零以防止偶然建立prepared transaction。如果你使用prepared transaction,你可能希望本参数值与max_connections一样大。这样每个session都可以有一个prepared transaction pending。当有流复制环境是,你必须确保在备库上该参数值要大于等于在主库上的该参数值,否则,不能在备库上运行查询语句。 +| 参数含义 | +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== work_mem + +[cols="136,387"] +|=== +h| 参数名称 h| work_mem +| 数据类型 | integer +| 默认值 | 4096 +| 取值范围 | 64到2147483647 +| 参数单位 | KB +| 参数含义 +a| 在写入磁盘临时文件之前,被查询操作(比如sort或者hash table)使用的内存最大值。若是指定本参数值时不带单位,那么是以KB为单位。请注意,针对复杂的查询,sort或者hash操作可能以parallel去运行,在开始向磁盘的临时文件写入数据之前,每个操作被允许最多使用本参数值对应的内存大小。同事,正在运行的多个session会并发执行这些操作。因此,使用的所有内存可以是本参数值的若干倍,当设置本参数值时,需要明确记住这个事实。Sort操作被如下使用:order by、distinct、merge joins;hash table被如下使用:hash joins、hash-base aggregation、在in子句中的基于hash的处理。 + +基于哈希的操作通常比基于排序的等效操作对内存可用性更加敏感。哈希表可用的内存是通过work_mem*hash_mem_multiplier来计算的。这使得基于哈希的操作使用的内存量可能超过通常的work_mem数量。 + +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效其他修改Reload即可生效 + +|=== + + + +==== hash_mem_multiplier + +[cols="136,387"] +|=== +h| 参数名称 h| hash_mem_multiplier +| 数据类型 | real +| 默认值 | 1 +| 取值范围 | 1到1000 +| 参数单位 | +| 参数含义 | 本参数值用于计算hash-base操作可以使用的最大内存。该最大内存是由work_mem*hash_mem_multiplier决定的。在经常有大量查询操作的环境中,考虑增加本参数值,特别是当简单的增加work_mem会导致内存压力时(内存压力通常以间歇性内存不足的形式出现)。设置我1.5或者2.0可能对混合负载有效。在work_mem参数值已经增加到40MB或者更多时,2.0-8.0或者更大范文内的更高设置可能会有效。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效其他修改Reload即可生效 + +|=== + + + +==== maintenance_work_mem + +[cols="136,387"] +|=== +h| 参数名称 h| maintenance_work_mem +| 数据类型 | integer +| 默认值 | 65536 +| 取值范围 | 1024到2147483647 +| 参数单位 | KB +| 参数含义 | 指定用于维护操作(maintenance operations)的最大可用的内存。维护操作包括:vacuum,create index, ALTER TABLE ADD FOREIGN KEY.若指定本参数值时不带单位,那默认的单位是KB。较大的本参数值有助于提升vacuuming以及restore database时的性能。请注意:当autovacuum运行时,最多有本参数值\* autovacuum_max_workers的内存被使用,因此,请小心设置本参数值,不要设置太高。可以使用配置参数autovacuum_work_mem来单独控制autovacuum时的内存使用。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Session级修改立即生效其他修改Reload即可生效 + +|=== + + + + +==== autovacuum_work_mem + +[cols="136,387"] +|=== +h| 参数名称 h| autovacuum_work_mem +| 数据类型 | integer +| 默认值 | -1,-1表示使用maintenance_work_mem配置参数值 +| 取值范围 | -1到2147483647 +| 参数单位 | KB +| 参数含义 | 本参数用于设置每个autovacuum worker process使用的最大内存大小。若指定本参数值时不带单位,那默认的单位是KB。当vacuum的行为运行在其他上下文环境中时,本参数不生效。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== logical_decoding_work_mem + +[cols="136,387"] +|=== +h| 参数名称 h| logical_decoding_work_mem +| 数据类型 | integer +| 默认值 | 65536,即64MB +| 取值范围 | 64到2147483647 +| 参数单位 | KB +| 参数含义 | 本参数用于设置在解码后的变化写入到本地disk之前,逻辑解码使用的最大内存大小。本参数限制了逻辑流复制连接使用的内存大小。由于每个复制连接只使用此大小的单个buffer,并且通常不会有许多这样的连接(受到max_wal_senders配置参数限制)。因此可以将本参数值设置为比work_mem高,从而减少写入磁盘的解码变化量。 +| 是否可session级修改 | 是 +| 修改后何时生效 | session级修改立即生效其他修改Reload即可生效 + +|=== + + +==== max_stack_depth + +[cols="136,387"] +|=== +h| 参数名称 h| max_stack_depth +| 数据类型 | integer +| 默认值 | 2048 +| 取值范围 | 100到2147483647 +| 参数单位 | KB +| 参数含义 | 本参数值指定PostgreSQL execution stack的最大安全深度。本参数值的理想设置是kernel执行的实际stack size limit(可以用操作系统命令ulimit -s或者ulimit -a进行查看)减去大约1MB的安全裕度。所以需要安全裕度,是因为并不是在服务器中的每个例程中都检查stack depth,而是只在可能递归的关键例程中检查stack depth。若指定本参数值时不带单位,那默认的单位是KB。本参数默认值为2MB,该值相对保守,不太可能有crash的风险。但是,它可能太小,无法执行复杂的函数。只有superuser才能更改此设置。本参数值设置为高于kernel的限制将意味着一个失控的递归函数可以crash掉一个单独的backend process。在PostgreSQL可以确定内核限制的平台上,服务器将不允许把本参数值设置为不安全的值。但是并非所有平台都提供该信息。因此建议谨慎选择本参数值。 +| 是否可session级修改 | 是,仅限于superuser可进行session级修改。 +| 修改后何时生效 | session级修改立即生效其他修改Reload即可生效 + +|=== + + +==== shared_memory_type + +[cols="136,387"] +|=== +h| 参数名称 h| shared_memory_type +| 数据类型 | enum +| 默认值 | mmap +| 取值范围 | {sysv,mmap,windows}, sysv,mmap适用于Linux平台;windows适用于windows平台。 +| 参数单位 | +| 参数含义 | 指定shared memory的实现方式。 mmap是指使用mmap分配的anonymous shared memory; sysv是指通过shmget分配的 System V shared memory ;windows是指Windows shared memory。通常不鼓励使用sysv值,因为它通常需要非默认的内核设置来允许较大的分配,而sysv值在任何平台上都不是默认的。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== dynamic_shared_memory_type + +[cols="136,387"] +|=== +h| 参数名称 h| dynamic_shared_memory_type +| 数据类型 | enum +| 默认值 | posix +| 取值范围 | {posix,sysv,mmap,windows} 其中posix,sysv,mmap适用于Linux平台;windows适用于Windows平台 +| 参数单位 | +| 参数含义 | 指定PostgreSQL使用的dynamic shared memory的实现方式。 posix是指使用shm_open分配的POSIX shared memory; sysv是指使用shmget分配的System V shared memory; windows是指Windows shared memory; mmap是指使用存在的data directory中的memory-mapped files模拟的shared memory。通常不鼓励使用mmap值,这在任何平台上都不是默认值,因为操作系统可能会反复将修改过的页面写回磁盘,从而增加系统I/O负载;但是,当pg_dynshmem子目录存储在RAM磁盘上,或者其他共享内存工具不可用时,它可能对调试有用。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +=== Reporting and Logging / Where to Log + +==== log_destination + +[cols="136,387"] +|=== +h| 参数名称 h| log_destination +| 数据类型 | string +| 默认值 | stderr +| 取值范围 | Linux平台下的取值有:stderr、csvlog、syslogWindows平台下的取值有:stderr、csvlog、eventlog +| 参数单位 | +| 参数含义 +a| PostgreSQL支持多种记录PostgreSQL消息的方法。包括stderr、csvlog、syslog,在windows平台下还有eventlog。当本参数值是一个列表时,请使用逗号分隔每个值。本参数仅能在postgresql.conf中设置或者在server command line中设置。当本参数值中含有csvlog时,日志条目被输出为csv格式(comma separated value),这便于程序加载log内容。需要将配置参数logging_collector设置为on才可以生成csv格式的log。当本参数值含有stderr或者csvlog时,current_logfiles文件被建立用来记录当前正在被logging collector进程使用的logfile的位置。这提供了一个查找当前正在使用的log的简便方法。 current_logfiles文件的内容如下(举例): stderr log/postgresql.log csvlog log/postgresql.csv当新的logfile被建立或者log_destination被加载时,current_logfiles文件会被重建。当本参数值不含有stderr或者csvlog,以及logging collector被禁用时,current_logfiles文件会被删除掉。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== logging_collector + +[cols="136,387"] +|=== +h| 参数名称 h| logging_collector +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数会启用logging collector进程,该进程是一个background process,用来捕获发送到stderr的log messages并重定向这些信息到log file中。这个方法比记录到syslog中要有用。因为有些类型的messages不会显示在syslog的输出中(一个例子是dynamic-linker failure messages,另外一个是脚本产生的error messages,比如archive_command).本参数仅仅可以在PostgreSQL启动时设置。logging collector设计为永不丢失消息。这意味着在负载极高的情况下,当logging collector落后时,服务器进程可能会在尝试发送额外日志消息时被阻止。相反,syslog更喜欢在无法写入消息时丢弃消息,这意味着在这种情况下它可能无法记录某些消息,但不会阻塞系统的其余部分。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + +==== log_directory + +[cols="136,387"] +|=== +h| 参数名称 h| log_directory +| 数据类型 | string +| 默认值 | log +| 取值范围 | +| 参数单位 | +| 参数含义 | 在logging_collector配置参数设置为on的情况下,本参数用于确定log file被建立在哪个目录下。本参数值可以是绝对路径,也可以是相对于data directory的相对路径。本参数仅能在postgresql.conf中设置或者在server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== log_filename + +[cols="136,387"] +|=== +h| 参数名称 h| log_filename +| 数据类型 | string +| 默认值 | postgresql-%Y-%m-%d_%H%M%S.log +| 取值范围 | +| 参数单位 | +| 参数含义 | 在logging_collector配置参数设置为on的情况下,本参数用于确定所创建的log file的文件名。本参数值被视为strftime pattern,因此可以使用%-escapes指定随时间变化的文件名(请注意,如果存在任何依赖于时区的%-转义,则计算将在配置参数log_timezone指定的时区中完成。)支持的%-转义与开放组的strftime规范中列出的那些类似。请注意,系统的strftime不是直接使用的,因此特定于平台(非标准)的扩展不起作用。如果本参数值中不带转义符,你应使用log rotation 工具以避免日志填充满整个磁盘。若是在log_destination配置参数中启用了csv格式的输出,那么会将.CSV附加到带时间戳的日志文件名. 以创建CSV格式输出的文件名(如果日志文件名以.log结尾,则替换后缀。)本参数仅能在postgresql.conf中设置或者在server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + +==== log_file_mode + +[cols="136,387"] +|=== +h| 参数名称 h| log_file_mode +| 数据类型 | string +| 默认值 | 0600, 0600表示只有PostgreSQL的owner可以读取或者写入log files +| 取值范围 | 0到511 +| 参数单位 | +| 参数含义 | 在logging_collector配置参数设置为on的情况下,在Unix/Linux系统中本参数用于设置logfile的权限(在Microsoft Windows平台上,本参数被忽略)。 参数值应该是以chmod和umask系统调用接受的格式指定的数字模式。 0600表示只有PostgreSQL的owner可以读取或者写入log files.其他通常有用的设置是0640,0640允许owner的group的成员去读取log files。请注意,要使用这样的设置,您需要更改log_directory目录以将文件存储在data directory目录之外的某个位置。无论如何,让日志文件具有广泛的可读性是不明智的,因为它们可能包含敏感数据本参数仅能在postgresql.conf中设置或者在server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_rotation_age + +[cols="136,387"] +|=== +h| 参数名称 h| log_rotation_age +| 数据类型 | integer +| 默认值 | 1440 +| 取值范围 | 0到35791394,0表示禁用掉基于time的new log file创建。 +| 参数单位 | 分钟 +| 参数含义 | 在logging_collector配置参数设置为on的情况下,本参数确定了一个单独的log file能使用的最长时间。在将此数量的数据发送到日志文件后,将创建一个新的日志文件。若指定本参数值时不带单位,那默认的单位是分钟。默认值是24小时。本参数仅能在postgresql.conf中设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_rotation_size + +[cols="136,387"] +|=== +h| 参数名称 h| log_rotation_size +| 数据类型 | integer +| 默认值 | 10240 +| 取值范围 | 0到2097151,0表示禁用掉基于size的new log file创建 +| 参数单位 | +| 参数含义 | 在logging_collector配置参数设置为on的情况下,本参数确定了一个单独的log file能使用的最大大小。将此数量的数据发送到日志文件后,将创建一个新的日志文件。若指定本参数值时不带单位,那默认的单位是KB。默认值是10MB。本参数仅能在postgresql.conf中设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_truncate_on_rotation + +[cols="136,387"] +|=== +h| 参数名称 h| log_truncate_on_rotation +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 在logging_collector配置参数设置为on的情况下,本参数将导致PostgreSQL截断(覆盖)而不是附加到任何同名的现有日志文件。请注意,只有在由于基于time(时间)的rotate而打开新文件时才会发生截断,而不是在服务器启动或基于size的rotate期间。当本参数值设置off时,在所有情况下都会附加到已有文件中。将本参数值与日志文件名(如postgresql-%H.log)结合使用会生成24个每小时一次的日志文件,然后周期性地覆盖它们。本参数仅能在postgresql.conf中设置或者在server command line中设置。举例:为了达到如下目的:保留7天的log,每天的log文件的文件名是server_log.Mon,server_log.Tue等等,然后用本周的log自动覆盖上周的log。该需求需要设置log_filename为server_log.%a, log_truncate_on_rotation为on,log_rotation_age为1440举例:为了达到如下目的:保留24小时的log,每小时一个log file,如果log file大小超过1GB时也需要很快进行rotate。该需求需要设置log_filename为server_log.%H%M, log_truncate_on_rotation为on,log_rotation_age为60,log_rotation_size为1000000.在log_filename中包括%M允许任何基于size的且可能在同一个小时内有多个log file的rotate +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== syslog_facility + +[cols="136,387"] +|=== +h| 参数名称 h| syslog_facility +| 数据类型 | enum +| 默认值 | local0 +| 取值范围 | {local0,local1,local2,local3,local4,local5,local6,local7} +| 参数单位 | +| 参数含义 | 当配置参数log_destination被设置为syslog时,本参数用于确定使用的syslog facility。本参数仅能在postgresql.conf中设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== syslog_ident + +[cols="136,387"] +|=== +h| 参数名称 h| syslog_ident +| 数据类型 | string +| 默认值 | postgres +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数设置了在操作系统syslog日志中用于标识PostgreSQL消息的关键字。本参数仅仅适用于Linux平台,因为只有Linux平台才有syslog.虽然在Windows平台下也能修改本参数值,但是该修改没有任何意义。本参数仅能在postgresql.conf中设置或者在server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== syslog_sequence_numbers + +[cols="136,387"] +|=== +h| 参数名称 h| syslog_sequence_numbers +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 +a| 当配置参数log_destination被设置为syslog并且本参数值设置为on时,PostgreSQL会在每条消息的前面加一个依次增大的顺序号,同一个命令的多条输出会以[2-1],[2-2]之类的次序标出:(如下截取自linux的/var/log/messages)image::PostgreSQL13%E6%96%87%E6%A1%A3%E4%B9%8BPG%E5%8F%82%E6%95%B0%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C_html_b376f05a85e6462b.png["",357,140] + +本参数设置为off的效果如下:(如下截取自linux的/var/log/messages)image::PostgreSQL13%E6%96%87%E6%A1%A3%E4%B9%8BPG%E5%8F%82%E6%95%B0%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C_html_340e68e94edcda77.png["",361,131]本参数仅能在postgresql.conf中设置或者在server command line中设置。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== syslog_split_messages + +[cols="136,387"] +|=== +h| 参数名称 h| syslog_split_messages +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当配置参数log_destination被设置为syslog并且本参数值设置为on时,消息被按行分割,长的行会被分割,以便填满1024Bytes,这是传统syslog实现上的典型大小限制。当设置为off时,PostgreSQL日志消息将按照原样传递给syslog服务,并由syslog服务来处理可能非常庞大的消息。如果syslog最终记录到一个文本文件中,那么无论哪种方式,效果都是一样的,最好保持该设置处于on状态,因为大多数syslog实现要么不能处理大型消息,要么需要专门配置来处理它们。但是,如果syslog最终要写入其他介质,那么将消息逻辑地保持在一起可能是必要的或更有用的。本参数仅能在postgresql.conf中设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== event_source + +[cols="136,387"] +|=== +h| 参数名称 h| event_source +| 数据类型 | bool +| 默认值 | PostgreSQL +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数仅仅适用于Windows平台,因为只有Windows平台才有event log,本参数值会体现在Windows操作系统的事件查看器的"Windows日志"-"应用程序"-"来源"一列。虽然在Linux平台下也能修改本参数值,但是该修改没有任何意义。本参数仅能在postgresql.conf中设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +=== Preset Options + +==== block_size + +[cols="136,387"] +|=== +h| 参数名称 h| block_size +| 数据类型 | Integer +| 默认值 | 8192 +| 取值范围 | 8192 +| 参数单位 | +| 参数含义 | 数据库使用的disk block的大小,该参数也影响其他的配置参数,比如shared_buffers,该参数通过编译时./configure命令的--with-blocksize选项确定 +| 是否可session级修改 | 否,不可修改。 +| 修改后何时生效 | 不可修改。 + +|=== + + +==== data_checksums + +[cols="136,387"] +|=== +h| 参数名称 h| data_checksums +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 显示data checksums是否启用。本参数值通过initdb时的-k选项或者--data-checksums选项确定。本参数值可以使用pg_checksums进行修改,pg_checksums命令具体用法请见pg_checksums --help +| 是否可session级修改 | 否 +| 修改后何时生效 | 立即生效 + +|=== + + +==== data_directory_mode + +[cols="136,387"] +|=== +h| 参数名称 h| data_directory_mode +| 数据类型 | integer +| 默认值 | 0700 +| 取值范围 | 0到511 +| 参数单位 | +| 参数含义 | 在linux/unix中显示data_directory参数值对应的目录的权限;在windows系统中,本参数值总是显示为0700 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改 + +|=== + + +==== debug_assertions + +[cols="136,387"] +|=== +h| 参数名称 h| debug_assertions +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 显示PG在编译时是否启用assertion。本参数值通过编译时./configure命令的--enable-cassert选项确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改 + +|=== + + +==== integer_datetimes + +[cols="136,387"] +|=== +h| 参数名称 h| integer_datetimes +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 支持64bit整型的date和time。本参数通过编译时./configure命令确定。注意:configure的--disable-integer-datetimes选项,是"obsolete option, no longer supported" +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改 + +|=== + + +==== lc_collate + +[cols="136,387"] +|=== +h| 参数名称 h| lc_collate +| 数据类型 | string +| 默认值 | en_US.UTF-8(根据操作系统环境变量不同而不同,见os命令locale的返回结果) +| 取值范围 | +| 参数单位 | +| 参数含义 | 字符串的排序规则(String sort order)。本参数值通过initdb时的--lc-collate确定,若是不指定该选项,initdb会取环境变量 +| 是否可session级修改 | 否 +| 修改后何时生效 | 在PG Database级别确定,确定后不可修改,只读参数 + +|=== + + + +==== lc_ctype + +[cols="136,387"] +|=== +h| 参数名称 h| lc_ctype +| 数据类型 | string +| 默认值 | en_US.UTF-8(根据操作系统环境变量不同而不同,见os命令locale的返回结果) +| 取值范围 | +| 参数单位 | +| 参数含义 | 字符分类(是否区分大小写,什么是字符等)。本参数通过initdb时的--lc-ctype确定,若是不指定该选项,initdb会取环境变量 +| 是否可session级修改 | 否 +| 修改后何时生效 | 在PG Database级别确定,确定后不可修改,只读参数。 + +|=== + + + +==== max_function_args + +[cols="136,387"] +|=== +h| 参数名称 h| max_function_args +| 数据类型 | integer +| 默认值 | 100 +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回函数参数的最大个数, +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== max_identifier_length + +[cols="136,387"] +|=== +h| 参数名称 h| max_identifier_length +| 数据类型 | integer +| 默认值 | 63 +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回标识符的最大长度 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== max_index_keys + +[cols="136,387"] +|=== +h| 参数名称 h| max_index_keys +| 数据类型 | integer +| 默认值 | 32 +| 取值范围 | +| 参数单位 | +| 参数含义 | 一个index最多能含有多少列 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== segment_size + +[cols="136,387"] +|=== +h| 参数名称 h| segment_size +| 数据类型 | integer +| 默认值 | 131072 +| 取值范围 | +| 参数单位 | 8KB +| 参数含义 | 本参数值确定了每个disk file中的page的数量。本参数值通过编译时./configure命令执行的--with-segsize=SEGSIZE选项确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== server_encoding + +[cols="136,387"] +|=== +h| 参数名称 h| server_encoding +| 数据类型 | string +| 默认值 | UTF8 +| 取值范围 | +| 参数单位 | +| 参数含义 | 数据库的编码 (即:字符集),本参数通过initdb时的-E或者--encoding参数确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== server_version + +[cols="136,387"] +|=== +h| 参数名称 h| server_version +| 数据类型 | string +| 默认值 | 默认值是当前PostgreSQL版本,格式为主版本号.次版本号 +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回PostgreSQL的版本号 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== server_version_num + +[cols="136,387"] +|=== +h| 参数名称 h| server_version_num +| 数据类型 | integer +| 默认值 | 130000,返回主版本号 +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回PostgreSQL的版本号 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== ssl_library + +[cols="136,387"] +|=== +h| 参数名称 h| ssl_library +| 数据类型 | string +| 默认值 | OpenSSL +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回PostgreSQL软件编译时的SSL library。本参数值通过./configure的--with-openssl选项确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + +==== wal_block_size + +[cols="136,387"] +|=== +h| 参数名称 h| wal_block_size +| 数据类型 | integer +| 默认值 | 8192 +| 取值范围 | +| 参数单位 | +| 参数含义 | 返回WAL中disk block的大小。本参数值通过./configure的--with-wal-blocksize选项确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +==== wal_segment_size + +[cols="136,387"] +|=== +h| 参数名称 h| wal_segment_size +| 数据类型 | string +| 默认值 | 16777216 +| 取值范围 | +| 参数单位 | Byte +| 参数含义 | 返回WAL Segments的大小。本参数值通过initdb的--wal-segsize选项确定。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 不可修改,只读参数 + +|=== + + + +=== Client Connection Defaults / Locale and Formatting + +==== DateStyle + +[cols="136,387"] +|=== +h| 参数名称 h| DateStyle +| 数据类型 | string +| 默认值 | ISO, MDY +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于设置date和time的显示格式,以及解释不明确日期输入值的规则。由于历史原因,本参数值包括两个部分:第一部分:output format specification (ISO, Postgres, SQL, or German);第二部分:the input/output specification for year/month/day ordering (DMY, MDY, or YMD)。上述两者可以单独设置,也可以一起设置。请注意,关键词Euro和European是DMY的同义词;关键词US和NonEnro是MDY的同义词;Initdb生成配置参数文件时,会根据os的locale命令的lc_time结果来设置本参数值。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== IntervalStyle + +[cols="136,387"] +|=== +h| 参数名称 h| IntervalStyle +| 数据类型 | enum +| 默认值 | postgres +| 取值范围 | postgres,postgres_verbose,sql_standard,iso_8601 +| 参数单位 | +| 参数含义 | 本参数用于设置interval values的显示格式。参数值sql_standard表示产生匹配SQL标准interval常量的输出;参数值postgres表示当DateStyle参数值设置为ISO时,产生匹配PostgreSQL8.4版本之前的输出;参数值postgres_verbose表示当DateStyle参数值设置为非ISO时,表示当DateStyle参数值设置为ISO时,参数值iso_8601表示产生匹配在ISO 8601标准的4.4.3.2章节中定义的时间间隔带"format with designators"匹配的输出。本参数值也会影响模糊的interval输入的解释。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== TimeZone + +[cols="136,387"] +|=== +h| 参数名称 h| TimeZone +| 数据类型 | String +| 默认值 | 内置的默认值是GMT,一般情况下,本参数值依据initdb时的操作系统时区而定,即:initdb时的操作系统时区是什么,initdb后postgresql.conf中的本参数值就是什么。注意:CentoOS7/8的操作系统当前时区请使用操作系统命令timedatectl status查询。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 为显示以及翻译timestamp设置时区。可用的时区名称可以通过pg_timezone_names视图进行查询。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== timezone_abbreviations + +[cols="136,387"] +|=== +h| 参数名称 h| timezone_abbreviations +| 数据类型 | string +| 默认值 | Default +| 取值范围 | +| 参数单位 | +| 参数含义 | 被PostgreSQL接受的datetime输入的时区简写。默认值Default在世界上大部分地区都有效。另外的有效值是Australia和India。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== extra_float_digits + +[cols="136,387"] +|=== +h| 参数名称 h| extra_float_digits +| 数据类型 | string +| 默认值 | 1 +| 取值范围 | -15到3 +| 参数单位 | +| 参数含义 | 设置浮点值(float4,float8以及地理数据类型)的显示的位数。extra_float_digits大于0时,原有精度最多增加3位, 小于0时, 精度最多减掉相应数值, 等于0时, float4精度为6位, float8精度为15 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== client_encoding + +[cols="136,387"] +|=== +h| 参数名称 h| client_encoding +| 数据类型 | string +| 默认值 | 取自Database encoding +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于设置客户端字符集。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效。 + +|=== + + + +==== lc_messages + +[cols="136,387"] +|=== +h| 参数名称 h| lc_messages +| 数据类型 | string +| 默认值 | 与系统locale设置有关 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数用于设置消息显示的语言。可接受的参数值是跟系统相关的。本参数值会影响发送到服务器运行日志以及客户端的消息,不正确的本参数值会影响服务器日志的可读性。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效,且只有超级用户才能更改此设置。 + +|=== + + + +==== lc_monetary + +[cols="136,387"] +|=== +h| 参数名称 h| lc_monetary +| 数据类型 | string +| 默认值 | 与系统locale设置有关 +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置用于格式化货币金额的语言环境,可接受的参数值是跟系统相关的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== lc_numeric + +[cols="136,387"] +|=== +h| 参数名称 h| lc_numeric +| 数据类型 | string +| 默认值 | 与系统locale设置有关 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值用于设置格式化数字。可接受的参数值是跟系统相关的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== lc_time + +[cols="136,387"] +|=== +h| 参数名称 h| lc_time +| 数据类型 | string +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值用于设置格式化的日期和时间。可接受的参数值是跟系统相关的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== default_text_search_config + +[cols="136,387"] +|=== +h| 参数名称 h| default_text_search_config +| 数据类型 | string +| 默认值 | 依据initdb时的lc_ctype对应的设置而定 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值用于设置当全文检索函数中不明确指定配置项时所用的全文检索配置项。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +=== Write-Ahead Log / Settings + +==== wal_level + +[cols="136,387"] +|=== +h| 参数名称 h| wal_level +| 数据类型 | enum +| 默认值 | replica +| 取值范围 | {minimal,replica,logical} +| 参数单位 | +| 参数含义 +a| 本参数定义了有多少信息被写入到WAL日志中。参数值replica表示WAL日志中写入了足够的信息以支持WAL Archiving和replicatin(包括在standby server上的read-only查询),参数值minimal表示WAL日志中移除了除了需要从crash或者immeidate shutdown进行recovery之外的信息。参数值logical添加了必要信息以支持逻辑解码(logical decoding),在本参数使用logical参数值的情况下,会使得WAL日志的数量变大,特别是很多表被配置为replica identity full并且很多delete和update被执行的情况下。本参数仅仅可以在PostgreSQL Start时修改。每个更高级别的参数值会包括更低级别参数值中记录的所有内容。但是最少的WAL不能包含足够的信息来从基本备份和WAL日志中重建数据,因此必须使用replica参数值来提供更多的信息以启用WAL归档(archive_mode)和流复制.在9.6之前的版本中,此参数值还可以是archive和hot_standby。在PG13版本中,这些仍被接受,但已映射到replica参数值上。当本参数设置为minimal时,如下操作会更快,因为如下操作在创建或重写它们的事务的其余部分中,没有记录永久关系的信息: ALTER ... SET TABLESPACE CLUSTER CREATE TABLE REFRESH MATERIALIZED VIEW(无CONCURRENTLY) REINDEX TRUNCATE + + +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + + + +==== fsync + +[cols="136,387"] +|=== +h| 参数名称 h| fsync +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数值为on时,通过发出fsync系统调用或者各种等价的方法(参见wal_sync_method配置参数),PostgreSQL会尝试确保更新被物理的写入disk。这就保证了PostgreSQL Cluster可以在操作系统或者硬件crash之后能recover(恢复)到一个一致的状态。当本参数值为off时,会带来性能优势,在电源故障或者系统crash时,这会导致不可恢复的数据损坏。仅仅当数据库的全部数据来源自外部数据的情况下,才建议将本参数值设置为off关闭fsync的场景包括:从备份文件中加载数据到PG中;使用PG进行数据的批处理,然后数据库会被废弃并重建;一个经常被重建的只读数据库克隆,并且不会用于failover.高质量的硬件不足以让本参数值设置为off基于可靠恢复的原因将本参数值从off改为on时,需要强制将kernel中修改过的buffer刷新到持久存储中,可以通过如下方法达到本目的: PostgreSQL Cluster关闭;当fsync参数值为on时运行initdb –sync-only,运行sync操作系统命令,unmount掉文件系统或者重启服务器操作系统。在很多场景中,针对非关键事务将synchronous_commit参数值设置为off可以提供比将fsync参数值设置为off更大的潜在优势,不会造成数据损坏等风险。本参数值只能在postgresql.conf文件或server command line中设置。如果关闭此参数,请考虑关闭full_page_writes。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== synchronous_commit + +[cols="136,387"] +|=== +h| 参数名称 h| synchronous_commit +| 数据类型 | enum +| 默认值 | on +| 取值范围 | {local,remote_write,remote_apply,on,off} +| 参数单位 | +| 参数含义 +a| 本参数值指定了在PostgreSQL数据库返回一个成功的提示给客户端之前,必须处理多少WAL数据。如果synchronous_standby_names是空,那么本参数有意义的参数值为on和off;remote_apply、remote_write、和local提供了与on参数值一样的本地同步级别。所有非off模式的本地行为是等待本地WAL刷新到Disk中。在off模式下,没有等待,因此存在一个延迟,这个延迟是给client报告成功与以后保证事务安全以防server crash之间的延迟(最大的延迟是三倍的wal_writer_delay参数值)。与fsync参数值不同,将此参数设置为off不会造成数据库不一致的任何风险。操作系统或者数据库的crash可能会导致一些最近据称已提交的事务丢失,但数据库状态将与这些事务完全中止时的状态相同,因此,当性能比事务持久性的精确确定性更重要时,将本参数设置为off是一个有用的选择。如果synchronous_standby_names是非空,本参数值用来控制事务提交是否等待在standby server上的WAL Record被处理。 + +当本参数值为remote_apply时,commit会等待直到从当前的同步standby指示它们已经收到事务的commit record并应用( applied),因此,它可以在standby 端被query可见,并且在standby端被写入持久性的存储中。这会导致比之前设置的更大的提交延迟,因为primary端会等standby端的WAL replay。 + +当本参数值为on时,commit会等待直到当前同步standby指示已经收到事务的commit record并且已经flush到持久性存储中。这确保了事务不会丢失,除非primary端和所有同步standby端的存储都发生损坏。 + +当本参数值为remote_write时,commit会等待直到当前同步standby指示已经收到事务的commit record并且已经写入到它们的文件系统中。本参数确保了在一个PostgreSQL 实例crash之后的数据持久,但是不针对standby端的操作系统级别的crash,因为,数据在standby端可能没有flush到持久性存储中。当参数值为local时,会导致commits一直在等待直到local flush到disk,而不是复制。当同步复制使用时,通常不需要这么做,但是为了完整而提供了这种方法。 + +此参数可随时更改;任何一个事务的行为都由提交时生效的设置决定。因此,让一些事务同步提交,而其他事务异步提交是可能的,也是有用的。例如,要在默认值相反时使单个多语句事务异步提交,请在事务中发出SET LOCAL synchronous_commit TO OFF + +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== wal_sync_method + +[cols="136,387"] +|=== +h| 参数名称 h| wal_sync_method +| 数据类型 | enum +| 默认值 | Linux和FreeBSD下默认值是fdatasyncWindows下默认值是open_datasync +| 取值范围 | {fsync,fdatasync,open_sync,open_datasync} +| 参数单位 | +| 参数含义 +a| 本参数值指定了强制将WAL写入Disk时使用的方法。当fsync参数值为off时,本参数值无关紧要。 open_datasync:使用open()的O_DSYNC选项写WAL Files fdatasync:每次commit时调用fdatasync() fsync:每次commit时调用fsync() fsync_writethrough:每次commit时调用fsync(),对disk write cache强制write-through open_sync:使用open()的O_SYNC选项写WAL Files + + open_*选项使用O_DIRECT(若是可用),不是上述所有选项都在所有平台下可用。默认值是在该平台下支持的上述列表中的第一个方法,除了在Linux平台和FreeBSD平台下fdatasync是默认值。默认值不一定理想,可能有必要更次此设置或系统配置的其他方面,以创建crash的安全配置或实现最佳性能。本参数值只能在postgresql.conf文件或server command line中设置。 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== full_page_writes + +[cols="136,387"] +|=== +h| 参数名称 h| full_page_writes +| 数据类型 | bool +| 默认值 | on +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 当本参数值为on时,在一个checkpoint发生之后,当第一个修改发生时,将full page(即:该修改所在的disk page中的全部内容)写入WAL日志中。这是需要的,因为在操作系统crash期间正在进行的page write可能仅部分完成,从而导致磁盘上的页包含新旧数据的混合。通常存储在WAL中的行级更改数据不足以在crash之后的恢复中完全还原一个page。存储full page image可以保证页面可以正确还原,但代价是增加必须写入WAL的数据量(因为WAL replay总是从检查点开始,所以在检查点之后的每个页面的第一次更改期间这样做就足够了。因此,降低整页写入成本的一种方法是增加checkpoint interval参数。)关闭此参数可加快正常操作,但在系统发生故障后,可能会导致不可恢复的数据损坏或静默数据损坏。风险类似于关闭fsync,虽然较小,但应该仅基于为fsync参数建议的相同情况关闭本参数。关闭此参数不会影响将WAL存档用于时间点恢复(PITR)。此参数只能在postgresql.conf文件或server command line中设置 + + +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_log_hints + +[cols="136,387"] +|=== +h| 参数名称 h| wal_log_hints +| 数据类型 | bool +| 默认值 | off +| 取值范围 | +| 参数单位 | +| 参数含义 | 当本参数值设置为on时,在一个checkpoint发生之后,当第一个修改发生时,将full page(即:该修改所在的disk page中的全部内容)写入WAL日志中。即使对于所谓的提示位的非关键修改也是如此。如果data ckecksums被启用,hint bit updates总是被记录在wal中,此时本参数值被忽略。你可以使用本参数值来测试当数据库cluster启用checksum之后的会生成多少额外的wal-logging.本参数仅能在server start时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | PG instance重启生效 + +|=== + + + + +==== wal_compression + +[cols="136,387"] +|=== +h| 参数名称 h| wal_compression +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数值为on时,在如下情况下PostgreSQL压缩一个全部的page image并写入到WAL中:full_page_writes参数值为on或者执行一次base backup。压缩的page image会在wal replay期间进行解压。启用本参数可以降低WAL日志的产生量而不会增加不可恢复的数据损坏的风险,但是在wal压缩以及解压过程中会有额外的cpu消耗。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,非session修改relaod生效 + +|=== + + + +==== wal_init_zero + +[cols="136,387"] +|=== +h| 参数名称 h| wal_init_zero +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数值为on时,会导致新的wal file以零填充,在某些文件系统中,这确保了在需要写入wal records之前的空间已被分配。但是,Copy-On-Write (COW)文件系统不会从本参数中获益,因此可以选择跳过不必要的工作。如果设置为off,则在创建文件时仅写入最后一个字节,以使其具有预期的大小。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,非session修改relaod生效 + +|=== + + + +==== wal_recycle + +[cols="136,387"] +|=== +h| 参数名称 h| wal_recycle +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数值为on时,会导致wal file被循环使用(通过renaming wal file的方式),避免了创建新wal file的需要。在COW文件系统中,本参数可能让create new wal file更快。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,非session修改relaod生效 + +|=== + + +==== wal_buffers + +[cols="136,387"] +|=== +h| 参数名称 h| wal_buffers +| 数据类型 | integer +| 默认值 | -1,即:shared_buffers配置参数值的1/32大小,不小于64KB也不大于一个wal segment大小。请注意这是默认值的取值范围,不是手工设置本参数值的取值范围。 +| 取值范围 | -1到262143 +| 参数单位 | 8KB +| 参数含义 | 分配给尚未写入到disk中的wal data的共享内存大小;如果自动选择太大或太小,则可以手动设置本参数值,但是任何小于32 KB的正数参数值.将被视为32 KB.如果指定的该值不带单位,则单位是WAL块的个数,即源码中符号常量XLOG_BLCKSZ,通常为8KB. 本参数值只能在服务器启动时设置。当每次事务提交时,wal buffer中的内容都会被写入disk中,因此,极大的本参数值不可能带来显著的益处。 +| 是否可session级修改 | 否 +| 修改后何时生效 | PG instance重启生效 + +|=== + + + +==== wal_writer_delay + +[cols="136,387"] +|=== +h| 参数名称 h| wal_writer_delay +| 数据类型 | integer +| 默认值 | 200 +| 取值范围 | 1到10000 +| 参数单位 | 毫秒 +| 参数含义 | 指定了wal writer进程写wal buffer到disk中的频率,以时间去衡量,当wal writer进程flush wal之后,wal writer进程会休眠本参数值一段时间,除非被一个异步提交事务很快唤醒。如果最后一次flush在小于wal_writer_delay参数值之前发生 以及 小于wal_writer_flush_after参数值对应的WAL生成量,那么WAL被写入操作系统而不是flush到disk中。请注意,在很多操作系统中,sleep delays的有效精度是10毫秒, +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== wal_writer_flush_after + +[cols="136,387"] +|=== +h| 参数名称 h| wal_writer_flush_after +| 数据类型 | Integer +| 默认值 | 128,即128*8KB=1MB +| 取值范围 | 0到2147483647 +| 参数单位 | 8KB +| 参数含义 | 本参数值指定了wal writer进程flush wal的频率,以wal的大小来衡量。如果最后一次flush在小于wal_writer_delay参数值之前发生 以及 小于wal_writer_flush_after参数值对应的WAL生成量,那么WAL被写入操作系统而不是flush到disk中。本参数值为0代表wal data总是被立即被flush到disk中。如果指定的该值不带单位,则单位是WAL块的个数,即源码中符号常量XLOG_BLCKSZ,通常为8KB. 本参数值只能在postgresql.conf或者server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_skip_threshold + +[cols="136,387"] +|=== +h| 参数名称 h| wal_skip_threshold +| 数据类型 | Integer +| 默认值 | 2048 +| 取值范围 | 0到2147483647 +| 参数单位 | KB +| 参数含义 | 当wal_level参数值为minimal并且在create或者rewriting一个永久关系之后进行事务提交,本参数控制怎么持久化新的数据。如果数据小于本参数值,PostgreSQL会将这些数据写入wal log,否则,PostgreSQL会针对受影响的文件使用一个fsync。取决于你的存储属性,如果这些commit正在拖慢并发事务,增大或者降低本参数值可能会有帮助. 本参数值不带单位时,默认以KB为单位。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效。 + +|=== + + + + +==== commit_delay + +[cols="136,387"] +|=== +h| 参数名称 h| commit_delay +| 数据类型 | Integer +| 默认值 | 0,零表示没有延迟。 +| 取值范围 | 0到100000 +| 参数单位 | 毫秒 +| 参数含义 | 设置本参数值会增加在wal flush启动之前的延迟。如果系统负载足够高以至于在给定的时间间隔内准备好提交其他事务,则这可以通过允许经由单个 WAL flush以提交大量事务来提高组提交吞吐量。但是,每次wal flush会增加延迟,最大延迟是本参数指指定的时间。如果没有其他事务会变成准备提交状态,延迟的时间是被浪费的,因此,如果当wal flush被初始化时,至少有commit_siblings个其他事务是active的情况下,延迟才被执行。同样,如果fsync被关闭,delay是不会被执行的。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,其他修改reload生效 + +|=== + + + +==== commit_siblings + +[cols="136,387"] +|=== +h| 参数名称 h| commit_siblings +| 数据类型 | Integer +| 默认值 | 5 +| 取值范围 | 0到1000 +| 参数单位 | +| 参数含义 | 在执行配置参数commit_delay指定的延迟之前,需要的最小的并发打开的事务数。值越大,在延迟间隔期间至少有一个其他事务准备好提交的可能性就越大 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +=== Developer Options + +==== allow_system_table_mods + +[cols="136,387"] +|=== +h| 参数名称 h| allow_system_table_mods +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 允许修改系统表的结构以及对系统表进行某些其他有风险的操作。否则即使对于超级用户也是不允许的。不明智地使用此设置可能会导致无法挽回的数据丢失或严重损坏数据库系统。只有超级用户才能更改此设置。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,其他修改reload生效 + +|=== + + +==== backtrace_functions + +[cols="136,387"] +|=== +h| 参数名称 h| backtrace_functions +| 数据类型 | string +| 默认值 | 空字符串 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值是以逗号分隔的C函数名称。如果一个错误被抛出并且错误发生地方的内部C函数名称与本参数值list中的值相匹配,然后backtrace与error message会被写入server log。不是所有的平台都支持backtrace功能,backtrace的质量取决于编译选项。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Session级修改立即生效,其他修改reload生效 + +|=== + + + + +==== ignore_system_indexes + +[cols="136,387"] +|=== +h| 参数名称 h| ignore_system_indexes +| 数据类型 | boolean +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当读取system table时忽略system index(但是当修改表时,依然会更新索引)。本参数用于从损坏的索引中恢复的场景中。本参数当session启动后无法改变 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效,但是仅仅针对reload之后的新session生效。 + +|=== + + + +==== post_auth_delay + +[cols="136,387"] +|=== +h| 参数名称 h| post_auth_delay +| 数据类型 | Integer +| 默认值 | 0,零表示禁用延迟。 +| 取值范围 | 0到2147 +| 参数单位 | 秒 +| 参数含义 | 在PostgreSQL构建认证阶段之后,当一个新server process被fork出来时的延迟的时间。本参数值用来给开发人员一个用debugger attach到server process的机会。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效,但是仅仅针对reload之后的新session生效。 + +|=== + + + +==== pre_auth_delay + +[cols="136,387"] +|=== +h| 参数名称 h| pre_auth_delay +| 数据类型 | Integer +| 默认值 | 0,零表示禁用延迟。 +| 取值范围 | 0到60 +| 参数单位 | 秒 +| 参数含义 | 在PostgreSQL构建认证阶段之前,在一个新server process被fork出来之后的延迟的时间。本参数值用来给开发人员一个使用debugger attach到server process以跟踪在认证阶段异常行为的机会。本参数只能在postgresql.conf中或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== trace_notify + +[cols="136,387"] +|=== +h| 参数名称 h| trace_notify +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 为LISTEN和NOTIFY命令生成大量的debugging输出。配置参数client_min_messages或者log_min_messages必须设置为DEBUG1或者更低才能发送该输出到client或者server log +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== trace_recovery_messages + +[cols="68,199"] +|=== +h| 参数名称 h| trace_recovery_messages +| 数据类型 | enum +| 默认值 | log,log不会影响log决策 +| 取值范围 | {debug5,debug4,debug3,debug2,debug1,log,notice,warning,error} +| 参数单位 | +| 参数含义 | 启用记录恢复相关的调试输出,否则将不会被记录。此参数允许用户覆盖log_min_messages的正常设置,但仅限于特定消息。本参数的目的是调试hot standby。其他值导致该优先级或更高优先级的与恢复相关的调试消息被记录,就好像它们具有LOG优先级一样。针对配置参数log_min_messages的通用设置会导致无条件发送messages到server log中。本参数只能在postgresql.conf中或者server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== trace_sort + +[cols="136,387"] +|=== +h| 参数名称 h| trace_sort +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当本参数值为on时,在sort操作期间,会发出有关资源使用的信息。本参数仅仅针对PostgreSQL编译时TRACE_SORT macro被定义时才有效(默认情况下,TRACE_SORT是被定义的) +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== trace_locks + +[cols="136,387"] +|=== +h| 参数名称 h| trace_locks +| 数据类型 | bool +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + + +==== trace_lwlocks + +[cols="136,387"] +|=== +h| 参数名称 h| trace_lwlocks +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== trace_userlocks + +[cols="136,387"] +|=== +h| 参数名称 h| trace_userlocks +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== trace_lock_oidmin + +[cols="136,387"] +|=== +h| 参数名称 h| trace_lock_oidmin +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== trace_lock_table + +[cols="136,387"] +|=== +h| 参数名称 h| trace_lock_table +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== debug_deadlocks + +[cols="136,387"] +|=== +h| 参数名称 h| debug_deadlocks +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== log_btree_build_stats + +[cols="136,387"] +|=== +h| 参数名称 h| log_btree_build_stats +| 数据类型 | +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + +==== wal_consistency_checking + +[cols="136,387"] +|=== +h| 参数名称 h| wal_consistency_checking +| 数据类型 | String +| 默认值 | 空串,空串意味着禁用本特性。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数的目的是检查WAL redo routine中的错误。当启用本参数时,与WAL记录一起修改的任何buffer的full page image都会添加到记录中。如果该记录随后被重放,系统将首先应用每个记录,然后测试由该记录修改的buffer是否与存储的image匹配。在某些情况下(如提示位),可以接受较小的变化,并将被忽略。任何意外的差异都将导致致命错误,从而终止恢复。本参数值可以设置为all,all表示检查所有记录,本参数值也可以设置为逗号分隔的resource manager列表,受到支持的resource manager 是heap、heap2、btree、hash、gin、gist、sequence、spgist、brin、generic +| 是否可session级修改 | 是,仅限于superuser进行修改 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== wal_debug + +[cols="136,387"] +|=== +h| 参数名称 h| wal_debug +| 数据类型 | bool +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | 当设置为on时,发出与wal相关的debugging out。本参数仅仅当PostgreSQL编译时定义了WAL_DEBUG macro的情况下才适用。 +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + +==== ignore_checksum_failure + +[cols="136,387"] +|=== +h| 参数名称 h| ignore_checksum_failure +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 本参数仅仅在data checksums启用的情况下才生效。在读取过程中检查到checksum失败通常会导致PostgreSQL报告一个error,从而中止当前事务。本参数值设置为on会导致PostgreSQL忽略故障(但是依然会报告警告)并继续处理。此行为可能导致crash、传播或隐藏corruption或其他严重问题。但是,如果block header是正常的,可能允许您越过错误并检索可能仍然存在于表中的未损坏的tuple。如果block header已损坏,那么即使启用本选项,也会报告错误。 +| 是否可session级修改 | 是,仅限于superuser在session级修改 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== zero_damaged_pages + +[cols="136,387"] +|=== +h| 参数名称 h| zero_damaged_pages +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 检测到一个损坏的page header通常会导致PostgreSQL报错一个error,并终止当前事务。设置本参数值为on会导致系统报告warning,将内存中损坏的页面清零,然后继续处理。这种行为会破坏数据,即:损坏页面上的所有行。但是,本参数确实允许您克服错误并从表中可能存在的任何未损坏的页面中检索行。如果由于硬件或软件错误而发生损坏,它对于恢复数据很有用。在您放弃从表的损坏页恢复数据的希望之前,您通常不应设置本参数。。清零页不会被强制写入磁盘,因此建议在再次关闭此参数之前重新创建表或索引。本参数值只能由超级用户更改。 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== ignore_invalid_pages + +[cols="136,387"] +|=== +h| 参数名称 h| ignore_invalid_pages +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当本参数值是off时,在recovery期间检测wal record中存在invalid pages之后,PostgreSQL会发出一个PANIC-level的error,进而会终止recovery。当本参数值设置为on时会导致PostgreSQL忽略wal record中的invalid pages(但是依然会报warning)继续进行recovery。本行为可能会导致crash,data loss,传播或者隐藏corruption,或者其他严重问题。但是,本参数会允许你绕过的PANIC-level的error,进而完成recovery,进而启动PostgreSQL。本参数仅能在PostgreSQL启动时设置。本参数仅仅在recovery或者standby mode下生效。 +| 是否可session级修改 | 否 +| 修改后何时生效 | 重启PG instance生效 + +|=== + + + +==== jit_debugging_support + +[cols="136,387"] +|=== +h| 参数名称 h| jit_debugging_support +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 注册JIT编译函数给debugger使用,本参数仅能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可对新的connection生效 + +|=== + + + + +==== jit_dump_bitcode + +[cols="136,387"] +|=== +h| 参数名称 h| jit_dump_bitcode +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 写出LLVM的bitcode以便利于JIT debugging, +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== jit_expressions + +[cols="136,387"] +|=== +h| 参数名称 h| jit_expressions +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当 JIT 编译被启用时,本参数用于确定表达式是否被 JIT 编译 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== jit_profiling_support + +[cols="136,387"] +|=== +h| 参数名称 h| jit_profiling_support +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 如果 LLVM 具有所需的功能,则发出允许perf分析 JIT 生成的函数所需的数据。这会将文件写入$HOME/.debug/jit/下; 用户负责在需要时执行清理。默认设置是off。该参数只能在服务器启动时设置。本参数仅能在PostgreSQL启动时设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可对新的connection生效 + +|=== + + + + +==== jit_tuple_deforming + +[cols="136,387"] +|=== +h| 参数名称 h| jit_tuple_deforming +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当JIT编译被启用的状态下,本参数用于确定允许不允许tuple deforming进行jit 编译 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload接口生效 + +|=== + + + + +=== Query Tuning / Planner Method Configuration + +==== enable_bitmapscan + +[cols="136,387"] +|=== +h| 参数名称 h| enable_bitmapscan +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对位图扫描计划类型的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + + +==== enable_gathermerge + +[cols="136,387"] +|=== +h| 参数名称 h| enable_gathermerge +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对gather merge计划类型的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== enable_hashagg + +[cols="136,387"] +|=== +h| 参数名称 h| enable_hashagg +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对hashed aggregation计划类型的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== enable_hashjoin + +[cols="136,387"] +|=== +h| 参数名称 h| enable_hashjoin +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对hash-join计划类型的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== enable_incremental_sort + +[cols="136,387"] +|=== +h| 参数名称 h| enable_incremental_sort +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 数单位 | +| 参数含义 | 启用或禁用query planner对incremental sort steps的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== enable_indexscan + +[cols="136,387"] +|=== +h| 参数名称 h| enable_indexscan +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对index-scan的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_indexonlyscan + +[cols="136,387"] +|=== +h| 参数名称 h| enable_indexonlyscan +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对index-only-scan的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== enable_material + +[cols="136,387"] +|=== +h| 参数名称 h| enable_material +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对materialization的使用,完全抑制物化是不可能的,但是关闭本参数可以防止query planner插入物化节点,除非在需要正确性的情况下。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_mergejoin + +[cols="136,387"] +|=== +h| 参数名称 h| enable_mergejoin +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对merge-join的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== enable_nestloop + +[cols="136,387"] +|=== +h| 参数名称 h| enable_nestloop +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对nested-loop的使用。完全抑制nested-loop连接是不可能的,但是如果有其他方法可用,关闭本参数会阻止query planner使用nested-loop。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_parallel_append + +[cols="136,387"] +|=== +h| 参数名称 h| enable_parallel_append +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对parallel-aware append的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_parallel_hash + +[cols="136,387"] +|=== +h| 参数名称 h| enable_parallel_hash +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对parall hash join的使用,在hash-join被禁用的情况下,本参数值无效。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== enable_partition_pruning + +[cols="136,387"] +|=== +h| 参数名称 h| enable_partition_pruning +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner的partitioned table中消除partition。这也控制计划器生成查询计划的能力。允许查询执行器在查询执行期间删除(忽略)分区 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_partitionwise_join + +[cols="136,387"] +|=== +h| 参数名称 h| enable_partitionwise_join +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对partitionwise join的使用,这允许在partitioned table上的join在匹配的partition上执行join。Partitionwise 目前仅适用于连接条件包括所有分区键的情况,这些分区键必须是相同的数据类型并且具有一对一匹配的子分区集。由于分区连接规划在规划期间可以使用明显更多的 CPU 时间和内存,本参数默认值为off +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_partitionwise_aggregate + +[cols="136,387"] +|=== +h| 参数名称 h| enable_partitionwise_aggregate +| 数据类型 | bool +| 默认值 | off +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对partitionwise grouping or aggregation的使用,这允许在partitioned table上的partitionwise grouping or aggregation会在每个partition上单独执行。如果GROUP BY子句不包含分区键,则只能在每个分区的基础上执行部分聚合,并且必须稍后执行最终确定。由于partitionwise grouping or aggregation在规划期间可能会使用更多的 CPU 时间和内存,本参数值为off +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_seqscan + +[cols="136,387"] +|=== +h| 参数名称 h| enable_seqscan +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对sequential scan的使用。完全抑制顺序扫描是不可能的,但是如果有其他方法可用,关闭本参数会阻止query planner使用sequential scan。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_sort + +[cols="136,387"] +|=== +h| 参数名称 h| enable_sort +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对explicit sort steps的使用。完全抑制显式排序是不可能的,但是如果有其他方法可用,关闭本参数会阻止query planner使用显式排序。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== enable_tidscan + +[cols="136,387"] +|=== +h| 参数名称 h| enable_tidscan +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 启用或禁用query planner对TID scan的使用 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +=== Reporting and Logging / What to Log + +==== application_name + +[cols="136,387"] +|=== +h| 参数名称 h| application_name +| 数据类型 | string +| 默认值 | psql +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数值的长度小于NAMEDATALEN值(NAMEDATALEN是源码中的符号常量,默认是64个字符)。本参数被连接到服务器上的应用程序设置,本参数值会显示在pg_stat_activity视图中,也会显示在csv log中。本参数值也可以被包括在配置参数log_line_prefix的参数值中。只有可打印的ASCII字符才可以用于本参数值。其他字符会被问号(?)取代。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== debug_print_parse + +[cols="136,387"] +|=== +h| 参数名称 h| debug_print_parse +| 数据类型 | bool +| 默认值 | +| 取值范围 | +| 参数单位 | +| 参数含义 | 在运行日志中记录query的parse tree。本消息在LOG消息级别的情况下被发出,因此,默认情况下,本消息会出现在运行日志中,但不会发给client。您可以通过调整client_min_messages配置参数、log_min_messages配置参数让消息发送给client。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== debug_print_rewritten + +[cols="136,387"] +|=== +h| 参数名称 h| debug_print_rewritten +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在运行日志中记录query的query rewriter output,。本消息在LOG消息级别的情况下被发出,因此,默认情况下,本消息会出现在运行日志中,但不会发给client。您可以通过调整client_min_messages配置参数、log_min_messages配置参数让消息发送给client。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== debug_print_plan + +[cols="136,387"] +|=== +h| 参数名称 h| debug_print_plan +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 在运行日志中记录query的execution plan。本消息在LOG消息级别的情况下被发出,因此,默认情况下,本消息会出现在运行日志中,但不会发给client。您可以通过调整client_min_messages配置参数、log_min_messages配置参数让消息发送给client。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== debug_pretty_print + +[cols="136,387"] +|=== +h| 参数名称 h| debug_pretty_print +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数设置为on时,会将debug_print_parse, debug_print_rewritten, or debug_print_plan配置参数产生的消息进行缩进,这会导致比设置为off时的compact格式更具有可读性但输出会更长。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_checkpoints + +[cols="136,387"] +|=== +h| 参数名称 h| log_checkpoints +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 将checkpoints 和restartpoints记录到运行日志中,一些统计信息被包括到消息中,如写入buffer的数量以及写buffer的耗时等。本参数仅能在postgresql.conf设置或者在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_connections + +[cols="136,387"] +|=== +h| 参数名称 h| log_connections +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当本参数值为on时,每一次尝试连接到PostgreSQL数据库以及客户端成功完成身份认证都会被记录到运行日志中。请注意:有些客户端程序(如psql)会连接两次以确定password是否需要,在该情况下,会有重复的"connection received"消息出现,该消息不一定表示有问题。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可对新的connection生效 + +|=== + + + +==== log_disconnections + +[cols="136,387"] +|=== +h| 参数名称 h| log_disconnections +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当本参数值为on时, session终止的信息会被记录到运行日志中。日志输出类似log_connections配置参数的输出信息,以及session的持续时间。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可对新的connection生效 + +|=== + + + +==== log_error_verbosity + +[cols="136,387"] +|=== +h| 参数名称 h| log_error_verbosity +| 数据类型 | enum +| 默认值 | default +| 取值范围 | {terse,default,verbose} +| 参数单位 | +| 参数含义 | 设置日志消息的详细程度。控制在PG运行日志中为记录的每条消息写入的详细程度。Terse排除了DETAIL、HINT、QUERY、和CONTEXT 级别的信息。Verbose输出包括SQLSTATE错误代码以及源码文件名称、函数名称、生成错误的行号。仅有superuser能修改本参数值 +| 是否可session级修改 | 是,仅限于superuser +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_hostname + +[cols="136,387"] +|=== +h| 参数名称 h| log_hostname +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 默认情况下,在运行日志中显示连接主机的 IP 地址。打开此参数也会导致记录主机名。请注意,根据您的主机名解析设置,这可能会造成不可忽视的性能损失。此参数只能在postgresql.conf文件中或在server command line中设置。 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== log_line_prefix + +[cols="136,387,50"] +|=== +h| 参数名称 h| log_line_prefix | +| 数据类型 | string | +| 默认值 | %m [%p] | +| 取值范围 | +| + +| 参数单位 | +| + +| 参数含义 +a| 控制运行日志中每行开头的输出内容。 +| + +| 是否可session级修改 | 否 | +| 修改后何时生效 | Reload即可生效。 | + +|=== + + +==== log_lock_waits + +[cols="136,387"] +|=== +h| 参数名称 h| log_lock_waits +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当一个session的等待时间长于配置参数deadlock_timeout参数值以获得锁时是否生成日志消息。这在锁定等待是否导致性能不佳时非常有用。只有superuser才能更改本设置。 +| 是否可session级修改 | 是,仅限于superuser进行修改 +| 修改后何时生效 | Reload即可生效。 + +|=== + + +==== log_parameter_max_length + +[cols="136,387"] +|=== +h| 参数名称 h| log_parameter_max_length +| 数据类型 | integer +| 默认值 | -1 +| 取值范围 | -1到1073741823 +| 参数单位 | Byte +| 参数含义 +a| 如果本参数值大于零,则使用非错误语句日志消息记录的每个绑定参数值将被修剪为本参数值个字节。零禁用非错误语句日志的绑定参数的日志记录。-1(默认)允许完整记录绑定参数。如果此值未指定单位,则将其视为字节。只有超级用户才能更改此设置。 + +此设置仅影响由于log_statement、log_duration和相关设置而打印的日志消息。此设置的非零值会增加一些开销,特别是如果参数以二进制形式发送,则需要转换为文本。 + +| 是否可session级修改 | 是,仅限于superuser进行修改 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_parameter_max_length_on_error + +[cols="136,387"] +|=== +h| 参数名称 h| log_parameter_max_length_on_error +| 数据类型 | integer +| 默认值 | 0 +| 取值范围 | -1到1073741823 +| 参数单位 | Byte +| 参数含义 | 如果大于零,错误消息中报告的每个绑定参数值都会被修剪到本参数值个字节。零(默认值)禁用在错误消息中包含绑定参数。-1允许完整打印绑定参数。如果此值未指定单位,则将其视为字节此设置的非零值会增加开销,因为PostgreSQL需要在每个语句开始时将参数值的文本表示存储在内存中,无论最终是否发生错误。以二进制形式发送绑定参数时的开销比以文本形式发送时要大,因为前者需要数据转换,而后者只需要复制字符串 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_statement + +[cols="136,387"] +|=== +h| 参数名称 h| log_statement +| 数据类型 | enum +| 默认值 | all +| 取值范围 | {none,ddl,mod,all} none是off的意思, ddl的含义是记录所有数据定义语句,如create、alter、drop; mod的含义是记录DDL语句之外,还会记录数据修改语句,如insert、update、delete、truncate以及copy from语句。PREPARE、EXECUTE和EXPLAIN ANALYZE语句所包含的命令的类型适当时,也会记录这些语句。all的含义是记录所有语句。 +| 参数单位 | +| 参数含义 | 控制在PG的运行日志中写入哪些类型的SQL语句。对于使用扩展查询协议的客户端来说,记录到运行日志是从一个执行消息被收到开始的。绑定参数值也会被记录。请注意,即使是本参数值设置为all,运行日志中也不会显示那些包含简单语法错误的SQL语句。因为仅仅在基本的解析完成并确定SQL语句的type之后,log message才会被发出。在扩展查询协议的情况下,本参数值同样不会记录在执行阶段之前(即:在parser分析或planner期间)失败的语句。设置log_min_error_statement为error(或者更低)以记录此类语句 +| 是否可session级修改 | 是,仅限于superuser进行修改 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_replication_commands + +[cols="136,387"] +|=== +h| 参数名称 h| log_replication_commands +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 是否将每个复制命令记录到PG运行日志中 +| 是否可session级修改 | 是,仅限于superuser修改 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_temp_files + +[cols="136,387"] +|=== +h| 参数名称 h| log_temp_files +| 数据类型 | integer +| 默认值 | -1,代表禁用本log功能 +| 取值范围 | -1到2147483647 +| 参数单位 | KB +| 参数含义 | 控制是否记录本临时文件的文件名和大小。临时文件被创建用以排序、hash以及临时查询结果。当本参数值被启用时,当临时文件被删除时,一个日志条目会被发出。本参数值为0时会记录所有的临时文件信息。本参数值为正数时表示仅仅会记录那些临时文件大小大于等于本参数值的临时文件。本参数值不指定单位时,默认值以KB为单位。本参数仅仅superuser可以修改。 +| 是否可session级修改 | 是,仅限于superuser进行修改。 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== log_timezone + +[cols="136,387"] +|=== +h| 参数名称 h| log_timezone +| 数据类型 | String +| 默认值 | 内置默认值是GMT,但该内置默认值通常在postgresql.conf中被覆盖; initdb将在会设置本参数值以便与系统环境相对应。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 设置在log message中使用的time zone。与TimeZone配置参数不同,此值是PostgreSQL Cluster范围的,因此所有会话将一致地报告时间戳。此参数只能在postgresql.conf文件中或在server command line中设置 +| 是否可session级修改 | 否 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +=== Client Connection Defaults / Statement Behavior + +==== client_min_messages + +[cols="68,199"] +|=== +h| 参数名称 h| client_min_messages +| 数据类型 | enum +| 默认值 | notice +| 取值范围 | {debug5,debug4,debug3,debug2,debug1,log,notice,warning,error} +| 参数单位 | +| 参数含义 | 控制将哪些消息级别发送到客户端。有效值为DEBUG5,DEBUG4,DEBUG3,DEBUG2,DEBUG1,LOG,NOTICE,WARNING和ERROR。每个级别包括其后的所有级别。级别越靠后,发送的消息就越少。请注意,本参数值log的级别与log_min_messages配置参数值log的级别是不同的。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== search_path + +[cols="136,387"] +|=== +h| 参数名称 h| search_path +| 数据类型 | string +| 默认值 | "$user", public +| 取值范围 | +| 参数单位 | +| 参数含义 +a| 当一个object(table, data type, function等等)不带前面的schema name时,本参数用来指定哪个schema name会被搜索到。当在不同的schema name中有相同的object name时,在search_path中第一个匹配的object的那个schema会被使用。若是一个object没有被search_path中的任何schema匹配到,那么,这个object使用时需要带schema name(即:前面带上 "schema.").本参数值需要以逗号分隔,当本参数值包括不存在schema name 或者user没有对该schema name的usage权限时,此类参数值会被忽略。本参数值中出现的$user,其含义是current_user,若是存在与该user同名的schema name并且该user有对该schema name的usage权限(若不是这样,$user会被忽略)不论在本参数值中包括不包括pg_catalog,pg_catalog总会被搜索到,若是在本参数值中包括pg_catalog,那么会按照在本参数值中出现的顺序去搜,若是在本参数值中不包括pg_catalog,那么,PostgreSQL会在本参数值之前去搜索pg_catalog.类似的,当前的session临时表schema pg_temp_nnn 若是存在的话,会总被搜索到。可以在本参数值中使用pg_temp来明确指定要对pg_temp_nnn进行搜索。若是在本参数值中不明确列出,那么,PostgreSQL会首先搜索pg_temp_nnn(在pg_catalog之前)。临时schema name仅仅被用来搜索relation(表、视图、序列等等)和data type name,临时schema name不能用来搜索function name或者operator name当一个object被建立时其前面不指定任何schema name时,该object的schema name是在本参数值中搜索到的第一个有效的schema。当本参数值为空时,一个错误会被抛出。 + +本参数的默认值是"$user", public,该默认值支持对一个数据库的共享使用(即:没有user有私有的schemas,并且都对public共享使用)、每个user schema的私有使用以及混合使用。其他的影响可以通过alter语句修改本参数值来获得,这个修改可以是全局的也可以每个user的。可以通过函数current_schemas来检查当前使用的有效的schema name,这与search_path的参数值并不完全一致,因为函数current_schemas显示了在本参数值中出现的item是如何解析的。 + +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== row_security + +[cols="136,387"] +|=== +h| 参数名称 h| row_security +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 本参数控制是否抛出错误以代替应用行安全策略。on代表正常应用行安全策略,off代表查询失败除非应用了至少行安全策略。在限制了行可见性导致错误的结果的情况下,可以将本参数值改为off。在默认情况下,pg_dump会进行该修改(即:修改本参数值为off)。本参数对可以绕过行安全策略的roles是无效的,即:superuser和那些带有bypassrls属性的role。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== default_table_access_method + +[cols="136,387"] +|=== +h| 参数名称 h| default_table_access_method +| 数据类型 | string +| 默认值 | heap +| 取值范围 | +| 参数单位 | +| 参数含义 | 本参数指定了create table或者create materialized views不带访问方法时table或者materialized views的访问方法,以及select …into语句使用时用到的访问方法。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== default_tablespace + +[cols="136,387"] +|=== +h| 参数名称 h| default_tablespace +| 数据类型 | string +| 默认值 | 空字符串,空字符串代表当前database的默认tablespace +| 取值范围 | +| 参数单位 | +| 参数含义 | 在create object(table和index)语句不明确指定tablespace情况下,本参数值指定了该object对应的tablespace。如果指定的本参数值与现有的任何tablespace不匹配,那么PostgreSQL会自动使用当前database的默认tablespace。如果一个非默认表空间被指定,那么user必须带有对该非默认表空间的create的权限,否则创建会失败本参数不适用于临时表。临时表对应的配置参数是temp_tablespaces。本参数也不适用于create database语句。默认情况下,一个新的database从template数据库中继承了tablespace。若是本参数值是非空字符串,然后partitioned table被创建,那么,该partitioned table的表空间被设置为该非空字符串,该非空字符串也是将来partition被建立的默认表空间,即使本配置参数值之后被更改。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效。 + +|=== + + + +==== temp_tablespaces + +[cols="136,387"] +|=== +h| 参数名称 h| temp_tablespaces +| 数据类型 | string +| 默认值 | 空字符串,空字符串代表所有的temporary objects都会被创建在当前数据库的默认表空间中。 +| 取值范围 | +| 参数单位 | +| 参数含义 | 在create temporary object(temp tables 和temp tables 上的indexes)语句不明确指定tablespace情况下,本参数值指定了该object对应的temporary tablespace。诸如排序生成的临时文件也被建立到这个temp_tablespaces指定的临时表空间中。本参数值是一系列的tablespace name的清单,当有多个tablespace name的情况下,每次创建临时对象时,PostgreSQL 都会从列表中随机选择一个tablespace name。除了在事务中,连续创建的临时对象被放置在列表中的连续表空间中。如果列表中选定的是空字符串,PostgreSQL会自动使用当前数据库的默认表空间。当temp_tablespaces以交互方式设置时,指定不存在的表空间会报错,指定用户没有CREATE权限的表空间也会报错。但是,当使用先前设置的值时,将忽略不存在的表空间,以及用户缺乏CREATE权限的表空间。此规则适用于在postgresql.conf设置本参数值的情况下 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== check_function_bodies + +[cols="136,387"] +|=== +h| 参数名称 h| check_function_bodies +| 数据类型 | bool +| 默认值 | on +| 取值范围 | on和off +| 参数单位 | +| 参数含义 | 当设置为off时,它会在CREATE FUNCTION期间禁用函数体字符串的验证。禁用验证可避免验证过程的副作用,并避免由于前向引用等问题导致的误报。在代表其他用户加载函数之前,将此参数设置为off;pg_dump会自动执行此操作 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== default_transaction_isolation + +[cols="136,387"] +|=== +h| 参数名称 h| default_transaction_isolation +| 数据类型 | enum +| 默认值 | read committed +| 取值范围 | {serializable,"repeatable read","read committed","read uncommitted"} +| 参数单位 | +| 参数含义 | 本参数用来控制新事务的隔离级别 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== default_transaction_read_only + +[cols="136,387"] +|=== +h| 参数名称 h| default_transaction_read_only +| 数据类型 | bool +| 默认值 | off,off的意思是read/write +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 本参数用来控制每个新事务的默认只读状态。一个只读事务不能改变(alter)一个非临时表. +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== default_transaction_deferrable + +[cols="136,387"] +|=== +h| 参数名称 h| default_transaction_deferrable +| 数据类型 | bool +| 默认值 | off +| 取值范围 | off和on +| 参数单位 | +| 参数含义 | 当运行在serializable隔离级别中时,一个deferrable的只读事务在它被允许继续处理之前可能会被延迟。然而,一旦它开始执行,它就不会产生任何确保可串行化所需的开销;所以序列化代码没有理由因为并发更新而强制中止该只读事务,这确保了对长时间运行的只读事务是很合适的。本参数控制每个新事务的默认的deferrable状态。当前,本参数对read-write事务是无效的,对隔离级别低于serializable的事务也是无效的 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== session_replication_role + +[cols="136,387"] +|=== +h| 参数名称 h| session_replication_role +| 数据类型 | enum +| 默认值 | origin +| 取值范围 | {origin,replica,local} +| 参数单位 | +| 参数含义 +a| 控制针对当前session的与复制相关的triggers和rules的触发(firing),设置本参数需要superuser权限,并且会导致之前cache起来的查询计划被丢弃掉。本参数的用意是逻辑复制系统在应用复制的更改时将本参数值设置为replica,这样做的结果是,触发器和规则(没有从默认配置更改)不会在复制副本上触发。详细信息,请参阅ALTER TABLE子句ENABLE TRIGGER和ENABLE RULE + + PostgreSQL在内部将参数值origin和local视为相同的值,第三方复制软件可能把这两个参数用于他们的目的,比如,使用local来指示一个session的变化不会被复制的session。因为外键是通过trigger实现的,因此,设置本参数为replica也会disable掉所有的外键约束检查。 + +| 是否可session级修改 | 是,仅限于superuser可进行修改。 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== statement_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| statement_timeout +| 数据类型 | integer +| 默认值 | 0,零代表禁用超时机制 +| 取值范围 | 0到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 终止掉运行时间超过本参数值时间长度的SQL语句。如果log_min_error_statement配置参数被设置为error或者更低级别,超时的SQL语句也会被记录下来。超时时间是如下计算的:从SQL语句到PostgreSQL数据库服务器端开始算,直到该语句被服务器处理完成。如果单个简单查询消息(single simple-Query message)中出现多个SQL语句,则将分别对每条语句应用超时.( PostgreSQL13之前的版本通常将超时处理为应用于整个查询字符串),在扩展查询协议中,当任何与查询相关的消息(Parse、Bind、Execute、descripe)到达PostgreSQL数据库时,超时就开始计时,并通过完成Execute或Sync消息而取消。在postgresql.conf中设置本参数值是不推荐的,因为这会影响所有session +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== lock_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| lock_timeout +| 数据类型 | integer +| 默认值 | 0,零代表禁用超时机制 +| 取值范围 | 0到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 终止掉在尝试获取表、索引、行或其他数据库对象上的锁的等待时间超过本参数值的任何语句。时间限制分别适用于每次锁获取尝试,该限制既适用于显式锁定请求(如LOCK TABLE,或SELECT FOR UPDATE without NOWAIT),也适用于隐式获取的锁。如果指定的值没有单位,则以毫秒为单位。值为零(默认值)将禁用超时。与statement_timeout配置参数不同,本超时只能在锁等待时发生。请注意,如果statement_timeout非零,设置lock_timeout为相同或更大的值是毫无意义的,因为语句超时总是首先触发。如果log_min_error_statement设置为ERROR或更低,则将记录超时的语句。在postgresql.conf中设置本参数值是不推荐的,因为这会影响所有session +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== idle_in_transaction_session_timeout + +[cols="136,387"] +|=== +h| 参数名称 h| idle_in_transaction_session_timeout +| 数据类型 | integer +| 默认值 | 0,零代表禁用超时机制 +| 取值范围 | 0到2147483647 +| 参数单位 | 毫秒 +| 参数含义 | 终止掉那些处于open transaction状态的并且idle时间长度超过本参数值的任何会话。这允许释放该会话持有的任何锁,并重用连接槽;它还允许对仅对此事务可见的元组进行vacuum。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + + +==== vacuum_freeze_table_age + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_freeze_table_age +| 数据类型 | integer +| 默认值 | 150000000 +| 取值范围 | 0到2000000000 +| 参数单位 | +| 参数含义 | 如果表的pg_class.relfrozenxid字段值已经达到本参数值,那么vacuum会执行一次侵略性的扫描(aggressive scan)。侵略性的扫描(aggressive scan)不同于常规vacuum(regular VACUUM), 侵略性的扫描(aggressive scan)会查看每个page以确定page中是否包括未冻结的xids或者mxids,而不是仅仅查看page中是否包括dead tuples。尽管用户可以将此值设置为 0 到 20 亿之间的任何值,但VACUUM会默默地将有效值限制为autovacuum_freeze_max_age 的95% ,以便有机会定期在为表启动反环绕自动清理(anti-wraparound autovacuum)之前手工运行VACUUM。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== vacuum_freeze_min_age + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_freeze_min_age +| 数据类型 | integer +| 默认值 | 50000000 +| 取值范围 | 0到1000000000 +| 参数单位 | +| 参数含义 | 本参数用于指定VACUUM在扫描表时用于决定是否冻结行版本的截止年龄(cutoff age,以事物计算), 尽管用户可以将此值设置为 0 到 10 亿之间的任何值,但VACUUM会默默地将有效值限制为autovacuum_freeze_max_age参数值的一半,这样强制 autovacuum之间的时间不会过短。 +| 是否可session级修改 | +| 修改后何时生效 | +|=== + + + + +==== vacuum_multixact_freeze_table_age + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_multixact_freeze_table_age +| 数据类型 | integer +| 默认值 | 150000000 +| 取值范围 | 0到2000000000 +| 参数单位 | +| 参数含义 | 如果表的pg_class. relminmxid字段值已经达到本参数值,那么vacuum会执行一次侵略性的扫描(aggressive scan)。侵略性的扫描(aggressive scan)不同于常规vacuum(regular VACUUM), 侵略性的扫描(aggressive scan)会查看每个page以确定page中是否包括未冻结的xids或者mxids,而不是仅仅查看page中是否包括dead tuples。尽管用户可以将此值设置为 0 到 20 亿之间的任何值,但VACUUM会默默地将有效值限制为autovacuum_multixact_freeze_max_age的95% ,以便有机会定期在为表启动反环绕自动清理(anti-wraparound autovacuum)之前手工运行VACUUM。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== vacuum_multixact_freeze_min_age + +[cols="136,387"] +|=== +h| 参数名称 h| vacuum_multixact_freeze_min_age +| 数据类型 | integer +| 默认值 | 5000000 +| 取值范围 | 0到1000000000 +| 参数单位 | +| 参数含义 | 本参数用于指定VACUUM在扫描表时用于决定是否冻结行版本的multixacts截止年龄(cutoff age), 尽管用户可以将此值设置为 0 到 10 亿之间的任何值,但VACUUM会默默地将有效值限制为autovacuum_multixact_freeze_max_age参数值的一半,这样强制 autovacuum之间的时间不会过短。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + + +==== bytea_output + +[cols="136,387"] +|=== +h| 参数名称 h| bytea_output +| 数据类型 | enum +| 默认值 | hex +| 取值范围 | {escape,hex} +| 参数单位 | +| 参数含义 | 本配置参数定义了对数据类型bytea的输出格式。 bytea数据类型在输入时对两种格式(escape和hex)均接受。escape代表传统的PostgreSQL格式。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== xmlbinary + +[cols="136,387"] +|=== +h| 参数名称 h| xmlbinary +| 数据类型 | enum +| 默认值 | base64 +| 取值范围 | {base64,hex} +| 参数单位 | +| 参数含义 | 设置二进制值在 XML 中的编码方式。例如,这适用于通过函数xmlelement或xmlforest将bytea值转换为XML的情况。可能的值为base64和hex,它们都在 XML 模式标准中定义。 +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== xmloption + +[cols="136,387"] +|=== +h| 参数名称 h| xmloption +| 数据类型 | enum +| 默认值 | content +| 取值范围 | {content,document} +| 参数单位 | +| 参数含义 | 本参数用于设置在XML和字符串值之间转换时DOCUMENT或CONTENT是隐式的。在PostgreSQL中,也可以使用下面的SQL标准来设置:SET XML OPTION { DOCUMENT \| CONTENT }; +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + + +==== gin_pending_list_limit + +[cols="136,387"] +|=== +h| 参数名称 h| gin_pending_list_limit +| 数据类型 | integer +| 默认值 | 4096 +| 取值范围 | 64到2147483647 +| 参数单位 | KB +| 参数含义 | 设置GIN索引的挂起列表(pending list)的最大大小,该列表在启用fastupdate时使用。如果列表的大小超过此最大值,则通过将列表中的条目批量移动到索引的主数据结构来清除列表。如果指定此值时没有单位,则将其作为千字节。默认值为4MB。通过更改索引存储参数,可以为单个GIN索引重写此设置. +| 是否可session级修改 | 是 +| 修改后何时生效 | Reload即可生效 + +|=== + diff --git a/CN/modules/ROOT/pages/master/110.adoc b/CN/modules/ROOT/pages/master/110.adoc new file mode 100644 index 00000000..aa21df0a --- /dev/null +++ b/CN/modules/ROOT/pages/master/110.adoc @@ -0,0 +1,5063 @@ +:sectnums: +:sectnumlevels: 16 + + +[.text-center] +== PostgreSQL 函数参考手册 + + +=== current_catalog + +[cols="145,378"] +|=== +h| 函数名称 h| current_catalog +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | Name +| 函数含义 | 获得当前的database 名称。 + +注意:在SQL标准中,databases被称之为catalogs。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_catalog; + current_catalog +----------------- + postgres +(1 row) + +postgres=# +---- +|=== + + +=== current_database() + +[cols="145,378"] +|=== +h| 函数名称 h| current_database() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 获得当前的database 名称。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_database(); + current_database +------------------ + postgres +(1 row) + +postgres=# +---- +|=== + + +=== current_query() + +[cols="145,378"] +|=== +h| 函数名称 h| current_query() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | text +| 函数含义 | 获得client端提交的当前执行的SQL语句的文本 +| 使用举例 +a| +[source,sql] +---- +postgres=# BEGIN; +BEGIN +postgres=*# select 1,current_query(); + ?column? \| current_query +----------+--------------------------- + 1 \| select 1,current_query(); +(1 row) + +postgres=*# select 2,current_query(); + ?column? \| current_query +----------+--------------------------- + 2 \| select 2,current_query(); +(1 row) + +postgres=*# ROLLBACK; +ROLLBACK +postgres=# +---- +|=== + + +=== current_role + +[cols="145,378"] +|=== +h| 函数名称 h| current_role +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 与current_user作用相同,获得当前执行上下文的username +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_role; + current_role +-------------- + pg131 +(1 row) + +postgres=# +---- + +|=== + + + + +=== current_schema + +[cols="145,378"] +|=== +h| 函数名称 h| current_schema +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 获得search path中的第一个schema名称(当search path为空时,返回空值)。当表或者其他对象建立不带schema名称时,本函数返回的schema就是该表或者该对象的schema +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_schema; + current_schema +---------------- + public +(1 row) + +postgres=# +---- + +|=== + + +=== current_schema() + +[cols="145,378"] +|=== +h| 函数名称 h| current_schema() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 作用与current_schema函数相同:获得search path中的第一个schema名称(当search path为空时,返回空值)。当表或者其他对象建立不带schema名称时,本函数返回的schema就是该表或者该对象的schema +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_schema(); + current_schema +---------------- + public +(1 row) + +postgres=# +---- + +|=== + + +=== current_schemas(include_implicit boolean) + +[cols="145,378"] +|=== +h| 函数名称 h| current_schemas(include_implicit boolean) +| 参数数据类型 | bool +| 函数返回值数据类型 | name +| 函数含义 | 以优先级顺序返回有效search_path中当前所有模式名称,如果入参为true,那么在函数返回结果中会包括隐式搜索的系统模式pg_catalog +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_schemas(false); + current_schemas +----------------- + {public} +(1 row) + +postgres=# select current_schemas(true); + current_schemas +--------------------- + {pg_catalog,public} +(1 row) + +postgres=# +---- + +|=== + + +=== current_user + +[cols="145,378"] +|=== +h| 函数名称 h| current_user +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 获得当前执行上下文的username +| 使用举例 +a| +[source,sql] +---- +postgres=# select current_user; + current_user +-------------- + pg131 +(1 row) + +postgres=# +---- +|=== + + + + +=== inet_client_addr() + +[cols="145,378"] +|=== +h| 函数名称 h| inet_client_addr() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | inet +| 函数含义 | 获得当前client的ip地址。如果返回值为空,表示当前连接是经过Unix-domain socket的 +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_client_addr(); + inet_client_addr +------------------ + +(1 row) + +postgres=# +---- + +|=== + + +=== inet_client_port() + +[cols="145,378"] +|=== +h| 函数名称 h| inet_client_port() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | integer +| 函数含义 | 获得当前client的端口号。如果返回值为空,表示当前连接是经过Unix-domain socket的 +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_client_port(); + inet_client_port +------------------ + +(1 row) + +postgres=# +---- + +|=== + + + +=== inet_server_addr() + +[cols="145,378"] +|=== +h| 函数名称 h| inet_server_addr() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | inet +| 函数含义 | 获得当前连接的pg数据库服务器的ip地址。如果返回值为空,表示当前连接是经过Unix-domain socket的。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_server_port(); + inet_server_port +------------------ + +(1 row) + +postgres=# +---- + +|=== + + + +=== inet_server_port() + +[cols="145,378"] +|=== +h| 函数名称 h| inet_server_port() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | integer +| 函数含义 | 获得当前连接的pg数据库服务器的端口号。如果返回值为空,表示当前连接是经过Unix-domain socket的。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_server_port(); + inet_server_port +------------------ + +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_backend_pid() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_backend_pid() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | integer +| 函数含义 | 获得附加到当前session的backend进程的进程ID +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_backend_pid(); + pg_backend_pid +---------------- + 4068 +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_blocking_pids(integer) + +[cols="145,378"] +|=== +h| 函数名称 h| pg_blocking_pids(integer) +| 参数数据类型 | Integer +| 函数返回值数据类型 | Integer[] +| 函数含义 +a| 返回入参pid的blocking pid(即:阻塞者pid)若是本函数返回空值,表示不存在阻塞者若是本函数返回值是零,那么表示阻塞者是prepared transacion,见下面的输出: +[source,sql] +---- +postgres=# select pg_blocking_pids(12947); pg_blocking_pids +------------------ +{0} +(1 row) + postgres=# +---- +频繁调用本函数会对数据库性能有影响,因为本函数在短时间内对lock manager's shared state进行排他访问(exclusive accesss) + +| 使用举例 +a| +[source,sql] +---- +Session1: +postgres=# SELECT pg_backend_pid(); + pg_backend_pid +---------------- + 32262 +(1 row) + +postgres=# CREATE TABLE tbl_students(rno int, name character varying(10)); +CREATE TABLE +postgres=# BEGIN TRANSACTION; +BEGIN +postgres=*# LOCK tbl_students IN ACCESS EXCLUSIVE MODE; +LOCK TABLE +postgres=*# + + +session2: +postgres=# SELECT pg_backend_pid(); + pg_backend_pid +---------------- + 32439 +(1 row) + +postgres=# INSERT INTO tbl_students VALUES (1,'Anvesh'); + + +session3: +postgres=# SELECT pg_blocking_pids(32439); + pg_blocking_pids +------------------ + {32262} +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_conf_load_time() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_conf_load_time() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | timestamp with time zone +| 函数含义 | 返回PG配置参数文件最后一次被reload的时间 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_conf_load_time(); + pg_conf_load_time +------------------------------- + 2021-03-22 12:46:18.962643+08 +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_current_logfile([text]); + +[cols="145,378"] +|=== +h| 函数名称 h| pg_current_logfile([text]); +| 参数数据类型 | 无输入参数或者text型输入参数 (csvlog、stderr) +| 函数返回值数据类型 | Text +| 函数含义 | 返回正在被logging collector进程使用的log file的path(是log_directory的值)和文件名。当logging collector是被禁用时,本函数返回结果是null。当有不同格式的多种log files存在时,不带任何参数的pg_current_logfile()函数返回有序列表(stderr、csvlog)中找到的第一种格式的文件path和文件名。当没有这两个格式的文件时,本函数返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_current_logfile(); + pg_current_logfile +-------------------------------------- + log/postgresql-2021-03-22_124618.log +(1 row) + +postgres=# select pg_current_logfile('stderr'); + pg_current_logfile +-------------------------------------- + log/postgresql-2021-03-22_124618.log +(1 row) + +postgres=# select pg_current_logfile('csvlog'); + pg_current_logfile +-------------------- + +(1 row) + +postgres=# show log_destination ; + log_destination +----------------- + stderr +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_my_temp_schema() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_my_temp_schema() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | oid +| 函数含义 | 返回当前会话的临时schema的OID,如果没有临时schema,本函数返回0(即:数字零) +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_my_temp_schema(); + pg_my_temp_schema +------------------- + 0 +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_is_other_temp_schema(oid) + +[cols="145,378"] +|=== +h| 函数名称 h| pg_is_other_temp_schema(oid) +| 参数数据类型 | oid +| 函数返回值数据类型 | boolean +| 函数含义 | 当入参的oid是其他session中临时schema的oid时,本函数返回true。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_is_other_temp_schema(16426); + pg_is_other_temp_schema +------------------------- + f +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_jit_available() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_jit_available() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | boolean +| 函数含义 | 如果jit编译器扩展是可用的并且jit配置参数设置为on的话,本函数返回true +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_jit_available(); + pg_jit_available +------------------ + f +(1 row) + +postgres=# select * from pg_config where name='CONFIGURE' AND SETTING LIKE '%--with-llvm%'; + name \| setting +------+--------- +(0 rows) + +postgres=# show jit; + jit +----- + on +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_listening_channels() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_listening_channels() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | setof text +| 函数含义 | 当前session正在监听的异步通知通道的名称 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_listening_channels(); + pg_listening_channels +----------------------- +(0 rows) + +postgres=# +---- + +|=== + + + + +=== pg_notification_queue_usage() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_notification_queue_usage() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | double precision +| 函数含义 | 返回被正在等待处理的通知占据的异步通知队列最大大小的比例。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_notification_queue_usage(); + pg_notification_queue_usage +----------------------------- + 0 +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_postmaster_start_time() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_postmaster_start_time() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | timestamp with time zone +| 函数含义 | 返回PG intance 启动的时间点 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_postmaster_start_time(); + pg_postmaster_start_time +------------------------------- + 2021-03-23 14:01:33.352011+08 +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_safe_snapshot_blocking_pids(integer) + +[cols="145,378"] +|=== +h| 函数名称 h| pg_safe_snapshot_blocking_pids(integer) +| 参数数据类型 | Integer +| 函数返回值数据类型 | integer[] +| 函数含义 | 返回阻止指定服务器进程ID获取安全快照的进程ID若是没有阻塞,则返回空array。一个运行SERIALIZABLE事务的session阻塞了一个SERIALIZABLE READ ONLY DEFERRABLE事务,防止后者获得snapshot,直到后者确认可以安全的避免获取任何谓词锁。频繁调用本函数会对数据库性能有影响,因为它在短时间内需要访问谓词锁管理器的共享状态(predicate lock manager's shared state) +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_safe_snapshot_blocking_pids(1234); + pg_safe_snapshot_blocking_pids +-------------------------------- + {} +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_trigger_depth() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_trigger_depth() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | integer +| 函数含义 | 返回PostgreSQL触发器的当前嵌套级别(如果没有从触发器内部直接或间接调用,则为返回值为0) +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_trigger_depth(); + pg_trigger_depth +------------------ + 0 +(1 row) + +postgres=# +---- + +|=== + + +=== user + +[cols="145,378"] +|=== +h| 函数名称 h| user +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | name +| 函数含义 | 获得当前执行上下文的username,等同于current_user函数 +| 使用举例 +a| +[source,sql] +---- +postgres=# select user; + user +------- + pg131 +(1 row) + +postgres=# +---- + +|=== + + + +=== Version() + +[cols="145,378"] +|=== +h| 函数名称 h| Version() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | text +| 函数含义 | 返回带有数据库版本号的字符串,您也可以查询server_version配置参数获得数据库版本号。对于机器可读的版本,请使用server_version_num配置参数。在软件开发过程中应该使用server_version_num配置参数或者PqserverVersion,而不是去解析文本的版本号(见下面的使用举例) +| 使用举例 +a| +[source,sql] +---- +postgres=# select version(); + version +--------------------------------------------------------------------------------------------------------- + PostgreSQL 13.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit +(1 row) + +postgres=# +---- +|=== + + +=== has_any_column_privilege(user, table, privilege) + +[cols="145,378"] +|=== +h| 函数名称 h| has_any_column_privilege(user, table, privilege) +| 参数数据类型 | user, table, privilege或者table, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 确定一个user是否对当前PG database中的某个table任一列有列权限确定当前user是否对当前PG database中的某个table任一列有列权限权限类型是SELECT, INSERT, UPDATE,REFERENCES的组合。 +| 使用举例 +a| +[source,sql] +---- +[pg131@VM-0-8-centos ~]$ psql -d cwbase3 -U lc0039999 +psql (13.1) +Type "help" for help. + +cwbase3=> \d + List of relations + Schema \| Name \| Type \| Owner +--------+-------+-------+----------- + public \| test1 \| table \| lc0039999 +(1 row) + +cwbase3=> select has_any_column_privilege('lc0039999','test1','select'); + has_any_column_privilege +-------------------------- + t +(1 row) + +cwbase3=> +cwbase3=> select has_any_column_privilege('test1','select,insert'); + has_any_column_privilege +-------------------------- + t +(1 row) + +cwbase3=> + +cwbase3=> select has_any_column_privilege('test1','select'); + has_any_column_privilege +-------------------------- + t +(1 row) + +cwbase3=> +---- +|=== + + + + +=== has_column_privilege(user, table, column, privilege) + +[cols="145,378"] +|=== +h| 函数名称 h| has_column_privilege(user, table, column, privilege); +| 参数数据类型 | user, table, column, privilege或者table, column, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user对特定表的某一列是否具有某种权限当前user对特定表的某一列是否具有某种权限权限类型是SELECT, INSERT, UPDATE,REFERENCES的组合。 +| 使用举例 +a| +[source,sql] +---- +cwbase3=> \d test1 + Table "public.test1" + Column \| Type \| Collation \| Nullable \| Default +--------+---------+-----------+----------+--------- + id \| integer \| \| \| + +cwbase3=> +cwbase3=> select has_column_privilege('lc0039999','test1','id','select'); + has_column_privilege +---------------------- + t +(1 row) + +cwbase3=> +cwbase3=> select has_column_privilege('test1','id','select'); + has_column_privilege +---------------------- + t +(1 row) + +cwbase3=> +---- +|=== + + + +=== has_database_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_database_privilege +| 参数数据类型 | user, database, privilege或者database, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定database有某种权限当前user是否对特定database有某种权限权限类型是CREATE, CONNECT, TEMPORARY, or TEMP的组合。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_database_privilege('lc0039999','cwbase3','create,connect,temp'); + has_database_privilege +------------------------ + t +(1 row) + +postgres=# select has_database_privilege('lc0019999','cwbase3','create,connect,temp'); + has_database_privilege +------------------------ + t +(1 row) + +postgres=# +---- +|=== + + + +=== has_foreign_data_wrapper_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_foreign_data_wrapper_privilege +| 参数数据类型 | user, fdw, privilege或者fdw, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定fdw有usage权限当前user是否对特定fdw有usage权限此处的权限只能指定usage +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_foreign_data_wrapper_privilege('lc0019999','file_fdw','usage'); + has_foreign_data_wrapper_privilege +------------------------------------ + f +(1 row) + +postgres=# +postgres=# select has_foreign_data_wrapper_privilege('file_fdw','usage'); + has_foreign_data_wrapper_privilege +------------------------------------ + t +(1 row) + +postgres=# +---- +|=== + + + + +=== has_function_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_function_privilege +| 参数数据类型 | user, function, privilege或者function, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定function有EXECUTE权限当前user是否对特定function有EXECUTE权限此处的权限只能是EXECUTE +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_function_privilege('lc0039999','version()','execute'); +has_function_privilege +------------------------ +t +(1 row) + postgres=# postgres=# select has_function_privilege('version()','execute'); + has_function_privilege + ------------------------ + t + (1 row) +postgres=# +---- +|=== + + +=== has_language_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_language_privilege +| 参数数据类型 | user, language, privilege或者language, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定procedural language有usage权限当前user是否对特定procedural language有usage权限此处的权限必须是usage +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_language_privilege('lc0019999','sql','usage'); +has_language_privilege +------------------------ +t +(1 row) + postgres=# select has_language_privilege('plpgsql','usage'); + has_language_privilege + ------------------------ + t + (1 row) + postgres=# +---- + 注意:此处的language可以从pg_language系统表查询到。 + +|=== + + + +=== has_schema_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_schema_privilege +| 参数数据类型 | user, schema, privilege或者schema, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定schema有usage或者create权限当前user是否对特定schema有usage或者create权限此处的权限必须是create或者usage的组合 +| 使用举例 +a| +[source,sql] +---- +postgres=# \dnS + List of schemas + Name \| Owner +--------------------+------- + information_schema \| pg131 + pg_catalog \| pg131 + pg_toast \| pg131 + public \| pg131 + s_abc \| pg131 +(5 rows) + +postgres=# select has_schema_privilege('lc0019999','s_abc','usage'); + has_schema_privilege +---------------------- + f +(1 row) + +postgres=# select has_schema_privilege('lc0019999','s_abc','usage,create'); + has_schema_privilege +---------------------- + f +(1 row) + +postgres=# +---- +|=== + + + +=== has_sequence_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_sequence_privilege +| 参数数据类型 | user, sequence, privilege或者sequence, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定sequence有特定权限当前user是否对特定sequence有特定权限此处的权限是USAGE, SELECT, UPDATE的组合。 +| 使用举例 +a| +[source,sql] +---- +postgres=# \ds+ + List of relations + Schema \| Name \| Type \| Owner \| Persistence \| Size \| Description +--------+--------------+----------+-------+-------------+------------+------------- + public \| gen_y_c1_seq \| sequence \| pg131 \| permanent \| 8192 bytes \| +(1 row) + +postgres=# select has_sequence_privilege('pg131','gen_y_c1_seq','usage'); + has_sequence_privilege +------------------------ + t +(1 row) + +postgres=# select has_sequence_privilege('lc0039999','gen_y_c1_seq','usage'); + has_sequence_privilege +------------------------ + f +(1 row) + +postgres=# +---- +|=== + + +=== has_server_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_server_privilege +| 参数数据类型 | user, server, privilege或者server, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定foreign server有usage权限特定user是否对特定foreign server有usage权限此处的权限必须是usage +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_server_privilege('s1','usage'); +has_server_privilege +---------------------- +t +(1 row) +postgres=# select has_server_privilege('s1','USAGE'); +has_server_privilege +---------------------- +t +(1 row) +postgres=# select has_server_privilege('pg123','s1','USAGE'); +has_server_privilege +---------------------- +t +(1 row) +postgres=# +---- +|=== + + + +=== has_table_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_table_privilege +| 参数数据类型 | user, table, privilege或者table, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定table有特定权限当前user是否对特定table有特定权限此处的权限是指如下的组合: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER,还可以带有WITH GRANT OPTION用来测试privilege是否带有grant option。当权限字符串有多个值(比如'insert, select')时,只要有任何一个权限是满足的,本函数会返回t有关对权限字符串的说明:权限字符串不区分大小写权限字符串的前后可以有一个或者多个空格(权限名字内部不能有空格) +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_table_privilege('t1',' select, insert '); + has_table_privilege +--------------------- + t +(1 row) + +postgres=# +[pg131@VM-0-8-centos ~]$ psql -d cwbase3 -U lc0039999 +psql (13.1) +Type "help" for help. + +cwbase3=> +cwbase3=> grant select on test1 to lc0019999; +GRANT +cwbase3=> exit +[pg131@VM-0-8-centos ~]$ psql -d cwbase3 -U lc0019999 +psql (13.1) +Type "help" for help. + +cwbase3=> select * from test1; + id + ---- + 1 + 2 + 3 + + 4 + 5 +(6 rows) + +cwbase3=> select has_table_privilege('test1','insert, select '); + has_table_privilege +--------------------- + t +(1 row) + +cwbase3=> select has_table_privilege('test1','insert'); + has_table_privilege +--------------------- + f +(1 row) + +cwbase3=> select has_table_privilege('test1',' insert '); + has_table_privilege +--------------------- + f +(1 row) + +cwbase3=> insert into test1 values(6); +ERROR: permission denied for table test1 +cwbase3=> +---- +|=== + + + +=== has_tablespace_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_tablespace_privilege +| 参数数据类型 | user, tablespace, privilege或者tablespace, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定tablesapce有特定权限当前user是否对特定tablespace有特定权限此处的权限必须是create +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_tablespace_privilege('ts1','create '); +has_tablespace_privilege +-------------------------- +t +(1 row) +postgres=# select has_tablespace_privilege('lc0019999','ts1','create '); +has_tablespace_privilege +-------------------------- +f +(1 row) +postgres=# +---- +|=== + + + +=== has_type_privilege + +[cols="145,378"] +|=== +h| 函数名称 h| has_type_privilege +| 参数数据类型 | user, type, privilege或者type, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定type有特定权限当前user是否对特定type有特定权限特定type可以使用type的name,也可以使用oid::regtype的形式此处的权限必须是USAGE +| 使用举例 +a| +[source,sql] +---- +postgres=# select has_type_privilege('bytea','usage'); +has_type_privilege +-------------------- +t +(1 row) +postgres=# select has_type_privilege('lc0019999','bytea','usage'); +has_type_privilege +-------------------- +t +(1 row) +postgres=# select has_type_privilege('lc0019999','17:regtype','usage'); +ERROR: syntax error at or near "17" +CONTEXT: invalid type name "17:regtype" +postgres=# select has_type_privilege('lc0019999',17::regtype,'usage'); +has_type_privilege +-------------------- +t +(1 row) +postgres=# select has_type_privilege('lc0019999','17::regtype','usage'); +ERROR: syntax error at or near "17" +CONTEXT: invalid type name "17::regtype" +postgres=# +---- +|=== + + + +=== pg_has_role + +[cols="145,378"] +|=== +h| 函数名称 h| pg_has_role +| 参数数据类型 | user, role, privilege或者role, privilege +| 函数返回值数据类型 | boolean +| 函数含义 | 特定user是否对特定role group有特定权限当前user是否对特定role group有特定权限此处的权限必须是member或者usage当权限是member时,表示特定user是否是特定role group的member当权限是usage时,表示在不执行set role时,特定user是否有特定role的权限 +| 使用举例 +a| +[source,sql] +---- +postgres=# create role editors; +CREATE ROLE +postgres=# create user maxwell; +CREATE ROLE +postgres=# create user ernest; +CREATE ROLE +postgres=# grant authors to editors; --editors can do what authors can do +GRANT ROLE +postgres=# grant editors to maxwell; --maxwell is an editor +GRANT ROLE +postgres=# grant authors to ernest; --ernest is an author +GRANT ROLE +postgres=# select pg_has_role('maxwll','editors','member'); +ERROR: role "maxwll" does not exist +postgres=# select pg_has_role('maxwell','editors','member'); + pg_has_role +------------- + t +(1 row) + +postgres=# select pg_has_role('maxwell','editors','usage'); + pg_has_role +------------- + t +(1 row) + +postgres=# select pg_has_role('maxwell','ernest','usage'); + pg_has_role +------------- + f +(1 row) + +postgres=# select pg_has_role('maxwell','ernest','member'); + pg_has_role +------------- + f +(1 row) + +postgres=# +---- + +|=== + + +=== row_security_active + +[cols="145,378"] +|=== +h| 函数名称 h| row_security_active +| 参数数据类型 | Table,可以是table name,也可以是table的oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在current_user的上下文中,特定table是否已开启row security +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_class where relname='test'; + oid +------- + 16860 +(1 row) + +postgres=# select row_security_active('test'); + row_security_active +--------------------- + f +(1 row) + +postgres=# select row_security_active(16860); + row_security_active +--------------------- + f +(1 row) + +postgres=# +---- + + +|=== + + + +=== acldefault + +[cols="145,378"] +|=== +h| 函数名称 h| acldefault +| 参数数据类型 | type, ownerId +| 函数返回值数据类型 | aclitem[] +| 函数含义 | 返回属于某个user oid对象的默认访问权限。当一个对象的ACL条目为null时这些访问权限是该对象的默认权限Type参数的取值如下:'c' for COLUMN'r' for TABLE 以及类似对象's' for SEQUENCE'd' for DATABASE'f' for FUNCTION 或者PROCEDURE'l' for LANGUAGE'L' for LARGE OBJECT'n' for SCHEMA't' for TABLESPACE'F' for FOREIGN DATA WRAPPER'S' for FOREIGN SERVER'T' for TYPE or DOMAIN +| 使用举例 +a| +[source,sql] +---- +postgres=# select acldefault('f',16877); +acldefault +-------------------------------------- +{=X/lc0039999,lc0039999=X/lc0039999} +(1 row) +postgres=# +---- +|=== + + + +=== aclexplode + +[cols="145,378"] +|=== +h| 函数名称 h| aclexplode +| 参数数据类型 | aclitem[] +| 函数返回值数据类型 | setof record +| 函数含义 | 解析 acl 权限 +| 使用举例 +a| +[source,sql] +---- +postgres=# select aclexplode('{=X/lc0039999,lc0039999=X/lc0039999}'); + aclexplode +------------------------- + (16877,0,EXECUTE,f) + (16877,16877,EXECUTE,f) + (2 rows) +postgres=# postgres=# select \* from aclexplode('{=X/lc0039999,lc0039999=X/lc0039999}'); + grantor \| grantee \| privilege_type \| is_grantable +---------+---------+----------------+-------------- + 16877 \| 0 \| EXECUTE \| f + 16877 \| 16877 \| EXECUTE \| f +(2 rows) +postgres=# +---- +|=== + + + +=== makeaclitem + +[cols="145,378"] +|=== +h| 函数名称 h| makeaclitem +| 参数数据类型 | grantee, grantor, privilege, grantable +| 函数返回值数据类型 | aclitem +| 函数含义 | 构建aclitem +| 使用举例 +a| +[source,sql] +---- +postgres=# select \* from makeaclitem(16877,16877,'EXECUTE',false); +makeaclitem +----------------------- +lc0039999=X/lc0039999 +(1 row) +postgres=# +---- +|=== + + + +=== pg_collation_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_collation_is_visible +| 参数数据类型 | collation_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定collation是否可见。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_collation where collname = 'zh_CN'; + oid \| collname \| collnamespace \| collowner \| collprovider \| collisdeterministic \| collencoding \| collcollate \| collctype \| collversion +-------+----------+---------------+-----------+--------------+---------------------+--------------+-------------+------------+------------- + 13086 \| zh_CN \| 11 \| 10 \| c \| t \| 2 \| zh_CN \| zh_CN \| 2.17 + 13243 \| zh_CN \| 11 \| 10 \| c \| t \| 6 \| zh_CN.utf8 \| zh_CN.utf8 \| 2.17 +(2 rows) + +postgres=# select pg_collation_is_visible(13086); + pg_collation_is_visible +------------------------- + f +(1 row) + +postgres=# select pg_collation_is_visible(13243); + pg_collation_is_visible +------------------------- + t +(1 row) + +postgres=# +postgres=# select pg_collation_is_visible('"zh_CN"'::regcollation); + pg_collation_is_visible +------------------------- + t +(1 row) + +postgres=# +---- +|=== + + + +=== pg_conversion_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_conversion_is_visible +| 参数数据类型 | conversion_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定conversion是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_conversion where conname like '%cn%'; + oid \| conname \| connamespace \| conowner \| conforencoding \| contoencoding \| conproc \| condefault +------+----------------+--------------+----------+----------------+---------------+----------------+------------ + 4422 \| euc_cn_to_mic \| 11 \| 10 \| 2 \| 7 \| euc_cn_to_mic \| t + 4423 \| mic_to_euc_cn \| 11 \| 10 \| 7 \| 2 \| mic_to_euc_cn \| t + 4480 \| euc_cn_to_utf8 \| 11 \| 10 \| 2 \| 6 \| euc_cn_to_utf8 \| t + 4481 \| utf8_to_euc_cn \| 11 \| 10 \| 6 \| 2 \| utf8_to_euc_cn \| t +(4 rows) + +postgres=# select pg_conversion_is_visible(4480); + pg_conversion_is_visible +-------------------------- + t +(1 row) + +postgres=# +---- + +|=== + + +=== pg_function_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_function_is_visible +| 参数数据类型 | function_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定function、procedures、aggregates是否可见。对于函数,如果路径前面没有相同名称和参数数据类型的对象,则搜索路径中的对象可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_proc where proname='version'; + oid +----- + 89 +(1 row) + +postgres=# select pg_function_is_visible(89); + pg_function_is_visible +------------------------ + t +(1 row) + +postgres=# +postgres=# select pg_function_is_visible('version'::regproc); + pg_function_is_visible +------------------------ + t +(1 row) + +postgres=# select pg_function_is_visible('version()'::regprocedure); + pg_function_is_visible +------------------------ + t +(1 row) + +postgres=# +---- + +|=== + + +=== pg_opclass_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_opclass_is_visible +| 参数数据类型 | opclass_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定operator class是否可见考虑因素是operator class name和相关的索引访问方法。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_opclass where opcname='array_ops'; + oid +------- + 10000 + 10001 + 10063 +(3 rows) + +postgres=# select pg_opclass_is_visible(10000); + pg_opclass_is_visible +----------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_operator_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_operator_is_visible +| 参数数据类型 | operator_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定operator 是否可见对于运算符,如果路径前面没有相同名称和参数数据类型的对象,则搜索路径中的对象可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oprname from pg_operator where oid=15; + oprname +--------- + = +(1 row) + +postgres=# select pg_operator_is_visible(15); + pg_operator_is_visible +------------------------ + t +(1 row) + +postgres=# +postgres=# select pg_operator_is_visible('=(integer,integer)'::regoperator); + pg_operator_is_visible +------------------------ + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_opfamily_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_opfamily_is_visible +| 参数数据类型 | opclass_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定operator family是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_opfamily where oid='397'; + oid \| opfmethod \| opfname \| opfnamespace \| opfowner +-----+-----------+-----------+--------------+---------- + 397 \| 403 \| array_ops \| 11 \| 10 +(1 row) + +postgres=# select pg_opfamily_is_visible(397); + pg_opfamily_is_visible +------------------------ + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_statistics_obj_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_statistics_obj_is_visible +| 参数数据类型 | stat_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定operator class是否可见 +| 使用举例 | +|=== + + + +=== pg_table_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_table_is_visible +| 参数数据类型 | table_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定的table、views、materialized views、 indexes、 sequences、foreign tables是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_class where relname='data1'; + oid +------- + 16384 +(1 row) + +postgres=# select pg_table_is_visible(16384); + pg_table_is_visible +--------------------- + t +(1 row) + +postgres=# +postgres=# SELECT pg_table_is_visible('public.data1'::regclass); + pg_table_is_visible +--------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_ts_config_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_ts_config_is_visible +| 参数数据类型 | config_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定text search configuration是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_ts_config where cfgname='greek'; + oid +------- + 13861 +(1 row) + +postgres=# select pg_ts_config_is_visible(13861); + pg_ts_config_is_visible +------------------------- + t +(1 row) + +postgres=# +postgres=# select pg_ts_config_is_visible('greek'::regconfig); + pg_ts_config_is_visible +------------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_ts_dict_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_ts_dict_is_visible +| 参数数据类型 | _dict_oid_ +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定text search dictionary是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid,dictname,dictinitoption from pg_ts_dict where dictname='greek_stem'; + oid \| dictname \| dictinitoption +-------+------------+-------------------- + 13860 \| greek_stem \| language = 'greek' +(1 row) + +postgres=# select pg_ts_dict_is_visible(13860); + pg_ts_dict_is_visible +----------------------- + t +(1 row) + +postgres=# +postgres=# select pg_ts_dict_is_visible('greek_stem'::regdictionary); + pg_ts_dict_is_visible +----------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_ts_parser_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_ts_parser_is_visible +| 参数数据类型 | parser_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定text search parser是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_ts_parser ; + oid \| prsname \| prsnamespace \| prsstart \| prstoken \| prsend \| prsheadline \| prslextype +------+---------+--------------+------------+----------------+----------+---------------+-------------- + 3722 \| default \| 11 \| prsd_start \| prsd_nexttoken \| prsd_end \| prsd_headline \| prsd_lextype +(1 row) + +postgres=# select pg_ts_parser_is_visible(3722); + pg_ts_parser_is_visible +------------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_ts_template_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_ts_template_is_visible +| 参数数据类型 | template_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定text search template是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_ts_template ; + oid \| tmplname \| tmplnamespace \| tmplinit \| tmpllexize +-------+-----------+---------------+----------------+------------------ + 3727 \| simple \| 11 \| dsimple_init \| dsimple_lexize + 3730 \| synonym \| 11 \| dsynonym_init \| dsynonym_lexize + 3733 \| ispell \| 11 \| dispell_init \| dispell_lexize + 3742 \| thesaurus \| 11 \| thesaurus_init \| thesaurus_lexize + 13845 \| snowball \| 11 \| dsnowball_init \| dsnowball_lexize +(5 rows) + +postgres=# select pg_ts_temp + +postgres=# select pg_ts_template_is_visible(3730); + pg_ts_template_is_visible +--------------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_type_is_visible + +[cols="145,378"] +|=== +h| 函数名称 h| pg_type_is_visible +| 参数数据类型 | type_oid +| 函数返回值数据类型 | boolean +| 函数含义 | 在当前schema search path中,特定type、domain是否可见 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid,typname from pg_type where typname='bool'; + oid \| typname +-----+--------- + 16 \| bool +(1 row) + +postgres=# select pg_type_is_visible(16); + pg_type_is_visible +-------------------- + t +(1 row) + +postgres=# +postgres=# SELECT pg_type_is_visible('pg_catalog.bool'::regtype); + pg_type_is_visible +-------------------- + t +(1 row) + +postgres=# +---- + +|=== + +=== format_type + +[cols="145,378"] +|=== +h| 函数名称 h| format_type +| 参数数据类型 | type_oid, typemod +| 函数返回值数据类型 | Text +| 函数含义 | 得到一个data type的SQL Name +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_type where typname='bool'; +-[ RECORD 1 ]--+--------- +oid \| 16 +typname \| bool +typnamespace \| 11 +typowner \| 10 +typlen \| 1 +typbyval \| t +typtype \| b +typcategory \| B +typispreferred \| t +typisdefined \| t +typdelim \| , +typrelid \| 0 +typelem \| 0 +typarray \| 1000 +typinput \| boolin +typoutput \| boolout +typreceive \| boolrecv +typsend \| boolsend +typmodin \| - +typmodout \| - +typanalyze \| - +typalign \| c +typstorage \| p +typnotnull \| f +typbasetype \| 0 +typtypmod \| -1 +typndims \| 0 +typcollation \| 0 +typdefaultbin \| +typdefault \| +typacl \| + +postgres=# +postgres=# select format_type(16,0); + format_type +------------- + boolean +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_get_constraintdef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_constraintdef +| 参数数据类型 | constraint_oid或者constraint_oid, pretty_bool +| 函数返回值数据类型 | text +| 函数含义 | 得到一个constraint的定义 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_constraintdef(16918); +pg_get_constraintdef +---------------------- +PRIMARY KEY (c1) +(1 row) +postgres=# +---- +|=== + + + +=== pg_get_expr + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_expr +| 参数数据类型 +a| pg_node_tree, relation_oid,或者 + +pg_node_tree, relation_oid, pretty_bool + +| 函数返回值数据类型 | Text +| 函数含义 | 反编译指定expression的内部格式,假设:其中的任何变量引用第二个参数指示的relation +| 使用举例 +a| +[source,sql] +---- +postgres=# CREATE TABLE tab1 (a int, b int) PARTITION BY RANGE(a); +CREATE TABLE +postgres=# CREATE TABLE tab1_p1 PARTITION OF tab1 FOR VALUES FROM (0) TO (100); +CREATE TABLE +postgres=# CREATE TABLE tab1_p2 PARTITION OF tab1 FOR VALUES FROM (100) TO (200); +CREATE TABLE +postgres=# select relname, pg_get_expr(relpartbound, oid) from pg_class where relispartition and relname ~ 'tab1' order by relname; + relname \| pg_get_expr +---------+-------------------------------- + tab1_p1 \| FOR VALUES FROM (0) TO (100) + tab1_p2 \| FOR VALUES FROM (100) TO (200) +(2 rows) + +postgres=# +---- + +|=== + + + +=== pg_get_functiondef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_functiondef +| 参数数据类型 | func_oid +| 函数返回值数据类型 | text +| 函数含义 +a| 获得function或者procedure的定义 + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_functiondef(89); +pg_get_functiondef +------------------------------------------------- +CREATE OR REPLACE FUNCTION pg_catalog.version()+ RETURNS text + LANGUAGE internal + STABLE PARALLEL SAFE STRICT + AS $function$pgsql_version$function$ + +(1 row) +postgres=# +---- +|=== + + + +=== pg_get_function_arguments + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_function_arguments +| 参数数据类型 | func_oid +| 函数返回值数据类型 | text +| 函数含义 +a| 获得function或者procedure的传入参数清单 + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_proc where proname='has_database_privilege'; +-[ RECORD 1 ] +oid \| 2250 +-[ RECORD 2 ] +oid \| 2251 +-[ RECORD 3 ] +oid \| 2252 +-[ RECORD 4 ] +oid \| 2253 +-[ RECORD 5 ] +oid \| 2254 +-[ RECORD 6 ] +oid \| 2255 + +postgres=# select pg_get_function_arguments(2250); +-[ RECORD 1 ]-------------+----------------- +pg_get_function_arguments \| name, text, text + +postgres=# \x +Expanded display is off. +postgres=# select pg_get_function_arguments(2250); + pg_get_function_arguments +--------------------------- + name, text, text +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_get_function_identity_arguments + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_function_identity_arguments +| 参数数据类型 | func_oid +| 函数返回值数据类型 | text +| 函数含义 +a| 获得参数清单以标识出function或者procedure + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_function_identity_arguments(2250); +pg_get_function_identity_arguments ------------------------------------ +name, text, text +(1 row) +postgres=# +---- +|=== + + + + + +=== pg_get_function_result + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_function_result +| 参数数据类型 | func_oid +| 函数返回值数据类型 | text +| 函数含义 | 获得function,若是procedure,返回null +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_function_result(89); +pg_get_function_result +------------------------ +text +(1 row) +postgres=# +---- +|=== + + + +=== pg_get_indexdef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_indexdef +| 参数数据类型 | index_oid或者index_oid, column_no, pretty_bool +| 函数返回值数据类型 | text +| 函数含义 | 获得索引的定义语句获得某个索引上第n个索引列的名称 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid from pg_class where relname='idx_2'; + oid +------- + 16427 +(1 row) + +postgres=# select pg_get_indexdef(16427); + pg_get_indexdef +--------------------------------------------------------- + CREATE INDEX idx_2 ON public.data1 USING btree (c1, c3) +(1 row) + +postgres=# + +postgres=# select pg_get_indexdef(16427,2,true); + pg_get_indexdef +----------------- + c3 +(1 row) + +postgres=# select pg_get_indexdef(16427,1,true); + pg_get_indexdef +----------------- + c1 +(1 row) + +postgres=# +---- + +|=== + + +=== pg_get_keywords + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_keywords +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | setof record +| 函数含义 | 返回PostgreSQL数据库中的SQL关键字清单返回结果中有3列(以逗号分隔),第一列是关键字名称,第二列catcode是category code U for unreserved C for column name T for type or function name R for reserved第三列catdesc是描述 +| 使用举例 a| +[source,sql] +---- +postgres=# select pg_get_keywords(); +pg_get_keywords +------------------------------------------------------------------ + (abort,U,unreserved) + (absolute,U,unreserved) + (access,U,unreserved) + (action,U,unreserved) + (add,U,unreserved) + (admin,U,unreserved) + (after,U,unreserved) + (aggregate,U,unreserved) + (all,R,reserved) + (also,U,unreserved) + (alter,U,unreserved) + (always,U,unreserved) + (analyse,R,reserved) + (analyze,R,reserved) + (and,R,reserved) +限于篇幅,本函数的输出仅摘录到此处 +---- +|=== + + + +=== pg_get_ruledef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_ruledef +| 参数数据类型 | rule_oid或者rule_oid, pretty_bool +| 函数返回值数据类型 | Text +| 函数含义 | 获得rule的create rule语句 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid ,rulename from pg_rewrite where rulename='pg_settings_u'; + oid \| rulename +-------+--------------- + 12168 \| pg_settings_u +(1 row) + +postgres=# select pg_get_ruledef(12168); + pg_get_ruledef +--------------------------------------------------------------------------------------------------- + CREATE RULE pg_settings_u AS + + ON UPDATE TO pg_catalog.pg_settings + + WHERE (new.name = old.name) DO SELECT set_config(old.name, new.setting, false) AS set_config; +(1 row) + +postgres=# +---- + +|=== + + +=== pg_get_serial_sequence + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_serial_sequence +| 参数数据类型 | table_name, column_name +| 函数返回值数据类型 | text +| 函数含义 | 获得自增列或者标识列使用的sequence的name +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_serial_sequence('gen_y','c1'); +pg_get_serial_sequence +------------------------ +public.gen_y_c1_seq +(1 row) +postgres=# +---- +|=== + + + +=== pg_get_statisticsobjdef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_statisticsobjdef +| 参数数据类型 | statobj_oid +| 函数返回值数据类型 | text +| 函数含义 | 获得extended statistics object的CREATE STATISTICS语句。 +| 使用举例 | + +|=== + + + +=== pg_get_triggerdef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_triggerdef +| 参数数据类型 | trigger_oid 或者trigger_oid, pretty_bool +| 函数返回值数据类型 | text +| 函数含义 | 获得trigger的create trigger语句 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_triggerdef(16992); +pg_get_triggerdef +------------------------------------------------------------------------------------------------------------ +CREATE TRIGGER example_trigger AFTER INSERT ON public.company FOR EACH ROW EXECUTE FUNCTION auditlogfunc() +(1 row) +postgres=# +---- +|=== + + + + + +=== pg_get_userbyid + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_userbyid +| 参数数据类型 | role_oid +| 函数返回值数据类型 | ~name~ +| 函数含义 | 获得特定role oid的role name +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_userbyid(16426); +pg_get_userbyid +----------------- +lc0029999 +(1 row) +postgres=# +---- +|=== + + +=== pg_get_viewdef + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_viewdef +| 参数数据类型 | view_name 或者 view_name, pretty_bool或者 view_oid或者 view_oid, pretty_bool或者view_oid, wrap_column_int +| 函数返回值数据类型 | text +| 函数含义 | 获得view的定义 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_viewdef('company_view'); +pg_get_viewdef +--------------------- +SELECT company.id,+ company.name, + company.age + FROM company; +(1 row) +postgres=# +---- +|=== + + +=== pg_index_column_has_property + +[cols="145,378"] +|=== +h| 函数名称 h| pg_index_column_has_property +| 参数数据类型 | index regclass, column integer, property text +| 函数返回值数据类型 | boolean +| 函数含义 +a| 测试索引列是否有特定的索引列属性。索引列属性见下: asc 索引列升序 desc 索引列降序 nulls_first null值在前 nulls_last null值在后 orderable 列是否具有任何定义的排序顺序? distance_orderable 列是否可以被"distance" operator 顺序扫描到, 比如 ORDER BY col <-> constant ? returnable index-only扫描是否可以返回列值 search_array 列是否原生支持 col = ANY(array)搜索 search_nulls 列是否支持IS NULL 和IS NOT NULL 搜索 + +注意:extension的访问方法可以为它们的indexes定义额外的属性名称。 + +本函数在如下情况下会返回NULL:属性名称未知(not known)或者不适用于特定的对象Oid或者column number不能标识出一个有效的对象。 + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_index_column_has_property('idx_2'::regclass,1,'desc'); +pg_index_column_has_property +------------------------------ +f +(1 row) +postgres=# select pg_index_column_has_property('idx_2'::regclass,1,'asc'); +pg_index_column_has_property +------------------------------ +t +(1 row) +postgres=# +---- +|=== + + + + + + +=== pg_index_has_property + +[cols="145,378"] +|=== +h| 函数名称 h| pg_index_has_property +| 参数数据类型 | index regclass, property text +| 函数返回值数据类型 | boolean +| 函数含义 +a| 测试一个index是否具有特定的索引属性。如下是索引属性的清单 clusterable 在cluster命令中是否可以用到index index_scan index 是否支持 plain (non-bitmap) scans? bitmap_scan index 是否支持 bitmap scans? backward_scan Can the scan direction be changed in mid-scan (to support FETCH BACKWARD on a cursor without needing materialization)? + +注意:extension的访问方法可以为它们的indexes定义额外的属性名称。 + +本函数在如下情况下会返回NULL:属性名称未知(not known)或者不适用于特定的对象oid不能标识出一个有效的对象。 + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_index_has_property('idx_2'::regclass,'index_scan'); +pg_index_has_property +----------------------- +t +(1 row) +postgres=# +---- +|=== + + + +=== pg_indexam_has_property + +[cols="145,378"] +|=== +h| 函数名称 h| pg_indexam_has_property +| 参数数据类型 | am oid, property text +| 函数返回值数据类型 | boolean +| 函数含义 +a| 测试一个index访问方法是否具有特定的属性。如下是索引访问方法属性清单: can_order 访问方法是否支持 ASC, DESC 以及CREATE INDEX的related keywords can_unique 访问方法是否支持unique indexes? can_multi_col 访问方法是否支持多列indexes? can_exclude 访问方法是否支持exclusion constraints? can_include 访问方法是否支持CREATE INDEX的 INCLUDE 子句 + + + +本函数在如下情况下会返回NULL:属性名称未知(not known)或者不适用于特定的对象 oid不能标识出一个有效的对象。 + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from pg_am; + oid \| amname \| amhandler \| amtype +------+--------+----------------------+-------- + 2 \| heap \| heap_tableam_handler \| t + 403 \| btree \| bthandler \| i + 405 \| hash \| hashhandler \| i + 783 \| gist \| gisthandler \| i + 2742 \| gin \| ginhandler \| i + 4000 \| spgist \| spghandler \| i + 3580 \| brin \| brinhandler \| i +(7 rows) + +postgres=# +postgres=# select pg_indexam_has_property(4000,'can_multi_col'); + pg_indexam_has_property +------------------------- + f +(1 row) + +postgres=# +postgres=# select pg_indexam_has_property(403,'can_unique'); + pg_indexam_has_property +------------------------- + t +(1 row) + +postgres=# +---- + +|=== + + + + +=== pg_options_to_table + +[cols="145,378"] +|=== +h| 函数名称 h| pg_options_to_table +| 参数数据类型 | options_array text[] +| 函数返回值数据类型 | setof record ( option_name text, option_value text ) +| 函数含义 | 返回pg_class.reloptions或者pg_attribute.attoptions表示的存储选项 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_options_to_table(reloptions) from pg_class where oid='16384'; +pg_options_to_table +--------------------------------------------- +(autovacuum_vacuum_insert_threshold,10000) +(autovacuum_vacuum_insert_scale_factor,0.1) +(2 rows) +postgres=# +---- +|=== + + + + +=== pg_tablespace_databases + +[cols="145,378"] +|=== +h| 函数名称 h| pg_tablespace_databases +| 参数数据类型 | tablespace oid +| 函数返回值数据类型 | setof oid +| 函数含义 | 返回特定tablespace中保存的object的database的oid,如果本函数返回任何值,那么就表示tablespace不为空并且不能被drop掉。若想查出在该表空间内有哪些对象,你需要连接到本函数返回的database中,并查询pg_class获得这些对象。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_tablespace_databases(1663); +pg_tablespace_databases +------------------------- +16424 +1 +16878 +14174 +14173 +(5 rows) +postgres=# +---- +|=== + + + + +=== pg_tablespace_location + +[cols="145,378"] +|=== +h| 函数名称 h| pg_tablespace_location +| 参数数据类型 | tablespace oid +| 函数返回值数据类型 | Text +| 函数含义 | 返回指定tablespace的文件系统路径 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_tablespace_location(16391); +pg_tablespace_location +------------------------ +/home/pg131/ts1 +(1 row) +postgres=# +---- +|=== + + + + +=== pg_typeof + +[cols="145,378"] +|=== +h| 函数名称 h| pg_typeof +| 参数数据类型 | any +| 函数返回值数据类型 | regtype +| 函数含义 | 指定值的数据类型的oid +| 使用举例 +a| +[source,sql] +---- +postgres=# SELECT pg_typeof(33.339999); +-[ RECORD 1 ]------ +pg_typeof \| numeric + +postgres=# SELECT typlen FROM pg_type WHERE oid = pg_typeof(33.339999); +-[ RECORD 1 ] +typlen \| -1 + +postgres=# +---- + +|=== + + + + +=== COLLATION FOR + +[cols="145,378"] +|=== +h| 函数名称 h| COLLATION FOR +| 参数数据类型 | "any" +| 函数返回值数据类型 | text +| 函数含义 | 返回指定值的collation的name,本函数的返回值是被双引号引起来的,如果入参表达式不能派生出collation,则返回null如果传入的参数不是可以collatable的data type,则会抛出错误 +| 使用举例 +a| +[source,sql] +---- +postgres=# select collation for(datname) from pg_database; +pg_collation_for +------------------ +"C" +"C" +"C" +"C" +"C" +(5 rows) +postgres=# +---- +|=== + + + + +=== to_regclass + +[cols="145,378"] +|=== +h| 函数名称 h| to_regclass +| 参数数据类型 | text +| 函数返回值数据类型 | Regclass +| 函数含义 | 将文本形式的relation name转换为oid,本函数的输入参数不可以是数字形式的oid。如果本函数未找到输入参数指定的name,本函数会返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regclass('public.data1'); +-[ RECORD 1 ]------ +to_regclass \| data1 + +postgres=# \x +Expanded display is off. +postgres=# select oid, relname from pg_class where oid=to_regclass('public.data1'); + oid \| relname +-------+--------- + 16384 \| data1 +(1 row) + +postgres=# +---- +|=== + + + + + + + +=== to_regcollation + +[cols="145,378"] +|=== +h| 函数名称 h| to_regcollation +| 参数数据类型 | Text +| 函数返回值数据类型 | regcollation +| 函数含义 | 将文本形式的collation name转换为oid,本函数的输入参数不可以是数字形式的oid。如果本函数未找到输入参数指定的name,本函数会返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regcollation('"POSIX"'); + to_regcollation +----------------- + "POSIX" +(1 行记录) + +postgres=# select * from pg_collation where oid=to_regcollation('"POSIX"'); + oid \| collname \| collnamespace \| collowner \| collprovider \| collisdeterministic \| collencoding \| collcollate \| collctype \| collversion +-----+----------+---------------+-----------+--------------+---------------------+--------------+-------------+-----------+------------- + 951 \| POSIX \| 11 \| 10 \| c \| t \| -1 \| POSIX \| POSIX \| +(1 行记录) + +postgres=# select oid,collname from pg_collation where oid=to_regcollation('"POSIX"'); + oid \| collname +-----+---------- + 951 \| POSIX +(1 行记录) + +postgres=# +---- + +|=== + + + + +=== to_regnamespace + +[cols="145,378"] +|=== +h| 函数名称 h| to_regnamespace +| 参数数据类型 | text +| 函数返回值数据类型 | regnamespace +| 函数含义 | 将文本形式的schema name转换为oid,本函数的输入参数不可以是数字形式的oid。如果本函数未找到输入参数指定的name,本函数会返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regnamespace('public'); +to_regnamespace +----------------- +public +(1 行记录) +postgres=# +---- +|=== + + + +=== to_regoper + +[cols="145,378"] +|=== +h| 函数名称 h| to_regoper +| 参数数据类型 | text +| 函数返回值数据类型 | regoper +| 函数含义 | 将文本形式的operator name转换为oid,本函数的输入参数不可以是数字形式的oid。如果本函数未找到输入参数指定的name或者含义不明确,本函数会返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid, oprname from pg_operator where oid=to_regoper('!'); + oid \| oprname +-----+--------- + 388 \| ! +(1 row) + +postgres=# select to_regoper('!'); + to_regoper +------------ + ! +(1 row) + +postgres=# +---- +|=== + + + +=== to_regoperator + +[cols="145,378"] +|=== +h| 函数名称 h| to_regoperator +| 参数数据类型 | text +| 函数返回值数据类型 | regoperator +| 函数含义 | 将文本形式的operator name(带参数类型)转换为oid,本函数的输入参数不可以是数字形式的oid。如果本函数未找到输入参数指定的name,本函数会返回NULL. +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid, oprname from pg_operator where oid=to_regoperator('+(integer,integer)'); + oid \| oprname +-----+--------- + 551 \| + +(1 row) + +postgres=# select to_regoperator('+(int4,int4)'); + to_regoperator +-------------------- + +(integer,integer) +(1 row) + +postgres=# +---- + +|=== + + + + + +=== to_regproc + +[cols="145,378"] +|=== +h| 函数名称 h| to_regproc +| 参数数据类型 | text +| 函数返回值数据类型 | regproc +| 函数含义 | 将文本的function或者procedure转换为其oid。如果本函数未找到输入参数指定的name或者含义不明确,本函数会返回NULL。本函数的输入参数不可以是数字形式的oid。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regproc('pg_stat_statements'); + to_regproc +-------------------- + pg_stat_statements +(1 row) + +postgres=# select oid,proname from pg_proc where oid=to_regproc('pg_stat_statements'); + oid \| proname +-------+-------------------- + 16401 \| pg_stat_statements +(1 row) + +postgres=# +---- + +|=== + + + +=== to_regprocedure + +[cols="145,378"] +|=== +h| 函数名称 h| to_regprocedure +| 参数数据类型 | text +| 函数返回值数据类型 | regprocedure +| 函数含义 | 将文本的function或者procedure(带参数)转换为其oid。如果本函数未找到输入参数指定的name,本函数会返回NULL。本函数的输入参数不可以是数字形式的oid。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regprocedure('pg_get_viewdef(text)'); + to_regprocedure +---------------------- + pg_get_viewdef(text) +(1 row) + +postgres=# select oid, proname from pg_proc where oid= to_regprocedure('pg_get_viewdef(text)'); + oid \| proname +------+---------------- + 1640 \| pg_get_viewdef +(1 row) + +postgres=# +---- + +|=== + + + +=== to_regrole + +[cols="145,378"] +|=== +h| 函数名称 h| to_regrole +| 参数数据类型 | text +| 函数返回值数据类型 | regrole +| 函数含义 | 将文本的role name转换为其oid。如果本函数未找到输入参数指定的name,本函数会返回NULL。本函数的输入参数不可以是数字形式的oid。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid,rolname from pg_roles where oid=to_regrole('lc0039999'); + oid \| rolname +-------+----------- + 16877 \| lc0039999 +(1 row) + +postgres=# select to_regrole('lc0039999'); + to_regrole +------------ + lc0039999 +(1 row) + +postgres=# +---- + +|=== + + + +=== to_regtype + +[cols="145,378"] +|=== +h| 函数名称 h| to_regtype +| 参数数据类型 | text +| 函数返回值数据类型 | regtype +| 函数含义 +a| 将文本的type name转换为其oid。如果本函数未找到输入参数指定的name,本函数会返回NULL。本函数的输入参数不可以是数字形式的oid。 + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_regtype('int4'); +to_regtype +------------ +integer +(1 row) +postgres=# select oid, typname from pg_type where oid=to_regtype('int4'); +oid \| typname +-----+--------- +23 \| int4 +(1 row) +postgres=# +---- +|=== + + + + +=== pg_describe_object + +[cols="145,378"] +|=== +h| 函数名称 h| pg_describe_object +| 参数数据类型 | classid oid, objid oid, objsubid integer +| 函数返回值数据类型 | text +| 函数含义 +a| 用于描述pg_depend系统表中保存的依赖对象。 + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select oid,relname from pg_class where oid in (select distinct classid from pg_depend) order by oid; + oid \| relname +------+------------------------- + 1247 \| pg_type + 1255 \| pg_proc + 1259 \| pg_class + 2328 \| pg_foreign_data_wrapper + 2602 \| pg_amop + 2603 \| pg_amproc + 2606 \| pg_constraint + 2612 \| pg_language + 2616 \| pg_opclass + 2617 \| pg_operator + 2618 \| pg_rewrite + 2620 \| pg_trigger + 2753 \| pg_opfamily + 3079 \| pg_extension + 3600 \| pg_ts_dict + 3602 \| pg_ts_config + 3764 \| pg_ts_template +(17 rows) + +postgres=# select * from pg_foreign_data_wrapper ; + oid \| fdwname \| fdwowner \| fdwhandler \| fdwvalidator \| fdwacl \| fdwoptions +-------+----------+----------+------------+--------------+--------+------------ + 16954 \| file_fdw \| 10 \| 16952 \| 16953 \| \| +(1 row) + +postgres=# select pg_describe_object(2328,16954,0); + pg_describe_object +------------------------------- + foreign-data wrapper file_fdw +(1 row) + +postgres=# +---- + +|=== + + + +=== pg_identify_object + +[cols="145,378"] +|=== +h| 函数名称 h| pg_identify_object +| 参数数据类型 | classid oid, objid oid, objsubid integer +| 函数返回值数据类型 | record ( type text, schema text, name text, identity text ) +| 函数含义 +a| 返回一个数据库对象的详细信息 + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_identify_object(2328,16954,0); +pg_identify_object +--------------------------------------------- +("foreign-data wrapper",,file_fdw,file_fdw) +(1 row) +postgres=# +---- +|=== + + + +=== pg_identify_object_as_address + +[cols="145,378"] +|=== +h| 函数名称 h| pg_identify_object_as_address +| 参数数据类型 | classid oid, objid oid, objsubid integer +| 函数返回值数据类型 | record ( type text, object_names text[], object_args text[] ) +| 函数含义 +a| 返回一个数据库对象的足够信息以标识出数据库对象 + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_identify_object_as_address(2328,16954,0); +pg_identify_object_as_address +---------------------------------------- +("foreign-data wrapper",{file_fdw},{}) +(1 row) +postgres=# +---- +|=== + + + + + +=== pg_get_object_address + +[cols="145,378"] +|=== +h| 函数名称 h| pg_get_object_address +| 参数数据类型 | type text, object_names text[], object_args text[] +| 函数返回值数据类型 | record ( classid oid, objid oid, objsubid integer ) +| 函数含义 +a| 本函数是pg_identify_object_as_address的反函数 + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_get_object_address('foreign-data wrapper','{file_fdw}','{}'); +pg_get_object_address +----------------------- +(2328,16954,0) +(1 row) +postgres=# +---- +|=== + + +=== col_description + +[cols="145,378"] +|=== +h| 函数名称 h| col_description +| 参数数据类型 | table oid, column integer +| 函数返回值数据类型 | text +| 函数含义 +a| 获取某个表的某个列的comment + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# create table t_comment(c1 int ); +CREATE TABLE +postgres=# comment on column t_comment.c1 is 'this is c1 comment!'; +COMMENT +postgres=# select oid from pg_class where oid=to_regclass('t_comment') +postgres-# ; + oid +------- + 17001 +(1 row) +postgres=# select col_description(17001,1); + col_description +--------------------- + this is c1 comment! +(1 row) +postgres=# +postgres=# select col_description(to_regclass('t_comment'),1); + col_description +--------------------- + this is c1 comment! +(1 row) + +postgres=# +---- +|=== + + + + +=== obj_description + +[cols="145,378"] +|=== +h| 函数名称 h| obj_description +| 参数数据类型 | object oid, catalog name 或者object oid +| 函数返回值数据类型 | text +| 函数含义 +a| 返回特定数据库对象的注释信息 + + + + +| 使用举例 +a| +[source,sql] +---- +postgres=# comment on table t_comment is ' table-level test comment'; +COMMENT +postgres=# \dt+ data1 + List of relations + Schema \| Name \| Type \| Owner \| Persistence \| Size \| Description +--------+-------+-------+-------+-------------+-------+------------- + public \| data1 \| table \| pg131 \| permanent \| 42 MB \| +(1 row) + +postgres=# \dt+ t_comment; + List of relations + Schema \| Name \| Type \| Owner \| Persistence \| Size \| Description +--------+-----------+-------+-------+-------------+---------+--------------------------- + public \| t_comment \| table \| pg131 \| permanent \| 0 bytes \| table-level test comment +(1 row) + +postgres=# select obj_description(17001); + obj_description +--------------------------- + table-level test comment +(1 row) + +postgres=# +---- +|=== + + + +=== shobj_description + +[cols="145,378"] +|=== +h| 函数名称 h| shobj_description +| 参数数据类型 | object oid, catalog name +| 函数返回值数据类型 | text +| 函数含义 | 返回特定共享数据库对象(如databases, roles, and tablespaces)的注释信息. +| 使用举例 +a| +[source,sql] +---- +postgres=# select shobj_description(14174,'pg_database'); +shobj_description +-------------------------------------------- +default administrative connection database +(1 row) +postgres=# +---- +|=== + + + +=== pg_current_xact_id + +[cols="145,378"] +|=== +h| 函数名称 h| pg_current_xact_id +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | xid8 +| 函数含义 | 返回当前的事务id,若是没有当前事务id,系统会自动指派一个新的事务id +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_current_xact_id(); +pg_current_xact_id +-------------------- +720 +(1 row) +postgres=# +---- +|=== + + + +=== pg_current_xact_id_if_assigned() + +[cols="145,378"] +|=== +h| 函数名称 h| pg_current_xact_id_if_assigned() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | xid8 +| 函数含义 | 返回当前的current transaction's ID,若是没有transaction's ID被指派,本函数返回NULL。如果事务可能是只读的,最好使用本函数,以避免不必要的XID消耗。 +| 使用举例 +a| +[source,sql] +---- +postgres=*# select pg_current_xact_id_if_assigned(); +pg_current_xact_id_if_assigned +-------------------------------- +(1 row) +postgres=*# update data1 set c2='data1_1' where c1=1; +UPDATE 1 +postgres=*# select pg_current_xact_id_if_assigned(); +pg_current_xact_id_if_assigned +-------------------------------- +722 +(1 row) +postgres=*# +---- +|=== + + + +=== pg_xact_status + +[cols="145,378"] +|=== +h| 函数名称 h| pg_xact_status +| 参数数据类型 | xid8 +| 函数返回值数据类型 | text +| 函数含义 | 返回近期事务的提交状态。本函数的执行结果是下面三个中的一个:in progress、commited、aborted。当事务足够老而没有在PostgreSQL中保存下来时,commit status会被丢弃,此时本函数返回结果为NULL。请注意,针对prepared transactions,本函数的返回结果为in progress,应用程序必须检查pg_prepared_xacts以确定一个transaction ID是否属于prepared transaction +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_xact_status(pg_current_xact_id()); +pg_xact_status +---------------- +in progress +(1 row) +postgres=# postgres=# select pg_xact_status(722::text::xid8); +pg_xact_status +---------------- +committed +(1 row) +postgres=# +---- +|=== + + + +=== pg_current_snapshot + +[cols="145,378"] +|=== +h| 函数名称 h| pg_current_snapshot +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | pg_snapshot +| 函数含义 +a| 返回当前的snapshot,这是一种显示哪个transaction id是正处于in-progress状态的数据结构。注意:有关pg_snapshot数据类型: pg_snapshot数据类型用于存储在一个特定时间点上的transaction ID visibility信息。 pg_snapshot数据类型的表示方法是xmin:xmax:xip_list这个xmin:xmax:xip_list就是pg_snapshot数据类型组成。见下: xmin:处于active状态的最小的transaction id,所有小于xmin的transaction id要么是committed (visible),要么是rolled back(dead) xmax:大于或者等于本xmax值的transaction id是在snapshot结束时未完成的,因此,xmax是不可见的。 xip_list:在生成snapshot时,处于in progress状态的transactions。在xmin <= X < xmax范围内并且不在本xip_list中的transaction ID 表示在snapshot生成时是已经完成的transaction ID,因此,根据commit status,要么是visible的要么是dead,本列表中不包括subtransactions的transaction IDs + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_current_snapshot(); +pg_current_snapshot +--------------------- +727:727: +(1 row) +postgres=# +---- +|=== + + + +=== pg_snapshot_xip + +[cols="145,378"] +|=== +h| 函数名称 h| pg_snapshot_xip +| 参数数据类型 | pg_snapshot +| 函数返回值数据类型 | setof xid8 +| 函数含义 | 返回snapshot中处于in-progress状态的transaction id +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_snapshot_xip('10:20:10,14,15'); +pg_snapshot_xip +----------------- +10 +14 +15 +(3 rows) +postgres=# +---- +|=== + + + +=== pg_snapshot_xmax + +[cols="145,378"] +|=== +h| 函数名称 h| pg_snapshot_xmax +| 参数数据类型 | pg_snapshot +| 函数返回值数据类型 | xid8 +| 函数含义 | 返回snapshot的xmax +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_snapshot_xmax('10:20:10,14,15'); +pg_snapshot_xmax +------------------ +20 +(1 row) +postgres=# +---- +|=== + + + +=== pg_snapshot_xmin + +[cols="145,378"] +|=== +h| 函数名称 h| pg_snapshot_xmin +| 参数数据类型 | pg_snapshot +| 函数返回值数据类型 | xid8 +| 函数含义 | 返回snapshot的xmin +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_snapshot_xmin('10:20:10,14,15'); +pg_snapshot_xmin +------------------ +10 +(1 row) +postgres=# +---- +|=== + + + +=== pg_visible_in_snapshot + +[cols="145,378"] +|=== +h| 函数名称 h| pg_visible_in_snapshot +| 参数数据类型 | xid8, pg_snapshot +| 函数返回值数据类型 | bool +| 函数含义 | 给定的事务ID是否对snapshot可见,即:给定的事务ID是否在生成snapshot之前完成。本函数对subtransaction ID不能给出正确的结果。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_visible_in_snapshot(722::text::xid8,'10:20:10,14,15'); +pg_visible_in_snapshot +------------------------ +f +(1 row) +postgres=# select pg_visible_in_snapshot(12::text::xid8,'10:20:10,14,15'); +pg_visible_in_snapshot +------------------------ +t +(1 row) +postgres=# +---- +|=== + + + +=== txid_current + +[cols="145,378"] +|=== +h| 函数名称 h| txid_current +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | bigint +| 函数含义 | 返回当前的事务id,若是没有当前事务id,系统会自动指派一个新的事务id。本函数(返回值是bigint数据类型)的作用与pg_current_xact_id(返回值是xid8数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_current(); +txid_current +-------------- +735 +(1 row) +postgres=# +---- +|=== + + + +=== txid_current_if_assigned() + +[cols="145,378"] +|=== +h| 函数名称 h| txid_current_if_assigned() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | bigint +| 函数含义 | 本函数(注意:返回值是bigint数据类型)的作用与pg_current_xact_id_if_assigned(注意:返回值是xid8数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +[pg131@VM-0-8-centos ~]$ psql -d postgres psql (13.1) +Type "help" for help. +postgres=# select txid_current_if_assigned(); +txid_current_if_assigned +-------------------------- +(1 row) +postgres=# begin; +BEGIN +postgres=*# select txid_current_if_assigned(); +txid_current_if_assigned +-------------------------- +(1 row) +postgres=*# select txid_current(); +txid_current +-------------- +738 +(1 row) +postgres=*# select txid_current_if_assigned(); +txid_current_if_assigned +-------------------------- +738 +(1 row) +---- +|=== + + + +=== txid_current_snapshot() + +[cols="145,378"] +|=== +h| 函数名称 h| txid_current_snapshot() +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | txid_snapshot +| 函数含义 | 返回当前的snapshot,这是一种显示哪个transaction id是正处于in-progress状态的数据结构。本函数(注意:返回值是txid_snapshot数据类型)的作用与pg_current_snapshot (注意:返回值是pg_snapshot数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_current_snapshot(); +txid_current_snapshot +----------------------- +741:741: +(1 row) + postgres=# \gdesc + Column \| Type + -----------------------+--------------- + txid_current_snapshot \| txid_snapshot + (1 row) +postgres=# +---- +|=== + + + +=== txid_snapshot_xip(txid_snapshot) + +[cols="145,378"] +|=== +h| 函数名称 h| txid_snapshot_xip(txid_snapshot) +| 参数数据类型 | txid_snapshot +| 函数返回值数据类型 | setof bigint +| 函数含义 | 返回snapshot中处于in-progress状态的transaction id。本函数(注意:返回值是txid_snapshot数据类型)的作用与pg_snapshot_xip (注意:返回值是pg_snapshot数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_snapshot_xip('10:20:10,14,15'); +txid_snapshot_xip +------------------- +10 +14 +15 +(3 rows) + postgres=# \gdesc + Column \| Type + -------------------+-------- + txid_snapshot_xip \| bigint + (1 row) +---- +|=== + + + +=== txid_snapshot_xmax + +[cols="145,378"] +|=== +h| 函数名称 h| txid_snapshot_xmax +| 参数数据类型 | txid_snapshot +| 函数返回值数据类型 | bigint +| 函数含义 | 返回snapshot的xmax。本函数(注意:返回值是bigint数据类型)的作用与pg_snapshot_xmax (注意:返回值是pg_snapshot数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_snapshot_xmax('10:20:10,14,15'); +txid_snapshot_xmax +-------------------- +20 +(1 row) + postgres=# \gdesc + Column \| Type + --------------------+-------- + txid_snapshot_xmax \| bigint + (1 row) +postgres=# +---- +|=== + + + +=== txid_snapshot_xmin + +[cols="145,378"] +|=== +h| 函数名称 h| txid_snapshot_xmin +| 参数数据类型 | txid_snapshot +| 函数返回值数据类型 | bigint +| 函数含义 | 返回snapshot的xmin。本函数(注意:返回值是bigint数据类型)的作用与pg_snapshot_xmin(注意:返回值是pg_snapshot数据类型)的作用是类似的,只是两个函数的返回值数据类型不同。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_snapshot_xmin('10:20:10,14,15'); +txid_snapshot_xmin +-------------------- +10 +(1 row) + postgres=# \gdesc + Column \| Type + --------------------+-------- + txid_snapshot_xmin \| bigint + (1 row) +postgres=# +---- +|=== + + + +=== txid_visible_in_snapshot + +[cols="145,378"] +|=== +h| 函数名称 h| txid_visible_in_snapshot +| 参数数据类型 | bigint, txid_snapshot +| 函数返回值数据类型 | boolean +| 函数含义 | 给定的事务ID是否对snapshot可见,即:给定的事务ID是否在生成snapshot之前完成。本函数对subtransaction ID不能给出正确的结果。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_visible_in_snapshot(722,'10:20:10,14,15'); +txid_visible_in_snapshot +-------------------------- +f +(1 row) + postgres=# select txid_visible_in_snapshot(12,'10:20:10,14,15'); + txid_visible_in_snapshot + -------------------------- + t + (1 row) +postgres=# +---- +|=== + + + +=== txid_status + +[cols="145,378"] +|=== +h| 函数名称 h| txid_status +| 参数数据类型 | bigint +| 函数返回值数据类型 | text +| 函数含义 | 返回近期事务的提交状态。本函数的执行结果是下面三个中的一个:in progress、commited、aborted。当事务足够老而没有在PostgreSQL中保存下来时,commit status会被丢弃,此时本函数返回结果为NULL。请注意,针对prepared transactions,本函数的返回结果为in progress,应用程序必须检查pg_prepared_xacts以确定一个transaction ID是否属于prepared transaction. +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_status(txid_current()); +txid_status +------------- +in progress +(1 row) + postgres=# select txid_current(); + txid_current + -------------- + 742 + (1 row) + postgres=# select txid_status(722); + txid_status + ------------- + committed + (1 row) +postgres=# +---- +|=== + + + + + +=== pg_xact_commit_timestamp + +[cols="145,378"] +|=== +h| 函数名称 h| pg_xact_commit_timestamp +| 参数数据类型 | xid +| 函数返回值数据类型 | timestamp with time zone +| 函数含义 a| 返回一个事务的提交时间。本函数能正常使用的前提就是配置参数track_commit_timestamp设置为on,否会有如下提示: +[source,sql] +---- +postgres=# select pg_xact_commit_timestamp(722::text::xid); +ERROR: could not get commit timestamp data +HINT: Make sure the configuration parameter "track_commit_timestamp" is set. +postgres=# +---- +| 使用举例 +a| +[source,sql] +---- +postgres=# select txid_current(); +txid_current +-------------- +743 +(1 row) + postgres=# select pg_xact_commit_timestamp(743::text::xid); + pg_xact_commit_timestamp + ------------------------------ + 2021-04-29 16:52:37.19133+08 + (1 row) +postgres=# +---- +|=== + + + +=== pg_last_committed_xact + +[cols="145,378"] +|=== +h| 函数名称 h| pg_last_committed_xact +| 参数数据类型 | 无输入数据类型 +| 函数返回值数据类型 | record ( xid xid, timestamp timestamp with time zone ) +| 函数含义 | 返回最后一个提交事务的transaction id和commit timestamp +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_last_committed_xact(); +pg_last_committed_xact +-------------------------------------- +(743,"2021-04-29 16:52:37.19133+08") +(1 row) +postgres=# +---- +|=== + + + + + +=== pg_control_checkpoint + +[cols="145,378"] +|=== +h| 函数名称 h| pg_control_checkpoint +| 参数数据类型 | 无输入数据类型 +| 函数返回值数据类型 | record +| 函数含义 | 本函数是从PostgreSQL控制文件中获取数据。本函数返回当前checkpoint状态的相关信息 +| 使用举例 +a| + +|=== + + + +=== pg_control_system + +[cols="145,378"] +|=== +h| 函数名称 h| pg_control_system +| 参数数据类型 | 无输入数据类型 +| 函数返回值数据类型 | record +| 函数含义 | 本函数是从PostgreSQL控制文件中获取数据。本函数返回当前控制文件状态的相关信息。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_control_system(); +pg_control_system +--------------------------------------------------------------- +(1300,202007201,6908228805274066467,"2021-04-29 16:57:56+08") +(1 row) +postgres=# +---- +|=== + + + +=== pg_control_init + +[cols="145,378"] +|=== +h| 函数名称 h| pg_control_init +| 参数数据类型 | 无输入数据类型 +| 函数返回值数据类型 | record +| 函数含义 | 本函数是从PostgreSQL控制文件中获取数据。本函数返回cluster初始化时的相关信息 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_control_init(); +pg_control_init +--------------------------------------------------- +(8,8192,131072,8192,16777216,64,32,1996,2048,t,0) +(1 row) +postgres=# +---- +|=== + + +=== pg_control_recovery + +[cols="145,378"] +|=== +h| 函数名称 h| pg_control_recovery +| 参数数据类型 | 无输入数据类型 +| 函数返回值数据类型 | record +| 函数含义 | 本函数是从PostgreSQL控制文件中获取数据。本函数返回恢复状态的信息。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pg_control_recovery(); +pg_control_recovery +--------------------- +(0/0,0,0/0,0/0,f) +(1 row) +postgres=# +---- +|=== + + +=== gen_random_uuid + +[cols="145,378"] +|=== +h| 函数名称 h| gen_random_uuid +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | uuid +| 函数含义 | 本函数返回version 4版本的uuid +| 使用举例 +a| +[source,sql] +---- +postgres=# select gen_random_uuid(); +gen_random_uuid +-------------------------------------- +39158a63-f6d0-4883-8765-8b8e9c9cae62 +(1 row) +postgres=# +---- +|=== + + + +=== array_to_tsvector + +[cols="145,378"] +|=== +h| 函数名称 h| array_to_tsvector +| 参数数据类型 | text[] +| 函数返回值数据类型 | tsvector +| 函数含义 | 将array of lexemes转换为tsvector +| 使用举例 +a| +[source,sql] +---- +postgres=# select array_to_tsvector('{fat,cat,rat}'::text[]); +array_to_tsvector +------------------- +'cat' 'fat' 'rat' +(1 row) +postgres=# +---- +|=== + + +=== get_current_ts_config + +[cols="145,378"] +|=== +h| 函数名称 h| get_current_ts_config +| 参数数据类型 | 无输入参数 +| 函数返回值数据类型 | regconfig +| 函数含义 | 返回当前默认的text search配置的oid(参见配置参数default_text_search_config) +| 使用举例 +a| +[source,sql] +---- +postgres=# select get_current_ts_config(); +get_current_ts_config +----------------------- +english +(1 row) +postgres=# +---- +|=== + + +=== length + +[cols="145,378"] +|=== +h| 函数名称 h| length +| 参数数据类型 | tsvector +| 函数返回值数据类型 | integer +| 函数含义 | 返回lexemes的数量 +| 使用举例 +a| +[source,sql] +---- +postgres=# select length('fat:2,4 cat:3 rat:5A'::tsvector); +length +-------- +3 +(1 row) +postgres=# +---- +|=== + + + +=== numnode + +[cols="145,378"] +|=== +h| 函数名称 h| numnode +| 参数数据类型 | tsquery +| 函数返回值数据类型 | integer +| 函数含义 | 返回lexemes加operator的数量 +| 使用举例 +a| +[source,sql] +---- +postgres=# select numnode('(fat & rat) \| cat'::tsquery) ; +numnode +--------- +5 +(1 row) +postgres=# +---- +|=== + + + + + +=== plainto_tsquery + +[cols="145,378"] +|=== +h| 函数名称 h| plainto_tsquery +| 参数数据类型 | [config regconfig,] query text +| 函数返回值数据类型 | tsquery +| 函数含义 | 将text转换为tsquery。其中,字符串中的任何标点都将被忽略 +| 使用举例 +a| +[source,sql] +---- +postgres=# select plainto_tsquery('english', 'The Fat Rats'); +plainto_tsquery +----------------- +'fat' & 'rat' +(1 row) +postgres=# +---- +|=== + + +=== phraseto_tsquery + +[cols="145,378"] +|=== +h| 函数名称 h| phraseto_tsquery +| 参数数据类型 | [config regconfig,] query text +| 函数返回值数据类型 | tsquery +| 函数含义 | 将text转换为tsquery。其中,字符串中的任何标点都将被忽略 +| 使用举例 +a| +[source,sql] +---- +postgres=# select phraseto_tsquery('english', 'The Fat Rats') ; +phraseto_tsquery +------------------ +'fat' <-> 'rat' +(1 row) +postgres=# +---- +|=== + + + +=== websearch_to_tsquery + +[cols="145,378"] +|=== +h| 函数名称 h| websearch_to_tsquery +| 参数数据类型 | [ _config_ regconfig, ] _query_ text +| 函数返回值数据类型 | tsquery +| 函数含义 | 将text转换为tsquery。引用的单词序列被转换成短语测试。"or"一词被理解为产生or运算符,破折号产生NOT运算符,忽略其他标点符号 +| 使用举例 +a| +[source,sql] +---- +postgres=# select websearch_to_tsquery('english', '"fat rat" or cat dog'); +websearch_to_tsquery +--------------------------------- +'fat' <-> 'rat' \| 'cat' & 'dog' +(1 row) +postgres=# +---- +|=== + + + +=== querytree + +[cols="145,378"] +|=== +h| 函数名称 h| querytree +| 参数数据类型 | tsquery +| 函数返回值数据类型 | text +| 函数含义 | 返回一个tsquery中的可索引部分。当返回结果为空或者T时,表示这是一个不可索引的query。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select querytree('foo & ! bar'::tsquery); +querytree +----------- +'foo' +(1 row) +postgres=# +---- +|=== + + + +=== setweight + +[cols="145,378"] +|=== +h| 函数名称 h| setweight +| 参数数据类型 | vector tsvector, weight "char"或者vector tsvector, weight "char", lexemes text[] +| 函数返回值数据类型 | tsvector +| 函数含义 | 为vector中的每个元素指定权重或者为在lexemes之内的vector中的每个元素指定权重 +| 使用举例 +a| +[source,sql] +---- +postgres=# select setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A'); +setweight +------------------------------- +'cat':3A 'fat':2A,4A 'rat':5A +(1 row) + postgres=# + postgres=# select setweight('fat:2,4 cat:3 rat:5,6B'::tsvector, 'A', '{cat,rat}'); + setweight + -------------------------------- + 'cat':3A 'fat':2,4 'rat':5A,6A + (1 row) +postgres=# +---- +|=== + + + +=== strip + +[cols="145,378"] +|=== +h| 函数名称 h| strip +| 参数数据类型 | tsvector +| 函数返回值数据类型 | tsvector +| 函数含义 | 从tsvector中抹掉position和weight +| 使用举例 +a| +[source,sql] +---- +postgres=# select strip('fat:2,4 cat:3 rat:5A'::tsvector); +strip +------------------- +'cat' 'fat' 'rat' +(1 row) +postgres=# +---- +|=== + + + +=== to_tsquery + +[cols="145,378"] +|=== +h| 函数名称 h| to_tsquery +| 参数数据类型 | regconfig, text 或者text +| 函数返回值数据类型 | tsquery +| 函数含义 | 将text转换为tsquery,本函数的返回结果必须由有效的tsquery operator进行连接。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_tsquery('english', 'The & Fat & Rats'); +to_tsquery +--------------- +'fat' & 'rat' +(1 row) + postgres=# select to_tsquery( 'The & Fat & Rats'); + to_tsquery + --------------- + 'fat' & 'rat' + (1 row) +postgres=# +---- +|=== + + + +=== to_tsvector + +[cols="145,378"] +|=== +h| 函数名称 h| to_tsvector +| 参数数据类型 | regconfig,text +| 函数返回值数据类型 | tsvector +| 函数含义 | 将text转换为tsvector ,结果中包括位置信息 +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_tsvector('english', 'The Fat Rats'); +to_tsvector +----------------- +'fat':2 'rat':3 +(1 row) +postgres=# +---- +|=== + + + + +=== to_tsvector + +[cols="145,378"] +|=== +h| 函数名称 h| to_tsvector +| 参数数据类型 | regconfig,json或者regconfig,jsonb +| 函数返回值数据类型 | tsvector +| 函数含义 | 将json文档中的每个字符串值转换为tsvector,结果值是按照文档顺序进行连接后输出的,当输入参数数据类型为jsonb时,json对象的字段的文档顺序是与实现相关的 +| 使用举例 +a| +[source,sql] +---- +postgres=# select to_tsvector('english', '{"aa": "The Fat Rats", "b": "dog"}'::json); +to_tsvector ------------------------- +'dog':5 'fat':2 'rat':3 +(1 row) + postgres=# postgres=# select to_tsvector('english', '{"aa": "The Fat Rats", "b": "dog"}'::jsonb); + to_tsvector + ------------------------- + 'dog':1 'fat':4 'rat':5 + (1 row) +postgres=# +---- +|=== + + +=== json_to_tsvector + +[cols="145,378"] +|=== +h| 函数名称 h| json_to_tsvector +| 参数数据类型 | [config regconfig,] json, jsonb +| 函数返回值数据类型 | tsvector +| 函数含义 | 将json文档中满足filter条件的每个item转换为一个tsvector。结果值是按照文档顺序进行连接后输出的,当输入参数数据类型为jsonb时,json对象的字段的文档顺序是与实现相关的。Filter条件必须是一个包括另个或者多个关键字的json 数组:string代表包括所有字符串值numeric代表包括所有数字值boolean代表包括所有boolean值key代表包括所有keyall代表包括上述所有。作为一个简单的例子,filter条件不可以是一个简单的并且是上述关键字之一的json值。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select json_to_tsvector('english', '{"a": "The Fat Rats", "b": 123}'::json, '["string", "numeric"]'); +json_to_tsvector +------------------------- +'123':5 'fat':2 'rat':3 +(1 row) +postgres=# +---- +|=== + + +=== jsonb_to_tsvector + +[cols="145,378"] +|=== +h| 函数名称 h| jsonb_to_tsvector +| 参数数据类型 | [config regconfig,] jsonb,jsonb +| 函数返回值数据类型 | tsvector +| 函数含义 | 将json文档中满足filter条件的每个item转换为一个tsvector。结果值是按照文档顺序进行连接后输出的,当输入参数数据类型为jsonb时,json对象的字段的文档顺序是与实现相关的。Filter条件必须是一个包括另个或者多个关键字的json 数组:string代表包括所有字符串值numeric代表包括所有数字值boolean代表包括所有boolean值key代表包括所有keyall代表包括上述所有。作为一个简单的例子,filter条件不可以是一个简单的并且是上述关键字之一的json值。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select jsonb_to_tsvector('english', '{"a": "The Fat Rats", "b": 123}'::jsonb, '["string", "numeric"]'); +jsonb_to_tsvector +------------------------- +'123':5 'fat':2 'rat':3 +(1 row) +postgres=# +---- +|=== + + + +=== ts_delete + +[cols="145,378"] +|=== +h| 函数名称 h| ts_delete +| 参数数据类型 | tsvector,text +| 函数返回值数据类型 | tsvector +| 函数含义 +a| 从vector中删除掉指定的lexeme + + +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, 'fat'); +ts_delete +------------------ +'cat':3 'rat':5A +(1 row) +postgres=# +---- +|=== + + +=== ts_delete + +[cols="145,378"] +|=== +h| 函数名称 h| ts_delete +| 参数数据类型 | tsvector,text[] +| 函数返回值数据类型 | tsvector +| 函数含义 +a| 从vector中删除掉指定的lexeme +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat']); +ts_delete ----------- +'cat':3 +(1 row) +postgres=# +---- +|=== + + + +=== ts_filter + +[cols="145,378"] +|=== +h| 函数名称 h| ts_filter +| 参数数据类型 | tsvector, "char"[] +| 函数返回值数据类型 | tsvector +| 函数含义 | 从vector中筛选出带有指定weights的元素 +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_filter('fat:2,4 cat:3b,7c rat:5A'::tsvector, '{a,b}'); +ts_filter +------------------- +'cat':3B 'rat':5A +(1 row) +postgres=# +---- +|=== + + + +=== ts_headline + +[cols="145,378"] +|=== +h| 函数名称 h| ts_headline +| 参数数据类型 | [config regconfig,] document text, query tsquery [, options text] +| 函数返回值数据类型 | text +| 函数含义 | 以简写的形式显示在document匹配到的query +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_headline('The fat cat ate the rat.', 'cat'); +ts_headline +--------------------------------- +The fat cat ate the rat. +(1 row) +postgres=# +---- +|=== + + +=== ts_headline + +[cols="145,378"] +|=== +h| 函数名称 h| ts_headline +| 参数数据类型 | [config regconfig,] document json, query tsquery [, options text] +| 函数返回值数据类型 | json +| 函数含义 | 以缩写的形式显示在json document匹配到的query +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_headline('{"cat":"raining cats and dogs"}'::json, 'cat'); +ts_headline +---------------------------------------- +{"cat":"raining cats and dogs"} +(1 row) +---- +|=== + + +=== ts_headline + +[cols="145,378"] +|=== +h| 函数名称 h| ts_headline +| 参数数据类型 | [config regconfig,] document jsonb, query tsquery [, options text] +| 函数返回值数据类型 | jsonb +| 函数含义 | 以缩写的形式显示在json document匹配到的query +| 使用举例 +a| +[source,sql] +---- +postgres=# select ts_headline('{"cat":"raining cats and dogs"}'::jsonb, 'cat'); +ts_headline +----------------------------------------- +{"cat": "raining cats and dogs"} +(1 row) +postgres=# +---- +|=== + + + +=== ts_rank + +[cols="145,378"] +|=== +h| 函数名称 h| ts_rank +| 参数数据类型 | [weights real[], ] vector tsvector, query tsquery [, normalization integer] +| 函数返回值数据类型 | real +| 函数含义 | 计算query与vector的匹配程度 +| 使用举例 +a| +[source,sql] +---- +postgres=# SELECT ts_rank(to_tsvector('The quick brown fox jumps over the lazy dog.'),to_tsquery('fox & dog')); ts_rank +------------ +0.09148999 +(1 row) +postgres=# +---- +|=== + + + +=== ts_rank_cd + +[cols="145,378"] +|=== +h| 函数名称 h| ts_rank_cd +| 参数数据类型 | [weights real[], ] vector tsvector, query tsquery [, normalization integer] +| 函数返回值数据类型 | real +| 函数含义 | 使用覆盖密度算法来计算query与vector的匹配程度 +| 使用举例 +a| +[source,sql] +---- +postgres=# SELECT ts_rank_cd('{0.1, 0.2, 0.4, 1.0}', to_tsvector('PostgreSQL full text search is a wonderful method'),to_tsquery('wonderful')); +ts_rank_cd +------------ +0.1 +(1 row) +postgres=# +---- +|=== + + +=== ts_rewrite + +[cols="145,378"] +|=== +h| 函数名称 h| ts_rewrite +| 参数数据类型 | query tsquery, target tsquery, substitute tsquery +| 函数返回值数据类型 | tsquery +| 函数含义 | 用substitute替换掉query中的target +| 使用举例 +a| +[source,sql] +---- +postgres=# SELECT ts_rewrite('c & b'::tsquery, 'b'::tsquery, 'bad\|bat'::tsquery); +ts_rewrite +------------------------- +( 'bad' \| 'bat' ) & 'c' +(1 row) +postgres=# +---- +|=== + + + +=== ts_rewrite + +[cols="145,378"] +|=== +h| 函数名称 h| ts_rewrite +| 参数数据类型 | query tsquery, select text +| 函数返回值数据类型 | tsquery +| 函数含义 | +| 使用举例 +a| +[source,sql] +---- +postgres=# CREATE TABLE test (col1 tsquery PRIMARY KEY, COL2 tsquery); +CREATE TABLE +postgres=# INSERT INTO test values ('p','q'); +INSERT 0 1 +postgres=# SELECT ts_rewrite('r & q'::tsquery, 'SELECT col1,col2 FROM test'); +ts_rewrite +------------ +'r' & 'q' +(1 row) +postgres=# +---- +|=== + + + +=== tsquery_phrase + +[cols="145,378"] +|=== +h| 函数名称 h| tsquery_phrase +| 参数数据类型 | query1 tsquery, query2 tsquery +| 函数返回值数据类型 | tsquery +| 函数含义 | 构造一个phrase query用于在连续的词位匹配query1和query2(同<->操作符) +| 使用举例 +a| +[source,sql] +---- +postgres=# select tsquery_phrase(to_tsquery('fat'), to_tsquery('cat')); +tsquery_phrase +----------------- +'fat' <-> 'cat' +(1 row) +postgres=# +---- +|=== + + +=== tsquery_phrase + +[cols="145,378"] +|=== +h| 函数名称 h| tsquery_phrase +| 参数数据类型 | query1 tsquery, query2 tsquery, distance integer +| 函数返回值数据类型 | tsquery +| 函数含义 | 构造一个词组查询,该词组搜索匹配query1且query2完全distance分开词素的匹配项 +| 使用举例 +a| +[source,sql] +---- +postgres=# select tsquery_phrase(to_tsquery('fat'), to_tsquery('cat'), 10); +tsquery_phrase +------------------ +'fat' <10> 'cat' +(1 row) +postgres=# +---- +|=== + + + + +=== tsvector_to_array + +[cols="145,378"] +|=== +h| 函数名称 h| tsvector_to_array +| 参数数据类型 | tsvector +| 函数返回值数据类型 | text[] +| 函数含义 | 将tsvector转换为词素数组 +| 使用举例 +a| +[source,sql] +---- +postgres=# select tsvector_to_array('fat:2,4 cat:3 rat:5A'::tsvector) ; +tsvector_to_array +------------------- +{cat,fat,rat} +(1 row) +postgres=# +---- +|=== + + + +=== unnest + +[cols="145,378"] +|=== +h| 函数名称 h| unnest +| 参数数据类型 | tsvector +| 函数返回值数据类型 | setof record ( lexeme text, positions smallint[], weights text ) +| 函数含义 | 将tsvector扩展为一行一个词素 +| 使用举例 +a| +[source,sql] +---- +postgres=# select * from unnest('cat:3 fat:2,4 rat:5A'::tsvector); + lexeme \| positions \| weights +--------+-----------+--------- + cat \| {3} \| {D} + fat \| {2,4} \| {D,D} + rat \| {5} \| {A} +(3 rows) +postgres=# +---- +|=== + + + +=== abbrev + +[cols="145,378"] +|=== +h| 函数名称 h| abbrev +| 参数数据类型 | inet +| 函数返回值数据类型 | text +| 函数含义 | 将inet转换为text的缩写显示格式 +| 使用举例 +a| +[source,sql] +---- +postgres=# select abbrev(inet '10.1.1.3'); +abbrev +---------- +10.1.1.3 +(1 row) +postgres=# +---- +|=== + + + +=== abbrev + +[cols="145,378"] +|=== +h| 函数名称 h| abbrev +| 参数数据类型 | cidr +| 函数返回值数据类型 | text +| 函数含义 | 将cidr转换为text的缩写显示格式,返回结果中去掉了netmask中右边的零 +| 使用举例 +a| +[source,sql] +---- +postgres=# select abbrev(cidr '10.1.0.0/16'); +abbrev +--------- +10.1/16 +(1 row) +postgres=# +---- +|=== + + + +=== broadcast + +[cols="145,378"] +|=== +h| 函数名称 h| broadcast +| 参数数据类型 | inet +| 函数返回值数据类型 | inet +| 函数含义 | 计算一个ip地址的广播地址 +| 使用举例 +a| +[source,sql] +---- +postgres=# select broadcast(inet '192.168.1.5/24'); +broadcast +------------------ +192.168.1.255/24 +(1 row) +postgres=# +---- +|=== + + + +=== family + +[cols="145,378"] +|=== +h| 函数名称 h| family +| 参数数据类型 | inet +| 函数返回值数据类型 | integer +| 函数含义 | 返回一个地址是IPV4(返回4)还是IPV6(返回6) +| 使用举例 +a| +[source,sql] +---- +postgres=# select family('fe80::5054:ff:fe99:540c') ; +family +-------- +6 +(1 row) + postgres=# select family(inet '172.1.0.23') ; + family + -------- + 4 + (1 row) +postgres=# +---- +|=== + + + +=== host + +[cols="145,378"] +|=== +h| 函数名称 h| host +| 参数数据类型 | inet +| 函数返回值数据类型 | text +| 函数含义 | 返回IP地址的text形式,且忽略掉netmask +| 使用举例 +a| +[source,sql] +---- +postgres=# select host(inet '192.168.1.0/24'); +host +------------- +192.168.1.0 +(1 row) +postgres=# +---- +|=== + + + +=== hostmask + +[cols="145,378"] +|=== +h| 函数名称 h| hostmask +| 参数数据类型 | Inet +| 函数返回值数据类型 | Inet +| 函数含义 | 返回ip地址的host mask +| 使用举例 +a| +[source,sql] +---- +postgres=# select hostmask(inet '192.168.23.20/30') ; +hostmask +---------- +0.0.0.3 +(1 row) +postgres=# +---- +|=== + + +=== inet_merge + +[cols="145,378"] +|=== +h| 函数名称 h| inet_merge +| 参数数据类型 | inet, inet +| 函数返回值数据类型 | cidr +| 函数含义 | 返回包含两个给定网络的最小网络 +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_merge(inet '192.168.1.5/24', inet '192.168.2.5/24'); +inet_merge +---------------- +192.168.0.0/22 +(1 row) +postgres=# +---- +|=== + + +=== inet_same_family + +[cols="145,378"] +|=== +h| 函数名称 h| inet_same_family +| 参数数据类型 | inet,inet +| 函数返回值数据类型 | bool +| 函数含义 | 返回两个ip地址是否属于同一个family +| 使用举例 +a| +[source,sql] +---- +postgres=# select inet_same_family(inet '192.168.1.5/24', inet '::1'); +inet_same_family +------------------ +f +(1 row) +postgres=# +---- +|=== + + + +=== masklen + +[cols="145,378"] +|=== +h| 函数名称 h| masklen +| 参数数据类型 | inet +| 函数返回值数据类型 | integer +| 函数含义 | 返回以位为单位的网络掩码长度 +| 使用举例 +a| +[source,sql] +---- +postgres=# select masklen(inet '192.168.1.5/24'); +masklen +--------- +24 +(1 row) +postgres=# +---- +|=== + + +=== netmask + +[cols="145,378"] +|=== +h| 函数名称 h| netmask +| 参数数据类型 | inet +| 函数返回值数据类型 | inet +| 函数含义 | 返回网络地址的网络掩码 +| 使用举例 +a| +[source,sql] +---- +postgres=# select netmask(inet '192.168.1.5/24'); +netmask +--------------- +255.255.255.0 +(1 row) +postgres=# +---- +|=== + + + +=== network + +[cols="145,378"] +|=== +h| 函数名称 h| network +| 参数数据类型 | inet +| 函数返回值数据类型 | inet +| 函数含义 | 返回地址的网络部分,将网络掩码右边的内容清零 +| 使用举例 +a| +[source,sql] +---- +postgres=# select network(inet '192.168.1.5/24') ; +network +---------------- +192.168.1.0/24 +(1 row) +postgres=# +---- +|=== + + + +=== set_masklen + +[cols="145,378"] +|=== +h| 函数名称 h| set_masklen +| 参数数据类型 | inet, integer +| 函数返回值数据类型 | inet +| 函数含义 | 为inet设置netmask长度,网络地址部分保持不变 +| 使用举例 +a| +[source,sql] +---- +postgres=# select set_masklen(inet '192.168.1.5/24', 16); +set_masklen +---------------- +192.168.1.5/16 +(1 row) +postgres=# +---- +|=== + + + +=== set_masklen + +[cols="145,378"] +|=== +h| 函数名称 h| set_masklen +| 参数数据类型 | cidr, integer +| 函数返回值数据类型 | cidr +| 函数含义 | 为cidr设置netmask长度,网络地址右边的设置为零 +| 使用举例 +a| +[source,sql] +---- +postgres=# select set_masklen(cidr '192.168.1.0/24', 16); +set_masklen +---------------- +192.168.0.0/16 +(1 row) +postgres=# +---- +|=== + + + +=== text + +[cols="145,378"] +|=== +h| 函数名称 h| text +| 参数数据类型 | inet +| 函数返回值数据类型 | text +| 函数含义 | 返回ip地址及其掩码的text形式 +| 使用举例 +a| +[source,sql] +---- +postgres=# select text(inet '192.168.1.5'); +text +---------------- +192.168.1.5/32 +(1 row) +postgres=# +---- +|=== + + +=== trunc + +[cols="145,378"] +|=== +h| 函数名称 h| trunc +| 参数数据类型 | macaddr +| 函数返回值数据类型 | macaddr +| 函数含义 | 将mac地址的最后三个字节清零,前缀可以与特定的网卡制造商关联 +| 使用举例 +a| +[source,sql] +---- +postgres=# select trunc(macaddr '12:34:56:78:90:ab') ; +trunc +------------------- +12:34:56:00:00:00 +(1 row) +postgres=# +---- +|=== + + +=== trunc + +[cols="145,378"] +|=== +h| 函数名称 h| trunc +| 参数数据类型 | macaddr8 +| 函数返回值数据类型 | macaddr8 +| 函数含义 | 将mac地址的最后五个字节清零,前缀可以与特定的网卡制造商关联 +| 使用举例 +a| +[source,sql] +---- +postgres=# select trunc(macaddr8 '12:34:56:78:90:ab:cd:ef') ; +trunc +------------------------- +12:34:56:00:00:00:00:00 +(1 row) +postgres=# +---- +|=== + + +=== macaddr8_set7bit + +[cols="145,378"] +|=== +h| 函数名称 h| macaddr8_set7bit +| 参数数据类型 | macaddr8 +| 函数返回值数据类型 | macaddr8 +| 函数含义 | 将地址的第7位设置为1,从而创建被称为修改后的EUI-64,以包含在IPv6地址中。 +| 使用举例 +a| +[source,sql] +---- +postgres=# select macaddr8_set7bit(macaddr8 '00:34:56:ab:cd:ef'); +macaddr8_set7bit +------------------------- +02:34:56:ff:fe:ab:cd:ef +(1 row) +postgres=# +---- +|=== + + +=== area + +[cols="145,378"] +|=== +h| 函数名称 h| area +| 参数数据类型 | geometric_type +| 函数返回值数据类型 | double precision +| 函数含义 | 计算面积,针对box, path, circle适用,path必须是能closed,否则会返回NULL +| 使用举例 +a| +[source,sql] +---- +postgres=# select area(box '(2,2),(0,0)'); +area +------ +4 +(1 row) +postgres=# +---- +|=== + + + +=== center + +[cols="145,378"] +|=== +h| 函数名称 h| center +| 参数数据类型 | geometric_type +| 函数返回值数据类型 | point +| 函数含义 | 计算中点,针对box, circle适用 +| 使用举例 +a| +[source,sql] +---- +postgres=# select center(box '(1,2),(0,0)') ; + center + --------- + (0.5,1) + (1 row) +postgres=# +---- +|=== + + +=== diagonal + +[cols="145,378"] +|=== +h| 函数名称 h| diagonal +| 参数数据类型 | box +| 函数返回值数据类型 | lseg +| 函数含义 | 获取box的对角线作为一个line segment,作用与lseg(box)一样 +| 使用举例 +a| +[source,sql] +---- +postgres=# select diagonal(box '(1,2),(0,0)'); +diagonal +--------------- +[(1,2),(0,0)] +(1 row) +postgres=# +---- +|=== + + +=== diameter + +[cols="145,378"] +|=== +h| 函数名称 h| diameter +| 参数数据类型 | circle +| 函数返回值数据类型 | double precision +| 函数含义 | 计算circle的直径 +| 使用举例 +a| +[source,sql] +---- +postgres=# select diameter(circle '<(0,0),2>') ; +diameter + ---------- + 4 +(1 row) +postgres=# +---- +|=== + + + +=== height + +[cols="145,378"] +|=== +h| 函数名称 h| height +| 参数数据类型 | box +| 函数返回值数据类型 | double precision +| 函数含义 | 计算box的垂直大小 +| 使用举例 +a| +[source,sql] +---- +postgres=# select height(box '(1,2),(0,0)'); + height + -------- + 2 + (1 row) +postgres=# +---- +|=== + + +=== isclosed + +[cols="145,378"] +|=== +h| 函数名称 h| isclosed +| 参数数据类型 | path +| 函数返回值数据类型 | bool +| 函数含义 | path是否是closed的 +| 使用举例 +a| +[source,sql] +---- +postgres=# select isclosed(path '((0,0),(1,1),(2,0))'); + isclosed + ---------- + t + (1 row) +postgres=# +---- +|=== + + +=== isopen + +[cols="145,378"] +|=== +h| 函数名称 h| isopen +| 参数数据类型 | path +| 函数返回值数据类型 | bool +| 函数含义 | Path是否是open的 +| 使用举例 +a| +[source,sql] +---- +postgres=# select isopen(path '[(0,0),(1,1),(2,0)]'); +isopen + -------- + t +(1 row) +postgres=# +---- +|=== + + + +=== length + +[cols="145,378"] +|=== +h| 函数名称 h| length +| 参数数据类型 | geometric_type +| 函数返回值数据类型 | double precision +| 函数含义 | 计算总长度,对lseg以及path适用 +| 使用举例 +a| +[source,sql] +---- +postgres=# select length(path '((-1,0),(1,0))') ; + length + -------- + 4 +(1 row) +postgres=# +---- +|=== + + + +=== npoints + +[cols="145,378"] +|=== +h| 函数名称 h| npoints +| 参数数据类型 | geometric_type +| 函数返回值数据类型 | integer +| 函数含义 | 返回point的数量,对path以及polygon适用 +| 使用举例 +a| +[source,sql] +---- +postgres=# select npoints(path '[(0,0),(1,1),(2,0)]'); +npoints +--------- + 3 + (1 row) +postgres=# +---- +|=== + + + +=== pclose + +[cols="145,378"] +|=== +h| 函数名称 h| pclose +| 参数数据类型 | path +| 函数返回值数据类型 | path +| 函数含义 | 将patch转换为closed的形式 +| 使用举例 +a| +[source,sql] +---- +postgres=# select pclose(path '[(0,0),(1,1),(2,0)]'); +pclose +--------------------- +((0,0),(1,1),(2,0)) +(1 row) +postgres=# +---- +|=== + + + +=== popen + +[cols="145,378"] +|=== +h| 函数名称 h| popen +| 参数数据类型 | path +| 函数返回值数据类型 | path +| 函数含义 | 将patch转换为open的形式 +| 使用举例 +a| +[source,sql] +---- +postgres=# select popen(path '((0,0),(1,1),(2,0))'); +popen +--------------------- +[(0,0),(1,1),(2,0)] +(1 row) +postgres=# +---- +|=== + + + + + + +=== radius + +[cols="145,378"] +|=== +h| 函数名称 h| radius +| 参数数据类型 | circle +| 函数返回值数据类型 | double precision +| 函数含义 | 求一个圆形的半径 +| 使用举例 +a| +[source,sql] +---- +postgres=# select radius(circle '<(0,0),2>'); + radius + -------- + 2 + (1 row) +postgres=# +---- +|=== + + + +=== slope + +[cols="145,378"] +|=== +h| 函数名称 h| slope +| 参数数据类型 | point,point +| 函数返回值数据类型 | double precision +| 函数含义 | 计算通过两个点的直线的斜率 +| 使用举例 +a| +[source,sql] +---- +postgres=# select slope(point '(0,0)', point '(2,1)'); + slope + ------- + 0.5 +(1 row) +postgres=# +---- +|=== + + + + +=== width + +[cols="145,378"] +|=== +h| 函数名称 h| width +| 参数数据类型 | double precision +| 函数返回值数据类型 | box +| 函数含义 | 计算box的horizontal size +| 使用举例 +a| +[source,sql] +---- +postgres=# select width(box '(1,2),(0,0)') ; +width +------- +1 +(1 row) +postgres=# +---- +|=== + + + + +=== box + +[cols="145,378"] +|=== +h| 函数名称 h| box +| 参数数据类型 | circle +| 函数返回值数据类型 | box +| 函数含义 | 计算圆内切的box +| 使用举例 +a| +[source,sql] +---- +postgres=# select box(circle '<(0,0),2>'); +box +------------------------------------------------------------------------------- +(1.414213562373095,1.414213562373095),(-1.414213562373095,-1.414213562373095) +(1 row) +postgres=# +---- +|=== + diff --git a/CN/modules/ROOT/pages/v4.5/2.adoc b/CN/modules/ROOT/pages/master/2.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/2.adoc rename to CN/modules/ROOT/pages/master/2.adoc diff --git a/CN/modules/ROOT/pages/v4.5/23.adoc b/CN/modules/ROOT/pages/master/23.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/23.adoc rename to CN/modules/ROOT/pages/master/23.adoc diff --git a/CN/modules/ROOT/pages/v4.5/3.adoc b/CN/modules/ROOT/pages/master/3.1.adoc similarity index 98% rename from CN/modules/ROOT/pages/v4.5/3.adoc rename to CN/modules/ROOT/pages/master/3.1.adoc index f3d75f01..2956fd53 100644 --- a/CN/modules/ROOT/pages/v4.5/3.adoc +++ b/CN/modules/ROOT/pages/master/3.1.adoc @@ -148,4 +148,4 @@ TIP: Docker运行IvorySQL时,需要添加额外参数,如 psql -d ivorysql - 现在可以开始使用IvorySQL啦!就是这么简单! -想要获得更多安装方式,请参考xref:v4.5/6.adoc[安装指南] \ No newline at end of file +想要获得更多安装方式,请参考xref:master/4.1.adoc[安装指南] diff --git a/CN/modules/ROOT/pages/v4.5/4.adoc b/CN/modules/ROOT/pages/master/3.2.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/4.adoc rename to CN/modules/ROOT/pages/master/3.2.adoc diff --git a/CN/modules/ROOT/pages/v4.5/5.adoc b/CN/modules/ROOT/pages/master/3.3.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/5.adoc rename to CN/modules/ROOT/pages/master/3.3.adoc diff --git a/CN/modules/ROOT/pages/v4.5/33.adoc b/CN/modules/ROOT/pages/master/33.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/33.adoc rename to CN/modules/ROOT/pages/master/33.adoc diff --git a/CN/modules/ROOT/pages/v4.5/6.adoc b/CN/modules/ROOT/pages/master/4.1.adoc similarity index 98% rename from CN/modules/ROOT/pages/v4.5/6.adoc rename to CN/modules/ROOT/pages/master/4.1.adoc index ec0ff9a1..c7bfc722 100644 --- a/CN/modules/ROOT/pages/v4.5/6.adoc +++ b/CN/modules/ROOT/pages/master/4.1.adoc @@ -14,7 +14,7 @@ IvorySQL安装方式包括以下5种: - <<源码安装>> - <> -本章将详细介绍每种方式的安装、运行及卸载过程。想要更快获得IvorySQL,请参阅xref:v4.5/3.adoc#快速开始[快速开始]。 +本章将详细介绍每种方式的安装、运行及卸载过程。想要更快获得IvorySQL,请参阅xref:master/3.1.adoc#快速开始[快速开始]。 同样,安装前请先创建一个用户,并赋予其root权限,安装、使用和卸载均以该用户执行。这里以ivorysql用户为例。 @@ -290,4 +290,4 @@ $ sudo rm -rf /opt/IvorySQL-4.5 ``` $ sudo dpkg -P IvorySQL-4.5 $ sudo rm -rf /opt/IvorySQL-4.5 -``` \ No newline at end of file +``` diff --git a/CN/modules/ROOT/pages/v4.5/7.adoc b/CN/modules/ROOT/pages/master/4.2.adoc similarity index 93% rename from CN/modules/ROOT/pages/v4.5/7.adoc rename to CN/modules/ROOT/pages/master/4.2.adoc index 359291e7..70ac6bf6 100644 --- a/CN/modules/ROOT/pages/v4.5/7.adoc +++ b/CN/modules/ROOT/pages/master/4.2.adoc @@ -8,9 +8,9 @@ == 主节点 === 安装并启动数据库 -yum源快速安装数据库,请参考xref:v4.5/3.adoc[快速安装]。 +yum源快速安装数据库,请参考xref:master/3.1.adoc#从yum源安装ivorysql数据库[从yum源安装ivorysql数据库]。 -想要获取更多安装方式,请参考xref:v4.5/6.adoc#安装指南[安装指南]。 +想要获取更多安装方式,请参考xref:master/4.1.adoc[安装指南]。 [NOTE] 主节点数据库需要安装并**启动** @@ -56,9 +56,9 @@ $ pg_ctl restart == 备节点 === 安装数据库 -Yum源快速安装数据库,请参考xref:v4.5/3.adoc#快速安装[快速安装]。 +Yum源快速安装数据库,请参考xref:master/3.1.adoc#从yum源安装ivorysql数据库[从yum源安装ivorysql数据库]。 -想要获取更多安装方式,请参考xref:v4.5/6.adoc#安装指南[安装指南]。 +想要获取更多安装方式,请参考xref:master/4.1.adoc[安装指南]。 [NOTE] 备节点数据库只需要安装,**不需要启动** @@ -173,4 +173,4 @@ ivorysql=# \l | | | | | | | | ivorysql=CTc/ivorysql test | ivorysql | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | (4 rows) -``` \ No newline at end of file +``` diff --git a/CN/modules/ROOT/pages/v4.5/8.adoc b/CN/modules/ROOT/pages/master/4.3.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/8.adoc rename to CN/modules/ROOT/pages/master/4.3.adoc diff --git a/CN/modules/ROOT/pages/v4.5/9.adoc b/CN/modules/ROOT/pages/master/4.4.adoc similarity index 99% rename from CN/modules/ROOT/pages/v4.5/9.adoc rename to CN/modules/ROOT/pages/master/4.4.adoc index aa9087fa..6171dfb8 100644 --- a/CN/modules/ROOT/pages/v4.5/9.adoc +++ b/CN/modules/ROOT/pages/master/4.4.adoc @@ -28,7 +28,7 @@ IvorySQL版本号由主要版本和次要版本组成。例如,IvorySQL 3.2 === 通过pg_dumpall升级数据 -传统的跨版本升级方法利用pg_dump/pg_dumpall逻辑备份到处数据库,然后在新版本中通过pg_restore进行还原。导出旧版本数据库时推荐使用新版本的pg_dump/pg_dumpall工具,可以利用最新的并行导出和还原功能,同时可以减少数据库膨胀问题。 +传统的跨版本升级方法利用pg_dump/pg_dumpall逻辑备份导出数据库,然后在新版本中通过pg_restore进行还原。导出旧版本数据库时推荐使用新版本的pg_dump/pg_dumpall工具,可以利用最新的并行导出和还原功能,同时可以减少数据库膨胀问题。 ​逻辑备份与还原非常简单但速度比较慢,停机时间取决于数据库的大小,因此适合中小型数据库的升级。 diff --git a/CN/modules/ROOT/pages/v4.5/10.adoc b/CN/modules/ROOT/pages/master/4.5.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/10.adoc rename to CN/modules/ROOT/pages/master/4.5.adoc diff --git a/CN/modules/ROOT/pages/v4.5/11.adoc b/CN/modules/ROOT/pages/master/5.1.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/11.adoc rename to CN/modules/ROOT/pages/master/5.1.adoc diff --git a/CN/modules/ROOT/pages/v4.5/12.adoc b/CN/modules/ROOT/pages/master/5.2.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/12.adoc rename to CN/modules/ROOT/pages/master/5.2.adoc diff --git a/CN/modules/ROOT/pages/v4.5/31.adoc b/CN/modules/ROOT/pages/master/6.1.1.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/31.adoc rename to CN/modules/ROOT/pages/master/6.1.1.adoc diff --git a/CN/modules/ROOT/pages/v4.5/30.adoc b/CN/modules/ROOT/pages/master/6.2.1.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/30.adoc rename to CN/modules/ROOT/pages/master/6.2.1.adoc diff --git a/CN/modules/ROOT/pages/master/6.3.1.adoc b/CN/modules/ROOT/pages/master/6.3.1.adoc new file mode 100644 index 00000000..4df8a918 --- /dev/null +++ b/CN/modules/ROOT/pages/master/6.3.1.adoc @@ -0,0 +1,44 @@ + +:sectnums: +:sectnumlevels: 5 + + += **功能概述** + +Oracle和IvorySQL中的 LIKE 语法是相同的,他们的区别在于表达式的类型,Oracle支持对数字、日期、字符串类型的列用 LIKE 关键字配合通配符来实现模糊查询。原生PostgreSQL只支持字符串类型,不支持日期、数字类型,IvorySQL通过扩展数据类型支持和操作符重载,实现了与 Oracle 兼容的 LIKE 操作符功能。 + +== 实现原理 + +PostgreSQL的字符串基本类型是text,所以 LIKE 是以text为基础,其他PostgreSQL类型隐式转换成text,不用创建opeartor就能自动转换;IvorySQL中oracle兼容的字符串类型是varchar2,因此创建一个varchar2的 LIKE 操作符,其他oracle的类型也通过隐式转换成varchar2实现不用创建操作符,也能使用 LIKE 操作符。 + +在之前实现oracle兼容数据类型时,IvorySQL做了integer,float8,float4 等一些数据类型到varchar2的隐式转换,没有直接到text的。因此实现这些兼容类型的 LIKE 操作符兼容,有两种方式。一种需要针对每个类型添加一个 LIKE 操作符,另一种是做一个基本的varchar2的 LIKE 操作符。在第二种实现方式中,IvorySQL针对float8,integer,number等已经做了向varchar2类型的隐式转换,这些数据类型可以和varchar2用同一个操作符,这样在创建操作符的时候只需要创建varchar2类型的 LIKE 操作符就可以。 + +=== 类型转换 + +可以通过以下SQL语句查看已经存在的类型隐式转换 +``` +-- 查询已存在的隐式转换路径(9503为varchar2的OID) +SELECT t1.typname AS source_type, t2.typname AS target_type +FROM pg_cast C +JOIN pg_type t1 ON C.castsource = t1.OID +JOIN pg_type t2 ON C.casttarget = t2.OID +WHERE C.casttarget = 9503; +``` +经过查看可得,需要进行兼容的类型全部都在该表中做了隐式转换,所以可以直接将这些类型转换为text类型然后进行模糊查询。 + +=== 核心函数实现 +```sql +CREATE OR REPLACE FUNCTION sys.varchar2like(varchar2, varchar2) +RETURNS bool AS $$ +SELECT $1::text LIKE $2::text; +$$ LANGUAGE SQL IMMUTABLE STRICT; + +CREATE OPERATOR ~~ ( + PROCEDURE = sys.varchar2like, + LEFTARG = varchar2, + RIGHTARG = varchar2 +); +``` +第一段代码定义了一个名为sys.varchar2like的函数,它接收两个varchar2类型的参数,通过将它们转换为PostgreSQL原生的text类型后执行标准的LIKE模式匹配,最终返回布尔值表示是否匹配。 +第二段代码创建了一个名为~~的操作符,它将使用前面定义的varchar2like函数作为实现,并指定该操作符左右两边的参数都必须是varchar2类型。 +这样就在IvorySQL中建立了一个与Oracle兼容的LIKE操作符,当用户使用~~操作符时,实际上是通过类型转换后调用PostgreSQL原生的LIKE功能来完成模式匹配,从而实现了Oracle的LIKE语义兼容。 \ No newline at end of file diff --git a/CN/modules/ROOT/pages/master/6.3.2.adoc b/CN/modules/ROOT/pages/master/6.3.2.adoc new file mode 100644 index 00000000..a172bed1 --- /dev/null +++ b/CN/modules/ROOT/pages/master/6.3.2.adoc @@ -0,0 +1,81 @@ + +:sectnums: +:sectnumlevels: 5 + + += **功能概述** + +IvorySQL提供了兼容Oracle的out参数功能,包括含有out参数的函数与过程、匿名块支持out参数、libpq支持out参数。 + +== 实现原理 + +=== 含有out参数的函数 + +对于pliSQL函数,在创建函数时,系统表pg_proc中存储函数参数为全部参数个数(包括OUT参数个数)及对应的参数数据类型。 + +在处理函数参数的interpret_function_parameter_list()函数中,根据参数模式,判断如果是IN OUT,则参数不能有默认值。 + +在make_return_stmt函数中,去掉如果发现有out参数报错的处理。 + +通过修改FuncnameGetCandidates函数,在函数查找时匹配包括out参数在内的所有参数。 + +函数编译时,构造一个row变量来容纳OUT参数变量和返回值变量。修改编译好的函数返回类型(function->fn_rettype)为RECORDOID。 + +函数执行时,在ExecInitFunc函数中调用新函数ExecInitFuncOutParams, 构造OUT参数计算节点,通过计算函数plisql_out_param将函数返回值和OUT参数值从tuple中分离,并且为OUT参数向外赋值。 + +=== 匿名块支持out参数 + +为了支持冒号占位符形式的绑定变量,修改ora_scan.l文件,添加语法,遇到冒号占位符返回ORAPARAM。在ora_gram.y文件中,在c_expr和赋值plassign_target的语法中,添加对ORAPARAM添加处理,构造一个OraParamRef节点。 + +新增 DO + USING 语法: +``` + DO [ LANGUAGE lang_name ] code [USING IN | OUT | IN OUT, ...] +``` +修改ora_gram.y文件,增加DO+USING语法支持。DoStmt结构体中增加 paramsmode 用于存储匿名块中的绑定变量模式等信息的列表。 + +对PBE过程的修改包括:exec_parse_message函数中,根据应用接口传过来的参数类型oid,识别出实参的模式;在exec_bind_message函数中,对于匿名块DO+USING,识别出USING后面参数的模式,向执行器传递参数信息。 + +含OUT参数匿名块的执行 + +1. 在PortalStart函数中对匿名块语句,调用CreateTupleDescFromParams函数,增加参数构造描述信息。 + +2. PLiSQL_function成员fn_prokind增加新值PROKIND_ANONYMOUS_BLOCK用来表示匿名块。 + +3. 在plisql_exec_function函数中,对有out参数的匿名块做判断,调用plisql_anonymous_return_out_parameter函数完成对OUT参数构造PLiSQL_row类型的变量,最后将row类型的变量求值当作匿名块函数的返回值。 + +=== libpq中调用含out参数的函数 + +修改Libpq以支持按位置和按参数名字绑定,涉及SQL端,PLiSQL端,libpq接口端。 + +1. SQL端:在服务器端实现系统函数 get_parameter_description,该函数根据SQL语句,返回变量名字与位置的关系。这个函数被用在libpq接口函数中。 + 返回的第一行name显示SQL类型,后面行依次显示占位符名字、位置信息。 + + ``` + ivorysql=# select * from get_parameter_description('insert into t values(:x, :y);'); + name | position + -------+---------- + false | 0 + :x | 1 + :y | 2 + (3 rows) + ``` + 对于匿名块语句,尚不支持。 + +2. PLiSQL端:主要是PL/iSQL块根据参数位置或参数名称调整参数内部标识。 + + 执行函数需要从绑定句柄中获取参数的值与类型的信息; + + 对out参数的返回列名称做一个特殊处理。如果是out参数,那么其列名称为_column_xxx,其中xxx是out参数的位置,从而根据绑定位置与返回的位置从结果集中给out参数赋值; + + 在PLiSQL执行端,根据参数名字出现的位置,调整名字转换成内部标识的变量,如$number。在返回到客户端的时候,发送描述信息给libpq, 从而达到返回的列名是由参数名字构造,LIBPQ端根据列名来给out参数赋值。 + +3. libpq接口端:提供准备、绑定、执行函数,这些函数与OCI接口相应函数类似。 + + 一般调用流程如下: + 使用IvyHandleAlloc分配语句句柄和错误句柄。 + 调用IvyStmtPrepare准备语句。 + 调用IvyBindByPos或IvyBindByName 绑定参数。 + 调用IvyStmtExecute 执行,可重复执行。 + 调用IvyFreeHandle 释放语句句柄和错误句柄。 + + 另外还实现了Ivyconnectdb,Ivystatus,Ivyexec,IvyresultStatus,IvyCreatePreparedStatement,IvybindOutParameterByPos,IvyexecPreparedStatement,IvyexecPreparedStatement2,Ivynfields,Ivyntuples,Ivyclear等一系列接口函数。 diff --git a/CN/modules/ROOT/pages/master/6.3.3.adoc b/CN/modules/ROOT/pages/master/6.3.3.adoc new file mode 100644 index 00000000..a4b9952f --- /dev/null +++ b/CN/modules/ROOT/pages/master/6.3.3.adoc @@ -0,0 +1,88 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += RowID + +== 目的 + +IvorySQL提供了兼容Oracle RowID的功能。RowID是一种伪列,在创建表时由数据库自动生成,对于数据库中的每一行,RowID 伪列返回该行的地址。 + +RowID 应当具备以下特性: + +|==== +| 1. 逻辑的标识每一行,且值唯一 +| 2. 可以通过ROWID快速查询和修改表的其他列,自身不能被插入和修改 +| 3. 用户可以控制是否开启此功能 +|==== + +== 实现说明 + +在IvorySQL中系统列 ctid 字段代表了数据行在表中的物理位置,也就是行标识(tuple identifier),由一对数值组成(块编号和行索引),可以通过ctid快速的查找表中的数据行,这样和Oracle的RowID行为很相似,但是ctid值有可能会改变(例如当update/ vacuum full时),因此ctid不适合作为一个长期的行标识。 + +我们选择了表的oid加一个序列值组成的复合类型来做为RowID值,其中的序列是系统列。如果RowID功能被开启,则在建表的同时创建一个名为table-id_rowid_seq 的序列。同时在heap_form_tuple构造函数中,为 HeapTupleHeaderData 的长度增加8个字节,并标识td->t_infomask = HEAP_HASROWID 位来表示rowid的存在。 + +在开启了ROWID的GUC参数或建表时带上 WITH ROWID 选项,或对普通表执行 ALTER TABLE … SET WITH ROWID 时会通过增加序列创建命令来创建一个序列。 +``` +/* + * Build a CREATE SEQUENCE command to create the sequence object, + * and add it to the list of things to be done before this CREATE/ALTER TABLE + */ + seqstmt = makeNode(CreateSeqStmt); + seqstmt->with_rowid = true; + seqstmt->sequence = makeRangeVar(snamespace, sname, -1); + seqstmt->options = lcons(makeDefElem("as", + (Node *) makeTypeNameFromOid(INT8OID, -1), + -1), + seqstmt->options); + seqstmt->options = lcons(makeDefElem("nocache", + NULL, + -1), + seqstmt->options); +``` + +同时为了快速通过RowID伪列查询到一行数据,默认会在表的RowID列上创建一个UNIQUE索引,以提供快速查询功能。 + +RowID列做为系统属性列其实现是通过在 heap.c 中新增一个系统列来实现的。 +``` +/* + * Compatible Oracle ROWID pseudo column. + */ +static const FormData_pg_attribute a7 = { + .attname = {"rowid"}, + .atttypid = ROWIDOID, + .attlen = -1, + .attnum = RowIdAttributeNumber, + .attcacheoff = -1, + .atttypmod = -1, + .attbyval = false, + .attalign = TYPALIGN_SHORT, + .attstorage = TYPSTORAGE_PLAIN, + .attnotnull = true, + .attislocal = true, +}; +``` + +在pg_class系统表中增加一个 bool 类型的字段 relhasrowid,用于标识建表时的 WITH ROWID选项,如果建表时带了WITH ROWID选项,则 relhasrowid为 t,否则为f。 +用户在执行 ALTER table … SET WITH ROWID/ WITHOUT ROWID 命令时,也会修改这个值。 + +``` + /* T if we generate ROWIDs for rows of rel */ + bool relhasrowid BKI_DEFAULT(f); +``` + +在RowID的存储方面,如果启用了RowID 伪列功能,则在插入表之前 heap_form_tuple函数会根据参数TupleDesc 中tdhasrowid 是否为true 在 HeapTupleHeaderData 中增加8个字节来存储序列值。 +在heap_prepare_insert 函数中获取序列的nextval值,存在HeapTupleHeader 相应的位置。 + +``` + if (relation->rd_rel->relhasrowid) + { + // Get the sequence next value + seqnum = nextval_internal(relation->rd_rowdSeqid, true); + // Set the HeapTupleHeader + HeapTupleSetRowId(tup, seqnum); + } +``` + + diff --git a/CN/modules/ROOT/pages/master/6.4.adoc b/CN/modules/ROOT/pages/master/6.4.adoc new file mode 100644 index 00000000..fcad85f5 --- /dev/null +++ b/CN/modules/ROOT/pages/master/6.4.adoc @@ -0,0 +1,126 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += GB18030 字符集服务端支持 + +== 目的 + +PostgreSQL 服务端提供了对 GB18030 字符集的全面支持。GB18030是中国国家标准,旨在包含所有汉字和多种少数民族文字,实现与Unicode的统一。在PostgreSQL中正确配置和使用GB18030字符集,对于处理和存储需要符合此标准的中文数据至关重要。 + +服务端 GB18030 支持应当具备以下特性: + +|==== +| 1. 支持 GB18030 作为服务端编码:initdb -E GB18030 可用,SHOW server_encoding 显示为 GB18030。 +| 2. 提供 GB18030 <-> UTF8 的双向转换。 +| 3. 支持多字节边界判定。 +|==== + +== 实现说明 + +=== initdb时通过-E指定GB18030或GB18030_2022 + +PostgreSQL已支持GB18030-2000版本作为客户端编码,通过扩展的方式支持GB18030_2022字符集与UTF的转换。 + +修改pg_enc来实现可指定GB18030作为服务端编码,PostgreSQL编码框架中增加底层函数以供pg内核调用。 + +设置一个全局变量is_load_gb18030_2022,默认为true,当用户指定-E选项时,在get_encoding_id中判断其设置的是否为gb18030_2022,如果是,将其字符串转为gb18030,然后将is_load_gb18030_2022 设为true,如果-E 选项为Gb18030,将其设为false。 + +在适当位置判断是否要加载插件,如果是,执行load_gb18030_2022,并将ivorysql.conf中的shared_preload_library添加gb18030_2022。 + +``` +if (encoding_name && *encoding_name) +{ + encoding_name_modify = pg_strdup(encoding_name); + if(pg_strcasecmp(encoding_name,"gb18030_2022") == 0) + { +    encoding_name_modify = pg_strdup("gb18030"); +    is_load_gb18030_2022 =  true; + } +   else if(pg_strcasecmp(encoding_name,"gb18030") == 0) +    is_load_gb18030_2022 = false; + +   if ((enc = pg_valid_server_encoding((const char *)encoding_name_modify)) >= 0) +    return enc; +} +``` + +=== 多字节处理 + +wchar.c,增加 GB18030 的函数指针: + +pg_gb180302wchar_with_len(const unsigned char *from, pg_wchar *to, int len) gb18030 -> wchar + +pg_wchar2gb18030_with_len(const pg_wchar *from, unsigned char *to, int len) wchar -> gb18030 + +pg_gb18030_mblen(const unsigned char *s):返回 1/2/4。 + +pg_gb18030_dsplen(const unsigned char *s):ASCII 显示宽度 1;其它按 1 处理(与UTF8一致)。 + +pg_gb18030_verifier(const unsigned char *s, int len):校验字节范围,拒绝非法序列。 + +=== 与客户端的交互 + +接收数据: 如果一个使用 UTF-8 编码的客户端连接上来,服务端在接收到数据后,会调用其内部的 utf8_to_gb18030 函数,将数据转换为 GB18030 格式,然后才进行验证和存储。 + +发送数据: 当该客户端执行 SELECT 查询时,服务端会从磁盘/内存中读取原生的 GB18030 数据,然后调用 gb18030_to_utf8 函数将其转换为 UTF-8 格式,最后再通过网络协议发送给客户端。 + +新增GB18030-2022.xml数据文件,通过perl脚本解析为map文件,提供 gb18030_to_utf8() 与 utf8_to_gb18030(),优先表驱动,覆盖不到的区间通过算法映射。 + +``` +static inline uint32 +unicode_to_utf8word(uint32 c) +{ + uint32 word; + + if (c <= 0x7F) + { + word = c; + } + else if (c <= 0x7FF) + { + word = (0xC0 | ((c >> 6) & 0x1F)) << 8; + word |= 0x80 | (c & 0x3F); + } + else if (c <= 0xFFFF) + { + word = (0xE0 | ((c >> 12) & 0x0F)) << 16; + word |= (0x80 | ((c >> 6) & 0x3F)) << 8; + word |= 0x80 | (c & 0x3F); + } + else + { + word = (0xF0 | ((c >> 18) & 0x07)) << 24; + word |= (0x80 | ((c >> 12) & 0x3F)) << 16; + word |= (0x80 | ((c >> 6) & 0x3F)) << 8; + word |= 0x80 | (c & 0x3F); + } + + return word; +} + +static uint32 +conv_18030_2022_to_utf8(uint32 code) +{ +#define conv18030(minunicode, mincode, maxcode) \ + if (code >= mincode && code <= maxcode) \ + return unicode_to_utf8word(gb_linear(code) - gb_linear(mincode) + minunicode) + + conv18030(0x0452, 0x8130D330, 0x8136A531); + conv18030(0x2643, 0x8137A839, 0x8138FD38); + conv18030(0x361B, 0x8230A633, 0x8230F237); + conv18030(0x3CE1, 0x8231D438, 0x8232AF32); + conv18030(0x4160, 0x8232C937, 0x8232F837); + conv18030(0x44D7, 0x8233A339, 0x8233C931); + conv18030(0x478E, 0x8233E838, 0x82349638); + conv18030(0x49B8, 0x8234A131, 0x8234E733); + conv18030(0x9FA6, 0x82358F33, 0x8336C738); + conv18030(0xE865, 0x8336D030, 0x84308534); + conv18030(0xFA2A, 0x84309C38, 0x84318537); + conv18030(0xFFE6, 0x8431A234, 0x8431A439); + conv18030(0x10000, 0x90308130, 0xE3329A35); + /* No mapping exists */ + return 0; +} +``` \ No newline at end of file diff --git a/CN/modules/ROOT/pages/v4.5/14.adoc b/CN/modules/ROOT/pages/master/7.1.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/14.adoc rename to CN/modules/ROOT/pages/master/7.1.adoc diff --git a/CN/modules/ROOT/pages/v4.5/26.adoc b/CN/modules/ROOT/pages/master/7.10.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/26.adoc rename to CN/modules/ROOT/pages/master/7.10.adoc diff --git a/CN/modules/ROOT/pages/v4.5/27.adoc b/CN/modules/ROOT/pages/master/7.11.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/27.adoc rename to CN/modules/ROOT/pages/master/7.11.adoc diff --git a/CN/modules/ROOT/pages/v4.5/28.adoc b/CN/modules/ROOT/pages/master/7.12.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/28.adoc rename to CN/modules/ROOT/pages/master/7.12.adoc diff --git a/CN/modules/ROOT/pages/v4.5/29.adoc b/CN/modules/ROOT/pages/master/7.13.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/29.adoc rename to CN/modules/ROOT/pages/master/7.13.adoc diff --git a/CN/modules/ROOT/pages/master/7.14.adoc b/CN/modules/ROOT/pages/master/7.14.adoc new file mode 100644 index 00000000..4e483b75 --- /dev/null +++ b/CN/modules/ROOT/pages/master/7.14.adoc @@ -0,0 +1,80 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += RowID + +== 目的 + +IvorySQL提供了兼容Oracle RowID的功能。RowID是一种伪列,在创建表时由数据库自动生成,对于数据库中的每一行,RowID 伪列返回该行的地址。 + +RowID 应当具备以下特性: + +|==== +| 1. 逻辑的标识每一行,且值唯一 +| 2. 可以通过ROWID快速查询和修改表的其他列,自身不能被插入和修改 +| 3. 用户可以控制是否开启此功能 +|==== + +== 功能开启 + +IvorySQL提供了多种方式来开启RowID功能。 + +=== 通过GUC参数开启 + +在IvorySQL 的兼容Oracle 模式下,可以通过 set ivorysql.default_with_rowids to on 来开启RowID,这个参数默认值为off。打开后创建的表,默认就带有了RowID列,可以通过 \d+ 表名 来查看。 + +``` +ivorysql=# show ivorysql.default_with_rowids; + ivorysql.default_with_rowids +------------------------------ + off +(1 row) +``` +``` +ivorysql=# create table t(a int); +CREATE TABLE +ivorysql=# \d+ t + Table "public.t" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Access method: heap +``` +=== 通过建表语句中增加 WITH ROWID 选项开启 + +用户可以选择在需要的表上带有这个选项,没有WITH ROWID选项,将会创建一个普通的表。 + +``` +ivorysql=# create table t2(a int) with rowid; +CREATE TABLE +ivorysql=# \d+ t2 + Table "public.t2" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Indexes: + "t2_16432_rowid_idx" btree (rowid) +Access method: heap +Has ROWID: yes +``` + +=== 通过对现有表ALTER TABLE … SET WITH ROWID开启 + +这种方式允许当一个普通表需要使用 ROWID 时,通过ATLER 命令去添加ROWID 列。 +也可以通过ALTER TABLE … SET WITHOUT ROWID命令去除RowID。 + +``` +ivorysql=# create table t3(a int); +CREATE TABLE +ivorysql=# alter table t3 set with rowid; +ALTER TABLE +ivorysql=# \d+ t3; + Table "public.t3" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Access method: heap +Has ROWID: yes +``` diff --git a/CN/modules/ROOT/pages/master/7.15.adoc b/CN/modules/ROOT/pages/master/7.15.adoc new file mode 100644 index 00000000..0de50f9e --- /dev/null +++ b/CN/modules/ROOT/pages/master/7.15.adoc @@ -0,0 +1,155 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += out参数 + +== 目的 + +IvorySQL提供了兼容Oracle的out参数功能,包括含有out参数的函数与过程、匿名块支持out参数、libpq支持out参数。 + +本文档旨在为使用人员介绍out参数的功能。 + +== 功能说明 + +IvorySQL提供了兼容Oracle的out参数功能,包括如下内容。 + +=== 含有out参数的函数 + +创建语法如下: +``` +CREATE [ OR REPLACE ] FUNCTION + name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) + [ RETURNS rettype + | RETURNS TABLE ( column_name column_type [, ...] ) ] + { LANGUAGE lang_name + | TRANSFORM { FOR TYPE type_name } [, ... ] + | WINDOW + | { IMMUTABLE | STABLE | VOLATILE } + | [ NOT ] LEAKPROOF + | { CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT } + | { [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER } + | PARALLEL { UNSAFE | RESTRICTED | SAFE } + | COST execution_cost + | ROWS result_rows + | SUPPORT support_function + | SET configuration_parameter { TO value | = value | FROM CURRENT } + | AS 'definition' + | AS 'obj_file', 'link_symbol' + | sql_body + } ... +``` +其中argmode可以是IN,OUT,INOUT(IN OUT),VARIADIC。如果不指定默认是IN。argmode也可以写在argname的后面。 + +不同于原生PG,兼容Oracle的out参数和返回值数据类型没有关联。IN OUT模式和OUT模式都不能有默认值。如果有out参数,则函数体中必须有RETURN语句。 + +=== 匿名块支持out参数 + +支持冒号占位符形式的绑定变量,例如: 1,:name。 + +新增新的DO+USING语法: DO [ LANGUAGE lang_name ] code [USING IN | OUT | IN OUT, ...] + +支持在libpq中按位置和按参数名字绑定变量,提供系统函数get_parameter_descr,该函数根据SQL语句,返回变量名字与位置的关系。 + +=== ibpq中调用含out参数的函数 + +libpq接口端提供准备、绑定、执行函数,这些函数与OCI相应函数类似。 + +使用流程为: +使用IvyHandleAlloc分配语句句柄和错误句柄。 +调用IvyStmtPrepare准备语句。 +调用IvyBindByPos或IvyBindByName 绑定参数。 +调用IvyStmtExecute 执行,可重复执行。 +调用IvyFreeHandle 释放语句句柄和错误句柄。 + +另外还实现了Ivyconnectdb,Ivystatus,Ivyexec,IvyresultStatus,IvyCreatePreparedStatement,IvybindOutParameterByPos,IvyexecPreparedStatement,IvyexecPreparedStatement2,Ivynfields,Ivyntuples,Ivyclear等一系列接口函数。 + +在源代码中 src/interfaces/libpq/ivytest 目录里可以找到示例程序。 + +== 测试用例 + +=== 含有out参数的函数 + +1. out参数和返回值数据类型没有关联 + + ``` + ivorysql=# create or replace function test_return_out(id integer,price out integer,name out varchar) return varchar + ivorysql-# as + ivorysql-# begin + ivorysql-# price := 20000; + ivorysql-# name := 'test a char out'; + ivorysql-# return 'welcome to QingDao'; + ivorysql-# end; + ivorysql-# / + CREATE FUNCTION + ``` + +2. IN OUT模式和OUT模式都不能有默认值 + + ``` + ivorysql=# create or replace function test_return_inout(id integer,price in out integer default 100,name out varchar) return varchar + ivorysql-# as + ivorysql-# begin + ivorysql-# price := 20000 + price; + ivorysql-# name := 'this is a test'; + ivorysql-# return 'welcome to QingDao'; + ivorysql-# end; + ivorysql-# / + ERROR: IN OUT formal parameters may have no default expressions + ``` + +3. 如果有out参数,并且函数返回类型不是void,则函数体中必须有RETURN语句 + + ``` + --if function's return type is non-void, the function body must has RETURN statement + --if there is no RETURN statement, the function can be created, but when it is called, + --an error is raised + ivorysql=# create or replace function f2(id integer,price out integer) return varchar + ivorysql-# as + ivorysql-# begin + ivorysql-# price := 2; + ivorysql-# end; + ivorysql-# / + CREATE FUNCTION + ivorysql=# declare + ivorysql-# a varchar(20); + ivorysql-# b int; + ivorysql-# begin + ivorysql-# a := f2(1, b); + ivorysql-# end; + ivorysql-# / + ERROR: Function returned without value + CONTEXT: PL/iSQL function f2(pg_catalog.int4,pg_catalog.int4) line 0 at RETURN + PL/iSQL function inline_code_block line 5 at assignment + ``` + +=== 匿名块支持out参数 + +1. 支持冒号占位符形式的绑定变量,新增DO+USING语法 + + ``` + ivorysql=# do $$ + ivorysql$# declare + ivorysql$# a int; + ivorysql$# begin + ivorysql$# :x := 1; + ivorysql$# :y := 2; + ivorysql$# end; $$ using out, out; + $1 | $2 + ----+---- + 1 | 2 + (1 row) + ``` + +2. 系统函数 get_parameter_descr + + ``` + ivorysql=# select * from get_parameter_description('insert into t values(:x,:y)'); + name | position + -------+---------- + false | 0 + :x | 1 + :y | 2 + (3 rows) + ``` diff --git a/CN/modules/ROOT/pages/v4.5/15.adoc b/CN/modules/ROOT/pages/master/7.2.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/15.adoc rename to CN/modules/ROOT/pages/master/7.2.adoc diff --git a/CN/modules/ROOT/pages/v4.5/16.adoc b/CN/modules/ROOT/pages/master/7.3.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/16.adoc rename to CN/modules/ROOT/pages/master/7.3.adoc diff --git a/CN/modules/ROOT/pages/v4.5/17.adoc b/CN/modules/ROOT/pages/master/7.4.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/17.adoc rename to CN/modules/ROOT/pages/master/7.4.adoc diff --git a/CN/modules/ROOT/pages/v4.5/18.adoc b/CN/modules/ROOT/pages/master/7.5.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/18.adoc rename to CN/modules/ROOT/pages/master/7.5.adoc diff --git a/CN/modules/ROOT/pages/v4.5/19.adoc b/CN/modules/ROOT/pages/master/7.6.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/19.adoc rename to CN/modules/ROOT/pages/master/7.6.adoc diff --git a/CN/modules/ROOT/pages/v4.5/20.adoc b/CN/modules/ROOT/pages/master/7.7.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/20.adoc rename to CN/modules/ROOT/pages/master/7.7.adoc diff --git a/CN/modules/ROOT/pages/v4.5/21.adoc b/CN/modules/ROOT/pages/master/7.8.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/21.adoc rename to CN/modules/ROOT/pages/master/7.8.adoc diff --git a/CN/modules/ROOT/pages/v4.5/22.adoc b/CN/modules/ROOT/pages/master/7.9.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/22.adoc rename to CN/modules/ROOT/pages/master/7.9.adoc diff --git a/CN/modules/ROOT/pages/v4.5/32.adoc b/CN/modules/ROOT/pages/master/8.adoc similarity index 93% rename from CN/modules/ROOT/pages/v4.5/32.adoc rename to CN/modules/ROOT/pages/master/8.adoc index d63cd5ac..7e8c2857 100644 --- a/CN/modules/ROOT/pages/v4.5/32.adoc +++ b/CN/modules/ROOT/pages/master/8.adoc @@ -3,7 +3,7 @@ :sectnumlevels: 5 :imagesdir: ./_images -= **IvorySQL社区协作流程** +== **IvorySQL社区协作流程** IvorySQL 社区采用一套 闭环式开源协作流程,确保从问题提出到版本发布,每一个环节都能闭合反馈、持续改进。这一流程鼓励用户与开发者形成良性互动,让社区开发始终围绕实际需求持续演进。 @@ -45,7 +45,7 @@ image::p23.jpg[] 通过这套完整的闭环协作机制,IvorySQL 实现了问题响应 → 开发贡献 → 质量保障 → 发布反馈的全流程闭合,推动项目持续健康演进。 -= **IvorySQL社区贡献指南** +== **IvorySQL社区贡献指南** IvorySQL是一个由核心开发团队主导、社区共同维护的开源项目。我们欢迎用户、贡献者和维护者的加入,共同推动IvorySQL的发展。如果您希望看到您的代码或文档更改被添加到IvorySQL并出现在将来的版本中,本节的内容介绍是您需要知道的。 @@ -61,7 +61,7 @@ IvorySQL是一个由核心开发团队主导、社区共同维护的开源项目 📢 请务必阅读并遵守我们的 https://github.com/IvorySQL/IvorySQL/blob/master/CODE_OF_CONDUCT_CN.md[IvorySQL社区行为准则]。 -== 注册Github账号 +=== 注册Github账号 无论您是要提交 Issue、参与讨论,还是贡献代码与文档,您都需要使用 GitHub 账号登录并与 IvorySQL 项目进行交互。 @@ -69,11 +69,11 @@ IvorySQL是一个由核心开发团队主导、社区共同维护的开源项目 IvorySQL源码托管在github: 。 -== 用户 +=== 用户 作为用户,您在使用 IvorySQL 过程中扮演着重要角色。我们鼓励您: -=== 反馈问题与需求 +==== 反馈问题与需求 * 发现 Bug、性能缺陷或文档不准确? @@ -81,7 +81,7 @@ IvorySQL源码托管在github: 。 如果您准备向社区上报 Bug 或者提交需求,请在 IvorySQL 社区对应的仓库上提交 Issue,并参考Issue xref:./33.adoc[提交指南]。 -=== 参与社区讨论 +==== 参与社区讨论 * 通过 https://lists.ivorysql.org[邮件列表]进行讨论 @@ -89,11 +89,11 @@ IvorySQL源码托管在github: 。 * 在 微信、Discord等聊天群参与技术交流 -== 贡献者 +=== 贡献者 我们欢迎代码、文档、测试等各类贡献。 -=== 签署CLA +==== 签署CLA 在提交代码或文档贡献之前,为了确保代码合法合规,个人或企业贡献者需要签署贡献者许可协议(CLA)。签署CLA是IvorySQL社区接受贡献的必要条件,以确保您的贡献被合法分发。请根据下列链接下载CLA进行签署并将签署后的CLA发送至 cla@ivorysql.org。 * https://www.ivorysql.org/zh-CN/assets/files/individual_cla-a81f001209eb5ce0f8ea7c3be4cc69b5.pdf[个人贡献者] @@ -101,7 +101,7 @@ IvorySQL源码托管在github: 。 未签署CLA的Pull Request将无法进入评审阶段。 -=== 找到您感兴趣的项目 +==== 找到您感兴趣的项目 我们将仓库划分为多个子项目,您可以从如下列表中找到感兴趣的项目及其代码仓库 @@ -119,17 +119,17 @@ IvorySQL源码托管在github: 。 |https://github.com/IvorySQL/ivorysql-wasm[Ivorysql_wasm] | 负责IvorySQL在线易用体验网站的开发和维护 |=== -=== 给自己分配Issue +==== 给自己分配Issue 您可以将自己创建的Issue或者愿意处理的Issue分配给自己。 只需要在评论框内输入/assign,机器人就会将问题分配给您。 每个 Issue 下面可能已经有参与者的交流和讨论,如果您感兴趣,也可以在评论框中发表自己的意见参与 Issue 讨论。 -=== 开发与提交Pull Request +==== 开发与提交Pull Request 对于提交一个PR应该保持一个功能,或者一个bug提交一次。禁止多个功能一次提交。 -==== Fork仓库 +===== Fork仓库 前往项目主页,点击Fork按钮,将IvorySQL项目Fork到您自己的GitHub账户中。 -==== 编码 +===== 编码 使用如下命令将项目克隆到本地进行开发: @@ -139,7 +139,7 @@ git checkout -b feature/your-feature-name 在提交代码前,请确保通过回归测试 -==== 创建一个Pull Request并提交 +===== 创建一个Pull Request并提交 打开你 Fork 的仓库: https://github.com/$user/IvorySQL.git @@ -156,25 +156,25 @@ leave a comment 点击Create pull request 按钮即可提交。 -== 维护者 +=== 维护者 维护者负责进行IvorySQL代码的管理,PR审查,主导版本发布与IvorySQL发展方向。 -=== 社区规划 +==== 社区规划 * 制定版本规划和 Roadmap * 跟踪与评估社区需求 * 维护公开的 TODO 列表 -=== 代码管理 +==== 代码管理 * 参与 Pull Request 评审 * 审查安全问题,保障项目健康 -=== 流程与治理机制 +==== 流程与治理机制 * 优化协作机制(代码贡献指南、PR 模板等) * 建立漏洞响应机制和行为守则 -== 致谢 -感谢每一位参与 IvorySQL 的开发者、文档编辑者、测试人员和使用者。正是有了你们的付出,IvorySQL 才能不断成长!我们欢迎所有人参与 IvorySQL 社区贡献,我们的目标是发展一个由贡献者组成的活跃、健康的社区。 \ No newline at end of file +=== 致谢 +感谢每一位参与 IvorySQL 的开发者、文档编辑者、测试人员和使用者。正是有了你们的付出,IvorySQL 才能不断成长!我们欢迎所有人参与 IvorySQL 社区贡献,我们的目标是发展一个由贡献者组成的活跃、健康的社区。 diff --git a/CN/modules/ROOT/pages/v4.5/24.adoc b/CN/modules/ROOT/pages/master/9.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/24.adoc rename to CN/modules/ROOT/pages/master/9.adoc diff --git a/CN/modules/ROOT/pages/v4.5/welcome.adoc b/CN/modules/ROOT/pages/master/welcome.adoc similarity index 100% rename from CN/modules/ROOT/pages/v4.5/welcome.adoc rename to CN/modules/ROOT/pages/master/welcome.adoc diff --git a/EN/antora.yml b/EN/antora.yml index ec9b2b8e..db0c4c6a 100644 --- a/EN/antora.yml +++ b/EN/antora.yml @@ -1,10 +1,10 @@ -name: ivorysql-doc -title: IvorySQL -version: v4.5 -start_page: v4.5/welcome.adoc -asciidoc: - attributes: - source-language: asciidoc@ - table-caption: false -nav: -- modules/ROOT/nav.adoc +name: ivorysql-doc +title: IvorySQL +version: master +start_page: master/welcome.adoc +asciidoc: + attributes: + source-language: asciidoc@ + table-caption: false +nav: +- modules/ROOT/nav.adoc diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index 370e6783..bcaec0c1 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -1,38 +1,45 @@ -* xref:v4.5/welcome.adoc[Welcome] -* xref:v4.5/1.adoc[Release] -* xref:v4.5/2.adoc[About] +* xref:master/welcome.adoc[Welcome] +* xref:master/1.adoc[Release] +* xref:master/2.adoc[About] * Getting Started with IvorySQL -** xref:v4.5/3.adoc[Quick Start] -** xref:v4.5/4.adoc[Monitoring] -** xref:v4.5/5.adoc[Maintenance] +** xref:master/3.1.adoc[Quick Start] +** xref:master/3.2.adoc[Monitoring] +** xref:master/3.3.adoc[Maintenance] * IvorySQL Advanced Feature -** xref:v4.5/6.adoc[Installation] -** xref:v4.5/7.adoc[Building Cluster] -** xref:v4.5/8.adoc[Developer] -** xref:v4.5/9.adoc[Operation Management] -** xref:v4.5/10.adoc[Migration] +** xref:master/4.1.adoc[Installation] +** xref:master/4.2.adoc[Building Cluster] +** xref:master/4.3.adoc[Developer] +** xref:master/4.4.adoc[Operation Management] +** xref:master/4.5.adoc[Migration] * IvorySQL Ecosystem -** xref:v4.5/11.adoc[PostGIS] -** xref:v4.5/12.adoc[pgvector] +** xref:master/5.1.adoc[PostGIS] +** xref:master/5.2.adoc[pgvector] * IvorySQL Architecture Design ** Query Processing -*** xref:v4.5/31.adoc[Dual Parser] +*** xref:master/6.1.1.adoc[Dual Parser] ** Compatibility Framework -*** xref:v4.5/30.adoc[initdb Process] +*** xref:master/6.2.1.adoc[initdb Process] +** Compatibility Features +*** xref:master/6.3.1.adoc[like] +*** xref:master/6.3.3.adoc[RowID] +*** xref:master/6.3.2.adoc[OUT Parameter] +** xref:master/6.4.adoc[GB18030 Character Set] * List of Oracle compatible features -** xref:v4.5/14.adoc[1、Ivorysql frame design] -** xref:v4.5/15.adoc[2、GUC Framework] -** xref:v4.5/16.adoc[3、Case conversion] -** xref:v4.5/17.adoc[4、Dual-mode design] -** xref:v4.5/18.adoc[5、Compatible with Oracle like] -** xref:v4.5/19.adoc[6、Compatible with Oracle anonymous block] -** xref:v4.5/20.adoc[7、Compatible with Oracle functions and stored procedures] -** xref:v4.5/21.adoc[8、Built-in data types and built-in functions] -** xref:v4.5/22.adoc[9、Added Oracle compatibility mode ports and IP] -** xref:v4.5/26.adoc[10、XML Function] -** xref:v4.5/27.adoc[11、Compatible with Oracle sequence] -** xref:v4.5/28.adoc[12、Package] -** xref:v4.5/29.adoc[13、Invisible Columns] -* xref:v4.5/23.adoc[Community contribution] -* xref:v4.5/24.adoc[Tool Reference] -* xref:v4.5/25.adoc[FAQ] \ No newline at end of file +** xref:master/7.1.adoc[1、Ivorysql frame design] +** xref:master/7.2.adoc[2、GUC Framework] +** xref:master/7.3.adoc[3、Case conversion] +** xref:master/7.4.adoc[4、Dual-mode design] +** xref:master/7.5.adoc[5、Compatible with Oracle like] +** xref:master/7.6.adoc[6、Compatible with Oracle anonymous block] +** xref:master/7.7.adoc[7、Compatible with Oracle functions and stored procedures] +** xref:master/7.8.adoc[8、Built-in data types and built-in functions] +** xref:master/7.9.adoc[9、Added Oracle compatibility mode ports and IP] +** xref:master/7.10.adoc[10、XML Function] +** xref:master/7.11.adoc[11、Compatible with Oracle sequence] +** xref:master/7.12.adoc[12、Package] +** xref:master/7.13.adoc[13、Invisible Columns] +** xref:master/7.14.adoc[14、RowID Column] +** xref:master/7.15.adoc[15、OUT Parameter] +* xref:master/8.adoc[Community contribution] +* xref:master/9.adoc[Tool Reference] +* xref:master/10.adoc[FAQ] diff --git a/EN/modules/ROOT/pages/v4.5/1.adoc b/EN/modules/ROOT/pages/master/1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/1.adoc rename to EN/modules/ROOT/pages/master/1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/25.adoc b/EN/modules/ROOT/pages/master/10.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/25.adoc rename to EN/modules/ROOT/pages/master/10.adoc diff --git a/EN/modules/ROOT/pages/v4.5/2.adoc b/EN/modules/ROOT/pages/master/2.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/2.adoc rename to EN/modules/ROOT/pages/master/2.adoc diff --git a/EN/modules/ROOT/pages/v4.5/3.adoc b/EN/modules/ROOT/pages/master/3.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/3.adoc rename to EN/modules/ROOT/pages/master/3.1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/4.adoc b/EN/modules/ROOT/pages/master/3.2.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/4.adoc rename to EN/modules/ROOT/pages/master/3.2.adoc diff --git a/EN/modules/ROOT/pages/v4.5/5.adoc b/EN/modules/ROOT/pages/master/3.3.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/5.adoc rename to EN/modules/ROOT/pages/master/3.3.adoc diff --git a/EN/modules/ROOT/pages/v4.5/6.adoc b/EN/modules/ROOT/pages/master/4.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/6.adoc rename to EN/modules/ROOT/pages/master/4.1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/7.adoc b/EN/modules/ROOT/pages/master/4.2.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/7.adoc rename to EN/modules/ROOT/pages/master/4.2.adoc diff --git a/EN/modules/ROOT/pages/v4.5/8.adoc b/EN/modules/ROOT/pages/master/4.3.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/8.adoc rename to EN/modules/ROOT/pages/master/4.3.adoc diff --git a/EN/modules/ROOT/pages/v4.5/9.adoc b/EN/modules/ROOT/pages/master/4.4.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/9.adoc rename to EN/modules/ROOT/pages/master/4.4.adoc diff --git a/EN/modules/ROOT/pages/v4.5/10.adoc b/EN/modules/ROOT/pages/master/4.5.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/10.adoc rename to EN/modules/ROOT/pages/master/4.5.adoc diff --git a/EN/modules/ROOT/pages/v4.5/11.adoc b/EN/modules/ROOT/pages/master/5.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/11.adoc rename to EN/modules/ROOT/pages/master/5.1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/12.adoc b/EN/modules/ROOT/pages/master/5.2.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/12.adoc rename to EN/modules/ROOT/pages/master/5.2.adoc diff --git a/EN/modules/ROOT/pages/v4.5/31.adoc b/EN/modules/ROOT/pages/master/6.1.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/31.adoc rename to EN/modules/ROOT/pages/master/6.1.1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/30.adoc b/EN/modules/ROOT/pages/master/6.2.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/30.adoc rename to EN/modules/ROOT/pages/master/6.2.1.adoc diff --git a/EN/modules/ROOT/pages/master/6.3.1.adoc b/EN/modules/ROOT/pages/master/6.3.1.adoc new file mode 100644 index 00000000..05934ffb --- /dev/null +++ b/EN/modules/ROOT/pages/master/6.3.1.adoc @@ -0,0 +1,54 @@ + +:sectnums: +:sectnumlevels: 5 + + += **Functional Overview** + +The LIKE syntax in Oracle and IvorySQL is identical. Their difference lies in the expression types: Oracle supports using the LIKE keyword with wildcards for fuzzy queries on columns of numeric, date, and string types. Native PostgreSQL only supports string types, not date or numeric types. IvorySQL achieves Oracle-compatible LIKE operator functionality by extending data type support and operator overloading. + +== Implementation Principle + +In PostgreSQL, the fundamental string type is text, so LIKE is text-based. Other PostgreSQL types implicitly convert to text, enabling automatic conversion without creating operators. In IvorySQL, the Oracle-compatible string type is varchar2. Therefore, a LIKE operator for varchar2 is created, and other Oracle types also utilize the LIKE operator by implicitly converting to varchar2 without requiring additional operator creation. + +In the previous implementation of Oracle-compatible data types, IvorySQL established implicit conversions from certain data types (such as integer, float8, float4) to varchar2, but not directly to text. + +To achieve LIKE operator compatibility for these types, there are two approaches: + +1、Add a separate LIKE operator for each individual type. + +2、Implement a base LIKE operator for varchar2. + +In the second approach, since IvorySQL already supports implicit conversions from float8, integer, number, etc., to varchar2, these data types can share the same operator. Thus, only a single LIKE operator for varchar2 needs to be created. + +=== Type Conversion + +You can use the following SQL statement to check existing implicit type conversions. +``` +-- Check existing implicit conversion paths (where 9503 is the OID of varchar2) +SELECT t1.typname AS source_type, t2.typname AS target_type +FROM pg_cast C +JOIN pg_type t1 ON C.castsource = t1.OID +JOIN pg_type t2 ON C.casttarget = t2.OID +WHERE C.casttarget = 9503; +``` +After reviewing, it can be observed that all the types requiring compatibility have implicit conversions defined in this table. Therefore, these types can be directly converted to the text type for fuzzy query operations. + +=== Core Function Implementation +```sql +CREATE OR REPLACE FUNCTION sys.varchar2like(varchar2, varchar2) +RETURNS bool AS $$ +SELECT $1::text LIKE $2::text; +$$ LANGUAGE SQL IMMUTABLE STRICT; + +CREATE OPERATOR ~~ ( + PROCEDURE = sys.varchar2like, + LEFTARG = varchar2, + RIGHTARG = varchar2 +); +``` +The first code segment defines a function named sys.varchar2like, which accepts two parameters of type varchar2. By converting them to PostgreSQL's native text type, it performs standard LIKE pattern matching and ultimately returns a boolean value indicating whether the match is successful. + +The second code segment creates an operator named ~~, which uses the previously defined varchar2like function as its implementation. It specifies that both the left and right operands of this operator must be of type varchar2. + +This establishes an Oracle-compatible LIKE operator in IvorySQL. When users employ the ~~ operator, it essentially invokes PostgreSQL's native LIKE functionality after type conversion, thereby achieving semantic compatibility with Oracle's LIKE behavior. \ No newline at end of file diff --git a/EN/modules/ROOT/pages/master/6.3.2.adoc b/EN/modules/ROOT/pages/master/6.3.2.adoc new file mode 100644 index 00000000..5707e1e3 --- /dev/null +++ b/EN/modules/ROOT/pages/master/6.3.2.adoc @@ -0,0 +1,82 @@ + +:sectnums: +:sectnumlevels: 5 + + += **Functional Overview** + +IvorySQL provides Oracle-compatible OUT parameter functionality, including functions and procedures with OUT parameters, support for OUT parameters in anonymous blocks, and libpq support for OUT parameters. + +== Implementation Principles + +=== Functions with OUT Parameters + +For PL/pgSQL functions, when creating a function, the system table pg_proc stores the total number of parameters (including OUT parameters) and their corresponding data types. + +In the interpret_function_parameter_list() function, which processes function parameters, it checks the parameter mode. If the mode is IN OUT, the parameter cannot have a default value. + +In the make_return_stmt function, the error handling for detecting OUT parameters has been removed. + +By modifying the FuncnameGetCandidates function, function lookup now matches all parameters, including OUT parameters. + +During function compilation, a row variable is constructed to hold OUT parameter variables and the return value variable. The compiled function's return type (function->fn_rettype) is modified to RECORDOID. + +During function execution, the ExecInitFunc function calls the new ExecInitFuncOutParams function to construct OUT parameter computation nodes. The plisql_out_param function separates the function return value and OUT parameter values from the tuple and assigns values to the OUT parameters externally. + +=== Support for OUT Parameters in Anonymous Blocks + +To support binding variables in the form of colon placeholders, the ora_scan.l file was modified to add syntax that returns ORAPARAM when a colon placeholder is encountered. In the ora_gram.y file, handling for ORAPARAM was added to the c_expr and plassign_target assignment syntax, constructing an OraParamRef node. + +New DO + USING syntax was added: +``` + DO [ LANGUAGE lang_name ] code [USING IN | OUT | IN OUT, ...] +``` +The ora_gram.y file was modified to support the DO+USING syntax. The DoStmt structure now includes a paramsmode field to store a list of binding variable modes and other information for anonymous blocks. + +Modifications to the PBE (Parse, Bind, Execute) process include: +In the exec_parse_message function, the parameter mode is identified based on the parameter type OID passed from the application interface. In the exec_bind_message function, for anonymous blocks with DO+USING, the parameter modes following USING are identified, and parameter information is passed to the executor. + +Execution of anonymous blocks with OUT parameters: +1. In the PortalStart function, for anonymous block statements, the CreateTupleDescFromParams function is called to construct parameter description information. + +2. A new value, PROKIND_ANONYMOUS_BLOCK, was added to the PLiSQL_function member fn_prokind to indicate an anonymous block. + +3. In the plisql_exec_function function, anonymous blocks with OUT parameters are evaluated. The plisql_anonymous_return_out_parameter function is called to construct a PLiSQL_row type variable for OUT parameters, and the evaluated row type variable is used as the return value of the anonymous block function. + +=== Calling Functions with OUT Parameters in libpq + +The libpq interface was modified to support binding by position and by parameter name, involving changes to the SQL layer, PL/pgSQL layer, and libpq interface layer. + +1. SQL Layer: A system function get_parameter_description was implemented on the server side. This function returns the relationship between variable names and their positions based on the SQL statement. It is used in libpq interface functions. + +The first row of the result shows the SQL type in the name column, followed by rows displaying placeholder names and position information. + +``` +ivorysql=# select * from get_parameter_description('insert into t values(:x, :y);'); + name | position +-------+---------- + false | 0 + :x | 1 + :y | 2 +(3 rows) +``` +Support for anonymous block statements is not yet implemented. + +2. PL/pgSQL Layer: The PL/pgSQL block adjusts the internal identification of parameters based on their position or name. + +The execution function retrieves parameter values and type information from the binding handle. + +For OUT parameters, a special handling of return column names is applied. If a parameter is an OUT parameter, its column name is formatted as _column_xxx, where xxx is the position of the OUT parameter. This allows assigning values to OUT parameters from the result set based on the binding position and return position. + +At the PLiSQL execution layer, parameter names are converted to internal identifiers (e.g., $number) based on their position. When returning to the client, description information is sent to libpq, ensuring that the returned column names are constructed from parameter names. The libpq side assigns values to OUT parameters based on these column names. + +3. libpq Interface Layer: Provides functions for preparing, binding, and executing statements, similar to the corresponding OCI functions. + +The general calling process is as follows: +Use IvyHandleAlloc to allocate statement and error handles. +Call IvyStmtPrepare to prepare the statement. +Call IvyBindByPos or IvyBindByName to bind parameters. +Call IvyStmtExecute to execute, which can be repeated. +Call IvyFreeHandle to release the statement and error handles. + +Additionally, a series of interface functions have been implemented, including Ivyconnectdb, Ivystatus, Ivyexec, IvyresultStatus, IvyCreatePreparedStatement, IvybindOutParameterByPos, IvyexecPreparedStatement, IvyexecPreparedStatement2, Ivynfields, Ivyntuples, and Ivyclear. \ No newline at end of file diff --git a/EN/modules/ROOT/pages/master/6.3.3.adoc b/EN/modules/ROOT/pages/master/6.3.3.adoc new file mode 100644 index 00000000..c5cb7f52 --- /dev/null +++ b/EN/modules/ROOT/pages/master/6.3.3.adoc @@ -0,0 +1,88 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += RowID + +== Objective + +IvorySQL provides Oracle-compatible RowID functionality. RowID is a pseudo-column automatically generated by the database when a table is created, returning the address of each row in the database. + +RowID should have the following characteristics: + +|==== +| 1. Logically identifies each row with a unique value +| 2. Allows quick querying and modification of other columns in the table via ROWID, but cannot be inserted or modified itself +| 3. Users can control whether this feature is enabled +|==== + +== Implementation Principles + +In IvorySQL, the system column ctid represents the physical location of a data row in a table, also known as the tuple identifier, which consists of a pair of values (block number and row index). The ctid allows for quick lookup of data rows in a table, behaving similarly to Oracle's RowID. However, the ctid value may change (e.g., during UPDATE or VACUUM FULL), making it unsuitable as a long-term row identifier. + +We chose a composite type consisting of the table's OID and a sequence value as the RowID value, where the sequence is a system column. If the RowID functionality is enabled, a sequence named table-id_rowid_seq is created simultaneously with the table. Additionally, in the heap_form_tuple constructor, the length of HeapTupleHeaderData is increased by 8 bytes, and the td->t_infomask = HEAP_HASROWID bit is set to indicate the presence of the RowID. + +When the RowID functionality is enabled via the GUC parameter, or by the WITH ROWID option in table creation, or by executing ALTER TABLE … SET WITH ROWID on an existing table, a sequence is created by adding a sequence creation command. +``` +/* + * Build a CREATE SEQUENCE command to create the sequence object, + * and add it to the list of things to be done before this CREATE/ALTER TABLE + */ + seqstmt = makeNode(CreateSeqStmt); + seqstmt->with_rowid = true; + seqstmt->sequence = makeRangeVar(snamespace, sname, -1); + seqstmt->options = lcons(makeDefElem("as", + (Node *) makeTypeNameFromOid(INT8OID, -1), + -1), + seqstmt->options); + seqstmt->options = lcons(makeDefElem("nocache", + NULL, + -1), + seqstmt->options); +``` + +To enable fast querying of a row using the RowID pseudo-column, a `UNIQUE` index is automatically created on the RowID column of the table by default to provide efficient query performance. + +The implementation of the RowID column as a system attribute column is achieved by adding a new system column in heap.c. +``` +/* + * Compatible Oracle ROWID pseudo column. + */ +static const FormData_pg_attribute a7 = { + .attname = {"rowid"}, + .atttypid = ROWIDOID, + .attlen = -1, + .attnum = RowIdAttributeNumber, + .attcacheoff = -1, + .atttypmod = -1, + .attbyval = false, + .attalign = TYPALIGN_SHORT, + .attstorage = TYPSTORAGE_PLAIN, + .attnotnull = true, + .attislocal = true, +}; +``` + +A boolean field `relhasrowid` has been added to the `pg_class` system table to indicate whether the `WITH ROWID` option was specified during table creation. If the `WITH ROWID` option is included when creating a table, `relhasrowid` is set to `t`; otherwise, it is set to `f`. +This value is also updated when a user executes the `ALTER TABLE … SET WITH ROWID` or `ALTER TABLE … SET WITHOUT ROWID` command. + +``` + /* T if we generate ROWIDs for rows of rel */ + bool relhasrowid BKI_DEFAULT(f); +``` + +Regarding RowID storage, if the RowID pseudo-column functionality is enabled, the `heap_form_tuple` function will add 8 bytes to the `HeapTupleHeaderData` to store the sequence value, depending on whether `tdhasrowid` in the `TupleDesc` parameter is `true`. +In the `heap_prepare_insert` function, the `nextval` of the sequence is obtained and stored in the corresponding position in the `HeapTupleHeader`. + +``` + if (relation->rd_rel->relhasrowid) + { + // Get the sequence next value + seqnum = nextval_internal(relation->rd_rowdSeqid, true); + // Set the HeapTupleHeader + HeapTupleSetRowId(tup, seqnum); + } +``` + + diff --git a/EN/modules/ROOT/pages/master/6.4.adoc b/EN/modules/ROOT/pages/master/6.4.adoc new file mode 100644 index 00000000..05776583 --- /dev/null +++ b/EN/modules/ROOT/pages/master/6.4.adoc @@ -0,0 +1,127 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += Server-Side Support for the GB18030 Character Set + +== Objective + +PostgreSQL provides comprehensive server-side support for the GB18030 character set. GB18030 is a Chinese national standard designed to include all Chinese characters and various minority scripts, aiming for alignment with Unicode. Proper configuration and use of the GB18030 character set within PostgreSQL are essential for processing and storing Chinese data that must comply with this standard. + +Server-side GB18030 support should provide the following features: +|==== +| 1. Support for GB18030 as a server encoding: initdb -E GB18030 is available, and SHOW server_encoding displays GB18030. +| 2. Provide bidirectional conversion between GB18030 and UTF8. +| 3. Support for multibyte character boundary determination. +|==== + +== Implementation Details + +=== Specifying GB18030 or GB18030_2022 with the -E Option during initdb + +PostgreSQL has historically supported the GB18030-2000 standard as a client-side encoding. Support for conversion between the GB18030_2022 character set and UTF-8 is provided via an extension. + +To enable GB18030 as a server encoding, modifications are made to pg_enc, and new low-level functions are added to the PostgreSQL encoding framework for invocation by the core system. + +A global variable, is_load_gb18030_2022, is introduced with a default value of true. When the -E option is used during initdb, the get_encoding_id function checks the specified encoding name. If the name is gb18030_2022, it is internally mapped to the gb18030 encoding ID, and the is_load_gb18030_2022 flag is set to true. If the -E option is GB18030, the flag is set to false. + +At the appropriate stage in the startup process, the system checks this flag to determine if the extension should be loaded. If required, the load_gb18030_2022 function is executed, and the gb18030_2022 extension is added to the shared_preload_libraries parameter in ivorysql.conf. +``` +if (encoding_name && *encoding_name) +{ + encoding_name_modify = pg_strdup(encoding_name); + if(pg_strcasecmp(encoding_name,"gb18030_2022") == 0) + { +    encoding_name_modify = pg_strdup("gb18030"); +    is_load_gb18030_2022 =  true; + } +   else if(pg_strcasecmp(encoding_name,"gb18030") == 0) +    is_load_gb18030_2022 = false; + +   if ((enc = pg_valid_server_encoding((const char *)encoding_name_modify)) >= 0) +    return enc; +} +``` + +=== Multibyte Character Handling + +Function pointers for GB18030 are added in wchar.c: + +pg_gb180302wchar_with_len(const unsigned char *from, pg_wchar *to, int len) gb18030 -> wchar + +pg_wchar2gb18030_with_len(const pg_wchar *from, unsigned char *to, int len) wchar -> gb18030 + +pg_gb18030_mblen(const unsigned char *s):Returns 1/2/4. + +pg_gb18030_dsplen(const unsigned char *s):Calculates the display width of a character. ASCII characters have a width of 1, while others are also treated as having a width of 1 . + +pg_gb18030_verifier(const unsigned char *s, int len):Verifies that a byte sequence is a valid GB18030 character, rejecting illegal sequences. + +=== Client-Server Interaction + +Receiving Data + +When a client using UTF-8 encoding connects to the server, the server, upon receiving data, invokes its internal utf8_to_gb18030 function. This converts the data to the GB18030 format, which is then validated and stored. + +Sending Data + +When the same client executes a SELECT query, the server reads the native GB18030 data from disk or memory. It then calls the gb18030_to_utf8 function to convert the data to UTF-8 format before sending it to the client via the network protocol. + +A new data file, GB18030-2022.xml, is introduced. This file is parsed by a Perl script to generate mapping files that provide the logic for the gb18030_to_utf8() and utf8_to_gb18030() conversion functions. The implementation prioritizes a table-driven approach, falling back to algorithmic mapping for ranges not covered by the tables. +``` +static inline uint32 +unicode_to_utf8word(uint32 c) +{ + uint32 word; + + if (c <= 0x7F) + { + word = c; + } + else if (c <= 0x7FF) + { + word = (0xC0 | ((c >> 6) & 0x1F)) << 8; + word |= 0x80 | (c & 0x3F); + } + else if (c <= 0xFFFF) + { + word = (0xE0 | ((c >> 12) & 0x0F)) << 16; + word |= (0x80 | ((c >> 6) & 0x3F)) << 8; + word |= 0x80 | (c & 0x3F); + } + else + { + word = (0xF0 | ((c >> 18) & 0x07)) << 24; + word |= (0x80 | ((c >> 12) & 0x3F)) << 16; + word |= (0x80 | ((c >> 6) & 0x3F)) << 8; + word |= 0x80 | (c & 0x3F); + } + + return word; +} + +static uint32 +conv_18030_2022_to_utf8(uint32 code) +{ +#define conv18030(minunicode, mincode, maxcode) \ + if (code >= mincode && code <= maxcode) \ + return unicode_to_utf8word(gb_linear(code) - gb_linear(mincode) + minunicode) + + conv18030(0x0452, 0x8130D330, 0x8136A531); + conv18030(0x2643, 0x8137A839, 0x8138FD38); + conv18030(0x361B, 0x8230A633, 0x8230F237); + conv18030(0x3CE1, 0x8231D438, 0x8232AF32); + conv18030(0x4160, 0x8232C937, 0x8232F837); + conv18030(0x44D7, 0x8233A339, 0x8233C931); + conv18030(0x478E, 0x8233E838, 0x82349638); + conv18030(0x49B8, 0x8234A131, 0x8234E733); + conv18030(0x9FA6, 0x82358F33, 0x8336C738); + conv18030(0xE865, 0x8336D030, 0x84308534); + conv18030(0xFA2A, 0x84309C38, 0x84318537); + conv18030(0xFFE6, 0x8431A234, 0x8431A439); + conv18030(0x10000, 0x90308130, 0xE3329A35); + /* No mapping exists */ + return 0; +} +``` \ No newline at end of file diff --git a/EN/modules/ROOT/pages/v4.5/14.adoc b/EN/modules/ROOT/pages/master/7.1.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/14.adoc rename to EN/modules/ROOT/pages/master/7.1.adoc diff --git a/EN/modules/ROOT/pages/v4.5/26.adoc b/EN/modules/ROOT/pages/master/7.10.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/26.adoc rename to EN/modules/ROOT/pages/master/7.10.adoc diff --git a/EN/modules/ROOT/pages/v4.5/27.adoc b/EN/modules/ROOT/pages/master/7.11.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/27.adoc rename to EN/modules/ROOT/pages/master/7.11.adoc diff --git a/EN/modules/ROOT/pages/v4.5/28.adoc b/EN/modules/ROOT/pages/master/7.12.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/28.adoc rename to EN/modules/ROOT/pages/master/7.12.adoc diff --git a/EN/modules/ROOT/pages/v4.5/29.adoc b/EN/modules/ROOT/pages/master/7.13.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/29.adoc rename to EN/modules/ROOT/pages/master/7.13.adoc diff --git a/EN/modules/ROOT/pages/master/7.14.adoc b/EN/modules/ROOT/pages/master/7.14.adoc new file mode 100644 index 00000000..c9555aa7 --- /dev/null +++ b/EN/modules/ROOT/pages/master/7.14.adoc @@ -0,0 +1,79 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += RowID + +== Objective + +IvorySQL provides Oracle-compatible RowID functionality. RowID is a pseudo-column automatically generated by the database when a table is created, returning the address of each row in the database. + +RowID should have the following characteristics: + +|==== +| 1. Logically identifies each row with a unique value +| 2. Allows quick querying and modification of other columns in the table via ROWID, but cannot be inserted or modified itself +| 3. Users can control whether this feature is enabled +|==== + +== Enable the functionality +IvorySQL provides multiple ways to enable the RowID functionality. + +=== Enable the functionality through GUC parameters + +In IvorySQL's Oracle-compatible mode, the RowID functionality can be enabled by setting ivorysql.default_with_rowids to on. The default value for this parameter is off. Once enabled, tables created will automatically include a RowID column, which can be viewed using `\d+ table_name`. + +``` +ivorysql=# show ivorysql.default_with_rowids; + ivorysql.default_with_rowids +------------------------------ + off +(1 row) +``` +``` +ivorysql=# create table t(a int); +CREATE TABLE +ivorysql=# \d+ t + Table "public.t" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Access method: heap +``` +=== Enable the functionality by adding the `WITH ROWID` option in the table creation statement. + +Users can choose to include this option for tables that require it; without the `WITH ROWID` option, a regular table will be created. + +``` +ivorysql=# create table t2(a int) with rowid; +CREATE TABLE +ivorysql=# \d+ t2 + Table "public.t2" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Indexes: + "t2_16432_rowid_idx" btree (rowid) +Access method: heap +Has ROWID: yes +``` + +=== Enable the functionality by executing the command `ALTER TABLE … SET WITH ROWID` on an existing table. + +This approach allows a regular table to add a ROWID column using the `ALTER` command when ROWID functionality is needed. +The ROWID can also be removed using the `ALTER TABLE … SET WITHOUT ROWID` command. + +``` +ivorysql=# create table t3(a int); +CREATE TABLE +ivorysql=# alter table t3 set with rowid; +ALTER TABLE +ivorysql=# \d+ t3; + Table "public.t3" + Column | Type | Collation | Nullable | Default | Invisible | Storage | Compression | Stats target | Description +--------+-----------------+-----------+----------+---------+-----------+---------+-------------+--------------+------------- + a | pg_catalog.int4 | | | | | plain | | | +Access method: heap +Has ROWID: yes +``` diff --git a/EN/modules/ROOT/pages/master/7.15.adoc b/EN/modules/ROOT/pages/master/7.15.adoc new file mode 100644 index 00000000..d7b6498f --- /dev/null +++ b/EN/modules/ROOT/pages/master/7.15.adoc @@ -0,0 +1,149 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += out parameter + +== Objective + +IvorySQL provides Oracle-compatible OUT parameter functionality, including functions and procedures with OUT parameters, support for OUT parameters in anonymous blocks, and libpq support for OUT parameters. + +This document aims to introduce the functionality of OUT parameters to users. + +== Function descriptions + +IvorySQL provides Oracle-compatible OUT parameter functionality, including the following features. + +=== functions with OUT parameters + +Syntax: +``` +CREATE [ OR REPLACE ] FUNCTION + name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) + [ RETURNS rettype + | RETURNS TABLE ( column_name column_type [, ...] ) ] + { LANGUAGE lang_name + | TRANSFORM { FOR TYPE type_name } [, ... ] + | WINDOW + | { IMMUTABLE | STABLE | VOLATILE } + | [ NOT ] LEAKPROOF + | { CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT } + | { [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER } + | PARALLEL { UNSAFE | RESTRICTED | SAFE } + | COST execution_cost + | ROWS result_rows + | SUPPORT support_function + | SET configuration_parameter { TO value | = value | FROM CURRENT } + | AS 'definition' + | AS 'obj_file', 'link_symbol' + | sql_body + } ... +``` +The argmode can be IN, OUT, INOUT (IN OUT), or VARIADIC. If not specified, the default is IN. The argmode can also be written after the argname. + +Unlike native PostgreSQL, Oracle-compatible OUT parameters are not associated with the return value data type. Neither IN OUT nor OUT modes can have default values. If there are OUT parameters and the function's return type is not void, the function body must include a RETURN statement. + +=== support for OUT parameters in anonymous blocks + +Supports binding variables in the form of colon placeholders, such as :1, :name. + +Added new DO+USING syntax: DO [ LANGUAGE lang_name ] code [USING IN | OUT | IN OUT, ...] + +Supports binding variables in libpq by position and by parameter name, providing the system function get_parameter_description, which returns the relationship between variable names and their positions based on the SQL statement. + +=== calling functions with OUT parameters in libpq + +The libpq interface provides functions for preparing, binding, and executing statements, which are similar to the corresponding OCI functions. +The usage process is as follows: + +Use IvyHandleAlloc to allocate statement and error handles. +Call IvyStmtPrepare to prepare the statement. +Call IvyBindByPos or IvyBindByName to bind parameters. +Call IvyStmtExecute to execute, which can be repeated. +Call IvyFreeHandle to release the statement and error handles. + +Additionally, a series of interface functions have been implemented, including Ivyconnectdb, Ivystatus, Ivyexec, IvyresultStatus, IvyCreatePreparedStatement, IvybindOutParameterByPos, IvyexecPreparedStatement, IvyexecPreparedStatement2, Ivynfields, Ivyntuples, and Ivyclear. + +Example programs can be found in the src/interfaces/libpq/ivytest directory of the source code. + +== test examples + +=== functions with OUT parameters +1. OUT parameters are not associated with the return value data type +``` +ivorysql=# create or replace function test_return_out(id integer,price out integer,name out varchar) return varchar +ivorysql-# as +ivorysql-# begin +ivorysql-# price := 20000; +ivorysql-# name := 'test a char out'; +ivorysql-# return 'welcome to QingDao'; +ivorysql-# end; +ivorysql-# / +CREATE FUNCTION +``` + +2. Neither IN OUT nor OUT modes can have default values +``` +ivorysql=# create or replace function test_return_inout(id integer,price in out integer default 100,name out varchar) return varchar +ivorysql-# as +ivorysql-# begin +ivorysql-# price := 20000 + price; +ivorysql-# name := 'this is a test'; +ivorysql-# return 'welcome to QingDao'; +ivorysql-# end; +ivorysql-# / +ERROR: IN OUT formal parameters may have no default expressions +``` + +3. If there are OUT parameters and the function's return type is not void, the function body must include a RETURN statement. +``` +--if function's return type is non-void, the function body must has RETURN statement +--if there is no RETURN statement, the function can be created, but when it is called, +--an error is raised +ivorysql=# create or replace function f2(id integer,price out integer) return varchar +ivorysql-# as +ivorysql-# begin +ivorysql-# price := 2; +ivorysql-# end; +ivorysql-# / +CREATE FUNCTION +ivorysql=# declare +ivorysql-# a varchar(20); +ivorysql-# b int; +ivorysql-# begin +ivorysql-# a := f2(1, b); +ivorysql-# end; +ivorysql-# / +ERROR: Function returned without value +CONTEXT: PL/iSQL function f2(pg_catalog.int4,pg_catalog.int4) line 0 at RETURN +PL/iSQL function inline_code_block line 5 at assignment +``` + +=== support OUT parameters in anonymous block +1. Supports binding variables in the form of colon placeholders and new DO+USING syntax +``` +ivorysql=# do $$ +ivorysql$# declare +ivorysql$# a int; +ivorysql$# begin +ivorysql$# :x := 1; +ivorysql$# :y := 2; +ivorysql$# end; $$ using out, out; + $1 | $2 +----+---- + 1 | 2 +(1 row) +``` +2. system function get_parameter_descr() +``` +ivorysql=# select * from get_parameter_description('insert into t values(:x,:y)'); + name | position +-------+---------- + false | 0 + :x | 1 + :y | 2 +(3 rows) +``` + + diff --git a/EN/modules/ROOT/pages/v4.5/15.adoc b/EN/modules/ROOT/pages/master/7.2.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/15.adoc rename to EN/modules/ROOT/pages/master/7.2.adoc diff --git a/EN/modules/ROOT/pages/v4.5/16.adoc b/EN/modules/ROOT/pages/master/7.3.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/16.adoc rename to EN/modules/ROOT/pages/master/7.3.adoc diff --git a/EN/modules/ROOT/pages/v4.5/17.adoc b/EN/modules/ROOT/pages/master/7.4.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/17.adoc rename to EN/modules/ROOT/pages/master/7.4.adoc diff --git a/EN/modules/ROOT/pages/v4.5/18.adoc b/EN/modules/ROOT/pages/master/7.5.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/18.adoc rename to EN/modules/ROOT/pages/master/7.5.adoc diff --git a/EN/modules/ROOT/pages/v4.5/19.adoc b/EN/modules/ROOT/pages/master/7.6.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/19.adoc rename to EN/modules/ROOT/pages/master/7.6.adoc diff --git a/EN/modules/ROOT/pages/v4.5/20.adoc b/EN/modules/ROOT/pages/master/7.7.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/20.adoc rename to EN/modules/ROOT/pages/master/7.7.adoc diff --git a/EN/modules/ROOT/pages/v4.5/21.adoc b/EN/modules/ROOT/pages/master/7.8.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/21.adoc rename to EN/modules/ROOT/pages/master/7.8.adoc diff --git a/EN/modules/ROOT/pages/v4.5/22.adoc b/EN/modules/ROOT/pages/master/7.9.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/22.adoc rename to EN/modules/ROOT/pages/master/7.9.adoc diff --git a/EN/modules/ROOT/pages/v4.5/23.adoc b/EN/modules/ROOT/pages/master/8.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/23.adoc rename to EN/modules/ROOT/pages/master/8.adoc diff --git a/EN/modules/ROOT/pages/v4.5/24.adoc b/EN/modules/ROOT/pages/master/9.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/24.adoc rename to EN/modules/ROOT/pages/master/9.adoc diff --git a/EN/modules/ROOT/pages/v4.5/welcome.adoc b/EN/modules/ROOT/pages/master/welcome.adoc similarity index 100% rename from EN/modules/ROOT/pages/v4.5/welcome.adoc rename to EN/modules/ROOT/pages/master/welcome.adoc