欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PostgreSQL11修改wal-segsize的操作

 更新時(shí)間:2021年01月07日 14:25:18   作者:kmblack1  
這篇文章主要介紹了PostgreSQL11修改wal-segsize的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

修改有風(fēng)險(xiǎn),謹(jǐn)慎行事。

PostgreSQL11以前改變wal-segsize(WAL段大小)必須在編譯時(shí)通過–with-wal-segsize參數(shù)確定,編譯后不可更改.

#PostgreSQL11之前的版本
#數(shù)據(jù)塊按8K劃分(--with-blocksize,單位為K,默認(rèn)為8K)
#WAL塊尺寸按8k劃分(--with-wal-blocksize,單位為K,默認(rèn)為8K)
#數(shù)據(jù)文件按1G一個(gè)分解(--with-segsize,單位為G,默認(rèn)為1G)
#WAL段尺寸按16MB劃分(--with-wal-segsize,單位為K,默認(rèn)為16MB)
./configure --with-blocksize=8--with-wal-blocksize=8--with-segsize=1 --with-wal-segsize=16

PostgreSQL11取消了編譯參數(shù)–with-wal-segsize.使用pg_resetwal(–wal-segsize)更改WAL段大小.

#PostgreSQL11先編譯程序
#數(shù)據(jù)塊按8K劃分(--with-blocksize,單位為K,默認(rèn)為8K)
#WAL塊尺寸按8k劃分(--with-wal-blocksize,單位為K,默認(rèn)為8K)
#數(shù)據(jù)文件按1G一個(gè)分解(--with-segsize,單位為G,默認(rèn)為1G)
./configure --with-blocksize=8--with-wal-blocksize=8--with-segsize=1

編譯完成并初始化后使用pg_resetwal修改wal-segsize

#首先停止PostgreSQL服務(wù)
pg_ctl -D /data/pgdata stop -m fast
#修改wal-segsize段大小,默認(rèn)單位是MB,值必須是2的冪并且在1到1024MB之間
pg_resetwal --wal-segsize=32 /data/pgdata;

查看

show block_size;
show wal_block_size;
show segment_size;
show wal_segment_size;
ls /data/pgdata/pg_wal -lh

補(bǔ)充:PostgreSQL 11 新特性解讀 : Initdb/Pg_resetwal支持修改WAL文件大小

PostgreSQL 11 版本的一個(gè)重要調(diào)整是支持 initdb 和 pg_resetwal 修改 WAL 文件大小,而 11 版本之前只能在編譯安裝 PostgreSQL 時(shí)設(shè)置 WAL 文件大小。這一特性能夠方便 WAL 文件的管理。

Release 的說明

Allow the WAL file size to be set via initdb (Beena Emerson)

Previously the 16MB default could only be changed at compile time.

下面分別演示通過 initdb 和 pg_resetwal 修改 WAL 文件大小。

使用 initdb 調(diào)整WAL文件大小

initdb 命令關(guān)于修改 WAL 文件大小選項(xiàng),如下:

--wal-segsize=size

Set the WAL segment size, in megabytes. This is the size of each individual file in the WAL log. The default size is 16 megabytes. The value must be a power of 2 between 1 and 1024 (megabytes). This option can only be set during initialization, and cannot be changed later.

It may be useful to adjust this size to control the granularity of WAL log shipping or archiving. Also, in databases with a high volume of WAL, the sheer number of WAL files per directory can become a performance and management problem. Increasing the WAL file size will reduce the number of WAL files.

WAL 日志文件大小默認(rèn)為16MB,該值必須是1到1024之間的2的次方,增大WAL文件大小能夠減少WAL日志文件的產(chǎn)生。

初始化一個(gè)新的 PostgreSQL 數(shù)據(jù)庫實(shí)例,指定WAL文件大小64MB,如下:

[pg11@pghost2 ~]$ initdb -E UTF8 --locale=C --wal-segsize=64 -D /home/pg11/data01 -U postgres -W
The files belonging to this database system will be owned by user "pg11".
This user must also own the server process.
 
The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".
 
Data page checksums are disabled.
 
Enter new superuser password: 
Enter it again: 
 
creating directory /home/pg11/data01 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
 
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
 
Success. You can now start the database server using:
 
 pg_ctl -D /home/pg11/data01 -l logfile start

修改 postgresql.conf 相關(guān)配置,之后啟動(dòng)數(shù)據(jù)庫。

[pg11@pghost2 data01]$ pg_ctl start -D /home/pg11/data01
waiting for server to start....2018-10-16 15:58:16.714 CST [10583] LOG: listening on IPv6 address "::1", port 1950
2018-10-16 15:58:16.714 CST [10583] LOG: listening on IPv4 address "127.0.0.1", port 1950
2018-10-16 15:58:16.731 CST [10583] LOG: listening on Unix socket "/tmp/.s.PGSQL.1950"
2018-10-16 15:58:16.762 CST [10584] LOG: database system was shut down at 2018-10-16 15:56:46 CST
2018-10-16 15:58:16.782 CST [10583] LOG: database system is ready to accept connections
 done
server started

驗(yàn)證WAL文件大小,如下:

[pg11@pghost2 ~]$ ll /home/pg11/data01/pg_wal
total 65M
-rw------- 1 pg11 pg11 64M Oct 16 16:03 000000010000000000000001
drwx------ 2 pg11 pg11 4.0K Oct 16 15:56 archive_status

可見WAL文件大小為64MB。

使用 pg_resetwal 調(diào)整WAL文件大小

pg_resetwal 用來重置WAL日志和一些控制信息,常用于數(shù)據(jù)庫恢復(fù)場景,不到萬不得已不輕易使用,以下演示使用pg_resetwal命令調(diào)整WAL日志文件大小,僅供測試參考,生產(chǎn)環(huán)境慎用。

pg_resetwal 命令關(guān)于調(diào)整WAL文件大小的選項(xiàng),如下:

--wal-segsize=wal_segment_size

Set the new WAL segment size, in megabytes. The value must be set to a power of 2 between 1 and 1024 (megabytes). See the same option of initdb for more information.

以下演示在已有PostgreSQL實(shí)例基礎(chǔ)上調(diào)整WAL日志文件大小。

查看當(dāng)前數(shù)據(jù)庫的 pg_wal 目錄,如下:

[pg11@pghost2 pg_wal]$ ll /database/pg11/pg_root/pg_wal/
total 2.3G
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000013
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000014
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000015
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000016
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000017
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000018
-rw------- 1 pg11 pg11 16M Sep 30 14:45 000000010000001700000019
-rw------- 1 pg11 pg11 16M Sep 30 14:45 00000001000000170000001A
-rw------- 1 pg11 pg11 16M Sep 30 14:45 00000001000000170000001B
...
省略
drwx------ 2 pg11 pg11 16K Oct 16 08:38 archive_status

pg_wal 目錄中已有大量WAL日志文件,WAL文件大小為16MB,計(jì)劃將WAL日志文件調(diào)整成64MB。

pg_resetwal 操作時(shí)需要關(guān)閉數(shù)據(jù)庫,如下。

[pg11@pghost2 ~]$ pg_ctl stop -m fast
waiting for server to shut down.... done
server stopped
pg_resetwal 命令調(diào)整WAL日志文件大小為 64MB:
[pg11@pghost2 ~]$ pg_resetwal --wal-segsize=64 -D /database/pg11/pg_root
Write-ahead log reset

驗(yàn)證WAL文件大小,如下:

[pg11@pghost2 ~]$ ll /database/pg11/pg_root/pg_wal/
total 65M
-rw------- 1 pg11 pg11 64M Oct 16 08:55 000000010000001700000029
drwx------ 2 pg11 pg11 16K Oct 16 08:55 archive_status

發(fā)現(xiàn) pg_wal 目錄中原有的WAL日志被清理,同時(shí)生成了大小為64MB新的WAL文件。

啟動(dòng)數(shù)據(jù)庫提示 min_wal_size 參數(shù)至少需設(shè)置成 wal_segment_size 大小為 2 倍。

[pg11@pghost2 ~]$ pg_ctl start
waiting for server to start....2018-10-16 09:01:26.096 CST [24318] FATAL: "min_wal_size" must be at least twice "wal_segment_size".
2018-10-16 09:01:26.096 CST [24318] LOG: database system is shut down
 stopped waiting
pg_ctl: could not start server
Examine the log output.

根據(jù)提示調(diào)整 postgresql.conf,設(shè)置如下:

min_wal_size = 128MB

啟動(dòng)數(shù)據(jù)庫正常,如下:

[pg11@pghost2 ~]$ pg_ctl start
waiting for server to start....2018-10-16 09:02:45.680 CST [24614] LOG: listening on IPv4 address "0.0.0.0", port 1930
2018-10-16 09:02:45.680 CST [24614] LOG: listening on IPv6 address "::", port 1930
2018-10-16 09:02:45.687 CST [24614] LOG: listening on Unix socket "/tmp/.s.PGSQL.1930"
2018-10-16 09:02:45.715 CST [24614] LOG: redirecting log output to logging collector process
2018-10-16 09:02:45.715 CST [24614] HINT: Future log output will appear in directory "log".

總結(jié)

以上演示了 11 版本通過 initdb 和 pg_resetwal 調(diào)整WAL文件大小。

pg_resetwal 會(huì)清除pg_wal目錄的WAL文件,本博客的測試樣例僅供參考,生產(chǎn)環(huán)境使用需慎重。

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

相關(guān)文章

  • Postgresql在mybatis中報(bào)錯(cuò):操作符不存在:character varying == unknown的問題

    Postgresql在mybatis中報(bào)錯(cuò):操作符不存在:character varying == unknown的問題

    這篇文章主要介紹了Postgresql在mybatis中報(bào)錯(cuò): 操作符不存在 character varying == unknown的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • PostgreSQL 數(shù)據(jù)庫跨版本升級常用方案解析

    PostgreSQL 數(shù)據(jù)庫跨版本升級常用方案解析

    這篇文章主要介紹了PostgreSQL 數(shù)據(jù)庫跨版本升級常用方案解析,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • 在postgresql中通過命令行執(zhí)行sql文件

    在postgresql中通過命令行執(zhí)行sql文件

    這篇文章主要介紹了在postgresql中通過命令行執(zhí)行sql文件,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL樹形結(jié)構(gòu)的遞歸查詢示例

    PostgreSQL樹形結(jié)構(gòu)的遞歸查詢示例

    這篇文章主要給大家介紹了關(guān)于PostgreSQL樹形結(jié)構(gòu)的遞歸查詢的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用PostgreSQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • PGSQL實(shí)現(xiàn)判斷一個(gè)空值字段,并將NULL值修改為其它值

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

    這篇文章主要介紹了PGSQL實(shí)現(xiàn)判斷一個(gè)空值字段,并將NULL值修改為其它值,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql安裝及配置超詳細(xì)教程

    postgresql安裝及配置超詳細(xì)教程

    這篇文章主要介紹了postgresql安裝及配置超詳細(xì)教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • 對Postgresql中的json和array使用介紹

    對Postgresql中的json和array使用介紹

    這篇文章主要介紹了對Postgresql中的json和array使用介紹,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL數(shù)據(jù)庫時(shí)間類型相加減操作

    PostgreSQL數(shù)據(jù)庫時(shí)間類型相加減操作

    PostgreSQL提供了許多函數(shù),這些函數(shù)返回與當(dāng)前日期和時(shí)間相關(guān)的值,下面這篇文章主要給大家介紹了關(guān)于PostgreSQL數(shù)據(jù)庫時(shí)間類型相加減操作的相關(guān)資料,需要的朋友可以參考下
    2023-10-10
  • PostgreSQL建立自增主鍵的2種方法總結(jié)

    PostgreSQL建立自增主鍵的2種方法總結(jié)

    這篇文章主要給大家介紹了關(guān)于PostgreSQL建立自增主鍵的2種方法,PostgreSQL主鍵自增是一種自動(dòng)增長的機(jī)制,可以為表中的每一行記錄分配唯一的標(biāo)識符,需要的朋友可以參考下
    2023-09-09
  • PostgreSQL教程(五):函數(shù)和操作符詳解(1)

    PostgreSQL教程(五):函數(shù)和操作符詳解(1)

    這篇文章主要介紹了PostgreSQL教程(五):函數(shù)和操作符詳解(1),本文講解了邏輯操作符、比較操作符、數(shù)學(xué)函數(shù)和操作符、三角函數(shù)列表、字符串函數(shù)和操作符等內(nèi)容,需要的朋友可以參考下
    2015-05-05

最新評論