pg_resetxlog is the tool of the last attempt to start your database again after:
You have deleted files that should not have from pg_xlog ;
You restored a file system level backup that did not specify the pg_xlog directory due to a backup system configuration error (this happens more than you think, people think that it has a name in the log, so it should not matter, I will leave it from backups ").
Damage to the file system due to hardware failure or hard disk failure damaged your data directory; or potentially even
A PostgreSQL error or an operating system error has damaged write-ahead logs (extremely rare).
As the manual says:
pg_resetxlog clears the log (WAL) [...]. This feature is sometimes necessary if these files are damaged. This should only be used as a last resort when the server does not start due to such corruption.
Do not run pg_resetxlog unless you know exactly what you are doing and why . If you are not sure, ask the pgsql-general mailing list or https://dba.stackexchange.com/ .
pg_resetxlog can corrupt your database , as the documentation warns. If you need to use it, you must REINDEX , reset your databases, restart initdb and restart your databases. Do not continue to use a damaged cluster. According to the documentation:
After running this command, it should be possible to start the server, but keep in mind that the database may contain inconsistent data due to partially completed transactions. You should immediately flush the data, run initdb and reboot. After rebooting, check for inconsistencies and repair if necessary.
If you just want to move your recording log directory to another location, you need to:
- Stop PostgreSQL
- Move
pg_xlog - Add symbolic link from old location to new location
- Launch PostgreSQL
Or, as the documentation says :
This is useful if the log is on a different drive with the main database files. This can be achieved by moving the pg_xlog directory to another location (while the server is off, from the course) and creating a symbolic link from the source location to the main data directory to a new location.
If PostgreSQL does not start, you did something wrong. Do not use pg_resetxlog to βfixβ it. Discard your changes and find out what you did wrong.
source share