1. 24 Jul, 2021 3 commits
    • Tom Lane's avatar
      Fix check for conflicting session- vs transaction-level locks. · 712ba6b8
      Tom Lane authored
      We have an implementation restriction that PREPARE TRANSACTION can't
      handle cases where both session-lifespan and transaction-lifespan locks
      are held on the same lockable object.  (That's because we'd otherwise
      need to acquire a new PROCLOCK entry during post-prepare cleanup, which
      is an operation that might fail.  The situation can only arise with odd
      usages of advisory locks, so removing the restriction is probably not
      worth the amount of effort it would take.)  AtPrepare_Locks attempted
      to enforce this, but its logic was many bricks shy of a load, because
      it only detected cases where the session and transaction locks had the
      same lockmode.  Locks of different modes on the same object would lead
      to the rather unhelpful message "PANIC: we seem to have dropped a bit
      somewhere".
      
      To fix, build a transient hashtable with one entry per locktag,
      not one per locktag + mode, and use that to detect conflicts.
      
      Per bug #17122 from Alexander Pyhalov.  This bug is ancient,
      so back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/17122-04f3c32098a62233@postgresql.org
      712ba6b8
    • Tom Lane's avatar
      Make printf("%s", NULL) print "(null)" instead of crashing. · 89ad14cd
      Tom Lane authored
      We previously took a hard-line attitude that callers should never print
      a null string pointer, and doing so is worthy of an assertion failure
      or crash.  However, we've long since flushed out any easy-to-find bugs
      of that nature.  What remains is a lot of code that perhaps could fail
      that way in hard-to-reach corner cases.  For example, in something as
      simple as
          ereport(ERROR,
                  (errcode(ERRCODE_UNDEFINED_OBJECT),
                   errmsg("constraint \"%s\" for table \"%s\" does not exist",
                          conname, get_rel_name(relid))));
      one must wonder whether it's completely guaranteed that get_rel_name
      cannot return NULL in this context.  If such a situation did occur,
      the existing policy converts what might be a pretty minor bug into
      a server crash condition.  This is not good for robustness.
      
      Hence, let's follow the lead of glibc and print "(null)" instead
      of failing.  We should, of course, still consider it a bug if that
      behavior is reachable in ordinary use; but crashing seems less
      desirable than not crashing.
      
      This fix works across-the-board in v12 and up, where we always use
      src/port/snprintf.c.  Before that, on most platforms we're at the mercy
      of the local libc, but it appears that Solaris 10 is the only supported
      platform where we'd still get a crash.  Most other platforms such as
      *BSD, macOS, and Solaris 11 have adopted glibc's behavior at some
      point.  (AIX and HPUX just print "" not "(null)", but that's close
      enough.)  I've not checked what Windows' native printf would do, but
      it doesn't matter because we've long used snprintf.c on that platform.
      
      In v12 and up, also const-ify related code so that we're not casting
      away const on the constant string.  This is just neatnik-ism, since
      next to no compilers will warn about that.
      
      Discussion: https://postgr.es/m/17098-b960f3616c861f83@postgresql.org
      89ad14cd
    • Tom Lane's avatar
      Remove configure-time thread safety checking (thread_test.c). · d5e913a8
      Tom Lane authored
      This testing was useful when it was written, nigh twenty years ago,
      but it seems fairly pointless for any platform built in the last
      dozen or more years.  (Compare also the comments at 8a212118.)
      Also we now have reports that the test program itself fails under
      ThreadSanitizer.  Rather than invest effort in fixing it, let's
      just drop it, and assume that the few people who still care
      already know they need to use --disable-thread-safety.
      
      Back-patch into v14, for consistency with 8a212118.
      
      Discussion: https://postgr.es/m/CADhDkKzPSiNvA3Hyq+wSR_icuPmazG0cFe=YnC3U-CFcYLc8Xw@mail.gmail.com
      d5e913a8
  2. 22 Jul, 2021 2 commits
  3. 21 Jul, 2021 4 commits
  4. 20 Jul, 2021 5 commits
    • Bruce Momjian's avatar
      doc: PG 14 relnote adjustments · f8d1333d
      Bruce Momjian authored
      Reported-by: Elena Indrupskaya
      
      Discussion: https://postgr.es/m/38555778-a56b-4aca-2581-e05582fc9bcf@postgrespro.ru
      
      Author: Elena Indrupskaya
      
      Backpatch-through: 14 only
      f8d1333d
    • Tom Lane's avatar
      Fix corner-case uninitialized-variable issues in plpgsql. · 899564e0
      Tom Lane authored
      If an error was raised during our initial attempt to check whether
      a successfully-compiled expression is "simple", subsequent calls of
      exec_stmt_execsql would suppose that stmt->mod_stmt was already computed
      when it had not been.  This could lead to assertion failures in debug
      builds; in production builds the effect would typically be to act as
      if INTO STRICT had been specified even when it had not been.  Of course
      that only matters if the subsequent attempt to execute the expression
      succeeds, so that the problem can only be reached by fixing a failure
      in some referenced, inline-able SQL function and then retrying the
      calling plpgsql function in the same session.
      
      (There might be even-more-obscure ways to change the expression's
      behavior without changing the plpgsql function, but that one seems
      like the only one people would be likely to hit in practice.)
      
      The most foolproof way to fix this would be to arrange for
      exec_prepare_plan to not set expr->plan until we've finished the
      subsidiary simple-expression check.  But it seems hard to do that
      without creating reference-count leak issues.  So settle for documenting
      the hazard in a comment and fixing exec_stmt_execsql to test separately
      for whether it's computed stmt->mod_stmt.  (That adds a test-and-branch
      per execution, but hopefully that's negligible in context.)  In v11 and
      up, also fix exec_stmt_call which had a variant of the same issue.
      
      Per bug #17113 from Alexander Lakhin.  Back-patch to all
      supported branches.
      
      Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org
      899564e0
    • Michael Paquier's avatar
      Fix some issues with WAL segment opening for pg_receivewal --compress · 3a0d2d0c
      Michael Paquier authored
      The logic handling the opening of new WAL segments was fuzzy when using
      --compress if a partial, non-compressed, segment with the same base name
      existed in the repository storing those files.  In this case, using
      --compress would cause the code to first check for the existence and the
      size of a non-compressed segment, followed by the opening of a new
      compressed, partial, segment.  The code was accidentally working
      correctly on most platforms as the buildfarm has proved, except
      bowerbird where gzflush() could fail in this code path.  It is wrong
      anyway to take the code path used pre-padding when creating a new
      partial, non-compressed, segment, so let's fix it.
      
      Note that this issue exists when users mix successive runs of
      pg_receivewal with or without compression, as discovered with the tests
      introduced by ffc9dda.
      
      While on it, this refactors the code so as code paths that need to know
      about the ".gz" suffix are down from four to one in walmethods.c, easing
      a bit the introduction of new compression methods.  This addresses a
      second issue where log messages generated for an unexpected failure
      would not show the compressed segment name involved, which was
      confusing, printing instead the name of the non-compressed equivalent.
      
      Reported-by: Georgios Kokolatos
      Discussion: https://postgr.es/m/YPDLz2x3o1aX2wRh@paquier.xyz
      Backpatch-through: 10
      3a0d2d0c
    • Peter Geoghegan's avatar
      Doc: vacuum_multixact_failsafe_age is multixact-based. · e1cdf617
      Peter Geoghegan authored
      Oversight in commit 1e55e7d1, which added a wraparound failsafe
      mechanism to VACUUM.
      
      Backpatch: 14-, where VACUUM failsafe was introduced.
      e1cdf617
    • Peter Geoghegan's avatar
      vacuumdb: Correct comment about --force-index-cleanup. · 9a3d41a2
      Peter Geoghegan authored
      Commit 3499df0d added a comment that incorrectly suggested that
      --force-index-cleanup did not appear in the same major version as the
      similar --no-index-cleanup option.  In fact, both options are new to
      PostgreSQL 14.
      
      Backpatch: 14-, where both options were introduced.
      9a3d41a2
  5. 19 Jul, 2021 3 commits
  6. 18 Jul, 2021 1 commit
    • Alexander Korotkov's avatar
      Support for unnest(multirange) · 244ad541
      Alexander Korotkov authored
      It has been spotted that multiranges lack of ability to decompose them into
      individual ranges.  Subscription and proper expanded object representation
      require substantial work, and it's too late for v14.  This commit
      provides the implementation of unnest(multirange), which is quite trivial.
      unnest(multirange) is defined as a polymorphic procedure.
      
      Catversion is bumped.
      
      Reported-by: Jonathan S. Katz
      Discussion: https://postgr.es/m/flat/60258efe-bd7e-4886-82e1-196e0cac5433%40postgresql.org
      Author: Alexander Korotkov
      Reviewed-by: Justin Pryzby, Jonathan S. Katz, Zhihong Yu, Tom Lane
      Reviewed-by: Alvaro Herrera
      244ad541
  7. 17 Jul, 2021 2 commits
  8. 16 Jul, 2021 4 commits
  9. 15 Jul, 2021 4 commits
  10. 14 Jul, 2021 4 commits
  11. 13 Jul, 2021 3 commits
    • Tom Lane's avatar
      Rename debug_invalidate_system_caches_always to debug_discard_caches. · 6201fa3c
      Tom Lane authored
      The name introduced by commit 4656e3d6 was agreed to be unreasonably
      long.  To match this change, rename initdb's recently-added
      --clobber-cache option to --discard-caches.
      
      Discussion: https://postgr.es/m/1374320.1625430433@sss.pgh.pa.us
      6201fa3c
    • David Rowley's avatar
      Robustify tuplesort's free_sort_tuple function · a92709fe
      David Rowley authored
      41469253e went to the trouble of removing a theoretical bug from
      free_sort_tuple by checking if the tuple was NULL before freeing it. Let's
      make this a little more robust by also setting the tuple to NULL so that
      should we be called again we won't end up doing a pfree on the already
      pfree'd tuple. Per advice from Tom Lane.
      
      Discussion: https://postgr.es/m/3188192.1626136953@sss.pgh.pa.us
      Backpatch-through: 9.6, same as 41469253e
      a92709fe
    • David Rowley's avatar
      Fix theoretical bug in tuplesort · a3b8d91c
      David Rowley authored
      This fixes a theoretical bug in tuplesort.c which, if a bounded sort was
      used in combination with a byval Datum sort (tuplesort_begin_datum), when
      switching the sort to a bounded heap in make_bounded_heap(), we'd call
      free_sort_tuple().  The problem was that when sorting Datums of a byval
      type, the tuple is NULL and free_sort_tuple() would free the memory for it
      regardless of that.  This would result in a crash.
      
      Here we fix that simply by adding a check to see if the tuple is NULL
      before trying to disassociate and free any memory belonging to it.
      
      The reason this bug is only theoretical is that nowhere in the current
      code base do we do tuplesort_set_bound() when performing a Datum sort.
      However, let's backpatch a fix for this as if any extension uses the code
      in this way then it's likely to cause problems.
      
      Author: Ronan Dunklau
      Discussion: https://postgr.es/m/CAApHDvpdoqNC5FjDb3KUTSMs5dg6f+XxH4Bg_dVcLi8UYAG3EQ@mail.gmail.com
      Backpatch-through: 9.6, oldest supported version
      a3b8d91c
  12. 12 Jul, 2021 5 commits