1. 26 Apr, 2017 1 commit
  2. 25 Apr, 2017 22 commits
  3. 24 Apr, 2017 7 commits
    • Bruce Momjian's avatar
      66fade8a
    • Tom Lane's avatar
      Revert "Use pselect(2) not select(2), if available, to wait in postmaster's loop." · 64925603
      Tom Lane authored
      This reverts commit 81069a9e.
      
      Buildfarm results suggest that some platforms have versions of pselect(2)
      that are not merely non-atomic, but flat out non-functional.  Revert the
      use-pselect patch to confirm this diagnosis (and exclude the no-SA_RESTART
      patch as the source of trouble).  If it's so, we should probably look into
      blacklisting specific platforms that have broken pselect.
      
      Discussion: https://postgr.es/m/9696.1493072081@sss.pgh.pa.us
      64925603
    • Tom Lane's avatar
      Use pselect(2) not select(2), if available, to wait in postmaster's loop. · 81069a9e
      Tom Lane authored
      Traditionally we've unblocked signals, called select(2), and then blocked
      signals again.  The code expects that the select() will be cancelled with
      EINTR if an interrupt occurs; but there's a race condition, which is that
      an already-pending signal will be delivered as soon as we unblock, and then
      when we reach select() there will be nothing preventing it from waiting.
      This can result in a long delay before we perform any action that
      ServerLoop was supposed to have taken in response to the signal.  As with
      the somewhat-similar symptoms fixed by commit 89390208, the main practical
      problem is slow launching of parallel workers.  The window for trouble is
      usually pretty short, corresponding to one iteration of ServerLoop; but
      it's not negligible.
      
      To fix, use pselect(2) in place of select(2) where available, as that's
      designed to solve exactly this problem.  Where not available, we continue
      to use the old way, and are no worse off than before.
      
      pselect(2) has been required by POSIX since about 2001, so most modern
      platforms should have it.  A bigger portability issue is that some
      implementations are said to be non-atomic, ie pselect() isn't really
      any different from unblock/select/reblock.  Still, we're no worse off
      than before on such a platform.
      
      There is talk of rewriting the postmaster to use a WaitEventSet and
      not do signal response work in signal handlers, at which point this
      could be reverted, since we'd be using a self-pipe to solve the race
      condition.  But that's not happening before v11 at the earliest.
      
      Back-patch to 9.6.  The problem exists much further back, but the
      worst symptom arises only in connection with parallel query, so it
      does not seem worth taking any portability risks in older branches.
      
      Discussion: https://postgr.es/m/9205.1492833041@sss.pgh.pa.us
      81069a9e
    • Tom Lane's avatar
      Run the postmaster's signal handlers without SA_RESTART. · 89390208
      Tom Lane authored
      The postmaster keeps signals blocked everywhere except while waiting
      for something to happen in ServerLoop().  The code expects that the
      select(2) will be cancelled with EINTR if an interrupt occurs; without
      that, followup actions that should be performed by ServerLoop() itself
      will be delayed.  However, some platforms interpret the SA_RESTART
      signal flag as meaning that they should restart rather than cancel
      the select(2).  Worse yet, some of them restart it with the original
      timeout delay, meaning that a steady stream of signal interrupts can
      prevent ServerLoop() from iterating at all if there are no incoming
      connection requests.
      
      Observable symptoms of this, on an affected platform such as HPUX 10,
      include extremely slow parallel query startup (possibly as much as
      30 seconds) and failure to update timestamps on the postmaster's sockets
      and lockfiles when no new connections arrive for a long time.
      
      We can fix this by running the postmaster's signal handlers without
      SA_RESTART.  That would be quite a scary change if the range of code
      where signals are accepted weren't so tiny, but as it is, it seems
      safe enough.  (Note that postmaster children do, and must, reset all
      the handlers before unblocking signals; so this change should not
      affect any child process.)
      
      There is talk of rewriting the postmaster to use a WaitEventSet and
      not do signal response work in signal handlers, at which point it might
      be appropriate to revert this patch.  But that's not happening before
      v11 at the earliest.
      
      Back-patch to 9.6.  The problem exists much further back, but the
      worst symptom arises only in connection with parallel query, so it
      does not seem worth taking any portability risks in older branches.
      
      Discussion: https://postgr.es/m/9205.1492833041@sss.pgh.pa.us
      89390208
    • Fujii Masao's avatar
      Get rid of extern declarations of non-existent functions. · cbc2270e
      Fujii Masao authored
      Those extern declartions were mistakenly added by commit 7c4f5240.
      
      Author: Petr Jelinek
      cbc2270e
    • Tom Lane's avatar
      Fix postmaster's handling of fork failure for a bgworker process. · 4fe04244
      Tom Lane authored
      This corner case didn't behave nicely at all: the postmaster would
      (partially) update its state as though the process had started
      successfully, and be quite confused thereafter.  Fix it to act
      like the worker had crashed, instead.
      
      In passing, refactor so that do_start_bgworker contains all the
      state-change logic for bgworker launch, rather than just some of it.
      
      Back-patch as far as 9.4.  9.3 contains similar logic, but it's just
      enough different that I don't feel comfortable applying the patch
      without more study; and the use of bgworkers in 9.3 was so small
      that it doesn't seem worth the extra work.
      
      transam/parallel.c is still entirely unprepared for the possibility
      of bgworker startup failure, but that seems like material for a
      separate patch.
      
      Discussion: https://postgr.es/m/4905.1492813727@sss.pgh.pa.us
      4fe04244
    • Tom Lane's avatar
      Code review for commands/statscmds.c. · 4b34624d
      Tom Lane authored
      Fix machine-dependent sorting of column numbers.  (Odd behavior
      would only materialize for column numbers above 255, but that's
      certainly legal.)
      
      Fix poor choice of SQLSTATE for some errors, and improve error message
      wording.  (Notably, "is not a scalar type" is a totally misleading way
      to explain "does not have a default btree opclass".)
      
      Avoid taking AccessExclusiveLock on the associated relation during DROP
      STATISTICS.  That's neither necessary nor desirable, and it could easily
      have put us into situations where DROP fails (compare commit 68ea2b7f).
      
      Adjust/improve comments.
      
      David Rowley and Tom Lane
      
      Discussion: https://postgr.es/m/CAKJS1f-GmCfPvBbAEaM5xoVOaYdVgVN1gicALSoYQ77z-+vLbw@mail.gmail.com
      4b34624d
  4. 23 Apr, 2017 8 commits
  5. 22 Apr, 2017 2 commits
    • Tom Lane's avatar
      Make PostgresNode.pm check server status more carefully. · 7d68f228
      Tom Lane authored
      PostgresNode blithely ignored the exit status of pg_ctl, and in general
      made no effort to be sure that the server was running when it should be.
      This caused it to miss server crashes, which is a serious shortcoming
      in a test scaffold.  Make it complain if pg_ctl fails, and modify the
      start and stop logic to complain if the server doesn't start, or doesn't
      stop, when expected.
      
      Also, have it turn off the "restart_after_crash" configuration parameter
      in created clusters, as bitter experience has shown that leaving that on
      can mask crashes too.
      
      We might at some point need variant functions that allow for, eg,
      server start failure to be expected.  But no existing test case appears
      to want that, and it surely shouldn't be the default behavior.
      
      Note that this *will* break the buildfarm, as it will expose known
      bugs that the previous testing failed to.  I'm committing it despite
      that, to verify that we get the expected failures in the buildfarm
      not just in manual testing.
      
      Back-patch into 9.6 where PostgresNode was introduced.  (The 9.6
      branch is not expected to show any failures.)
      
      Discussion: https://postgr.es/m/21432.1492886428@sss.pgh.pa.us
      7d68f228
    • Tom Lane's avatar
      Make PostgresNode::append_conf append a newline automatically. · 8a19c1a3
      Tom Lane authored
      Although the documentation for append_conf said clearly that it didn't
      add a newline, many test authors seem to have forgotten that ... or maybe
      they just consulted the example at the top of the POD documentation,
      which clearly shows adding a config entry without bothering to add a
      trailing newline.  The worst part of that is that it works, as long as
      you don't do it more than once, since the backend isn't picky about
      whether config files end with newlines.  So there's not a strong forcing
      function reminding test authors not to do it like that.  Upshot is that
      this is a terribly fragile way to go about things, and there's at least
      one existing test case that is demonstrably broken and not testing what
      it thinks it is.
      
      Let's just make append_conf append a newline, instead; that is clearly
      way safer than the old definition.
      
      I also cleaned up a few call sites that were unnecessarily ugly.
      (I left things alone in places where it's plausible that additional
      config lines would need to be added someday.)
      
      Back-patch the change in append_conf itself to 9.6 where it was added,
      as having a definitional inconsistency between branches would obviously
      be pretty hazardous for back-patching TAP tests.  The other changes are
      just cosmetic and don't need to be back-patched.
      
      Discussion: https://postgr.es/m/19751.1492892376@sss.pgh.pa.us
      8a19c1a3