AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 186103
Accepted
Dina
Dina
Asked: 2017-09-16 15:52:29 +0800 CST2017-09-16 15:52:29 +0800 CST 2017-09-16 15:52:29 +0800 CST

存档文件夹 PostgreSQL 流复制中的 WAL 文件太多

  • 772

我在流复制中配置了两台 Postgresql 9.5 服务器。日志文件中没有错误,服务器似乎是同步的。

大师 postgresl.config

archive_command = 'test ! -f mnt/server/archivedir/%f && cp %p mnt/server/archivedir/%f'
wal_keep_segments = 32

其他一切几乎都是默认的。然而我在存档目录中有 1600 多个文件!由于篇幅限制,我敢于删除其中的一些。我想弄清楚是什么原因造成的。我还看到同一目录的从属服务器上只有非常旧的文件。

我唯一能想到的是我最近对数据库进行了还原。我删除了数据库,创建了它并进行了备份还原。我这样做了好几次。奴隶似乎已经赶上了变化。但是对于每个备份还原,我在存档文件夹中都有大量的 WAL 文件。希望对可能发生的事情有所了解。

postgresql replication
  • 2 2 个回答
  • 4425 Views

2 个回答

  • Voted
  1. Best Answer
    jjanes
    2017-09-17T12:11:09+08:002017-09-17T12:11:09+08:00

    wal_keep_segments告诉它要在目录中保留多少文件pg_xlog,而不是存档目录。

    PostgreSQL 不会为您管理存档目录,这取决于您。它甚至不知道存档位置在哪里(或什么),这就是为什么它要求您提供archive_command,而不仅仅是一个目录。就 PostgreSQL 而言,您的存档命令可以通过 od 传递文件,将输出发送到带有无酸纸的行式打印机,然后将其放入 3 环活页夹中并将它们存储在您的阁楼中。虽然更常见的是加密它们并将它们上传到亚马逊的 S3,比如说。

    两者一起使用有点奇怪,至少对于相对简单的设置来说是wal_keep_segments这样archive_command。如果您只想要一个流式副本并且不需要进行时间点恢复的能力,您可以完全关闭归档。

    如果您确实想继续使用存档但在不再需要文件时将其清理,您可以使用该archive_cleanup_command设置。但是现在我们有了流复制和复制槽,这几乎已经过时了。

    • 3
  2. zaratustra689
    2020-08-15T13:26:52+08:002020-08-15T13:26:52+08:00

    正如我在这篇文章https://stackoverflow.com/a/63401901/10043142中所说的那样,PostgreSQL Wiki ( https://wiki.postgresql.org/wiki/Streaming_Replication ) 在下面的文章第 5 步中说了一些重要的事情:

    # To enable read-only queries on a standby server, wal_level must be set to
    # "hot_standby". But you can choose "archive" if you never connect to the
    # server in standby mode.
    wal_level = hot_standby
    
    # Set the maximum number of concurrent connections from the standby servers.
    max_wal_senders = 5
    
    # To prevent the primary server from removing the WAL segments required for
    # the standby server before shipping them, set the minimum number of segments
    # retained in the pg_xlog directory. At least wal_keep_segments should be
    # larger than the number of segments generated between the beginning of
    # online-backup and the startup of streaming replication. If you enable WAL
    # archiving to an archive directory accessible from the standby, this may
    # not be necessary.
    wal_keep_segments = 32
    
    # Enable WAL archiving on the primary to an archive directory accessible from
    # the standby. If wal_keep_segments is a high enough number to retain the WAL
    # segments required for the standby server, this is not necessary.
    archive_mode    = on
    archive_command = 'cp %p /path_to/archive/%f'
    
    • -1

相关问题

  • 运行时间偏移延迟复制的最佳实践

  • 存储过程可以防止 SQL 注入吗?

  • PostgreSQL 中 UniProt 的生物序列

  • PostgreSQL 9.0 Replication 和 Slony-I 有什么区别?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve