1. 16 Mar, 2022 1 commit
    • Thomas Munro's avatar
      Wake up for latches in CheckpointWriteDelay(). · 78c0f85e
      Thomas Munro authored
      The checkpointer shouldn't ignore its latch.  Other backends may be
      waiting for it to drain the request queue.  Hopefully real systems don't
      have a full queue often, but the condition is reached easily when
      shared_buffers is small.
      
      This involves defining a new wait event, which will appear in the
      pg_stat_activity view often due to spread checkpoints.
      
      Back-patch only to 14.  Even though the problem exists in earlier
      branches too, it's hard to hit there.  In 14 we stopped using signal
      handlers for latches on Linux, *BSD and macOS, which were previously
      hiding this problem by interrupting the sleep (though not reliably, as
      the signal could arrive before the sleep begins; precisely the problem
      latches address).
      Reported-by: default avatarAndres Freund <andres@anarazel.de>
      Reviewed-by: default avatarAndres Freund <andres@anarazel.de>
      Discussion: https://postgr.es/m/20220226213942.nb7uvb2pamyu26dj%40alap3.anarazel.de
      78c0f85e
  2. 15 Mar, 2022 1 commit
    • Thomas Munro's avatar
      Back-patch LLVM 14 API changes. · d9f7ad54
      Thomas Munro authored
      Since LLVM 14 has stopped changing and is about to be released,
      back-patch the following changes from the master branch:
      
        e6a7600202105919bffd62b3dfd941f4a94e082b
        807fee1a39de6bb8184082012e643951abb9ad1d
        a56e7b66010f330782243de9e25ac2a6596be0e1
      
      Back-patch to 11, where LLVM JIT support came in.
      d9f7ad54
  3. 11 Mar, 2022 1 commit
    • Tom Lane's avatar
      Restore the previous semantics of get_constraint_index(). · 8dcd1c35
      Tom Lane authored
      Commit 8b069ef5 changed this function to look at pg_constraint.conindid
      rather than searching pg_depend.  That was a good performance improvement,
      but it failed to preserve the exact semantics.  The old code would only
      return an index that was "owned by" (internally dependent on) the
      specified constraint, whereas the new code will also return indexes that
      are just referenced by foreign key constraints.  This confuses ALTER
      TABLE, which was implicitly expecting the previous semantics, into
      failing with errors like
          ERROR:  relation 146621 has multiple clustered indexes
      or
          ERROR:  "pk_attbl" is not an index for table "atref"
      
      We can fix this without reverting the performance improvement by adding
      a contype check in get_constraint_index().  Another way could be to
      make ALTER TABLE check it, but I'm worried that extension code could
      also have subtle dependencies on the old semantics.
      
      Tom Lane and Japin Li, per bug #17409 from Holly Roberts.
      Back-patch to v14 where the error crept in.
      
      Discussion: https://postgr.es/m/17409-52871dda8b5741cb@postgresql.org
      8dcd1c35
  4. 09 Mar, 2022 1 commit
  5. 05 Mar, 2022 1 commit
  6. 04 Mar, 2022 2 commits
    • Tom Lane's avatar
      Fix pg_regress to print the correct postmaster address on Windows. · a008c03d
      Tom Lane authored
      pg_regress reported "Unix socket" as the default location whenever
      HAVE_UNIX_SOCKETS is defined.  However, that's not been accurate
      on Windows since 8f3ec75d.  Update this logic to match what libpq
      actually does now.
      
      This is just cosmetic, but still it's potentially misleading.
      Back-patch to v13 where 8f3ec75d came in.
      
      Discussion: https://postgr.es/m/3894060.1646415641@sss.pgh.pa.us
      a008c03d
    • Tom Lane's avatar
      Fix bogus casting in BlockIdGetBlockNumber(). · 5c9d17e9
      Tom Lane authored
      This macro cast the result to BlockNumber after shifting, not before,
      which is the wrong thing.  Per the C spec, the uint16 fields would
      promote to int not unsigned int, so that (for 32-bit int) the shift
      potentially shifts a nonzero bit into the sign position.  I doubt
      there are any production systems where this would actually end with
      the wrong answer, but it is undefined behavior per the C spec, and
      clang's -fsanitize=undefined option reputedly warns about it on some
      platforms.  (I can't reproduce that right now, but the code is
      undeniably wrong per spec.)  It's easy to fix by casting to
      BlockNumber (uint32) in the proper places.
      
      It's been wrong for ages, so back-patch to all supported branches.
      
      Report and patch by Zhihong Yu (cosmetic tweaking by me)
      
      Discussion: https://postgr.es/m/CALNJ-vT9r0DSsAOw9OXVJFxLENoVS_68kJ5x0p44atoYH+H4dg@mail.gmail.com
      5c9d17e9
  7. 03 Mar, 2022 1 commit
    • Tom Lane's avatar
      Clean up assorted failures under clang's -fsanitize=undefined checks. · b0bc196e
      Tom Lane authored
      Most of these are cases where we could call memcpy() or other libc
      functions with a NULL pointer and a zero count, which is forbidden
      by POSIX even though every production version of libc allows it.
      We've fixed such things before in a piecemeal way, but apparently
      never made an effort to try to get them all.  I don't claim that
      this patch does so either, but it gets every failure I observe in
      check-world, using clang 12.0.1 on current RHEL8.
      
      numeric.c has a different issue that the sanitizer doesn't like:
      "ln(-1.0)" will compute log10(0) and then try to assign the
      resulting -Inf to an integer variable.  We don't actually use the
      result in such a case, so there's no live bug.
      
      Back-patch to all supported branches, with the idea that we might
      start running a buildfarm member that tests this case.  This includes
      back-patching c1132aae3 (Check the size in COPY_POINTER_FIELD),
      which previously silenced some of these issues in copyfuncs.c.
      
      Discussion: https://postgr.es/m/CALNJ-vT9r0DSsAOw9OXVJFxLENoVS_68kJ5x0p44atoYH+H4dg@mail.gmail.com
      b0bc196e
  8. 02 Mar, 2022 1 commit
    • Tom Lane's avatar
      Allow root-owned SSL private keys in libpq, not only the backend. · 2a1f8463
      Tom Lane authored
      This change makes libpq apply the same private-key-file ownership
      and permissions checks that we have used in the backend since commit
      9a83564c.  Namely, that the private key can be owned by either the
      current user or root (with different file permissions allowed in the
      two cases).  This allows system-wide management of key files, which
      is just as sensible on the client side as the server, particularly
      when the client is itself some application daemon.
      
      Sync the comments about this between libpq and the backend, too.
      
      Back-patch of a59c79564 and 50f03473e into all supported branches.
      
      David Steele
      
      Discussion: https://postgr.es/m/f4b7bc55-97ac-9e69-7398-335e212f7743@pgmasters.net
      2a1f8463
  9. 25 Feb, 2022 2 commits
    • Tom Lane's avatar
      Disallow execution of SPI functions during plperl function compilation. · ac910bb2
      Tom Lane authored
      Perl can be convinced to execute user-defined code during compilation
      of a plperl function (or at least a plperlu function).  That's not
      such a big problem as long as the activity is confined within the
      Perl interpreter, and it's not clear we could do anything about that
      anyway.  However, if such code tries to use plperl's SPI functions,
      we have a bigger problem.  In the first place, those functions are
      likely to crash because current_call_data->prodesc isn't set up yet.
      In the second place, because it isn't set up, we lack critical info
      such as whether the function is supposed to be read-only.  And in
      the third place, this path allows code execution during function
      validation, which is strongly discouraged because of the potential
      for security exploits.  Hence, reject execution of the SPI functions
      until compilation is finished.
      
      While here, add check_spi_usage_allowed() calls to various functions
      that hadn't gotten the memo about checking that.  I think that perhaps
      plperl_sv_to_literal may have been intentionally omitted on the grounds
      that it was safe at the time; but if so, the addition of transforms
      functionality changed that.  The others are more recently added and
      seem to be flat-out oversights.
      
      Per report from Mark Murawski.  Back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/9acdf918-7fff-4f40-f750-2ffa84f083d2@intellasoft.net
      ac910bb2
    • Andres Freund's avatar
      pg_waldump: Fix error message for WAL files smaller than XLOG_BLCKSZ. · 9ff7fd90
      Andres Freund authored
      When opening a WAL file smaller than XLOG_BLCKSZ (e.g. 0 bytes long) while
      determining the wal_segment_size, pg_waldump checked errno, despite errno not
      being set by the short read. Resulting in a bogus error message.
      
      Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
      Discussion: https://postgr.es/m/20220214.181847.775024684568733277.horikyota.ntt@gmail.com
      Backpatch: 11-, the bug was introducedin fc49e24f
      9ff7fd90
  10. 24 Feb, 2022 1 commit
  11. 23 Feb, 2022 1 commit
  12. 22 Feb, 2022 1 commit
    • Michael Paquier's avatar
      Add compute_query_id = regress · 627c79a1
      Michael Paquier authored
      "regress" is a new mode added to compute_query_id aimed at facilitating
      regression testing when a module computing query IDs is loaded into the
      backend, like pg_stat_statements.  It works the same way as "auto",
      meaning that query IDs are computed if a module enables it, except that
      query IDs are hidden in EXPLAIN outputs to ensure regression output
      stability.
      
      Like any GUCs of the kind (force_parallel_mode, etc.), this new
      configuration can be added to an instance's postgresql.conf, or just
      passed down with PGOPTIONS at command level.  compute_query_id uses an
      enum for its set of option values, meaning that this addition ensures
      ABI compatibility.
      
      Using this new configuration mode allows installcheck-world to pass when
      running the tests on an instance with pg_stat_statements enabled,
      stabilizing the test output while checking the paths doing query ID
      computations.
      
      Reported-by: Anton Melnikov
      Reviewed-by: Julien Rouhaud
      Discussion: https://postgr.es/m/1634283396.372373993@f75.i.mail.ru
      Discussion: https://postgr.es/m/YgHlxgc/OimuPYhH@paquier.xyz
      Backpatch-through: 14
      627c79a1
  13. 21 Feb, 2022 1 commit
    • Andres Freund's avatar
      Fix temporary object cleanup failing due to toast access without snapshot. · 7bbfe599
      Andres Freund authored
      When cleaning up temporary objects during process exit the cleanup could fail
      with:
        FATAL: cannot fetch toast data without an active snapshot
      
      The bug is caused by RemoveTempRelationsCallback() not setting up a
      snapshot. If an object with toasted catalog data needs to be cleaned up,
      init_toast_snapshot() could fail with the above error.
      
      Most of the time however the the problem is masked due to cached catalog
      snapshots being returned by GetOldestSnapshot(). But dropping an object can
      cause catalog invalidations to be emitted. If no further catalog accesses are
      necessary between the invalidation processing and the next toast datum
      deletion, the bug becomes visible.
      
      It's easy to miss this bug because it typically happens after clients
      disconnect and the FATAL error just ends up in the log.
      
      Luckily temporary table cleanup at the next use of the same temporary schema
      or during DISCARD ALL does not have the same problem.
      
      Fix the bug by pushing a snapshot in RemoveTempRelationsCallback(). Also add
      isolation tests for temporary object cleanup, including objects with toasted
      catalog data.
      
      A future HEAD only commit will add more assertions.
      
      Reported-By: Miles Delahunty
      Author: Andres Freund
      Discussion: https://postgr.es/m/CAOFAq3BU5Mf2TTvu8D9n_ZOoFAeQswuzk7yziAb7xuw_qyw5gw@mail.gmail.com
      Backpatch: 10-
      7bbfe599
  14. 20 Feb, 2022 2 commits
  15. 18 Feb, 2022 1 commit
    • Tom Lane's avatar
      Suppress warning about stack_base_ptr with late-model GCC. · 2e30d77a
      Tom Lane authored
      GCC 12 complains that set_stack_base is storing the address of
      a local variable in a long-lived pointer.  This is an entirely
      reasonable warning (indeed, it just helped us find a bug);
      but that behavior is intentional here.  We can work around it
      by using __builtin_frame_address(0) instead of a specific local
      variable; that produces an address a dozen or so bytes different,
      in my testing, but we don't care about such a small difference.
      Maybe someday a compiler lacking that function will start to issue
      a similar warning, but we'll worry about that when it happens.
      
      Patch by me, per a suggestion from Andres Freund.  Back-patch to
      v12, which is as far back as the patch will go without some pain.
      (Recently-established project policy would permit a back-patch as
      far as 9.2, but I'm disinclined to expend the work until GCC 12
      is much more widespread.)
      
      Discussion: https://postgr.es/m/3773792.1645141467@sss.pgh.pa.us
      2e30d77a
  16. 16 Feb, 2022 1 commit
  17. 14 Feb, 2022 2 commits
  18. 12 Feb, 2022 1 commit
    • Tom Lane's avatar
      Fix thinko in PQisBusy(). · ae27b1ac
      Tom Lane authored
      In commit 1f39a1c0 I made PQisBusy consider conn->write_failed, but
      that is now looking like complete brain fade.  In the first place, the
      logic is quite wrong: it ought to be like "and not" rather than "or".
      This meant that once we'd gotten into a write_failed state, PQisBusy
      would always return true, probably causing the calling application to
      iterate its loop until PQconsumeInput returns a hard failure thanks
      to connection loss.  That's not what we want: the intended behavior
      is to return an error PGresult, which the application probably has
      much cleaner support for.
      
      But in the second place, checking write_failed here seems like the
      wrong thing anyway.  The idea of the write_failed mechanism is to
      postpone handling of a write failure until we've read all we can from
      the server; so that flag should not interfere with input-processing
      behavior.  (Compare 7247e243.)  What we *should* check for is
      status = CONNECTION_BAD, ie, socket already closed.  (Most places that
      close the socket don't touch asyncStatus, but they do reset status.)
      This primarily ensures that if PQisBusy() returns true then there is
      an open socket, which is assumed by several call sites in our own
      code, and probably other applications too.
      
      While at it, fix a nearby thinko in libpq's my_sock_write: we should
      only consult errno for res < 0, not res == 0.  This is harmless since
      pqsecure_raw_write would force errno to zero in such a case, but it
      still could confuse readers.
      
      Noted by Andres Freund.  Backpatch to v12 where 1f39a1c0 came in.
      
      Discussion: https://postgr.es/m/20220211011025.ek7exh6owpzjyudn@alap3.anarazel.de
      ae27b1ac
  19. 11 Feb, 2022 1 commit
    • Tom Lane's avatar
      Don't use_physical_tlist for an IOS with non-returnable columns. · 277e744a
      Tom Lane authored
      createplan.c tries to save a runtime projection step by specifying
      a scan plan node's output as being exactly the table's columns, or
      index's columns in the case of an index-only scan, if there is not a
      reason to do otherwise.  This logic did not previously pay attention
      to whether an index's columns are returnable.  That worked, sort of
      accidentally, until commit 9a3ddeb51 taught setrefs.c to reject plans
      that try to read a non-returnable column.  I have no desire to loosen
      setrefs.c's new check, so instead adjust use_physical_tlist() to not
      try to optimize this way when there are non-returnable column(s).
      
      Per report from Ryan Kelly.  Like the previous patch, back-patch
      to all supported branches.
      
      Discussion: https://postgr.es/m/CAHUie24ddN+pDNw7fkhNrjrwAX=fXXfGZZEHhRuofV_N_ftaSg@mail.gmail.com
      277e744a
  20. 10 Feb, 2022 5 commits
    • Tom Lane's avatar
      Make pg_ctl stop/restart/promote recheck postmaster aliveness. · 1e8c5cf7
      Tom Lane authored
      "pg_ctl stop/restart" checked that the postmaster PID is valid just
      once, as a side-effect of sending the stop signal, and then would
      wait-till-timeout for the postmaster.pid file to go away.  This
      neglects the case wherein the postmaster dies uncleanly after we
      signal it.  Similarly, once "pg_ctl promote" has sent the signal,
      it'd wait for the corresponding on-disk state change to occur
      even if the postmaster dies.
      
      I'm not sure how we've managed not to notice this problem, but it
      seems to explain slow execution of the 017_shm.pl test script on AIX
      since commit 4fdbf9af5, which added a speculative "pg_ctl stop" with
      the idea of making real sure that the postmaster isn't there.  In the
      test steps that kill-9 and then restart the postmaster, it's possible
      to get past the initial signal attempt before kill() stops working
      for the doomed postmaster.  If that happens, pg_ctl waited till
      PGCTLTIMEOUT before giving up ... and the buildfarm's AIX members
      have that set very high.
      
      To fix, include a "kill(pid, 0)" test (similar to what
      postmaster_is_alive uses) in these wait loops, so that we'll
      give up immediately if the postmaster PID disappears.
      
      While here, I chose to refactor those loops out of where they were.
      do_stop() and do_restart() can perfectly well share one copy of the
      wait-for-stop loop, and it seems desirable to put a similar function
      beside that for wait-for-promote.
      
      Back-patch to all supported versions, since pg_ctl's wait logic
      is substantially identical in all, and we're seeing the slow test
      behavior in all branches.
      
      Discussion: https://postgr.es/m/20220210023537.GA3222837@rfd.leadboat.com
      1e8c5cf7
    • Andrew Dunstan's avatar
      Use gendef instead of pexports for building windows .def files · 92f60f53
      Andrew Dunstan authored
      Modern msys systems lack pexports but have gendef instead, so use that.
      
      Discussion: https://postgr.es/m/3ccde7a9-e4f9-e194-30e0-0936e6ad68ba@dunslane.net
      
      Backpatch to release 9.4 to enable building with perl on older branches.
      Before that pexports is not used for plperl.
      92f60f53
    • Tom Lane's avatar
      Make timeout.c more robust against missed timer interrupts. · 2e211c16
      Tom Lane authored
      Commit 09cf1d52 taught schedule_alarm() to not do anything if
      the next requested event is after when we expect the next interrupt
      to fire.  However, if somehow an interrupt gets lost, we'll continue
      to not do anything indefinitely, even after the "next interrupt" time
      is obviously in the past.  Thus, one missed interrupt can break
      timeout scheduling for the life of the session.  Michael Harris
      reported a scenario where a bug in a user-defined function caused this
      to happen, so you don't even need to assume kernel bugs exist to think
      this is worth fixing.  We can make things more robust at little cost
      by detecting the case where signal_due_at is before "now" and forcing
      a new setitimer call to occur.  This isn't a completely bulletproof
      fix of course; but in our typical usage pattern where we frequently set
      timeouts and clear them before they are reached, the interrupt will
      get re-enabled after at most one timeout interval, which with a little
      luck will be before we really need it.
      
      While here, let's mark signal_due_at as volatile, since the signal
      handler can both examine and set it.  I'm not sure there's any
      actual risk given that signal_pending is already volatile, but
      it's surely questionable.
      
      Backpatch to v14 where this logic came in.
      
      Michael Harris and Tom Lane
      
      Discussion: https://postgr.es/m/CADofcAWbMrvgwSMqO4iG_iD3E2v8ZUrC-_crB41my=VMM02-CA@mail.gmail.com
      2e211c16
    • Daniel Gustafsson's avatar
      Set SNI ClientHello extension to localhost in tests · 5f00ef06
      Daniel Gustafsson authored
      The connection strings in the SSL client tests were using the host
      set up from Cluster.pm which is a temporary pathname. When SNI is
      enabled we pass the host to OpenSSL in order to set the server name
      indication ClientHello extension via SSL_set_tlsext_host_name.
      
      OpenSSL doesn't validate the hostname apart from checking the max
      length, but LibreSSL checks for RFC 5890 conformance which results
      in errors during testing as the pathname from Cluster.pm is not a
      valid hostname.
      
      Fix by setting the host explicitly to localhost, as that's closer
      to the intent of the test.
      
      Backpatch through 14 where SNI support came in.
      Reported-by: default avatarNazir Bilal Yavuz <byavuz81@gmail.com>
      Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
      Discussion: https://postgr.es/m/17391-304f81bcf724b58b@postgresql.org
      Backpatch-through: 14
      5f00ef06
    • Noah Misch's avatar
      Use Test::Builder::todo_start(), replacing $::TODO. · 1a83297d
      Noah Misch authored
      Some pre-2017 Test::More versions need perfect $Test::Builder::Level
      maintenance to find the variable.  Buildfarm member snapper reported an
      overall failure that the file intended to hide via the TODO construct.
      That trouble was reachable in v11 and v10.  For later branches, this
      serves as defense in depth.  Back-patch to v10 (all supported versions).
      
      Discussion: https://postgr.es/m/20220202055556.GB2745933@rfd.leadboat.com
      1a83297d
  21. 09 Feb, 2022 2 commits
  22. 07 Feb, 2022 2 commits
  23. 06 Feb, 2022 1 commit
  24. 05 Feb, 2022 2 commits
    • Tom Lane's avatar
      Doc: be clearer that foreign-table partitions need user-added constraints. · d0cd7b77
      Tom Lane authored
      A very well-informed user might deduce this from what we said already,
      but I'd bet against it.  Lay it out explicitly.
      
      While here, rewrite the comment about tuple routing to be more
      intelligible to an average SQL user.
      
      Per bug #17395 from Alexander Lakhin.  Back-patch to v11.  (The text
      in this area is different in v10 and I'm not sufficiently excited
      about this point to adapt the patch.)
      
      Discussion: https://postgr.es/m/17395-8c326292078d1a57@postgresql.org
      d0cd7b77
    • Tom Lane's avatar
      Test, don't just Assert, that mergejoin's inputs are in order. · d13a838e
      Tom Lane authored
      There are two Asserts in nodeMergejoin.c that are reachable if
      the input data is not in the expected order.  This seems way too
      fragile.  Alexander Lakhin reported a case where the assertions
      could be triggered with misconfigured foreign-table partitions,
      and bitter experience with unstable operating system collation
      definitions suggests another easy route to hitting them.  Neither
      Assert is in a place where we can't afford one more test-and-branch,
      so replace 'em with plain test-and-elog logic.
      
      Per bug #17395.  While the reported symptom is relatively recent,
      collation changes could happen anytime, so back-patch to all
      supported branches.
      
      Discussion: https://postgr.es/m/17395-8c326292078d1a57@postgresql.org
      d13a838e
  25. 04 Feb, 2022 1 commit
    • Tom Lane's avatar
      First-draft release notes for 14.2. · ab22eea8
      Tom Lane authored
      As usual, the release notes for older branches will be made by cutting
      these down, but put them up for community review first.
      ab22eea8
  26. 03 Feb, 2022 3 commits
  27. 02 Feb, 2022 1 commit