Subject: PostgreSQL14.2 can not start because of huge_page_size is equal to 1048576

From: 类延良 <[email-masked]>
Date: Mon, 9 May 2022 21:56:41 +0800 (CST)

My rhel 7.9 enabled 1GB hugepagesize,and in this rhel7.9,there is a postgresql 14.2 (from compile installation).
[root@localhost ~]# cat /proc/meminfo |grep -i hugep
AnonHugePages:      8192 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:    1048576 kB
[root@localhost ~]# hugeadm --pool-list
      Size  Minimum  Current  Maximum  Default
1073741824        0        0        0        *
[root@localhost ~]# 

after I change pg parameter huge_page_size to 1048576， I can not start PostgreSQL 14.2 . the following is the error,

[pg142@localhost data]$ grep huge postgresql.conf
#huge_pages = try# on, off, or try
huge_page_size = 1048576# zero for system default
[pg142@localhost data]$ pg_ctl start
waiting for server to start....2022-05-09 04:36:58.220 GMT [1719] LOG:  invalid value for parameter "huge_page_size": 1048576
2022-05-09 04:36:58.220 GMT [1719] DETAIL:  huge_page_size must be 0 on this platform.
2022-05-09 12:36:58.220 CST [1719] FATAL:  configuration file "/home/pg142/data/postgresql.conf" contains errors
 stopped waiting
pg_ctl: could not start server
Examine the log output.
[pg142@localhost data]$ 

I want to know why ？

---

From: John Wiencek <[email-masked]>
Date: Mon, 9 May 2022 09:09:20 -0500

Found this:

https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-HUGE-PAGES <https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-HUGE-PAGES>

See section:    19.4.5. Linux Huge Pages

"The default behavior for huge pages in PostgreSQL is to use them when possible, with the system's default huge page size, and to fall back to normal pages on failure. To enforce the use of huge pages, you can set huge_pages <https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-HUGE-PAGES> to on in postgresql.conf. Note that with this setting PostgreSQL will fail to start if not enough huge pages are available.”

> On May 9, 2022, at 8:56 AM, 类延良 <[email-masked]> wrote:
> 
> #huge_pages = try			# on, off, or try
> huge_page_size = 1048576			# zero for system default

---

From: 类延良 <[email-masked]>
Date: Mon, 9 May 2022 23:20:14 +0800 (CST)

Thanks a lot for your reply!
huge_page_size parameter is PG 14 new parameter.
 the error is---“DETAIL:  huge_page_size must be 0 on this platform”。
my os is rhel linux ， in the linux platform ， is  there  no method to change huge_page_size  ？？？
but  in the pg14 documents，there is  some words about ---“Non-default settings are currently supported only on Linux”。
so ，I do not know  which one is correct

[root@localhost ~]# echo 2072 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

[root@localhost ~]# cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

2057

[root@localhost ~]# 

[root@localhost ~]# 

[root@localhost ~]# cd $PGDATA

[root@localhost data]# grep huge postgresql.conf

grep: postgresql.conf: No such file or directory

[root@localhost data]# su - pg142

Last login: Mon May  9 22:47:48 CST 2022 on pts/0

[pg142@localhost ~]$ cd $PGDATA

huge_pages = try# on, off, or try

huge_page_size = 2048# zero for system default

[pg142@localhost data]$ hugeadm --pool-list

   2097152     2057     2057     2057          ---->>>but  non-default hugepagesize is 2048KB

1073741824        3        3        3        *   ---->>>default hugepagesize is 1gb

waiting for server to start....2022-05-09 15:09:15.023 GMT [1733] LOG:  invalid value for parameter "huge_page_size": 2048

2022-05-09 15:09:15.023 GMT [1733] DETAIL:  huge_page_size must be 0 on this platform.

2022-05-09 23:09:15.023 CST [1733] FATAL:  configuration file "/home/pg142/data/postgresql.conf" contains errors

 stopped waiting

Examine the log output.

[pg142@localhost data]$ 

At 2022-05-09 22:09:20, "John Wiencek" <[email-masked]> wrote:

Found this:

https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-HUGE-PAGES

"The default behavior for huge pages in PostgreSQL is to use them when possible, with the system's default huge page size, and to fall back to normal pages on failure. To enforce the use of huge pages, you can set huge_pages to on in postgresql.conf. Note that with this setting PostgreSQL will fail to start if not enough huge pages are available.”

I want to know why ？

---

From: Ron <[email-masked]>
Date: Mon, 9 May 2022 10:39:52 -0500

On 5/9/22 08:56, 类延良 wrote:
> My rhel 7.9 enabled 1GB hugepagesize,and in this rhel7.9,there is a 
> postgresql 14.2 (from compile installation).
> after I change pg parameter huge_page_size to 1048576， I can not start 
> PostgreSQL 14.2 . the following is the error,
> waiting for server to start....2022-05-09 04:36:58.220 GMT [1719] LOG:  
> invalid value for parameter "huge_page_size": 1048576
> 2022-05-09 04:36:58.220 GMT [1719] DETAIL: huge_page_size *must be 0* on 
> this platform.
> 2022-05-09 12:36:58.220 CST [1719] FATAL:  configuration file 
> "/home/pg142/data/postgresql.conf" contains errors
>  stopped waiting

The DETAIL message says " huge_page_size *must be 0*", but you did not set 
huge_page_size to 0.

That may be the problem.

-- 
Angular momentum makes the world go 'round.

---

From: "yanliang lei" <[email-masked]>
Date: Tue, 10 May 2022 00:15:55 +0800 (CST)

Thanks a lot for your reply！

The DETAIL message says " huge_page_size must be 0", but you did not set huge_page_size to 0. 
---huge_page_size is the pg14 new parameter，The default value of this parameter is zero (0). When set to 0, the default huge page size on the system will be used. 
in the pg 14 documents---‘Non-default settings are currently supported only on Linux.’ so ， I want to try to find a method to let PostgreSQL 14 to use non-default hugepagesize，
if the documents tell me---"Non-default settings are not supported on Linux", I won't do the following test case！
From the result of the following test case，we can see:  PostgreSQL 14.2 software start log “huge_page_size must be 0 on this platform”   and  the pg 14 documents---‘Non-default settings are currently supported only on Linux. ----These  two descriptions are obviously contradictory！！！

the following is my latest test case：

2057

[root@localhost ~]# 

[root@localhost ~]# 

huge_pages = try # on, off, or try

huge_page_size = 2048 # zero for system default

waiting for server to start....2022-05-09 15:09:15.023 GMT [1733] LOG:  invalid value for parameter "huge_page_size": 2048   --->>> I want to use 2M hugepagesize 

 stopped waiting

Examine the log output.

[pg142@localhost data]$ 

在 2022-05-09 23:39:52，"Ron" <[email-masked]> 写道：

I want to know why ？

The DETAIL message says " huge_page_size must be 0", but you did not set huge_page_size to 0. 

That may be the problem.

---

From: Tom Lane <[email-masked]>
Date: Mon, 09 May 2022 12:27:14 -0400

"yanliang lei" <[email-masked]> writes:
> ---huge_page_size is the pg14 new parameter£¬The default value of this parameter is zero (0). When set to 0, the default huge page size on the system will be used. 
> in the pg 14 documents---¡®Non-default settings are currently supported only on Linux.¡¯ so £¬ I want to try to find a method to let PostgreSQL 14 to use non-default hugepagesize£¬

The code that's throwing the error says

	/* Recent enough Linux only, for now.  See GetHugePageSize(). */

I don't know what "recent enough" is in this context, but evidently
RHEL7 isn't it (no surprise considering that's a trailing-edge distro
at this point).

I don't find it surprising that the authors of this feature didn't
try to document exactly which Linux versions it can be used on.
Keeping such documentation accurate would be a nightmare.

			regards, tom lane

---

From: "yanliang lei" <[email-masked]>
Date: Tue, 10 May 2022 00:58:31 +0800 (CST)

Thanks a lot for your reply！
Oh,I see！
I will test this case in the rhel8.5（ RHEL 8.5  is the latest version of RHEL so far）
I will post my test result  through this email。

---

From: "yanliang lei" <[email-masked]>
Date: Fri, 13 May 2022 22:07:24 +0800 (CST)

on RHEL8.5 PostgreSQL 14.2 can enable non-default Hugepage size
the detail  result is : 

in the RHEL 8.X, PostgreSQL can use non-default hugepagesize， and in the RHEL 7.X, PostgreSQL can not use non-default hugepagesize！

so ,please modify pg documents(https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-HUGE-PAGES),

the following is the  detail. 

[pg142@rhel85 data]$ cat /etc/redhat-release 

Red Hat Enterprise Linux release 8.5 (Ootpa)

[pg142@rhel85 data]$ uname -r

4.18.0-348.el8.x86_64

[pg142@rhel85 data]$ 

[pg142@rhel85 ~]$ grep ^Huge /proc/meminfo 

HugePages_Total:       0

HugePages_Free:        0

HugePages_Rsvd:        0

HugePages_Surp:        0

Hugepagesize:    1048576 kB    ----->>> OS default hugepagesize is 1GB

Hugetlb:               0 kB

[pg142@rhel85 ~]$ 

[pg142@rhel85 ~]$ head -1 $PGDATA/postmaster.pid

1679

[pg142@rhel85 ~]$ pmap 1679| awk '/rw-s/ && /zero/ {print $2}'

828480K

[pg142@rhel85 ~]$ 

(828480K+256*1024)/2048=533  ----->>>PostgreSQL uses 533 hugepages which size is 2MB

in the  /boot/grub2/grubenv file ，add: hugepagesz=2M hugepages=533

[root@rhel85 ~]# grub2-editenv - list | grep kernelopts

kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet default_hugepagesz=1G

[root@rhel85 ~]# 

grub2-editenv - set "kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet default_hugepagesz=1G hugepagesz=2M hugepages=533"

grub2-editenv - list | grep kernelopts

systemctl reboot

after OS reboot, we can see :

root@rhel85 ~]# hugeadm --pool-list

   2097152      533      533      533         

1073741824        0        0        0        *

[root@rhel85 ~]# 

[root@rhel85 ~]# cat /proc/meminfo |grep -i huge

AnonHugePages:     16384 kB

ShmemHugePages:        0 kB

FileHugePages:         0 kB

HugePages_Total:       0

HugePages_Free:        0

HugePages_Rsvd:        0

HugePages_Surp:        0

Hugepagesize:    1048576 kB

Hugetlb:         1091584 kB

[root@rhel85 ~]# 

then modify parameter  huge_page_size=2048 in the postgreSQL 14.2 postgresql.conf

[pg142@rhel85 data]$ grep huge_page_size postgresql.conf 

[pg142@rhel85 data]$ 

[pg142@rhel85 data]$ pg_ctl start

waiting for server to start....2022-05-13 21:26:24.051 CST [1694] LOG:  starting PostgreSQL 14.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-3), 64-bit

2022-05-13 21:26:24.051 CST [1694] LOG:  listening on IPv6 address "::1", port 5432

2022-05-13 21:26:24.051 CST [1694] LOG:  listening on IPv4 address "127.0.0.1", port 5432

2022-05-13 21:26:24.053 CST [1694] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

2022-05-13 21:26:24.058 CST [1695] LOG:  database system was shut down at 2022-05-13 21:22:22 CST

2022-05-13 21:26:24.063 CST [1694] LOG:  database system is ready to accept connections

 done

server started

[pg142@rhel85 data]$ pg_ctl status

pg_ctl: server is running (PID: 1694)

/home/pg142/soft/bin/postgres

[pg142@rhel85 data]$ 

[pg142@rhel85 data]$ psql -d postgres

psql (14.2)

Type "help" for help.

postgres=# show huge_page_size;

 huge_page_size 

----------------

 2MB

(1 row)

postgres=# show huge_pages;

 huge_pages 

------------

 try

(1 row)

postgres=# 

At 2022-05-10 00:58:31, "yanliang lei" <[email-masked]> wrote: