PostgreSQL 9.3 Have pg_basebackup --write-recovery-conf output a minimal recovery.conf

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介:
Have pg_basebackup --write-recovery-conf output a minimal recovery.conf (Zoltán B?sz?rményi, Magnus Hagander)
This simplifies setting up a standby server.
AI 代码解读

个人感觉没有太大的意义.

[测试]
-- 命令行帮助
pg93@db-172-16-3-33-> pg_basebackup --help
pg_basebackup takes a base backup of a running PostgreSQL server.

Usage:
  pg_basebackup [OPTION]...

Options controlling the output:
  -D, --pgdata=DIRECTORY receive base backup into directory
  -F, --format=p|t       output format (plain (default), tar)
  -R, --write-recovery-conf
                         write recovery.conf after backup
  -x, --xlog             include required WAL files in backup (fetch mode)
  -X, --xlog-method=fetch|stream
                         include required WAL files with specified method
  -z, --gzip             compress tar output
  -Z, --compress=0-9     compress tar output with given compression level

General options:
  -c, --checkpoint=fast|spread
                         set fast or spread checkpointing
  -l, --label=LABEL      set backup label
  -P, --progress         show progress information
  -v, --verbose          output verbose messages
  -V, --version          output version information, then exit
  -?, --help             show this help, then exit

Connection options:
  -d, --dbname=CONNSTR   connection string
  -h, --host=HOSTNAME    database server host or socket directory
  -p, --port=PORT        database server port number
  -s, --status-interval=INTERVAL
                         time between status packets sent to server (in seconds)
  -U, --username=NAME    connect as specified database user
  -w, --no-password      never prompt for password
  -W, --password         force password prompt (should happen automatically)
AI 代码解读

-- 使用pg_basebackup并使用-R选项
pg93@db-172-16-3-33-> pg_basebackup -D /pgdata/digoal/1921/data03/test -F p --write-recovery-conf 
WARNING:  skipping special file "./.s.PGSQL.1999"
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived
pg93@db-172-16-3-33-> cd /pgdata/digoal/1921/data03/test/
AI 代码解读

-- 自动生成的recovery.conf文件.
pg93@db-172-16-3-33-> cat recovery.conf
standby_mode = 'on'
primary_conninfo = 'user=''postgres'' port=''1999'' sslmode=''prefer'' sslcompression=''1'' '
AI 代码解读


[参考]
1. src/bin/pg_basebackup/pg_basebackup.c
00071 /* Contents of recovery.conf to be generated */
00072 static PQExpBuffer recoveryconfcontents = NULL;
...
00680             if (basetablespace && writerecoveryconf)
00681             {
00682                 char        header[512];
00683                 int         padding;
00684 
00685                 tarCreateHeader(header, "recovery.conf", NULL,
00686                                 recoveryconfcontents->len,
00687                                 0600, 04000, 02000,
00688                                 time(NULL));
00689 
00690                 padding = ((recoveryconfcontents->len + 511) & ~511) - recoveryconfcontents->len;
00691 
00692                 WRITE_TAR_DATA(header, sizeof(header));
00693                 WRITE_TAR_DATA(recoveryconfcontents->data, recoveryconfcontents->len);
00694                 if (padding)
00695                     WRITE_TAR_DATA(zerobuf, padding);
00696             }
...
01190 /*
01191  * Write a recovery.conf file into the directory specified in basedir,
01192  * with the contents already collected in memory.
01193  */
01194 static void
01195 WriteRecoveryConf(void)
01196 {
01197     char        filename[MAXPGPATH];
01198     FILE       *cf;
01199 
01200     sprintf(filename, "%s/recovery.conf", basedir);
01201 
01202     cf = fopen(filename, "w");
01203     if (cf == NULL)
01204     {
01205         fprintf(stderr, _("%s: could not create file \"%s\": %s\n"), progname, filename, strerror(errno));
01206         disconnect_and_exit(1);
01207     }
01208 
01209     if (fwrite(recoveryconfcontents->data, recoveryconfcontents->len, 1, cf) != 1)
01210     {
01211         fprintf(stderr,
01212                 _("%s: could not write to file \"%s\": %s\n"),
01213                 progname, filename, strerror(errno));
01214         disconnect_and_exit(1);
01215     }
01216 
01217     fclose(cf);
01218 }
AI 代码解读

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
打赏
0
0
0
0
20695
分享
相关文章
PostgreSQL 时间点恢复(PITR)在异步流复制主从模式下,如何避免主备切换后PITR恢复(备库、容灾节点、只读节点)走错时间线(timeline , history , partial , restore_command , recovery.conf)
标签 PostgreSQL , 恢复 , 时间点恢复 , PITR , restore_command , recovery.conf , partial , history , 任意时间点恢复 , timeline , 时间线 背景 政治正确非常重要,对于数据库来说亦如此,一个基于流复制的HA架构的集群,如果还有一堆只读节点,当HA集群发生了主备切换后,这些只读节点能否与新的主节点保持
1888 0
PostgreSQL 12: Recovery.conf 文件参数合并到 postgresql.conf
PostgreSQL 12 的一个重要变化是 recovery.conf 配置文件中的参数合并到 postgresql.conf,recovery.conf 不再使用,我们看看手册的说明,如下: 发行说明 Move recovery.
4942 0
PostgreSQL recovery.conf恢复配置
PostgreSQL recovery.conf恢复配置
LXJ
591 0
PostgreSQL recovery.conf 配置文件整合到 postgresql.conf
标签 PostgreSQL , recovery.conf , postgresql.conf 背景 PostgreSQL 12版本以前,配置PostgreSQL数据库恢复、流复制STANDBY,都需要配置recovery.conf,如果要修改配置,需要重启数据库。
3199 0
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍(中)
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍
527 0
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍(下)
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍
451 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等