GVKun编程网logo

postgresql 中的几个 timeout参数 用法说明

8

在这篇文章中,我们将为您详细介绍postgresql中的几个timeout参数用法说明的内容。此外,我们还会涉及一些关于centos7下源码编译安装php支持PostgreSQLpostgresql手

在这篇文章中,我们将为您详细介绍postgresql 中的几个 timeout参数 用法说明的内容。此外,我们还会涉及一些关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、Postgres 超时 (Timeout) 详解、PostgreSQL 13 配置参数archive_timeout、PostgreSQL 13 配置参数authentication_timeout的知识,以帮助您更全面地了解这个主题。

本文目录一览:

postgresql 中的几个 timeout参数 用法说明

postgresql 中的几个 timeout参数 用法说明

  项目招商找A5 快速获取精准代理名单

这篇文章主要介绍了postgresql中的几个timeout参数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。

今天整理了下 postgresql 几个 timeout 参数

select version();
                         version                        
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit
(1 row)
select *
from pg_settings ps
where 1=1
and ps.name like '%timeout%'
;
        name         | setting | unit |              category              |                    short_desc                     |       extra_desc       | context | vartype | source | min_val | max_val  | enumvals | boot_val | reset_val | sourcefile | sourceline | pending_restart
-------------------------------------+---------+------+--------------------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------+-----------+---------+---------+---------+------------+----------+----------+-----------+------------+------------+-----------------
 archive_timeout           | 0    | s  | Write-Ahead Log / Archiving                 | Forces a switch to the next WAL file if a new file has not been started within N seconds. |                   | sighup  | integer | default | 0    | 1073741823 |     | 0    | 0     |      |      | f
 authentication_timeout       | 60   | s  | Connections and Authentication / Security and Authentication | Sets the maximum allowed time to complete client authentication.             |                   | sighup  | integer | default | 1    | 600    |     | 60    | 60    |      |      | f
 checkpoint_timeout         | 300   | s  | Write-Ahead Log / Checkpoints                | Sets the maximum time between automatic WAL checkpoints.                 |                   | sighup  | integer | default | 30   | 86400   |     | 300   | 300    |      |      | f
 deadlock_timeout          | 1000  | ms  | Lock Management                       | Sets the time to wait on a lock before checking for deadlock.               |                   | superuser | integer | default | 1    | 2147483647 |     | 1000   | 1000   |      |      | f
 idle_in_transaction_session_timeout | 0    | ms  | Client Connection Defaults / Statement Behavior       | Sets the maximum allowed duration of any idling transaction.               | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f
 lock_timeout            | 0    | ms  | Client Connection Defaults / Statement Behavior       | Sets the maximum allowed duration of any wait for a lock.                 | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f
 statement_timeout          | 0    | ms  | Client Connection Defaults / Statement Behavior       | Sets the maximum allowed duration of any statement.                    | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f
 wal_receiver_timeout        | 60000  | ms  | Replication / Standby Servers                | Sets the maximum wait time to receive data from the primary.               |                   | sighup  | integer | default | 0    | 2147483647 |     | 60000  | 60000   |      |      | f
 wal_sender_timeout         | 60000  | ms  | Replication / Sending Servers                | Sets the maximum time to wait for WAL replication.                    |                   | sighup  | integer | default | 0    | 2147483647 |     | 60000  | 60000   |      |      | f
(9 rows)

 

下面简单介绍下这几个参数

archive_timeout控制服务器周期性地切换到一个新的 WAL 段文件,通俗的讲,就是定时归档。

authentication_timeout完成服务器认证的最长时间,如果在这个时间内没有完成认证,服务器将关闭连接。

checkpoint_timeout自动 WAL 检查点之间的最长时间,增大这个参数会使数据库崩溃后恢复的时间加长。

deadlock_timeout进行死锁检测之前在一个锁上等待的总时间

idle_in_transaction_session_timeout空闲事务超时。终止任何已经闲置超过这个参数所指定的时间(以毫秒计)的打开事务的会话。 这使得该会话所持有的任何锁被释放,并且其所持有的连接槽可以被重用, 它也允许只对这个事务可见的元组被清理。

lock_timeout锁等待超时。语句在试图获取表、索引、行或其他数据库对象上的锁时等到超过指定的毫秒数,该语句将被中止。不推荐在postgresql.conf中设置。

statement_timeout控制语句执行时长,单位是ms。超过设定值,该语句将被中止。

不推荐在postgresql.conf中设置,如非要设置,应该设置一个较大值。

wal_receiver_timeout中止处于非活动状态超过指定毫秒数的复制链接。这对于正在接收的后备服务器检测主服务器崩溃或网络断开有用。设置为0会禁用超时机制。这个参数只能在postgresql.conf文件中或在服务器命令行上设置。默认值是 60 秒。

wal_sender_timeout中断那些停止活动超过指定毫秒数的复制连接。这对发送服务器检测一个后备机崩溃或网络中断有用。设置为0将禁用该超时机制。这个参数只能在postgresql.conf文件中或在服务器命令行上设置。默认值是 60 秒。

补充:Postgresql数据库修改deadlock_timeout参数

某产品线提出要将Postgresql测试库中 deadlock_timeout 参数 修改为1s

该库平时不在自己手中维护,故实际操作步骤如下

(1)确定数据库安装所属用户

查看下都有哪些账户,可能是postgresql使用的

bash-4.1$ cd /home
bash-4.1$ ls
aquota.user enterprisedb lost+found prouser puppet

 

(2)确定数据库安装路径:

bash-4.1$ ps -ef | grep post 查看服务进程,找到应用安装目录 /opt/app/PostgresPlus/9.2AS/

1500 1891 1 0 2018 ? 01:01:47 /opt/app/PostgresPlus/9.2AS/bin/edb-postgres -D /DATA/data_utl

(3)切换到 enterprisedb 用户,并登陆数据库

bash-4.1$ su - enterprisedb
bash-4.1$ psql -U enterprisedb
psql (9.2.14.31)
Type “help” for help.

 

查看当前该参数配置 3s

edb=# show deadlock_timeout;

deadlock_timeout

3s(1 row)

(4)查看该参数

1pending_restart —boolean— true if the value has been changed in the configuration file but needs a restart; or false otherwise.

即该参数为实时生效型参数

(5)尝试使用

1test=# alter system set deadlock_timeout=‘1s';

报错如下:

ERROR: syntax error at or near “system”LINE 1:

alter system set deadlock_timeout=‘1s';

查询到解释:

alter system 命令 只对 9.4以后的版本 的版本有效,

(6)尝试执行

1set deadlock_timeout=‘1s'

edb=# show deadlock_timeout;

显示为1s

但是其余用户登录路,发现该参数依然为 3s

----即该方法为session级别设置,类似于oracle的alter session set

(7) 尝试修改 pg配置文件,进入/DATA/data_utl 路径修改

bash-4.1$ pwd
/DATA/data_utl
bash-4.1$ ls
base pgbin pg_ident.conf pg_notify pg_stat_tmp pg_twophase postgresql.conf postmaster.opts
dbms_pipe pg_clog pg_log pg_serial pg_subtrans PG_VERSION postgresql.conf.20191119 postmaster.pid
global pg_hba.conf pg_multixact pg_snapshots pg_tblspc pg_xlog postgresql.conf.bak utlp.sql
vi postgresql.conf

 

将其中 deadlock_timeout 配置修改为1s

(8)重新加载数据库

bash-4.1$ ./pg_ctl reloadserver signaled

(9)查看该参数已生效

edb=# show deadlock_timeout;
deadlock_timeout
1s
(1 row)

 

退出

1edb=# \q

第9步也可通过重启数据库生效

停止指令:

1./pg_ctl stop -m fast

启动指令:

1./pg_ctl -D /DATA/data_utl start

文章来源:

来源地址:https://www.jb51.net/article/204221.htm

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 yy@haotui.cn 举报,一经查实,本站将立刻删除。

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

1. 下载源码

$ mkdir /usr/downloads
$ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz
$ tar -xvf php-5.6.20.tar.gz
$ mv php-5.6.20 /usr/local/src
$ cd !$ & cd php-5.6.20
登录后复制

2. 阅读安装指导

$ ls -also
$ less README
$ less INSTALL
登录后复制

3. 安装依赖包

$ yum install apr apr-util apr-devel apr-util-devel prce lynx
登录后复制

4. 安装httpd

$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz
$ tar -xvf httpd-2.4.20.tar.gz
$ cd httpd-2.4.20
$ ./configure \
--prefix=/usr/local/programs/apache2 \
--enable-rewrite \
--enable-so \
--enable-headers \
--enable-expires \
--with-mpm=worker \
--enable-modules=most \
--enable-deflate \
--enable-module=shared
$ make
$ make install
$ cd /usr/local/programs/apache2
$ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本
$ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/
$ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置
## 将apache加入系统服务
vi /etc/rc.d/rc.local
```
/usr/local/programs/apache2/bin/apachectl start
```
$ cat /etc/rc.local
登录后复制

4. 安装postgresql

立即学习“PHP免费学习笔记(深入)”;

$ yum install readline-devel  ## 安装readline依赖
$ cd /usr/downloads
$ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2
$ tar -xvf postgresql-9.5.0.tar.bz2
$ cd postgresql-9.5.0
$ ./configure --prefix=/usr/local/programs/postgresql
$ make
$ su
$ make install
$ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库
$ cd /usr/local/programs/postgresql
$ bin/psql --version  ## 检查运行情况
## 开始对postgresql的配置
$ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge
``` 
PATH=/usr/local/programs/postgresql:$PATH
export PATH
```
$ source /etc/profile ## 更新环境变量

## 增加用户和其他文件夹
$ adduser postgres
$ passwd postgres 
$ mkdir /usr/local/programs/postgresql/logs
$ mkdir /usr/local/programs/postgresql/data
$ chown postgres /usr/local/programs/postgresql/data
$ su - postgres

## 初始化数据库
$ ./bin/initdb -D ./data
$ ./bin/createdb test
$ ./bin/psql test
## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下
$ ./bin/postgres -D ./data >./logs/start-log-1.log 2>&1 &
$ ./bin/psql --list  ##列出数据库
## ok,安装完成

## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做
## 编辑数据库配置及权限文件:
$ vi /usr/local/programs/postgresql/data/postgresql.conf   ## 数据库配置文件
$ chown postgres postgresql.conf
$ chmod 644 postgresql.conf
$ vi /usr/local/programs/postgresql/data/pg_hba.conf   ## 权限文件
$ vi /usr/local/programs/postgresql/data/pg_ident.conf

## 设置开机自启动:
$ vi /etc/rc.d/rc.local    ## 添加如下内容
```
/usr/local/programs/postgresql/bin/postgresql start
```
登录后复制

5. 安装php

## 源码已经在第一步中下载,现在开始安装:
$ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel
$ ./configure \
--prefix=/usr/local/programs/php \
--with-apxs2=/usr/local/programs/apache2/bin/apxs \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-zlib-dir \
--enable-mbstring \
--with-pgsql=/usr/local/programs/postgresql \
--with-pdo-pgsql=/usr/local/programs/postgresql 
$ make
$ make test
> Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt]  XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
> Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt]  XFAIL REASON: See Bug #49184
> Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt]  XFAIL REASON: Padding is not implemented yet
> zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
> zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
>Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt]  XFAIL REASON: bug is not fixed yet

## 查阅官方的bug,发现:
> id=66582: status : Closed. Fixed in master (PHP7)
> id=42718: status : Assigned
> id=42718: reference to id=49184, unsolved for many years
## 那就不关心了,直接装吧
$ make install
> You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path

## 那就按它说的设置吧
$ cp php.ini-development /usr/local/programs/php/lib/php.ini
```
include_path = ".;/usr/local/programs/php/lib/php"

## 然后,编辑httpd的设置,确保其能正确解析php文件
```
...
LoadModule php5_module modules/libphp5.so
...
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5

...
<ifmodule dir_module>
    DirectoryIndex index.html index.php
</ifmodule>     
```

## 重启httpd,测试
$ cd /usr/local/programs/apache2
$ bin/httpd -h
$ bin/httpd -k stop
$ bin/httpd -f conf/httpd.conf
## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧
$ vi htdocs/index.php
```
<?php phpinfo(); ?>
```
$ curl http://localhost/index.php |grep postgresql
#ok
登录后复制

后续应该做的事

* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Postgres 超时 (Timeout) 详解

Postgres 超时 (Timeout) 详解

原文地址 https://www.bytebase.com/blog/postgres-timeout/

PostgreSQL 提供各种超时 (Timeout) 设置,通过控制某些进程的持续时间来帮助管理和优化数据库操作。这些超时对于确保系统的稳定性和性能至关重要,尤其是在高流量或复杂查询的环境中。让我们一一回顾。

(一)语句超时 (statement_timeout)
statement_timeout 设置了单个查询允许执行的最长时间限制。如果查询超过了这个时间限制,PostgreSQL 将自动终止查询并返回错误信息。

ERROR:  canceling statement due to statement timeout
错误:由于语句超时而取消语句

如果单个 simple-Query 消息中出现多个 SQL 语句,则超时将分别应用于每个语句。statement_timeout 可有效防止长时间运行的查询占用过多资源或导致数据库出现性能问题。

(二)锁超时 (lock_timeout)
lock_timeout 控制一个事务为获得数据库对象(如表或行)上的锁而等待的时间,然后才会放弃并返回错误。

ERROR:  canceling statement due to lock timeout
错误:由于锁超时而取消语句

在 Postgres 中,等待获取资源锁的事务会阻塞需要在同一资源上获取冲突锁的传入事务。对于获取重量级锁(如运行 DDL 语句)的事务,建议设置 lock_timeout。常见的做法是创建一个单独的 Postgres 用户来运行 DDL,并为该用户设置一个较短的 lock_timeout。

ALTER ROLE ddl_user SET lock_timeout = 10000; -- 10 秒

(三)事务会话空闲超时 (idle_in_transaction_session_timeout)
idle_in_transaction_session_timeout 控制会话在事务中空闲的最长时间。如果会话在事务中的空闲时间超过指定的超时时间,PostgreSQL 将自动终止会话并回滚正在进行的事务。

ERROR:  terminating connection due to idle-in-transaction timeout
错误:由于事务中的空闲超时而终止连接

假设您有一个应用程序,在等待用户输入或执行一些与数据库无关的处理时,偶尔会让事务处于进行状态。如果一个事务处于进行和空闲状态的时间过长,它可能会持有表或行上的锁,从而阻止其他事务访问这些资源。通过设置 idle_in_transaction_session_timeout 可以自动终止这些空闲会话,确保资源不会被不必要地占用。即使没有重要的锁,一个进行中的事务会阻止清理( vacumm)已经被删除,但在当前事务仍然可见的元组;因此,长时间处于空闲状态会导致表膨胀。

(四)空闲会话超时 (idle_session_timeout)
idle_session_timeout 控制会话在被自动终止前的最长空闲时间。与 idle_in_transaction_session_timeout 不同的是,idle_session_timeout 只适用于在事务中处于空闲状态的会话,而 idle_session_timeout 则适用于任何处于空闲状态的会话,无论它是否在事务中。

ERROR:  terminating connection due to idle session timeout
错误:由于空闲会话超时而终止连接

在使用连接池或其他中间件时要小心,因为这样的层可能不会对意外的连接关闭做出很好的反应。好的做法是为交互式处理创建一个单独的 Postgres 用户,并相应地设置 idle_session_timeout。

ALTER ROLE interactive_user SET idle_session_timeout = 600000; -- 10 分钟

(五)事务超时 (transaction_timeout)

即将发布的 Postgres 17 版本将引入新的 transaction_timeout。从文档中可以看到
在一个事务中终止任何超过指定时间的会话。该限制既适用于显式事务(以 BEGIN 开始),也适用于与单条语句相对应的隐式事务。
一个典型的网络服务由 3 个主要部分组成:

  • 网络服务器
  • 应用程序服务器
  • 数据库服务器

为防止长时间连接,通常会在网络服务器和应用程序服务器上设置连接超时。当网络服务器/应用服务器已经终止连接时,再处理事务就太浪费了。在引入事务超时(transaction_timeout)之前,没有防止长时间事务的可靠方法。即使同时设置了 statement_timeout 和 idle_in_transaction_session_timeout,如果事务是由短语句和中间的短暂停顿组成的,那么该事务仍然是开放的。
你可能想知道,为什么 PostgreSQL 花了这么长时间才推出一个直接的事务超时功能 -- 迟到总比不到好 !顺便说一句,MySQL 也没有这个功能 。

参考资料:
官方文档 (https://www.postgresql.org/docs/current/runtime-config-client...)
pgsql-hackers 关于引入 transaction_timeout 的讨论 (https://www.postgresql.org/message-id/flat/f508267d1ba8f0bfd7...)


更多资讯,请关注 Bytebase 公号:Bytebase

PostgreSQL 13 配置参数archive_timeout

PostgreSQL 13 配置参数archive_timeout

参数名称

archive_timeout

参数值数据类型

integer

默认值

0

取值范围

0到1073741823

参数单位

若是不指定单位,那默认的单位是秒

参数含义

强制进行wal segments归档的时长。使用本参数归档出来的wal segment与正常的wal segment是相同的大小。因此,本参数值设置太小会对存储空间有浪费。本参数可以在postgresql.conf或者server command line设置。

是否可session级修改

修改后何时生效

Reload即可生效

PostgreSQL 13 配置参数authentication_timeout

PostgreSQL 13 配置参数authentication_timeout

参数名称

authentication_timeout

数据类型

Integer

默认值

60

取值范围

1到600

参数单位

秒,如果指定本参数值时不带单位,默认为秒

参数含义

允许完成连接认证的最长时间。如果客户端没有在本参数值指定的时间内完成连接认证,PostgreSQL数据库会关闭此次连接。本参数用于防止大量的客户端无限制的占用连接。本参数仅仅可以在postgresql.conf设置或者在server command line设置。

是否可session级修改

修改后何时生效

Reload即可生效

今天的关于postgresql 中的几个 timeout参数 用法说明的分享已经结束,谢谢您的关注,如果想了解更多关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、Postgres 超时 (Timeout) 详解、PostgreSQL 13 配置参数archive_timeout、PostgreSQL 13 配置参数authentication_timeout的相关知识,请在本站进行查询。

本文标签:

上一篇浅谈PostgreSQL和SQLServer的一些差异

下一篇centos命令行控制电脑发出滴滴声――使用beep把警告变为music(centos关闭声音)