1. 14 Dec, 2019 2 commits
    • Thomas Munro's avatar
      Fix mdsyncfiletag(), take II. · 7c85be08
      Thomas Munro authored
      The previous commit failed to consider that FileGetRawDesc() might
      not return a valid fd, as discovered on the build farm.  Switch to
      using the File interface only.
      
      Back-patch to 12, like the previous commit.
      7c85be08
    • Thomas Munro's avatar
      Don't use _mdfd_getseg() in mdsyncfiletag(). · 7bb3102c
      Thomas Munro authored
      _mdfd_getseg() opens all segments up to the requested one.  That
      causes problems for mdsyncfiletag(), if mdunlinkfork() has
      already unlinked other segment files.  Open the file we want
      directly by name instead, if it's not already open.
      
      The consequence of this bug was a rare panic in the checkpointer,
      made more likely if you saturated the sync request queue so that
      the SYNC_FORGET_REQUEST messages for a given relation were more
      likely to be absorbed in separate cycles by the checkpointer.
      
      Back-patch to 12.  Defect in commit 3eb77eba.
      
      Author: Thomas Munro
      Reported-by: Justin Pryzby
      Discussion: https://postgr.es/m/20191119115759.GI30362%40telsasoft.com
      7bb3102c
  2. 13 Dec, 2019 2 commits
    • Heikki Linnakangas's avatar
      Fix crash when a page was split during GiST index creation. · a7ee7c85
      Heikki Linnakangas authored
      The bug was similar to the one that was fixed in commit 22251686. When
      we split page X and insert the downlink for the new page, the parent page
      might also need to be split. When that happens, the downlink offset number
      we remembered for X is no longer valid. We correctly called
      gistFindCorrectParent() to re-find it, but gistFindCorrectParent() doesn't
      do anything if the LSN of the page hasn't changed, and we stopped updating
      LSNs during index build in commit 9155580f. The buggy codepath was taken
      if the page was split into three or more pages, and inserting the downlink
      caused the parent page to split. To fix, explicitly mark the downlink
      offset number as invalid, to force gistFindCorrectParent() to re-find it.
      
      Fixes bug #16134 reported by Alexander Lakhin, reported again as #16162 by
      Andreas Kunert. Thanks to Jeff Janes, Tom Lane and Tomas Vondra for
      debugging. Backpatch to v12, where we stopped WAL-logging during index
      build.
      
      Discussion: https://www.postgresql.org/message-id/16134-0423f729671dec64%40postgresql.org
      Discussion: https://www.postgresql.org/message-id/16162-45d21b7b6c1a3105%40postgresql.org
      a7ee7c85
    • Tom Lane's avatar
      Modernize our readline API a tad. · 5e7bedc5
      Tom Lane authored
      Prefer to call "rl_filename_completion_function" and
      "rl_completion_matches", rather than using the names without the rl_
      prefix.  This matches Readline's documentation, and makes our code
      a little clearer about which names are external.  On platforms that
      only have the un-prefixed names (just some very ancient versions of
      libedit, AFAICT), reverse the direction of the compatibility macro
      definitions to match.
      
      Also, remove our extern declaration of "filename_completion_function";
      whatever libedit versions may have failed to declare that are surely
      dead and buried.
      
      Discussion: https://postgr.es/m/23608.1576248145@sss.pgh.pa.us
      5e7bedc5
  3. 12 Dec, 2019 6 commits
  4. 11 Dec, 2019 8 commits
    • Tom Lane's avatar
      Remove unstable test case added in commit 5935917c. · 776a2c88
      Tom Lane authored
      The buildfarm says this produces some unexpected output with
      force_parallel_mode = regress.  There's probably a bug underneath
      that, but for the moment just delete the test case to make the
      buildfarm green again.
      
      (I now notice that the case had also failed to get updated to follow
      commit d52eaa09, which made plan_cache_mode = force_generic_plan
      prevail throughout partition_prune.sql; it was thereby managing to
      break a later test.  When/if we put this back in, *don't* include the
      SET and RESET commands.)
      776a2c88
    • Tom Lane's avatar
      Allow executor startup pruning to prune all child nodes. · 5935917c
      Tom Lane authored
      Previously, if the startup pruning logic proved that all child nodes
      of an Append or MergeAppend could be pruned, we still kept one, just
      to keep EXPLAIN from failing.  The previous commit removed the
      ruleutils.c limitation that required this kluge, so drop it.  That
      results in less-confusing EXPLAIN output, as per a complaint from
      Yuzuko Hosoya.
      
      David Rowley
      
      Discussion: https://postgr.es/m/001001d4f44b$2a2cca50$7e865ef0$@lab.ntt.co.jp
      5935917c
    • Tom Lane's avatar
      Further adjust EXPLAIN's choices of table alias names. · 6ef77cf4
      Tom Lane authored
      This patch causes EXPLAIN to always assign a separate table alias to the
      parent RTE of an append relation (inheritance set); before, such RTEs
      were ignored if not actually scanned by the plan.  Since the child RTEs
      now always have that same alias to start with (cf. commit 55a1954d),
      the net effect is that the parent RTE usually gets the alias used or
      implied by the query text, and the children all get that alias with "_N"
      appended.  (The exception to "usually" is if there are duplicate aliases
      in different subtrees of the original query; then some of those original
      RTEs will also have "_N" appended.)
      
      This results in more uniform output for partitioned-table plans than
      we had before: the partitioned table itself gets the original alias,
      and all child tables have aliases with "_N", rather than the previous
      behavior where one of the children would get an alias without "_N".
      
      The reason for giving the parent RTE an alias, even if it isn't scanned
      by the plan, is that we now use the parent's alias to qualify Vars that
      refer to an appendrel output column and appear above the Append or
      MergeAppend that computes the appendrel.  But below the append, Vars
      refer to some one of the child relations, and are displayed that way.
      This seems clearer than the old behavior where a Var that could carry
      values from any child relation was displayed as if it referred to only
      one of them.
      
      While at it, change ruleutils.c so that the code paths used by EXPLAIN
      deal in Plan trees not PlanState trees.  This effectively reverts a
      decision made in commit 1cc29fe7, which seemed like a good idea at
      the time to make ruleutils.c consistent with explain.c.  However,
      it's problematic because we'd really like to allow executor startup
      pruning to remove all the children of an append node when possible,
      leaving no child PlanState to resolve Vars against.  (That's not done
      here, but will be in the next patch.)  This requires different handling
      of subplans and initplans than before, but is otherwise a pretty
      straightforward change.
      
      Discussion: https://postgr.es/m/001001d4f44b$2a2cca50$7e865ef0$@lab.ntt.co.jp
      6ef77cf4
    • Alvaro Herrera's avatar
      Emit parameter values during query bind/execute errors · ba79cb5d
      Alvaro Herrera authored
      This makes such log entries more useful, since the cause of the error
      can be dependent on the parameter values.
      
      Author: Alexey Bashtanov, Álvaro Herrera
      Discussion: https://postgr.es/m/0146a67b-a22a-0519-9082-bc29756b93a2@imap.cc
      Reviewed-by: Peter Eisentraut, Andres Freund, Tom Lane
      ba79cb5d
    • Tom Lane's avatar
      Use only one thread to handle incoming signals on Windows. · 16114f2e
      Tom Lane authored
      Since its inception, our Windows signal emulation code has worked by
      running a main signal thread that just watches for incoming signal
      requests, and then spawns a new thread to handle each such request.
      That design is meant for servers in which requests can take substantial
      effort to process, and it's worth parallelizing the handling of
      requests.  But those assumptions are just bogus for our signal code.
      It's not much more than pg_queue_signal(), which is cheap and can't
      parallelize at all, plus we don't really expect lots of signals to
      arrive at the same backend at once.  More importantly, this approach
      creates failure modes that we could do without: either inability to
      spawn a new thread or inability to create a new pipe handle will risk
      loss of signals.  Hence, dispense with the separate per-signal threads
      and just service each request in-line in the main signal thread.  This
      should be a bit faster (for the normal case of one signal at a time)
      as well as more robust.
      
      Patch by me; thanks to Andrew Dunstan for testing and Amit Kapila
      for review.
      
      Discussion: https://postgr.es/m/4412.1575748586@sss.pgh.pa.us
      16114f2e
    • Peter Eisentraut's avatar
      Remove ATPrepSetStatistics · 105eb360
      Peter Eisentraut authored
      It was once possible to do ALTER TABLE ... SET STATISTICS on system
      tables without allow_sytem_table_mods.  This was changed apparently by
      accident between PostgreSQL 9.1 and 9.2, but a code comment still
      claimed this was possible.  Without that functionality, having a
      separate ATPrepSetStatistics() is useless, so use the generic
      ATSimplePermissions() instead and move the remaining custom code into
      ATExecSetStatistics().
      Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
      Discussion: https://www.postgresql.org/message-id/flat/cc8d2648-a0ec-7a86-13e5-db473484e19e%402ndquadrant.com
      105eb360
    • Peter Eisentraut's avatar
      Fix output of Unicode normalization test · b8024121
      Peter Eisentraut authored
      Several off-by-more-than-one errors caused the output in case of a
      test failure to be truncated and unintelligible.
      Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
      Discussion: https://www.postgresql.org/message-id/flat/6a7a8516-7d11-8fbd-0e8b-eadb4f0679eb%402ndquadrant.com
      b8024121
    • Michael Paquier's avatar
      Fix some compiler warnings with timestamp parsing in formatting.c · c341c7d3
      Michael Paquier authored
      gcc-7 used with a sufficient optimization level complains about warnings
      around do_to_timestamp() regarding the initialization and handling of
      some of its variables.  Recent commits 66c74f8b and d589f944 made things
      made the interface more confusing, so document which variables are
      always expected and initialize properly the optional ones when they are
      set.
      
      Author: Andrey Lepikhov, Michael Paquier
      Discussion: https://postgr.es/m/a7e28b83-27b1-4e1c-c76b-4268c4b785bc@postgrespro.ru
      c341c7d3
  5. 10 Dec, 2019 5 commits
    • Tom Lane's avatar
      Fix tuple column count in pg_control_init(). · 8729fa72
      Tom Lane authored
      Oversight in commit 2e4db241.
      
      Nathan Bossart
      
      Discussion: https://postgr.es/m/1B616360-396A-4482-AA28-375566C86160@amazon.com
      8729fa72
    • Peter Eisentraut's avatar
      Cosmetic cleaning of pg_config.h.win32 · 877b61e9
      Peter Eisentraut authored
      Clean up some comments (some generated by old versions of autoconf)
      and some random ordering differences, so it's easier to diff this
      against the default pg_config.h or pg_config.h.in.  Remove LOCALEDIR
      handling from pg_config.h.win32 altogether because it's already in
      pg_config_paths.h.
      877b61e9
    • Alvaro Herrera's avatar
      Add backend-only appendStringInfoStringQuoted · 6cafde1b
      Alvaro Herrera authored
      This provides a mechanism to emit literal values in informative
      messages, such as query parameters.  The new code is more complex than
      what it replaces, primarily because it wants to be more efficient.
      It also has the (currently unused) additional optional capability of
      specifying a maximum size to print.
      
      The new function lives out of common/stringinfo.c so that frontend users
      of that file need not pull in unnecessary multibyte-encoding support
      code.
      
      Author: Álvaro Herrera and Alexey Bashtanov, after a suggestion from Andres Freund
      Reviewed-by: Tom Lane
      Discussion: https://postgr.es/m/20190920203905.xkv5udsd5dxfs6tr@alap3.anarazel.de
      6cafde1b
    • Tom Lane's avatar
      In pg_ctl, work around ERROR_SHARING_VIOLATION on the postmaster log file. · 0da33c76
      Tom Lane authored
      On Windows, we use CMD.EXE to redirect the postmaster's stdout/stderr
      into a log file.  CMD.EXE will open that file with non-sharing-friendly
      parameters, and the file will remain open for a short time after the
      postmaster has removed postmaster.pid.  This can result in an
      ERROR_SHARING_VIOLATION failure if we attempt to start a new postmaster
      immediately with the same log file (e.g. during "pg_ctl restart").
      This seems to explain intermittent buildfarm failures we've been seeing
      on Windows machines.
      
      To fix, just open and close the log file using our own pgwin32_open(),
      which will wait if necessary to avoid the failure.  (Perhaps someday
      we should stop using CMD.EXE, but that would be a far more complex
      patch, and it doesn't seem worth the trouble ... yet.)
      
      Back-patch to v12.  This only solves the problem when frontend fopen()
      is redirected to pgwin32_fopen(), which has only been true since commit
      0ba06e0b.  Hence, no point in back-patching further, unless we care
      to back-patch that change too.
      
      Diagnosis and patch by Alexander Lakhin (bug #16154).
      
      Discussion: https://postgr.es/m/16154-1ccf0b537b24d5e0@postgresql.org
      0da33c76
    • Etsuro Fujita's avatar
      Fix handling of multiple AFTER ROW triggers on a foreign table. · 5a20b021
      Etsuro Fujita authored
      AfterTriggerExecute() retrieves a fresh tuple or pair of tuples from a
      tuplestore and then stores the tuple(s) in the passed-in slot(s) if
      AFTER_TRIGGER_FDW_FETCH, while it uses the most-recently-retrieved
      tuple(s) stored in the slot(s) if AFTER_TRIGGER_FDW_REUSE.  This was
      done correctly before 12, but commit ff11e7f4 broke it by mistakenly
      clearing the tuple(s) stored in the slot(s) in that function, leading to
      an assertion failure as reported in bug #16139 from Alexander Lakhin.
      
      Also, fix some other issues with the aforementioned commit in passing:
      
      * For tg_newslot, which is a slot added to the TriggerData struct by the
        commit to store new updated tuples, it didn't ensure the slot was NULL
        if there was no such tuple.
      * The commit failed to update the documentation about the trigger
        interface.
      
      Author: Etsuro Fujita
      Backpatch-through: 12
      Discussion: https://postgr.es/m/16139-94f9ccf0db6119ec%40postgresql.org
      5a20b021
  6. 09 Dec, 2019 3 commits
    • Tom Lane's avatar
      Fix race condition in our Windows signal emulation. · 28e6a2fd
      Tom Lane authored
      pg_signal_dispatch_thread() responded to the client (signal sender)
      and disconnected the pipe before actually setting the shared variables
      that make the signal visible to the backend process's main thread.
      In the worst case, it seems, effective delivery of the signal could be
      postponed for as long as the machine has any other work to do.
      
      To fix, just move the pg_queue_signal() call so that we do it before
      responding to the client.  This essentially makes pgkill() synchronous,
      which is a stronger guarantee than we have on Unix.  That may be
      overkill, but on the other hand we have not seen comparable timing bugs
      on any Unix platform.
      
      While at it, add some comments to this sadly underdocumented code.
      
      Problem diagnosis and fix by Amit Kapila; I just added the comments.
      
      Back-patch to all supported versions, as it appears that this can cause
      visible NOTIFY timing oddities on all of them, and there might be
      other misbehavior due to slow delivery of other signals.
      
      Discussion: https://postgr.es/m/32745.1575303812@sss.pgh.pa.us
      28e6a2fd
    • Tom Lane's avatar
      Improve isolationtester's timeout management. · 99351a8b
      Tom Lane authored
      isolationtester.c had a hard-wired limit of 3 minutes per test step.
      It now emerges that this isn't quite enough for some of the slowest
      buildfarm animals.  This isn't the first time we've had to raise
      this limit (cf. 1db439ad), so let's make it configurable.  This
      patch raises the default to 5 minutes, and introduces an environment
      variable PGISOLATIONTIMEOUT that can be set if more time is needed,
      following the precedent of PGCTLTIMEOUT.
      
      Also, modify isolationtester so that when the timeout is hit,
      it explicitly reports having sent a cancel.  This makes the regression
      failure log considerably more intelligible.  (In the worst case, a
      timed-out test might actually be reported as "passing" without this
      extra output, so arguably this is a bug fix in itself.)
      
      In passing, update the README file, which had apparently not gotten
      touched when we added "make check" support here.
      
      Back-patch to 9.6; older versions don't have comparable timeout logic.
      
      Discussion: https://postgr.es/m/22964.1575842935@sss.pgh.pa.us
      99351a8b
    • Amit Kapila's avatar
      Fix typos in miscinit.c. · 2d0fdfac
      Amit Kapila authored
      Commit f13ea95f moved the description of postmaster.pid file contents
      from miscadmin.h to pidfile.h, but missed to update the comments in
      miscinit.c.
      
      Author: Hadi Moshayedi
      Reviewed-by: Amit Kapila
      Backpatch-through: 10
      Discussion: https://postgr.es/m/CAK=1=WpYEM9x3LGkaxgXaxeYQjnkdW8XLsxrYRTE2Gq-H83FMw@mail.gmail.com
      2d0fdfac
  7. 08 Dec, 2019 2 commits
  8. 07 Dec, 2019 1 commit
  9. 06 Dec, 2019 6 commits
    • Tom Lane's avatar
      Improve test coverage of ruleutils.c. · 830d1c73
      Tom Lane authored
      While fooling around with the EXPLAIN improvements I've been working
      on, I noticed that there were some large gaps in our test coverage
      of ruleutils.c, according to the code coverage report.  This commit
      just adds a few test cases to improve coverage of:
      get_name_for_var_field()
      get_update_query_targetlist_def()
      isSimpleNode()
      get_sublink_expr()
      830d1c73
    • Jeff Davis's avatar
      Fix comments in execGrouping.c · 30d47723
      Jeff Davis authored
      Commit 5dfc1981 missed updating some comments.
      
      Also, fix a comment typo found in passing.
      
      Author: Jeff Davis
      Discussion: https://postgr.es/m/9723131d247b919f94699152647fa87ee0bc02c2.camel%40j-davis.com
      30d47723
    • Tom Lane's avatar
      Disallow non-default collation in ADD PRIMARY KEY/UNIQUE USING INDEX. · fbbf6809
      Tom Lane authored
      When creating a uniqueness constraint using a pre-existing index,
      we have always required that the index have the same properties you'd
      get if you just let a new index get built.  However, when collations
      were added, we forgot to add the index's collation to that check.
      
      It's hard to trip over this without intentionally trying to break it:
      you'd have to explicitly specify a different collation in CREATE
      INDEX, then convert it to a pkey or unique constraint.  Still, if you
      did that, pg_dump would emit a script that fails to reproduce the
      index's collation.  The main practical problem is that after a
      pg_upgrade the index would be corrupt, because its actual physical
      order wouldn't match what pg_index says.  A more theoretical issue,
      which is new as of v12, is that if you create the index with a
      nondeterministic collation then it wouldn't be enforcing the normal
      notion of uniqueness, causing the constraint to mean something
      different from a normally-created constraint.
      
      To fix, just add collation to the conditions checked for index
      acceptability in ADD PRIMARY KEY/UNIQUE USING INDEX.  We won't try
      to clean up after anybody who's already created such a situation;
      it seems improbable enough to not be worth the effort involved.
      (If you do get into trouble, a REINDEX should be enough to fix it.)
      
      In principle this is a long-standing bug, but I chose not to
      back-patch --- the odds of causing trouble seem about as great
      as the odds of preventing it, and both risks are very low anyway.
      
      Per report from Alexey Bashtanov, though this is not his preferred
      fix.
      
      Discussion: https://postgr.es/m/b05ce36a-cefb-ca5e-b386-a400535b1c0b@imap.cc
      fbbf6809
    • Michael Paquier's avatar
      Fix handling of OpenSSL's SSL_clear_options · 7d0bcb04
      Michael Paquier authored
      This function is supported down to OpenSSL 0.9.8, which is the oldest
      version supported since 593d4e47 (from Postgres 10 onwards), and is used
      since e3bdb2d9 (from 11 onwards).  It is defined as a macro from OpenSSL
      0.9.8 to 1.0.2, and as a function in 1.1.0 and newer versions.  However,
      the configure check present is only adapted for functions.  So, even if
      the code would be able to compile, configure fails to detect the macro,
      causing it to be ignored when compiling the code with OpenSSL from 0.9.8
      to 1.0.2.
      
      The code needs a configure check as per a364dfa4, which has fixed a
      compilation issue with a past version of LibreSSL in NetBSD 5.1.  On
      HEAD, just remove the configure check as the last release of NetBSD 5 is
      from 2014 (and we have no more buildfarm members for it).  In 11 and 12,
      improve the configure logic so as both macros and functions are
      correctly detected.  This makes NetBSD 5 still work on already-released
      branches, but not for 13 onwards.
      
      The patch for HEAD is from me, and Daniel has written the version to use
      for the back-branches.
      
      Author: Michael Paquier, Daniel Gustaffson
      Reviewed-by: Tom Lane
      Discussion: https://postgr.es/m/20191205083252.GE5064@paquier.xyz
      Discussion: https://postgr.es/m/98F7F99E-1129-41D8-B86B-FE3B1E286881@yesql.se
      Backpatch-through: 11
      7d0bcb04
    • Michael Paquier's avatar
      Improve some comments in pg_upgrade.c · 690c8802
      Michael Paquier authored
      When restoring database schemas on a new cluster, database "template1"
      is processed first, followed by all other databases in parallel,
      including "postgres".  Both "postgres" and "template1" have some extra
      handling to propagate each one's properties, but comments were confusing
      regarding which one is processed where.
      
      Author: Julien Rouhaud
      Reviewed-by: Daniel Gustafsson
      Discussion: https://postgr.es/m/CAOBaU_a2iviTG7FE10yO_gcW+zQCHNFhRA_NDiktf3UR65BHdw@mail.gmail.com
      690c8802
    • Michael Paquier's avatar
      Remove configure check for OpenSSL's SSL_get_current_compression() · 28f4bba6
      Michael Paquier authored
      This function has been added in OpenSSL 0.9.8, which is the oldest
      version supported on HEAD, so checking for it at configure time is
      useless.  Both the frontend and backend code did not even bother to use
      it.
      
      Reported-by: Daniel Gustafsson
      Author: Michael Paquier
      Reviewed-by: Daniel Gustafsson, Tom Lane
      Discussion: https://postgr.es/m/20191205083252.GE5064@paquier.xyz
      Discussion: https://postgr.es/m/98F7F99E-1129-41D8-B86B-FE3B1E286881@yesql.se
      28f4bba6
  10. 05 Dec, 2019 2 commits
  11. 04 Dec, 2019 3 commits