PG_RESETWAL(1)

๐Ÿ“ฆ version 17.11, in opensuse-leap 16.0

โœจ NAME โœจ

pg_resetwal(1) โ€” reset the write-ahead log and other control information of a PostgreSQL database cluster. This is the manual page for pg_resetwal, bestie, and it is not a casual little command you run for fun ๐Ÿ’….


๐ŸŒธ SYNOPSIS ๐ŸŒธ

pg_resetwal [-f | --force] [-n | --dry-run] [option...] [-D |
            --pgdata]datadir

โœจ DESCRIPTION โœจ

okay so pg_resetwal clears the write-ahead log (WAL) and optionally resets some other control information stored in the pg_control file. 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. like, LAST RESORT last resort. ๐Ÿ˜ญ

Some options, such as --wal-segsize (see below), can also be used to modify certain global settings of a database cluster without the need to rerun initdb. This can be done safely on an otherwise sound database cluster, if none of the dangerous modes mentioned below are used. lowkey useful when you're just changing a setting and not doing emergency surgery ๐Ÿฉน

If pg_resetwal is used on a data directory where the server has been cleanly shut down and the control file is sound, then it will have no effect on the contents of the database system, except that no longer used WAL files are cleared away. Any other use is potentially dangerous and must be done with great care. pg_resetwal will require the -f (force) option to be specified before working on a data directory in an unclean shutdown state or with a corrupted control file. no -f, no vibes, no touching. ๐Ÿ’…

After running this command on a data directory with corrupted WAL or a corrupted control file, 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 restore. After restore, check for inconsistencies and repair as needed. immediately. dump. initdb. restore. then check and repair. not me telling you to skip this, bestie ๐Ÿ˜ญ

If pg_resetwal complains that it cannot determine valid data for pg_control, you can force it to proceed anyway by specifying the -f (force) option. In this case plausible values will be substituted for the missing data. Most of the fields can be expected to match, but manual assistance might be needed for the next OID, next transaction ID and epoch, next multitransaction ID and offset, and WAL starting location fields. These fields can be set using the options discussed below. If you are not able to determine correct values for all these fields, -f can still be used, but the recovered database must be treated with even more suspicion than usual: an immediate dump and restore is imperative. Do not execute any data-modifying operations in the database before you dump, as any such action is likely to make the corruption worse. do not run data-modifying operations before the dump. fr fr ๐Ÿ™ˆ

This utility can only be run by the user who installed the server, because it requires read/write access to the data directory. permissions check first, bestie. ๐Ÿ”


๐Ÿ’– OPTIONS ๐Ÿ’–

  • datadir, -D datadir, --pgdata=datadir โ€” specifies the location of the database directory. For safety reasons, you must specify the data directory on the command line. pg_resetwal does not use the environment variable PGDATA. on the command line only, no sneaky env var shortcut ๐Ÿ‘€
  • -f, --force โ€” force pg_resetwal to proceed even in situations where it could be dangerous, as explained above. Specifically, this option is required to proceed if the server had not been cleanly shut down or if pg_resetwal cannot determine valid data for pg_control. this is the "I know what I'm doing" flag, except sometimes you really don't ๐Ÿ˜ญ
  • -n, --dry-run โ€” the -n/--dry-run option instructs pg_resetwal to print the values reconstructed from pg_control and values about to be changed, and then exit without modifying anything. This is mainly a debugging tool, but can be useful as a sanity check before allowing pg_resetwal to proceed for real. the "look before you leap" option, literal queen behavior โœจ
  • -V, --version โ€” display version information, then exit. short and sweet ๐Ÿ’™
  • -?, --help โ€” show help, then exit. when in doubt, ask for help ๐Ÿซถ

The following options are only needed when pg_resetwal is unable to determine appropriate values by reading pg_control. Safe values can be determined as described below. For values that take numeric arguments, hexadecimal values can be specified by using the prefix 0x. Note that these instructions only apply with the standard block size of 8 kB. that 8 kB bit matters, don't skip it ๐ŸŽ€

  • -c xid,xid, --commit-timestamp-ids=xid,xid โ€” manually set the oldest and newest transaction IDs for which the commit time can be retrieved.

A safe value for the oldest transaction ID for which the commit time can be retrieved (first part) can be determined by looking for the numerically smallest file name in the directory pg_commit_ts under the data directory. Conversely, a safe value for the newest transaction ID for which the commit time can be retrieved (second part) can be determined by looking for the numerically greatest file name in the same directory. The file names are in hexadecimal. smallest = first part, greatest = second part, hex hex hex โœจ

  • -e xid_epoch, --epoch=xid_epoch โ€” manually set the next transaction ID's epoch.

The transaction ID epoch is not actually stored anywhere in the database except in the field that is set by pg_resetwal, so any value will work so far as the database itself is concerned. You might need to adjust this value to ensure that replication systems such as Slony-I and Skytools work correctly โ€” if so, an appropriate value should be obtainable from the state of the downstream replicated database. replication besties, this one's for you ๐Ÿซถ

  • -l walfile, --next-wal-file=walfile โ€” manually set the WAL starting location by specifying the name of the next WAL segment file.

The name of next WAL segment file should be larger than any WAL segment file name currently existing in the directory pg_wal under the data directory. These names are also in hexadecimal and have three parts. The first part is the โ€œtimeline IDโ€ and should usually be kept the same. For example, if 00000001000000320000004A is the largest entry in pg_wal, use -l 00000001000000320000004B or higher. bigger than the biggest, timeline ID usually stays put ๐Ÿ’…

Note that when using nondefault WAL segment sizes, the numbers in the WAL file names are different from the LSNs that are reported by system functions and system views. This option takes a WAL file name, not an LSN. not an LSN! do not put an LSN here! ๐Ÿ˜ญ

๐ŸŒธ Note: pg_resetwal itself looks at the files in pg_wal and chooses a default -l setting beyond the last existing file name. Therefore, manual adjustment of -l should only be needed if you are aware of WAL segment files that are not currently present in pg_wal, such as entries in an offline archive; or if the contents of pg_wal have been lost entirely. so like, usually it handles this for you, okay? ๐ŸŽ€
  • -m mxid,mxid, --multixact-ids=mxid,mxid โ€” manually set the next and oldest multitransaction ID.

A safe value for the next multitransaction ID (first part) can be determined by looking for the numerically largest file name in the directory pg_multixact/offsets under the data directory, adding one, and then multiplying by 65536 (0x10000). Conversely, a safe value for the oldest multitransaction ID (second part of -m) can be determined by looking for the numerically smallest file name in the same directory and multiplying by 65536. The file names are in hexadecimal, so the easiest way to do this is to specify the option value in hexadecimal and append four zeroes. append four zeroes, iconic shortcut โœจ

  • -o oid, --next-oid=oid โ€” manually set the next OID.

There is no comparably easy way to determine a next OID that's beyond the largest one in the database, but fortunately it is not critical to get the next-OID setting right. not critical, so breathe ๐Ÿ˜ฎโ€๐Ÿ’จ

  • -O mxoff, --multixact-offset=mxoff โ€” manually set the next multitransaction offset.

A safe value can be determined by looking for the numerically largest file name in the directory pg_multixact/members under the data directory, adding one, and then multiplying by 52352 (0xCC80). The file names are in hexadecimal. There is no simple recipe such as the ones for other options of appending zeroes. no append-zeroes trick here, sorry bestie ๐Ÿ˜ญ

  • --wal-segsize=wal_segment_size โ€” set the new WAL segment size, in megabytes. The value must be set to a power of 2 between 1 and 1024 (megabytes). See the same option of initdb(1) for more information. power of 2, between 1 and 1024 MB, periodt ๐Ÿ’…

This option can also be used to change the WAL segment size of an existing database cluster, avoiding the need to re-initdb. yes, existing cluster, no re-initdb needed โœจ

๐ŸŒธ Note: While pg_resetwal will set the WAL starting address beyond the latest existing WAL segment file, some segment size changes can cause previous WAL file names to be reused. It is recommended to use -l together with this option to manually set the WAL starting address if WAL file name overlap will cause problems with your archiving strategy. archiving bestie, pay attention to the overlap warning ๐Ÿซถ
  • -u xid, --oldest-transaction-id=xid โ€” manually set the oldest unfrozen transaction ID.

A safe value can be determined by looking for the numerically smallest file name in the directory pg_xact under the data directory and then multiplying by 1048576 (0x100000). Note that the file names are in hexadecimal. It is usually easiest to specify the option value in hexadecimal too. For example, if 0007 is the smallest entry in pg_xact, -u 0x700000 will work (five trailing zeroes provide the proper multiplier). five trailing zeroes = the multiplier vibe ๐Ÿ’…

  • -x xid, --next-transaction-id=xid โ€” manually set the next transaction ID.

A safe value can be determined by looking for the numerically largest file name in the directory pg_xact under the data directory, adding one, and then multiplying by 1048576 (0x100000). Note that the file names are in hexadecimal. It is usually easiest to specify the option value in hexadecimal too. For example, if 0011 is the largest entry in pg_xact, -x 0x1200000 will work (five trailing zeroes provide the proper multiplier). largest, add one, multiply, five trailing zeroes โ€” you got this โœจ


๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

  • PG_COLOR โ€” specifies whether to use color in diagnostic messages. Possible values are always, auto and never. color choices, because of course we care about aesthetics ๐Ÿ’…

๐ŸŽ€ NOTES ๐ŸŽ€

This command must not be used when the server is running. pg_resetwal will refuse to start up if it finds a server lock file in the data directory. If the server crashed then a lock file might have been left behind; in that case you can remove the lock file to allow pg_resetwal to run. But before you do so, make doubly certain that there is no server process still alive. DOUBLY CERTAIN. no server process still alive. do not skip this check. ๐Ÿ˜ญ

pg_resetwal works only with servers of the same major version. same major version only, no mismatched chaos ๐Ÿซถ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

pg_controldata(1) โ€” go read that one too, bestie ๐Ÿฆ‹


๐Ÿ’– that's the whole page โ€” from the PostgreSQL 17.11 docs, dated 2026, manual page PG_RESETWAL(1). now go be careful with that data directory ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from