summaryrefslogtreecommitdiff
path: root/src/bin/pg_upgrade/controldata.c
AgeCommit message (Collapse)Author
2025-04-18Make pg_upgrade log message with control file path translatable.Fujii Masao
Commit 173c97812ff replaced the hardcoded "global/pg_control" in pg_upgrade log message with a string literal concatenation of XLOG_CONTROL_FILE macro. However, this change made the message untranslatable. This commit fixes the issue by using %s with XLOG_CONTROL_FILE instead of that literal concatenation, allowing the message to be translated properly. It also wraps the file path in double quotes for consistency with similar log messages. Author: Kyotaro Horiguchi <[email protected]> Reviewed-by: Masao Fujii <[email protected]> Discussion: https://postgr.es/m/[email protected]
2025-04-07Use XLOG_CONTROL_FILE macro consistently for control file name.Fujii Masao
The XLOG_CONTROL_FILE macro (defined in access/xlog_internal.h) represents the control file name. While some parts of the codebase already use this macro, others previously hardcoded the file name as a string. This commit replaces those hardcoded strings with the macro, ensuring consistent usage throughout the code. This makes future maintenance easier and improves searchability, for example when grepping for control file usage. Author: Anton A. Melnikov <[email protected]> Reviewed-by: Daniel Gustafsson <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: Masao Fujii <[email protected]> Discussion: https://postgr.es/m/[email protected]
2025-03-25pg_upgrade: Add --swap for faster file transfer.Nathan Bossart
This new option instructs pg_upgrade to move the data directories from the old cluster to the new cluster and then to replace the catalog files with those generated for the new cluster. This mode can outperform --link, --clone, --copy, and --copy-file-range, especially on clusters with many relations. However, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if --sync-method=syncfs is used. To handle that, we recommend using --sync-method=fsync with this mode, and pg_upgrade internally uses "initdb --sync-only --no-sync-data-files" for file synchronization. pg_upgrade will synchronize the catalog files as they are transferred. We assume that the database files transferred from the old cluster were synchronized prior to upgrade. This mode also complicates reverting to the old cluster, so we recommend restoring from backup upon failure during or after file transfer. We did consider teaching pg_upgrade how to generate a revert script for such failures, but we decided against it due to the rarity of failing during file transfer, the complexity of generating the script, and the potential for misusing the script. The new mode is limited to clusters located in the same file system. With some effort, we could probably support upgrades between different file systems, but this mode is unlikely to offer much benefit if we have to copy the files across file system boundaries. It is also limited to upgrades from version 10 or newer. There are a few known obstacles for using swap mode to upgrade from older versions. For example, the visibility map format changed in v9.6, and the sequence tuple format changed in v10. In fact, swap mode omits the --sequence-data option in its uses of pg_dump and instead reuses the old cluster's sequence data files. While teaching swap mode to deal with these kinds of changes is surely possible (and we may have to deal with similar problems in the future, anyway), it doesn't seem worth the effort to support upgrades from long-unsupported versions. Reviewed-by: Greg Sabino Mullane <[email protected]> Reviewed-by: Robert Haas <[email protected]> Discussion: https://postgr.es/m/Zyvop-LxLXBLrZil%40nathan
2025-02-21pg_upgrade: Preserve default char signedness value from old cluster.Masahiko Sawada
Commit 44fe30fdab6 introduced the 'default_char_signedness' field in controlfile. Newly created database clusters always set this field to 'signed'. This change ensures that pg_upgrade updates the 'default_char_signedness' to 'unsigned' if the source database cluster has signedness=false. For source clusters from v17 or earlier, which lack the 'default_char_signedness' information, pg_upgrade assumes the source cluster was initialized on the same platform where pg_upgrade is running. It then sets the 'default_char_signedness' value according to the current platform's default character signedness. Reviewed-by: Noah Misch <[email protected]> Discussion: https://postgr.es/m/CB11ADBC-0C3F-4FE0-A678-666EE80CBB07%40amazon.com
2025-01-01Update copyright for 2025Bruce Momjian
Backpatch-through: 13
2024-07-26pg_upgrade: Move live_check variable to user_opts.Nathan Bossart
At the moment, pg_upgrade stores whether it is doing a "live check" (i.e., the user specified --check and the old server is still running) in a local variable scoped to main(). This live_check variable is passed to several functions. To further complicate matters, a few call sites provide a hard-coded "false" as the live_check argument. Specifically, this is done when calling these functions for the new cluster, for which any live-check-only paths won't apply. This commit moves the live_check variable to the global user_opts variable, which stores information about the options the user specified on the command line. This allows us to remove the live_check parameter from several functions. For the functions with callers that provide a hard-coded "false" as the live_check argument (e.g., get_control_data()), we verify the given cluster is the old cluster before taking any live-check-only paths. This small refactoring effort helps simplify some proposed changes that would parallelize many of pg_upgrade's once-in-each-database tasks using libpq's asynchronous APIs. By removing the live_check parameter, we can more easily convert the functions to callbacks for the new parallel system. Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/20240516211638.GA1688936%40nathanxps13
2024-03-13Make the order of the header file includes consistentPeter Eisentraut
Similar to commit 7e735035f20. Author: Richard Guo <[email protected]> Reviewed-by: Bharath Rupireddy <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/CAMbWs4-WhpCFMbXCjtJ%2BFzmjfPrp7Hw1pk4p%2BZpU95Kh3ofZ1A%40mail.gmail.com
2024-03-12Use printf's %m format instead of strerror(errno) in more placesMichael Paquier
Most callers of strerror() are removed from the backend code. The remaining callers require special handling with a saved errno from a previous system call. The frontend code still needs strerror() where error states need to be handled outside of fprintf. Note that pg_regress is not changed to use %m as the TAP output may clobber errno, since those functions call fprintf() and friends before evaluating the format string. Support for %m in src/port/snprintf.c has been added in d6c55de1f99a, hence all the stable branches currently supported include it. Author: Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/[email protected]
2024-01-04Update copyright for 2024Bruce Momjian
Reported-by: Michael Paquier Discussion: https://postgr.es/m/[email protected] Backpatch-through: 12
2023-07-20pg_upgrade: include additional detail in cluster checkDaniel Gustafsson
When the cluster failed the pg_controldata check for clean shut down we only reported that it did so, not why. The state of the cluster can be important information when diagnosing the failed upgrade attempt, so instead include it in the error message. Discussion: https://postgr.es/m/[email protected]
2023-01-02Update copyright for 2023Bruce Momjian
Backpatch-through: 11
2022-11-15Check return value of pclose() correctlyPeter Eisentraut
Some callers didn't check the return value of pclose() or ClosePipeStream() correctly. Either they didn't check it at all or they treated it like the return of fclose(). The correct way is to first check whether the return value is -1, and then report errno, and then check the return value like a result from system(), for which we already have wait_result_to_str() to make it simpler. To make this more compact, expand wait_result_to_str() to also handle -1 explicitly. Reviewed-by: Ankit Kumar Pandey <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
2022-09-15Revert ill-considered change in pg_resetwal output.Tom Lane
Commit 31dcfae83 changed one pg_resetwal output string, and a corresponding test in pg_upgrade, without sufficient thought for the consequences. We can't change that output without creating hazards for cross-version upgrades, since pg_upgrade needs to be able to read the output of several different versions of pg_resetwal. There may well be external tools with the same requirement. For the moment, just revert those two changes. What we really ought to do here is have a separate, stable, easily machine-readable output format for pg_resetwal and pg_controldata, as proposed years ago by Alvaro. Once that's in place and tools no longer need to depend on the exact spelling of the human-readable output, we can put back this change. Discussion: https://postgr.es/m/[email protected]
2022-09-14Use the terminology "WAL file" not "log file" more consistently.Tom Lane
Referring to the WAL as just "log" invites confusion with the postmaster log, so avoid doing that in docs and error messages. Also shorten "WAL segment file" to just "WAL file" in various places. Bharath Rupireddy, reviewed by Nathan Bossart and Kyotaro Horiguchi Discussion: https://postgr.es/m/CALj2ACUeXa8tDPaiTLexBDMZ7hgvaN+RTb957-cn5qwv9zf-MQ@mail.gmail.com
2022-08-29Clean up inconsistent use of fflush().Tom Lane
More than twenty years ago (79fcde48b), we hacked the postmaster to avoid a core-dump on systems that didn't support fflush(NULL). We've mostly, though not completely, hewed to that rule ever since. But such systems are surely gone in the wild, so in the spirit of cleaning out no-longer-needed portability hacks let's get rid of multiple per-file fflush() calls in favor of using fflush(NULL). Also, we were fairly inconsistent about whether to fflush() before popen() and system() calls. While we've received no bug reports about that, it seems likely that at least some of these call sites are at risk of odd behavior, such as error messages appearing in an unexpected order. Rather than expend a lot of brain cells figuring out which places are at hazard, let's just establish a uniform coding rule that we should fflush(NULL) before these calls. A no-op fflush() is surely of trivial cost compared to launching a sub-process via a shell; while if it's not a no-op then we likely need it. Discussion: https://postgr.es/m/[email protected]
2022-08-12pg_upgrade: Fix some minor code issuesPeter Eisentraut
96ef3b8ff1cf1950e897fd2f766d4bd9ef0d5d56 accidentally copied a not applicable comment from the float8_pass_by_value code to the data_checksums code. Remove that. 87d3b35a1ca31a9d947a8f919a6006679216dff0 changed pg_upgrade to checking the checksum version rather than just the Boolean presence of checksums, but didn't change the field type in its ControlData struct from bool. So this would not work correctly if there ever is a checksum version larger than 1.
2022-07-12Remove trailing newlines in pg_upgrade's message strings.Tom Lane
pg_upgrade does not use common/logging.c, which is unfortunate but changing it to do so seems like more work than is justified. However, we really need to make it work more like common/logging.c in one respect: the latter expects supplied message strings to not end with a newline, instead adding one internally. As it stands, pg_upgrade's logging facilities expect a caller-supplied newline in some cases and not others, which is already an invitation to bugs, but the inconsistency with our other frontend code makes it worse. There are already several places with missing or extra newlines, and it's inevitable that there won't be more if we let this stand. Hence, run around and get rid of all trailing newlines in message strings, and add an Assert that there's not one, similar to the existing Assert in common/logging.c. Adjust the logging functions to supply a newline at the right places. (Some of these strings also have a *leading* newline, which would be a good thing to get rid of too; but this patch doesn't attempt that.) There are some consequent minor changes in output. The ones that aren't outright bug fixes are generally removal of extra blank lines that the original coding intentionally inserted. It didn't seem worth being bug-compatible with that. Patch by me, reviewed by Kyotaro Horiguchi and Peter Eisentraut Discussion: https://postgr.es/m/[email protected]
2022-01-08Update copyright for 2022Bruce Momjian
Backpatch-through: 10
2021-07-27pg_resetxlog: add option to set oldest xid & use by pg_upgradeBruce Momjian
Add pg_resetxlog -u option to set the oldest xid in pg_control. Previously -x set this value be -2 billion less than the -x value. However, this causes the server to immediately scan all relation's relfrozenxid so it can advance pg_control's oldest xid to be inside the autovacuum_freeze_max_age range, which is inefficient and might disrupt diagnostic recovery. pg_upgrade will use this option to better create the new cluster to match the old cluster. Reported-by: Jason Harvey, Floris Van Nee Discussion: https://postgr.es/m/[email protected], [email protected] Author: Bertrand Drouvot Backpatch-through: 9.6
2021-01-02Update copyright for 2021Bruce Momjian
Backpatch-through: 9.5
2020-12-30Use setenv() in preference to putenv().Tom Lane
Since at least 2001 we've used putenv() and avoided setenv(), on the grounds that the latter was unportable and not in POSIX. However, POSIX added it that same year, and by now the situation has reversed: setenv() is probably more portable than putenv(), since POSIX now treats the latter as not being a core function. And setenv() has cleaner semantics too. So, let's reverse that old policy. This commit adds a simple src/port/ implementation of setenv() for any stragglers (we have one in the buildfarm, but I'd not be surprised if that code is never used in the field). More importantly, extend win32env.c to also support setenv(). Then, replace usages of putenv() with setenv(), and get rid of some ad-hoc implementations of setenv() wannabees. Also, adjust our src/port/ implementation of unsetenv() to follow the POSIX spec that it returns an error indicator, rather than returning void as per the ancient BSD convention. I don't feel a need to make all the call sites check for errors, but the portability stub ought to match real-world practice. Discussion: https://postgr.es/m/[email protected]
2020-12-28Revert "Add key management system" (978f869b99) & later commitsBruce Momjian
The patch needs test cases, reorganization, and cfbot testing. Technically reverts commits 5c31afc49d..e35b2bad1a (exclusive/inclusive) and 08db7c63f3..ccbe34139b. Reported-by: Tom Lane, Michael Paquier Discussion: https://postgr.es/m/[email protected]
2020-12-25Add key management systemBruce Momjian
This adds a key management system that stores (currently) two data encryption keys of length 128, 192, or 256 bits. The data keys are AES256 encrypted using a key encryption key, and validated via GCM cipher mode. A command to obtain the key encryption key must be specified at initdb time, and will be run at every database server start. New parameters allow a file descriptor open to the terminal to be passed. pg_upgrade support has also been added. Discussion: https://postgr.es/m/CA+fd4k7q5o6Nc_AaX6BcYM9yqTbC6_pnH-6nSD=54Zp6NBQTCQ@mail.gmail.com Discussion: https://postgr.es/m/[email protected] Author: Masahiko Sawada, me, Stephen Frost
2020-10-06pg_upgrade; change major version comparisons to use <=, not <Bruce Momjian
This makes checking for older major versions more consistent. Backpatch-through: 9.5
2020-01-01Update copyrights for 2020Bruce Momjian
Backpatch-through: update all files in master, backpatch legal files through 9.4
2019-10-25Make the order of the header file includes consistent in non-backend modules.Amit Kapila
Similar to commit 7e735035f2, this commit makes the order of header file inclusion consistent for non-backend modules. In passing, fix the case where we were using angle brackets (<>) for the local module includes instead of quotes (""). Author: Vignesh C Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/CALDaNm2Sznv8RR6Ex-iJO6xAdsxgWhCoETkaYX=+9DW3q0QCfA@mail.gmail.com
2019-06-08Update stale comments, and fix comment typos.Noah Misch
2019-05-22Initial pgindent run for v12.Tom Lane
This is still using the 2.0 version of pg_bsd_indent. I thought it would be good to commit this separately, so as to document the differences between 2.0 and 2.1 behavior. Discussion: https://postgr.es/m/[email protected]
2019-04-28Use preprocessor conditions compatible with Emacs indent.Noah Misch
Emacs wrongly indented hundreds of subsequent lines.
2019-01-02Update copyright for 2019Bruce Momjian
Backpatch-through: certain files through 9.4
2018-08-17pg_upgrade: issue helpful error message for use on standbysBruce Momjian
Commit 777e6ddf1723306bd2bf8fe6f804863f459b0323 checked for a shut down message from a standby and allowed it to continue. This patch reports a helpful error message in these cases, suggesting to use rsync as documented. Diagnosed-by: Martín Marqués Discussion: https://postgr.es/m/CAPdiE1xYCow-reLjrhJ9DqrMu-ppNq0ChUUEvVdxhdjGRD5_eA@mail.gmail.com Backpatch-through: 9.3
2018-08-14pg_upgrade: fix shutdown check for standby serversBruce Momjian
Commit 244142d32afd02e7408a2ef1f249b00393983822 only tested for the pg_controldata output for primary servers, but standby servers have different "Database cluster state" output, so check for that too. Diagnosed-by: Michael Paquier Discussion: https://postgr.es/m/[email protected] Backpatch-through: 9.3
2018-07-31pg_upgrade: fix --check for live source server checksBruce Momjian
Fix for commit 244142d32afd02e7408a2ef1f249b00393983822. Backpatch-through: 9.3
2018-07-28pg_upgrade: check for clean server shutdownsBruce Momjian
Previously pg_upgrade checked for the pid file and started/stopped the server to force a clean shutdown. However, "pg_ctl -m immediate" removes the pid file but doesn't do a clean shutdown, so check pg_controldata for a clean shutdown too. Diagnosed-by: Vimalraj A Discussion: https://postgr.es/m/CAFKBAK5e4Q-oTUuPPJ56EU_d2Rzodq6GWKS3ncAk3xo7hAsOZg@mail.gmail.com Backpatch-through: 9.3
2018-04-09Revert "Allow on-line enabling and disabling of data checksums"Magnus Hagander
This reverts the backend sides of commit 1fde38beaa0c3e66c340efc7cc0dc272d6254bb0. I have, at least for now, left the pg_verify_checksums tool in place, as this tool can be very valuable without the rest of the patch as well, and since it's a read-only tool that only runs when the cluster is down it should be a lot safer.
2018-04-05Allow on-line enabling and disabling of data checksumsMagnus Hagander
This makes it possible to turn checksums on in a live cluster, without the previous need for dump/reload or logical replication (and to turn it off). Enabling checkusm starts a background process in the form of a launcher/worker combination that goes through the entire database and recalculates checksums on each and every page. Only when all pages have been checksummed are they fully enabled in the cluster. Any failure of the process will revert to checksums off and the process has to be started. This adds a new WAL record that indicates the state of checksums, so the process works across replicated clusters. Authors: Magnus Hagander and Daniel Gustafsson Review: Tomas Vondra, Michael Banck, Heikki Linnakangas, Andrey Borodin
2018-01-03Update copyright for 2018Bruce Momjian
Backpatch-through: certain files through 9.3
2017-07-14pg_upgrade i18n: Fix "%s server/cluster" wordingAlvaro Herrera
The original wording was impossible to translate correctly. Discussion: https://postgr.es/m/[email protected]
2017-06-21Phase 3 of pgindent updates.Tom Lane
Don't move parenthesized lines to the left, even if that means they flow past the right margin. By default, BSD indent lines up statement continuation lines that are within parentheses so that they start just to the right of the preceding left parenthesis. However, traditionally, if that resulted in the continuation line extending to the right of the desired right margin, then indent would push it left just far enough to not overrun the margin, if it could do so without making the continuation line start to the left of the current statement indent. That makes for a weird mix of indentations unless one has been completely rigid about never violating the 80-column limit. This behavior has been pretty universally panned by Postgres developers. Hence, disable it with indent's new -lpl switch, so that parenthesized lines are always lined up with the preceding left paren. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/[email protected] Discussion: https://postgr.es/m/[email protected]
2017-02-15pg_upgrade: Fix problems caused by renaming pg_resetxlog.Robert Haas
Commit 85c11324cabaddcfaf3347df78555b30d27c5b5a renamed pg_resetxlog to pg_resetwal, but didn't make pg_upgrade smart enough to cope with the situation. Michael Paquier, per a complaint from Jeff Janes
2017-02-09Rename user-facing tools with "xlog" in the name to say "wal".Robert Haas
This means pg_receivexlog because pg_receivewal, pg_resetxlog becomes pg_resetwal, and pg_xlogdump becomes pg_waldump.
2017-01-03Update copyright via script for 2017Bruce Momjian
2016-10-01Improve error reporting in pg_upgrade's file copying/linking/rewriting.Tom Lane
The previous design for this had copyFile(), linkFile(), and rewriteVisibilityMap() returning strerror strings, with the caller producing one-size-fits-all error messages based on that. This made it impossible to produce messages that described the failures with any degree of precision, especially not short-read problems since those don't set errno at all. Since pg_upgrade has no intention of continuing after any error in this area, let's fix this by just letting these functions call pg_fatal() for themselves, making it easy for each point of failure to have a suitable error message. Taking this approach also allows dropping cleanup code that was unnecessary and was often rather sloppy about preserving errno. To not lose relevant info that was reported before, pass in the schema name and table name of the current table so that they can be included in the error reports. An additional problem was the use of getErrorText(), which was flat out wrong for all but a couple of call sites, because it unconditionally did "_dosmaperr(GetLastError())" on Windows. That's only appropriate when reporting an error from a Windows-native API, which only a couple of the callers were actually doing. Thus, even the reported strerror string would be unrelated to the actual failure in many cases on Windows. To fix, get rid of getErrorText() altogether, and just have call sites do strerror(errno) instead, since that's the way all the rest of our frontend programs do it. Add back the _dosmaperr() calls in the two places where that's actually appropriate. In passing, make assorted messages hew more closely to project style guidelines, notably by removing initial capitals in not-complete-sentence primary error messages. (I didn't make any effort to clean up places I didn't have another reason to touch, though.) Per discussion of a report from Thomas Kellerer. Back-patch to 9.6, but no further; given the relative infrequency of reports of problems here, it's not clear it's worth adapting the patch to older branches. Patch by me, but with credit to Alvaro Herrera for spotting the issue with getErrorText's misuse of _dosmaperr(). Discussion: <[email protected]>
2016-06-09pgindent run for 9.6Robert Haas
2016-02-12pg_upgrade: Add C comment about NextXID delimiterBruce Momjian
We don't test the catversion for the NextXID delimiter change, we just test the string contents; explain why. Reported-by: Michael Paquier
2016-02-12Change delimiter used for display of NextXIDJoe Conway
NextXID has been rendered in the form of a pg_lsn even though it really is not. This can cause confusion, so change the format from %u/%u to %u:%u, per discussion on hackers. Complaint by me, patch by me and Bruce, reviewed by Michael Paquier and Alvaro. Applied to HEAD only. Author: Joe Conway, Bruce Momjian Reviewed-by: Michael Paquier, Alvaro Herrera Backpatch-through: master
2016-01-15Fix spelling mistakes.Robert Haas
Same patch submitted independently by David Rowley and Peter Geoghegan.
2016-01-02Update copyright for 2016Bruce Momjian
Backpatch certain files through 9.1
2015-11-24pg_upgrade: fix CopyFile() on Windows to fail on file existenceBruce Momjian
Also fix getErrorText() to return the right error string on failure. This behavior now matches that of other operating systems. Report by Noah Misch Backpatch through 9.1
2015-10-13-- email subject limit -----------------------------------------Bruce Momjian
-- gitweb summary limit -------------------------- pg_upgrade: reorder controldata checks to match program output Also improve comment for how float8_pass_by_value is used. Backpatch through 9.5