暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 15 preview - pg_basebackup 增强, 支持服务端备份目的地 target = server, blackhole

原创 digoal 2022-01-20
605

作者

digoal

日期

2022-01-21

标签

PostgreSQL , pg_basebackup


pg_basebackup 可以远程备份数据库, 通过流复制协议将数据文件、WAL日志传输到远程(客户端)的备份机器上.

但是pg_basebackup 15又支持了target选项:
- 用户可以将数据备份到数据库服务器可访问的目录中, 为什么有这样的需求呢?
- 例如 --target=server:/backupdir/20220121 表示备份到数据库服务器的/backupdir/20220121目录中.
- 这个需求的原因可能是:
- 某些备份目的地只有数据库所在的服务器能访问. 客户端访问不了.
- 不希望通过网络传输, 怕占用网络带宽. 或者存储带宽更高, 可以更快的完成备份.
- 用户还可以将数据备份到黑洞中(也是服务端行为), 用于调试目的.
- --target=blackhole

target=server需要拥有pg_write_server_files角色权限:

+        server requires superuser privileges or being granted the
+        <literal>pg_write_server_files</literal> role. If the target is set to

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=3500ccc39b0dadd1068a03938e4b8ff562587ccc

Support base backup targets.    
author  Robert Haas <rhaas@postgresql.org>      
Tue, 16 Nov 2021 20:20:50 +0000 (15:20 -0500)    
committer   Robert Haas <rhaas@postgresql.org>      
Thu, 20 Jan 2022 15:46:33 +0000 (10:46 -0500)    
commit  3500ccc39b0dadd1068a03938e4b8ff562587ccc    
tree    1c5d639bebf9c9f493a4cebffd59baa4c7dafbb9    tree    
parent  f80900be06f784a6bda705800305c550e05d6edf    commit | diff    
Support base backup targets.    
pg_basebackup now has a --target=TARGET[:DETAIL] option. If specfied,    
it is sent to the server as the value of the TARGET option to the    
BASE_BACKUP command. If DETAIL is included, it is sent as the value of    
the new TARGET_DETAIL option to the BASE_BACKUP command.  If the    
target is anything other than 'client', pg_basebackup assumes that it    
will now be the server's job to write the backup in a location somehow    
defined by the target, and that it therefore needs to write nothing    
locally. However, the server will still send messages to the client    
for progress reporting purposes.    
On the server side, we now support two additional types of backup    
targets.  There is a 'blackhole' target, which just throws away the    
backup data without doing anything at all with it. Naturally, this    
should only be used for testing and debugging purposes, since you will    
not actually have a backup when it finishes running. More usefully,    
there is also a 'server' target, so you can now use something like    
'pg_basebackup -Xnone -t server:/SOME/PATH' to write a backup to some    
location on the server. We can extend this to more types of targets    
in the future, and might even want to create an extensibility    
mechanism for adding new target types.    
Since WAL fetching is handled with separate client-side logic, it's    
not part of this mechanism; thus, backups with non-default targets    
must use -Xnone or -Xfetch.    
Patch by me, with a bug fix by Jeevan Ladhe.  The patch set of which    
this is a part has also had review and/or testing from Tushar Ahuja,    
Suraj Kharage, Dipesh Pandit, and Mark Dilger.    
Discussion: http://postgr.es/m/CA+TgmoaYZbz0=Yk797aOJwkGJC-LK3iXn+wzzMx7KdwNpZhS5g@mail.gmail.com    

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7f6772317b4a4f9d30c25d1853571fca6d834f0c

Adjust server-side backup to depend on pg_write_server_files.
author  Robert Haas <rhaas@postgresql.org>  
Fri, 28 Jan 2022 17:26:33 +0000 (12:26 -0500)
committer   Robert Haas <rhaas@postgresql.org>  
Fri, 28 Jan 2022 17:31:40 +0000 (12:31 -0500)
commit  7f6772317b4a4f9d30c25d1853571fca6d834f0c
tree    24ad2d60e545cb57f5351d89630899757bf473ec    tree
parent  51891d5a95605c4e98324731b386345d89c5a71e    commit | diff
Adjust server-side backup to depend on pg_write_server_files.
I had made it depend on superuser, but that seems clearly inferior.
Also document the permissions requirement in the straming replication
protocol section of the documentation, rather than only in the
section having to do with pg_basebackup.
Idea and patch from Dagfinn Ilmari Mannsåker.
Discussion: http://postgr.es/m/87bkzw160u.fsf@wibble.ilmari.org

期望 PostgreSQL 增加什么功能?

PolarDB for PostgreSQL云原生分布式开源数据库

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论