1. 27 Jul, 2021 1 commit
    • Bruce Momjian's avatar
      pg_resetxlog: add option to set oldest xid & use by pg_upgrade · 695b4a11
      Bruce Momjian authored
      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/20190615183759.GB239428@rfd.leadboat.com, 87da83168c644fd9aae38f546cc70295@opammb0562.comp.optiver.com
      
      Author: Bertrand Drouvot
      
      Backpatch-through: 9.6
      695b4a11
  2. 20 May, 2021 1 commit
    • Tom Lane's avatar
      Clean up cpluspluscheck violation. · 6d59a218
      Tom Lane authored
      "typename" is a C++ keyword, so pg_upgrade.h fails to compile in C++.
      Fortunately, there seems no likely reason for somebody to need to
      do that.  Nonetheless, it's project policy that all .h files should
      pass cpluspluscheck, so rename the argument to fix that.
      
      Oversight in 57c081de; back-patch as that was.  (The policy requiring
      pg_upgrade.h to pass cpluspluscheck only goes back to v12, but it
      seems best to keep this code looking the same in all branches.)
      6d59a218
  3. 07 May, 2021 1 commit
  4. 29 Apr, 2021 1 commit
    • Tom Lane's avatar
      Fix some more omissions in pg_upgrade's tests for non-upgradable types. · 57c081de
      Tom Lane authored
      Commits 29aeda6e et al closed up some oversights involving not checking
      for non-upgradable types within container types, such as arrays and
      ranges.  However, I only looked at version.c, failing to notice that
      there were substantially-equivalent tests in check.c.  (The division
      of responsibility between those files is less than clear...)
      
      In addition, because genbki.pl does not guarantee that auto-generated
      rowtype OIDs will hold still across versions, we need to consider that
      the composite type associated with a system catalog or view is
      non-upgradable.  It seems unlikely that someone would have a user
      column declared that way, but if they did, trying to read it in another
      PG version would likely draw "no such pg_type OID" failures, thanks
      to the type OID embedded in composite Datums.
      
      To support the composite and reg*-type cases, extend the recursive
      query that does the search to allow any base query that returns
      a column of pg_type OIDs, rather than limiting it to exactly one
      starting type.
      
      As before, back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/2798740.1619622555@sss.pgh.pa.us
      57c081de
  5. 02 Jan, 2021 1 commit
  6. 30 Dec, 2020 1 commit
    • Tom Lane's avatar
      Use setenv() in preference to putenv(). · 7ca37fb0
      Tom Lane authored
      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/2065122.1609212051@sss.pgh.pa.us
      7ca37fb0
  7. 28 Dec, 2020 1 commit
  8. 25 Dec, 2020 1 commit
  9. 09 Nov, 2020 1 commit
  10. 02 Nov, 2020 1 commit
    • Thomas Munro's avatar
      Track collation versions for indexes. · 257836a7
      Thomas Munro authored
      Record the current version of dependent collations in pg_depend when
      creating or rebuilding an index.  When accessing the index later, warn
      that the index may be corrupted if the current version doesn't match.
      
      Thanks to Douglas Doole, Peter Eisentraut, Christoph Berg, Laurenz Albe,
      Michael Paquier, Robert Haas, Tom Lane and others for very helpful
      discussion.
      
      Author: Thomas Munro <thomas.munro@gmail.com>
      Author: Julien Rouhaud <rjuju123@gmail.com>
      Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com> (earlier versions)
      Discussion: https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com
      257836a7
  11. 04 Mar, 2020 1 commit
  12. 01 Jan, 2020 1 commit
  13. 14 Oct, 2019 1 commit
    • Tomas Vondra's avatar
      Check for tables with sql_identifier during pg_upgrade · 0ccfc282
      Tomas Vondra authored
      Commit 7c15cef8 changed sql_identifier data type to be based on name
      instead of varchar.  Unfortunately, this breaks on-disk format for this
      data type.  Luckily, that should be a very rare problem, as this data
      type is used only in information_schema views, so this only affects user
      objects (tables, materialized views and indexes).  One way to end in
      such situation is to do CTAS with a query on those system views.
      
      There are two options to deal with this - we can either abort pg_upgrade
      if there are user objects with sql_identifier columns in pg_upgrade, or
      we could replace the sql_identifier type with varchar.  Considering how
      rare the issue is expected to be, and the complexity of replacing the
      data type (e.g. in matviews), we've decided to go with the simple check.
      
      The query is somewhat complex - the sql_identifier data type may be used
      indirectly - through a domain, a composite type or both, possibly in
      multiple levels.  Detecting this requires a recursive CTE.
      
      Backpatch to 12, where the sql_identifier definition changed.
      
      Reported-by: Hans Buschmann
      Author: Tomas Vondra
      Reviewed-by: Tom Lane
      Backpatch-to: 12
      Discussion: https://postgr.es/m/16045-673e8fa6b5ace196%40postgresql.org
      0ccfc282
  14. 19 Aug, 2019 1 commit
  15. 13 Aug, 2019 1 commit
  16. 29 Jul, 2019 1 commit
  17. 27 Jul, 2019 1 commit
    • Peter Eisentraut's avatar
      pg_upgrade: Default new bindir to pg_upgrade location · 959f6d6a
      Peter Eisentraut authored
      Make the directory where the pg_upgrade binary resides the default for
      new bindir, as running the pg_upgrade binary from where the new
      cluster is installed is a very common scenario.  Setting this as the
      defauly bindir for the new cluster will remove the need to provide it
      explicitly via -B in many cases.
      
      To support directories being missing from option parsing, extend the
      directory check with a missingOk mode where the path must be filled at
      a later point before being used.  Also move the exec_path check to
      earlier in setup to make sure we know the new cluster bindir when we
      scan for required executables.
      
      This removes the exec_path from the OSInfo struct as it is not used
      anywhere.
      
      Author: Daniel Gustafsson <daniel@yesql.se>
      Reviewed-by: default avatarPeter Eisentraut <peter.eisentraut@2ndquadrant.com>
      Discussion: https://www.postgresql.org/message-id/flat/9328.1552952117@sss.pgh.pa.us
      959f6d6a
  18. 22 May, 2019 1 commit
  19. 07 May, 2019 1 commit
  20. 15 Mar, 2019 1 commit
  21. 02 Jan, 2019 1 commit
  22. 01 Dec, 2018 1 commit
    • Tom Lane's avatar
      Add a --socketdir option to pg_upgrade. · 2d34ad84
      Tom Lane authored
      This allows control of the directory in which the postmaster sockets
      are created for the temporary postmasters started by pg_upgrade.
      The default location remains the current working directory, which is
      typically fine, but if it is deeply nested then its pathname might
      be too long to be a socket name.
      
      In passing, clean up some messiness in pg_upgrade's option handling,
      particularly the confusing and undocumented way that configuration-only
      datadirs were handled.  And fix check_required_directory's substantially
      under-baked cleanup of directory pathnames.
      
      Daniel Gustafsson, reviewed by Hironobu Suzuki, some code cleanup by me
      
      Discussion: https://postgr.es/m/E72DD5C3-2268-48A5-A907-ED4B34BEC223@yesql.se
      2d34ad84
  23. 07 Nov, 2018 1 commit
    • Peter Eisentraut's avatar
      pg_upgrade: Allow use of file cloning · 3a769d82
      Peter Eisentraut authored
      Add another transfer mode --clone to pg_upgrade (besides the existing
      --link and the default copy), using special file cloning calls.  This
      makes the file transfer faster and more space efficient, achieving
      speed similar to --link mode without the associated drawbacks.
      
      On Linux, file cloning is supported on Btrfs and XFS (if formatted with
      reflink support).  On macOS, file cloning is supported on APFS.
      Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
      3a769d82
  24. 28 Jul, 2018 1 commit
  25. 09 Apr, 2018 1 commit
  26. 05 Apr, 2018 1 commit
    • Magnus Hagander's avatar
      Allow on-line enabling and disabling of data checksums · 1fde38be
      Magnus Hagander authored
      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
      1fde38be
  27. 05 Feb, 2018 1 commit
    • Tom Lane's avatar
      Ensure that all temp files made during pg_upgrade are non-world-readable. · a926eb84
      Tom Lane authored
      pg_upgrade has always attempted to ensure that the transient dump files
      it creates are inaccessible except to the owner.  However, refactoring
      in commit 76a7650c broke that for the file containing "pg_dumpall -g"
      output; since then, that file was protected according to the process's
      default umask.  Since that file may contain role passwords (hopefully
      encrypted, but passwords nonetheless), this is a particularly unfortunate
      oversight.  Prudent users of pg_upgrade on multiuser systems would
      probably run it under a umask tight enough that the issue is moot, but
      perhaps some users are depending only on pg_upgrade's umask changes to
      protect their data.
      
      To fix this in a future-proof way, let's just tighten the umask at
      process start.  There are no files pg_upgrade needs to write at a
      weaker security level; and if there were, transiently relaxing the
      umask around where they're created would be a safer approach.
      
      Report and patch by Tom Lane; the idea for the fix is due to Noah Misch.
      Back-patch to all supported branches.
      
      Security: CVE-2018-1053
      a926eb84
  28. 09 Jan, 2018 1 commit
    • Bruce Momjian's avatar
      pg_upgrade: prevent check on live cluster from generating error · d25ee300
      Bruce Momjian authored
      Previously an inaccurate but harmless error was generated when running
      --check on a live server before reporting the servers as compatible.
      The fix is to split error reporting and exit control in the exec_prog()
      API.
      
      Reported-by: Daniel Westermann
      
      Backpatch-through: 10
      d25ee300
  29. 03 Jan, 2018 1 commit
  30. 08 Nov, 2017 1 commit
    • Peter Eisentraut's avatar
      Change TRUE/FALSE to true/false · 2eb4a831
      Peter Eisentraut authored
      The lower case spellings are C and C++ standard and are used in most
      parts of the PostgreSQL sources.  The upper case spellings are only used
      in some files/modules.  So standardize on the standard spellings.
      
      The APIs for ICU, Perl, and Windows define their own TRUE and FALSE, so
      those are left as is when using those APIs.
      
      In code comments, we use the lower-case spelling for the C concepts and
      keep the upper-case spelling for the SQL concepts.
      Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
      2eb4a831
  31. 25 Aug, 2017 1 commit
  32. 14 Jul, 2017 1 commit
  33. 21 Jun, 2017 2 commits
    • Tom Lane's avatar
      Phase 3 of pgindent updates. · 382ceffd
      Tom Lane authored
      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/E1dAmxK-0006EE-1r@gemulon.postgresql.org
      Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
      382ceffd
    • Tom Lane's avatar
      Phase 2 of pgindent updates. · c7b8998e
      Tom Lane authored
      Change pg_bsd_indent to follow upstream rules for placement of comments
      to the right of code, and remove pgindent hack that caused comments
      following #endif to not obey the general rule.
      
      Commit e3860ffa wasn't actually using
      the published version of pg_bsd_indent, but a hacked-up version that
      tried to minimize the amount of movement of comments to the right of
      code.  The situation of interest is where such a comment has to be
      moved to the right of its default placement at column 33 because there's
      code there.  BSD indent has always moved right in units of tab stops
      in such cases --- but in the previous incarnation, indent was working
      in 8-space tab stops, while now it knows we use 4-space tabs.  So the
      net result is that in about half the cases, such comments are placed
      one tab stop left of before.  This is better all around: it leaves
      more room on the line for comment text, and it means that in such
      cases the comment uniformly starts at the next 4-space tab stop after
      the code, rather than sometimes one and sometimes two tabs after.
      
      Also, ensure that comments following #endif are indented the same
      as comments following other preprocessor commands such as #else.
      That inconsistency turns out to have been self-inflicted damage
      from a poorly-thought-through post-indent "fixup" in pgindent.
      
      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/E1dAmxK-0006EE-1r@gemulon.postgresql.org
      Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
      c7b8998e
  34. 20 Jun, 2017 1 commit
    • Bruce Momjian's avatar
      pg_upgrade: start/stop new server after pg_resetwal · b710248d
      Bruce Momjian authored
      When commit 0f33a719 removed the
      instructions to start/stop the new cluster before running rsync, it was
      now possible for pg_resetwal/pg_resetxlog to leave the final WAL record
      at wal_level=minimum, preventing upgraded standby servers from
      reconnecting.
      
      This patch fixes that by having pg_upgrade unconditionally start/stop
      the new cluster after pg_resetwal/pg_resetxlog has run.
      
      Backpatch through 9.2 since, though the instructions were added in PG
      9.5, they worked all the way back to 9.2.
      
      Discussion: https://postgr.es/m/20170620171844.GC24975@momjian.us
      
      Backpatch-through: 9.2
      b710248d
  35. 19 May, 2017 1 commit
  36. 01 Mar, 2017 1 commit
  37. 25 Jan, 2017 1 commit
    • Tom Lane's avatar
      Change unknown-type literals to type text in SELECT and RETURNING lists. · 1e7c4bb0
      Tom Lane authored
      Previously, we left such literals alone if the query or subquery had
      no properties forcing a type decision to be made (such as an ORDER BY or
      DISTINCT clause using that output column).  This meant that "unknown" could
      be an exposed output column type, which has never been a great idea because
      it could result in strange failures later on.  For example, an outer query
      that tried to do any operations on an unknown-type subquery output would
      generally fail with some weird error like "failed to find conversion
      function from unknown to text" or "could not determine which collation to
      use for string comparison".  Also, if the case occurred in a CREATE VIEW's
      query then the view would have an unknown-type column, causing similar
      failures in queries trying to use the view.
      
      To fix, at the tail end of parse analysis of a query, forcibly convert any
      remaining "unknown" literals in its SELECT or RETURNING list to type text.
      However, provide a switch to suppress that, and use it in the cases of
      SELECT inside a set operation or INSERT command.  In those cases we already
      had type resolution rules that make use of context information from outside
      the subquery proper, and we don't want to change that behavior.
      
      Also, change creation of an unknown-type column in a relation from a
      warning to a hard error.  The error should be unreachable now in CREATE
      VIEW or CREATE MATVIEW, but it's still possible to explicitly say "unknown"
      in CREATE TABLE or CREATE (composite) TYPE.  We want to forbid that because
      it's nothing but a foot-gun.
      
      This change creates a pg_upgrade failure case: a matview that contains an
      unknown-type column can't be pg_upgraded, because reparsing the matview's
      defining query will now decide that the column is of type text, which
      doesn't match the cstring-like storage that the old materialized column
      would actually have.  Add a checking pass to detect that.  While at it,
      we can detect tables or composite types that would fail, essentially
      for free.  Those would fail safely anyway later on, but we might as
      well fail earlier.
      
      This patch is by me, but it owes something to previous investigations
      by Rahila Syed.  Also thanks to Ashutosh Bapat and Michael Paquier for
      review.
      
      Discussion: https://postgr.es/m/CAH2L28uwwbL9HUM-WR=hromW1Cvamkn7O-g8fPY2m=_7muJ0oA@mail.gmail.com
      1e7c4bb0
  38. 03 Jan, 2017 1 commit
  39. 01 Oct, 2016 1 commit
    • Tom Lane's avatar
      Improve error reporting in pg_upgrade's file copying/linking/rewriting. · f002ed2b
      Tom Lane authored
      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: <nsjrbh$8li$1@blaine.gmane.org>
      f002ed2b