最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

postgresql 中的參數(shù)查看和修改方式

 更新時間:2021年01月16日 15:08:07   作者:久違的太陽  
這篇文章主要介紹了postgresql 中的參數(shù)查看和修改方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

1.查看參數(shù)文件的位置

使用show 命令查看,比較常用的show config_file.此還可以查看pg_settings數(shù)據(jù)字典.

test=# show config_file;
     config_file     
------------------------------
 /data/pgdata/postgresql.conf
(1 row)
test=# show hba_file 
test-# ;
     hba_file     
--------------------------
 /data/pgdata/pg_hba.conf
(1 row)
test=# show ident_file ;
     ident_file     
----------------------------
 /data/pgdata/pg_ident.conf

2.查看當(dāng)前會話的參數(shù)值

可以使用show命令或者查看pg_settings字典.

使用show all可以查看全部的參數(shù)值.show 參數(shù)名查看指定參數(shù)

test=# show all;
-------------------------------------+------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------
 allow_system_table_mods       | off                         | Allows modifications of the structure of system tables.
 application_name          | psql                         | Sets the application name to be reported in statistics and logs.
 archive_command           | test ! -f /data/archive/%f && cp %p /data/archive/%f | Sets the shell command that will be called to archive a WAL file.
 archive_mode            | on                          | Allows archiving of WAL files using archive_command.
 archive_timeout           | 0                          | Forces a switch to the next WAL file if a new file has not been started within N seconds.
 array_nulls             | on                          | Enable input of NULL elements in arrays.
...
 
test=# show work_mem;
 work_mem 
----------
 4MB
(1 row)
 
test=# \x
Expanded display is on.
test=# select * from pg_settings where name in ('work_mem')
test-# ;
-[ RECORD 1 ]---+----------------------------------------------------------------------------------------------------------------------
name      | work_mem
setting     | 4096
unit      | kB
category    | Resource Usage / Memory
short_desc   | Sets the maximum memory to be used for query workspaces.
extra_desc   | This much memory can be used by each internal sort operation and hash table before switching to temporary disk files.
context     | user
vartype     | integer
source     | default
min_val     | 64
max_val     | 2147483647
enumvals    | 
boot_val    | 4096
reset_val    | 4096
sourcefile   | 
sourceline   | 
pending_restart | f

3.修改pg的參數(shù)值

1.全局修改pg的參數(shù).

有些參數(shù)只有當(dāng)pg服務(wù)重啟的時候才生效,典型的例子就是shared_buffers,定義了共享內(nèi)存的大小.

許多參數(shù)在pg服務(wù)運行的時候就能修改.再更改之后像服務(wù)器執(zhí)行一個reload操作,強制pg重新讀取postgresql.conf,因此你只需要編輯postgresql.conf文件,再執(zhí)行 pg_ctl reload 即可 . 對于需要重啟的,在修改完postgresql后需要執(zhí)行 pg_ctl restart

對于9.5以后的版本,可以通過查看pg_file_settings查看你設(shè)置的參數(shù)是否生效.例如如果你設(shè)置了一個參數(shù)需要重啟數(shù)據(jù)庫才能生效或者設(shè)置錯誤,那么在此字典中會出現(xiàn)報錯.

test=# select * from pg_file_settings where error is not null;
      sourcefile       | sourceline | seqno |   name    | setting | applied |      error       
-----------------------------------+------------+-------+-----------------+---------+---------+------------------------------
 /data/pgdata/postgresql.auto.conf |     4 |  22 | max_connections | 10000  | f    | setting could not be applied
(1 row)

對于9.4以后的版本,你還可以使用 alter system 命令修改參數(shù).使用alter system命令將修改postgresql.auto.conf文件,而不是postgresql.conf,這樣可以很好的保護postgresql.conf文件,加入你使用很多alter system命令后搞的一團糟,那么你只需要刪除postgresql.auto.conf,再重新加載即可.

test=# show work_mem;
 work_mem 
----------
 4MB
(1 row)
test=# alter system set work_mem='8MB';
ALTER SYSTEM
test=# show work_mem;
 work_mem 
----------
 4MB
(1 row)

查看postgresql.auto.conf:

[postgres@postgresql1 pgdata]$ cat postgresql.auto.conf 
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
work_mem = '8MB'

使用pg_ctl reload重新load配置文件,再查看參數(shù)值:

 
test=# show work_mem ;
 work_mem 
----------
 8MB
(1 row)

2.直接使用set命令,在會話層修改,修改之后將被用于未來的每一個事務(wù),只對當(dāng)前會話有效:

test=# 
test=# set work_mem='16MB';
SET
test=# show work_mem;
 work_mem 
----------
 16MB
(1 row)

我們打開另外一個會話,查看work_mem參數(shù),可以發(fā)現(xiàn)work_mem還是4MB

postgres=# show work_mem;
 work_mem 
----------
 4MB
(1 row)

3.set命令后添加 local關(guān)鍵字, 只在當(dāng)前事務(wù)中修改,只在當(dāng)前事務(wù)內(nèi)有效:

test=# show work_mem;
 work_mem 
----------
 16MB
(1 row)
test=# begin;
BEGIN
test=# set local work_mem='8MB';
SET
test=# show work_mem;
 work_mem 
----------
 8MB
(1 row)
test=# commit;
COMMIT
test=# show work_mem;
 work_mem 
----------
 16MB

4.使用 reset恢復(fù)參數(shù)的默認(rèn)值

再pg_settings字典reset_val字段表示了如果使用reset,則此參數(shù)恢復(fù)的默認(rèn)值為多少

使用 reset 參數(shù)名 來恢復(fù)某個參數(shù)的默認(rèn)值,使用 reset all來恢復(fù)所有的參數(shù)值.

test=# show work_mem;
 work_mem 
----------
 16MB
(1 row)
test=# reset work_mem;
RESET
test=# show work_mem;
 work_mem 
----------
 4MB
(1 row)
 
test=# reset all;
RESET

5.為特定的用戶組設(shè)置參數(shù)

一.為特定的數(shù)據(jù)庫里的所有的用戶設(shè)置參數(shù),例如為test數(shù)據(jù)庫所有的連接設(shè)置work_mem為16MB:

test=# alter database test set work_mem='16MB';
ALTER DATABASE

二.為數(shù)據(jù)庫中的某個特定用戶設(shè)置參數(shù).例如為brent用戶,設(shè)置work_mem為2MB:

postgres=# alter role brent set work_mem='2MB';
ALTER ROLE

經(jīng)過測試發(fā)現(xiàn),如果你同時為數(shù)據(jù)庫和用戶設(shè)置了特定參數(shù),那么以用戶為準(zhǔn).例如上面的,如果我用brent用戶連接到test數(shù)據(jù)庫,那么我的work_mem應(yīng)該為2MB:

postgres=# \c test brent
You are now connected to database "test" as user "brent".
test=> 
test=> 
test=> show work_mem;
 work_mem 
----------
 2MB

三.為某個特定用戶連接到特定的數(shù)據(jù)庫設(shè)置參數(shù).例如為用戶brent在數(shù)據(jù)庫test中設(shè)置work_mem為8MB

test=# alter role brent in database test set work_mem='8MB';
ALTER ROLE

上面說的三種設(shè)置,優(yōu)先級遞增,也就是說,如果設(shè)置了1,2,3那么就以第3個為準(zhǔn),如果設(shè)置了1,2那么就是以2為準(zhǔn),以此類推.

pg對此的實現(xiàn)方法和當(dāng)用戶連接數(shù)據(jù)庫的時候,立刻手動執(zhí)行set命令的效果完全相同

查看你當(dāng)前的參數(shù)值是從何處指定,可以通過查詢pg_setttings中的source字段獲取,例如如果設(shè)置了database級別的參數(shù).那么查詢結(jié)果應(yīng)該如下:

test=# select name,setting,source from pg_settings where name='work_mem';
  name  | setting | source 
----------+---------+----------
 work_mem | 16384  | database

其它的,例如設(shè)置了第三種:

test=# \c test brent
You are now connected to database "test" as user "brent".
test=> select name,setting,source from pg_settings where name='work_mem';
  name  | setting |  source   
----------+---------+---------------
 work_mem | 8192  | database user

補充:postgresql重要參數(shù)解析及優(yōu)化

1,max_connections 200

最大客戶端連接數(shù)。每個連接在后端都會對應(yīng)相應(yīng)的進程,耗費一定的內(nèi)存資源。如果連接數(shù)上千,需要使用連接池工具。

2,shared_buffers 25% of total memory

數(shù)據(jù)庫用于緩存數(shù)據(jù)的內(nèi)存大小。該參數(shù)默認(rèn)值很低(考慮不同的系統(tǒng)平臺),需要調(diào)整。不宜太大,很多實踐表明,大于1/3的內(nèi)存會降低性能。

3,effective_cache_size 50%-75% of total memory

This is a guideline for how much memory you expect to be available in the OS and PostgreSQL buffer caches, not an allocation! 這個參數(shù)只在查詢優(yōu)化器選擇時使用,并不是實際分配的內(nèi)存,該參數(shù)越大,查詢優(yōu)化器越傾向于選擇索引掃描。

4,checkpoint_segments 256 checkpoint_completion_target 0.9

checkponit_segments wal個數(shù)達到多少個數(shù)checkponit,還有一個參數(shù)checkponit_timeout,控制最長多長時間checkpoint。對于寫入比較大的數(shù)據(jù)庫,該值越大越好。但是值越大,執(zhí)行恢復(fù)的時間越長。

checkpoint_completion_target 控制checkponit write 分散寫入,值越大越分散。默認(rèn)值0.5,0.9是一個比較合適的值。

5,work_mem

用于排序,默認(rèn)值即可。每個連接都會分配一定work_mem,這個是會實際分配的內(nèi)存,不宜過大,默認(rèn)值即可。如果要使用語句中有較大的排序操作,可以在會話級別設(shè)置該參數(shù),set work_men = ‘2GB',提高執(zhí)行速度。

6,maintanance_work_mem

維護性操作使用的內(nèi)存。例如:vacuum ,create index,alter table add foreign key,restoring database dumps.做這些操作時可以臨時設(shè)置該值大小,加快執(zhí)行速度。set session maintanance_work_mem = ‘2GB';

7,random_page_cost (默認(rèn)值 4) seq_page_cost(默認(rèn)值 1)

設(shè)置優(yōu)化器獲取一個隨機頁的cost,相比之下一個順序掃描頁的cost為1.

當(dāng)使用較快的存儲,如raid arrays,scsi,ssd時,可以適當(dāng)調(diào)低該值。有利于優(yōu)化器懸著索引掃描。ssd 時,可以設(shè)置為2.

8,autovacuum

—maintenance_work_mem 1-2GB

—autovacuum_max_workers

如果有多個小型表,分配更多的workers,更少的mem。

大型表,更多的men,更少的workers。

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • 查看PostgreSQL進程父子關(guān)系的兩種方法

    查看PostgreSQL進程父子關(guān)系的兩種方法

    在 PostgreSQL 數(shù)據(jù)庫運維中,理解主進程與各子進程之間的父子關(guān)系對于故障排查和性能分析至關(guān)重要,下面詳細(xì)介紹兩種常用的方法及其應(yīng)用場景,需要的朋友可以參考下
    2026-03-03
  • PostgreSQL數(shù)據(jù)庫升級的完整流程與注意事項

    PostgreSQL數(shù)據(jù)庫升級的完整流程與注意事項

    在現(xiàn)代軟件開發(fā)和運維實踐中,數(shù)據(jù)庫作為核心基礎(chǔ)設(shè)施,其穩(wěn)定性和性能至關(guān)重要,PostgreSQL 作為一款功能強大、開源且高度可靠的數(shù)據(jù)庫管理系統(tǒng),持續(xù)推出新版本以增強性能、安全性和功能特性,所以本文將深入探討 PostgreSQL 數(shù)據(jù)庫升級的完整流程,需要的朋友可以參考下
    2026-03-03
  • 基于postgreSql 常用查詢小結(jié)

    基于postgreSql 常用查詢小結(jié)

    這篇文章主要介紹了基于postgreSql 常用查詢小結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL copy 命令教程詳解

    PostgreSQL copy 命令教程詳解

    這篇文章主要介紹了PostgreSQL copy 命令教程詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • PostGresql 實現(xiàn)四舍五入、小數(shù)轉(zhuǎn)換、百分比的用法說明

    PostGresql 實現(xiàn)四舍五入、小數(shù)轉(zhuǎn)換、百分比的用法說明

    這篇文章主要介紹了PostGresql 實現(xiàn)四舍五入、小數(shù)轉(zhuǎn)換、百分比的用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • Postgresql JSON對象和數(shù)組查詢功能實現(xiàn)

    Postgresql JSON對象和數(shù)組查詢功能實現(xiàn)

    這篇文章主要介紹了Postgresql JSON對象和數(shù)組查詢功能實現(xiàn),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11
  • PostgreSQL數(shù)據(jù)庫中窗口函數(shù)的語法與使用

    PostgreSQL數(shù)據(jù)庫中窗口函數(shù)的語法與使用

    這PostgreSQL中提供了窗口函數(shù),一個窗口函數(shù)在一系列與當(dāng)前行有某種關(guān)聯(lián)的表行上進行一種計算。下面這篇文章主要給大家介紹了關(guān)于PostgreSQL數(shù)據(jù)庫中窗口函數(shù)的語法與使用的相關(guān)資料,需要的朋友可以參考下
    2019-03-03
  • PGSQL實現(xiàn)判斷一個空值字段,并將NULL值修改為其它值

    PGSQL實現(xiàn)判斷一個空值字段,并將NULL值修改為其它值

    這篇文章主要介紹了PGSQL實現(xiàn)判斷一個空值字段,并將NULL值修改為其它值,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • 詳解PostgreSQL 語法中關(guān)鍵字的添加

    詳解PostgreSQL 語法中關(guān)鍵字的添加

    這篇文章主要介紹了詳解PostgreSQL 語法中關(guān)鍵字的添加的相關(guān)資料,這里說明下在parser語法解析模塊添加關(guān)鍵字,需要的朋友可以參考下
    2017-08-08
  • 使用docker compose啟動postgresql的示例代碼

    使用docker compose啟動postgresql的示例代碼

    要在啟動 PostgreSQL 容器時執(zhí)行特定的初始化文件,可以使用 Docker 的 docker-entrypoint-initdb.d 目錄,這個目錄下的 SQL 文件會在容器啟動時被自動執(zhí)行,下面是如何修改 Docker Compose 配置文件,以便在啟動時執(zhí)行初始化 SQL 腳本,需要的朋友可以參考下
    2024-10-10

最新評論

阳东县| 富源县| 海宁市| 庆元县| 太原市| 浪卡子县| 凤庆县| 湘潭市| 左权县| 鄂温| 无极县| 句容市| 随州市| 疏勒县| 潜山县| 新晃| 和田县| 浦县| 林西县| 称多县| 卢湾区| 理塘县| 高州市| 隆德县| 新安县| 庆城县| 海城市| 梓潼县| 双流县| 会同县| 民和| 禹城市| 丰县| 清新县| 大港区| 宁城县| 朔州市| 开化县| 盱眙县| 定兴县| 临夏市|