Closed sincatter closed 1 year ago
/hexo/next/:url
: No maintainer listed, possibly a v1 or misconfigured routeTo maintainers: if you are not willing to be disturbed, list your username in
scripts/workflow/test-issue/call-maintainer.js
. In this way, your username will be wrapped in an inline code block when tagged so you will not be notified.
如果有任何路由无法匹配,issue 将会被自动关闭。如果 issue 和路由无关,请使用 NOROUTE
关键词,或者留下评论。我们会重新审核。
If there is any route not found, the issue will be closed automatically. Please use NOROUTE
for a route-irrelevant issue or leave a comment if it is a mistake.
/test
/hexo/next/blog.japinli.top
Successfully generated as following:
collate.icu.utf8
这个测试用例在 REL_14_STABLE
分支始终无法跑过,但是在 REL_15_STABLE
却可以正常运行。同时由于 collate.icu.utf8
失败还将导致 foreign_data
测试用例也失败了。
下面是详细的错误信息。
1 | diff -U3 /home/japin/Codes/postgres/build/../src/test/regress/expected/collate.icu.utf8.out /home/japin/Codes/postgres/build/src/test/regress/results/collate.icu.utf8.out |
从上面的错误信息我们可以看到回归测试在执行 CREATE COLLATION test1 (provider = icu, lc_collate = 'C.UTF-8', lc_ctype = 'en_US.UTF-8');
语句时出现了非期望的情况。通过查看 collate.icu.utf8.out
文件,我们可以定位到如下内容:
1 | do $$ |
测试用例使用 current_setting()
来获取 lc_collate
和 lc_ctype
的值,并且期望这两个值是相同的,但是在实际的回归测试时,lc_collate
为 C.UTF-8
而 lc_ctype
为 en_US.UTF-8
,从而导致测试用例失败。
然而,当我尝试使用 make installcheck
运行回归测试时,一切又都正常了。
考虑到这个是和 locale
相关,因此我确认了一下该环境下的 locale
设置。
1 | $ locale |
可以看到 LANG
的设置与其他的不同,我尝试用 export LANG=en_US.UTF-8
重新导出环境变量,然后在执行 make check
,此时一切就正常了。
从结果来看,回归测试的失败是由于 LANG
的设置不合理导致的。那么为什么 REL_15_STABLE
没有遇到这个情况呢?
如下所示,查看 REL_15_STABLE
的 collate.icu.utf8.out
测试,可以发现它将 lc_collate
和 lc_ctype
合并为 locale
了,因此没有导致回归测试失败。
1 | $ git show origin/REL_15_STABLE:src/test/regress/expected/collate.icu.utf8.out | grep -A 3 -B 2 'CREATE COLLATION test1' |
这是 PG 15 开发分支的 f2553d43
提交引入的。
1 | diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql |
那么为什么 LANG
会影响到数据库的 lc_collate
和 lc_ctype
呢?在我的环境变量中又是配置了 LC_COLLATE
和 LC_CTYPE
的,同时也可以注意到 LC_ALL
也配置了。
关于环境变量 LANG
,LC_ALL
和 LC_*
的优先级如下所示:
The environment variables LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME, (LC_*), and NLSPATH provide for the support of internationalised applications. The standard utilities make use of these environment variables as described in this section and the individual ENVIRONMENT VARIABLES sections for the utilities. If these variables specify locale categories that are not based upon the same underlying codeset, the results are unspecified.
The values of locale categories are determined by a precedence order; the first condition met below determines the value:
- If the LC_ALL environment variable is defined and is not null, the value of LC_ALL is used.
- If the LC_* environment variable ( LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the value of the environment variable is used to initialise the category that corresponds to the environment variable.
- If the LANG environment variable is defined and is not null, the value of the LANG environment variable is used.
- If the LANG environment variable is not set or is set to the empty string, the implementation-dependent default locale is used.
从上面我看可以看到,LC_ALL
的优先级是最高的,其次是 LC_*
,最后是 LANG
,那么为什么 make check
的时候会出现 LC_COLLATE
和 LC_CTYPE
不一致的情况呢?(这里更准确的说应该是 current_setting('lc_collate')
和 current_setting('lc_ctype')
不一致。)
待进一步分析。
上面已经提到了如何解决这个问题,我们可以重新导出 LANG
环境变量,使其与 LC_ALL
、LC_CTYPE
和 LC_COLLATE
一致。
[1] https://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html
pg_basebackup
和 pg_probackup
两种备份方式。
下表是本次实验的基本环境,每个节点都安装了 PostgreSQL 15 及 pg_probackup
2.5.12。
IP | 说明 |
---|---|
10.9.10.106 | 数据库节点 |
10.9.10.109 | 备份节点 |
首先,我们在数据库节点初始化数据库,并进行相关的配置。
1 | $ initdb -k -D testdb |
为了确保 pg_probackup
能够正常运行,我们还需要授权 u01
用户对于 pg_backup_start()
、pg_backup_stop()
和 pg_create_restore_point()
函数的可执行权限。
1 | $ psql postgres -c "GRANT EXECUTE ON FUNCTION pg_backup_start TO u01" |
接着我们创建两个表空间,一个用于存储表、一个用于存储索引。
1 | $ mkdir tblspc idxspc |
最后,使用 pgbench
导入数据。
1 | $ pgbench -i -s 50 --tablespace tblspc --index-tablespace idxspc postgres |
pg_basebackup
备份恢复表空间一切准备就绪,现在我们使用 pg_basebackup
来备份 PostgreSQL 表空间,在备份节点执行下面的命令:
1 | $ pg_basebackup -h 10.9.10.106 -p 5432 -U u01 -D basebackupdb |
可以看到表空间直接就备份过来了,无需任何额外的操作。我们将备库启动起来可以看到备份的数据。
1 | $ pg_ctl start -l log -D basebackupdb |
如果我们想要将表空间备份到不同的路径,那么我们需要使用 --tablespace-mapping, -T
选项,如下所示:
1 | $ pg_basebackup -h 10.9.10.106 -p 5432 -U u01 -D basebackupdb \ |
从上面可以看到表空间 tblspc, idxspc
分别指向了 /mnt/workspace/tblspc, /mnt/workspace/idxspc
。
pg_probackup
备份恢复表空间首先,初始化备份目录。
1 | $ pg_probackup init -B /mnt/workspace/BackupTest |
接着,创建备份实例(您需要先配置备份节点到数据库节点的 SSH 互信)。
1 | $ pg_probackup add-instance -B /mnt/workspace/BackupTest --instance lab --pgdata /home/japin/lab/testdb \ |
--pgdata
指定数据库存储的路径--remote-host
指定 SSH 连接地址--remote-port
指定 SSH 连接端口--remote-user
指定 SSH 连接用户--remote-path
指定远端 pg_probackup
的路径完成上述准备工作之后,现在我们可以执行备份操作了。这里我们以全备作为示例。
1 | $ pg_probackup backup -B /mnt/workspace/BackupTest --instance lab --pgdata /home/japin/lab/testdb \ |
通过查看备份目录我们可以看到 pg_probackup
在备份的时候是将表空间的信息直接备份到了 pg_tblspc
目录下面。
1 | $ ls -al /mnt/workspace/BackupTest/backups/lab/RWSH8U/database/pg_tblspc/16389/PG_15_202209061/5/ |
最后,我们来测试恢复过程。
1 | $ pg_probackup restore -B /mnt/workspace/BackupTest --instance lab --pgdata $PWD/db-backup |
可以看到表空间恢复到了 /home/japin/lab/idxspc
和 /home/japin/lab/tblspc
,这与备份前的路径是一致的,我们启动数据库验证一下。
1 | $ psql postgres -c 'SELECT oid, spcname, pg_tablespace_location(oid) FROM pg_tablespace'; |
同样地,我们可以在恢复的时候指定表空间的路径。
1 | $ pg_ctl stop -l log -D $PWD/db-backup |
从日志信息中可以看到 /home/japin/lab/idxspc
将被映射到 /mnt/workspace/idxspc
,/home/japin/lab/tblspc
将被映射到 /mnt/workspace/tblspc
。同样地,启动数据库服务器进行验证。
1 | $ pg_ctl start -l log -D $PWD/db-backup |
pg_basebackup
和 pg_probackup
均支持表空间的备份,它们的不同在于 pg_basebackup
在备份的时候需要指定表空间映射关系(在与源数据库不一致的情况下),而 pg_probackup
在备份时则不需要指定表空间映射,但是在恢复的时候需要提供映射关系(如果需要)。
有涩舌者,俗云鸽口是也。
来到市中买桐油,向店主曰:“我要买桐桐桐……”油字再也说不出口。
店主取笑曰:“你这人倒会打铜鼓,何不再敲通铜锣与我听?”
鸽者怒曰:“你不要当当当面来腾腾腾倒刮刮刮削我。”
scram_iterations
参数来定义 SCRAM 的迭代次数。
参数 scram_iterations
的默认值为 4096,这与 PostgreSQL 之前的硬编码值相同(同时也是 RFC 7677 里面定义的最小迭代次数)。如下所示,我们创建了三个用户,它们使用了不同的迭代次数。
1 | [local]:889416 postgres=# \timing |
从创建用户语句的执行时间上我们可以看到迭代次数越小、执行的速度越快。接着我们看看 pg_authid
表中 rolpassword
的存储。
1 | SELECT rolname, |
可以看到 rolpassword
里面记录了 SCRAM 的迭代次数。
SCRAM 的迭代次数越大,对抗暴力攻击的能力就越强,但是任何事情都是有两面性的;迭代次数越大,带来的问题就是连接的时候认证的时间越长(从上面创建用户的执行时间就可以看出端倪)。这里我们使用 pgbench 对不同的迭代次数进行连接测试。
首先创建一个测试文件用于 pgbench 执行,如下所示:
1 | $ cat pgbench-empty.sql |
接着我们需要修改 pg_hba.conf
,确保其使用 SCRAM-SHA-256 认证方式,修改之后的结果如下所示(这里我使用的是本地连接):
1 | [local]:914251 postgres=# select * from pg_hba_file_rules ; |
接着我们需要配置用户的密码,您可以使用 ~/.pgpass
进行配置,这里为了简便,我们在创建用户的时候使用了相同的密码,因此使用 PGPASSWORD
环境变量。
1 | $ export PGPASSWORD=hello |
测试结果如下所示:
1 | $ pgbench -n -T 30 -f pgbench-empty.sql -C -U scram_1 postgres |
虽然这只是一个默认的数据库实例,但是不同迭代次数对数据库的性能影响还是比较大的,因此在使用的时候我们需要在安全性与性能之间做好权衡。
[1] https://www.postgresql.org/docs/16/runtime-config-connection.html#GUC-SCRAM-ITERATIONS
[2] https://paquier.xyz/postgresql-2/postgres-16-scram-iterations/
北地产梨甚佳,北人至南,索梨食,不得。
南人因进萝卜,曰:“此敝乡土产之梨也。”
北人曰:“此物吃下,转气就臭,味又带辣,只该唤他做臭辣梨。”
路由地址
完整路由地址
相关文档
https://docs.rsshub.app/blog.html#hexo
预期是什么?
实际发生了什么?
部署
RSSHub 演示 (https://rsshub.app)
部署相关信息
docker-compose version 1.29.2, build unknown 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
额外信息
这不是重复的 issue