pg_resetxlog是做什么的?以及它如何运作? [英] What does pg_resetxlog do? And how does it work?

查看:297
本文介绍了pg_resetxlog是做什么的?以及它如何运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一下postgres文档,并给出了下面的提要:

I have looked at the postgres documentation and the synopsis below is given:

pg_resetxlog [-f] [-n] [-ooid ] [-x xid ] [-e xid_epoch ] [-m mxid ] [-O mxoff ] [-l timelineid,fileid,seg ] datadir

但是在文档中没有任何内容解释数据目录是什么。
%postgres-path%/ 9.0 / data 还是%postgres-path%/ 9.0 / data / pgxlog 吗?

But at no point in the documentation do they explain what the datadir is. Is it the %postgres-path%/9.0/data or could it be %postgres-path%/9.0/data/pgxlog ?

此外,如果我想更改xlog目录,是否可以简单地将项目移动到当前 pg_xlog中目录并运行命令以指向另一个目录? (假设我当前的pg_xlog目录位于 / data1 / postgres / data / pg_xlog 中,而我希望日志进入的目录为: / data2 / pg_xlog

Also, if I want to change my xlog directory, can I simply move the items in my current pg_xlog directory and run the command to point to another directory? (Assume my current pg_xlog directory is in /data1/postgres/data/pg_xlog AND the directory I want it the logs to go to is: /data2/pg_xlog)

以下命令能否实现我刚刚描述的内容?

Would the following command achieve what I've just described?

mv /data1/postgres/data/pg_xlog /data2/pg_xlog
pg_resetxlog /data2


推荐答案

pg_resetxlog 是在以下情况下使数据库重新运行的最后手段:

pg_resetxlog is a tool of last resort for getting your database running again after:


  • 您已从 pg_xlog ;

您恢复了文件系统级备份,由于备份系统配置错误,该文件省略了 pg_xlog 目录(这种情况比您想象的要多,人们认为登录名称,因此它必须不重要;我将其保留在备份之外)。

You restored a file system level backup that omitted the pg_xlog directory due to a backup system configuration mistake (this happens more than you'd think, people think "it has log in the name so it must be unimportant; I'll leave it out of the backups").

由于硬件故障或硬盘故障导致的文件系统损坏损坏了您的数据目录;甚至可能甚至

File-system corruption due to a hardware fault or hard drive failure damaged your data directory; or potentially even

PostgreSQL错误或操作系统错误损坏了预写日志(非常罕见)。

a PostgreSQL bug or operating system bug damaged the write-ahead logs (exceedingly rare).

如手册所述:


pg_resetxlog清除预写日志(WAL)[...]。如果这些文件已损坏,则有时需要此
函数。当服务器由于这种损坏而无法启动
时,只能将
用作最后的手段。

pg_resetxlog clears the write-ahead log (WAL) [...]. This function is sometimes needed if these files have become corrupted. It should be used only as a last resort, when the server will not start due to such corruption.

请勿运行 pg_resetxlog ,除非您确切地知道自己在做什么以及为什么。如果不确定,请在 pgsql常规邮件列表https://dba.stackexchange.com/

Do not run pg_resetxlog unless you know exactly what you are doing and why. If you are unsure, ask on the pgsql-general mailing list or on https://dba.stackexchange.com/.

<$ c $文档警告,c> pg_resetxlog 可能会损坏数据库。如果必须使用它,则应 REINDEX ,转储​​数据库,重新初始化db,然后重新加载数据库。不要只是继续使用损坏的群集。根据文档:

pg_resetxlog may corrupt your database, as the documentation warns. If you have to use it, you should REINDEX, dump your database(s), re-initdb, and reload your databases. Do not just continue using the damaged cluster. As per the documentation:


运行此命令后,应该可以启动服务器
,但请记住由于
是部分提交的交易,因此数据库中可能包含不一致的数据。您应该立即转储
数据,运行initdb并重新加载。重新加载后,检查不一致性
并根据需要进行修复。

After running this command, it should be possible to start the server, but bear in mind that the database might contain inconsistent data due to partially-committed transactions. You should immediately dump your data, run initdb, and reload. After reload, check for inconsistencies and repair as needed.

如果您只是想移动预写日志目录到另一个位置,您应该:

If you simply want to move your write-ahead log directory to another location, you should:


  • 停止PostgreSQL

  • 移动 pg_xlog

  • 从旧位置到新位置添加符号链接

  • 启动PostgreSQL

  • Stop PostgreSQL
  • Move pg_xlog
  • Add a symbolic link from the old location to the new location
  • Start PostgreSQL

或者,作为文档中的内容


如果日志与$ b $位于不同的磁盘上,则非常有利b主数据库文件。这可以通过将pg_xlog
目录移动到另一个位置(在关闭服务器的
过程中)并将符号链接从
主数据目录中的原始位置创建到

It is advantageous if the log is located on a different disk from the main database files. This can be achieved by moving the pg_xlog directory to another location (while the server is shut down, of course) and creating a symbolic link from the original location in the main data directory to the new location.

如果PostgreSQL无法启动,则说明您做错了什么。不要使用 pg_resetxlog 对其进行修复。撤消更改并找出您做错了什么。

If PostgreSQL fails to start, you've done something wrong. Do not use pg_resetxlog to "fix" it. Undo your changes and work out what you did wrong.

这篇关于pg_resetxlog是做什么的?以及它如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆