1. 28 Jun, 2015 3 commits
    • Heikki Linnakangas's avatar
      Add missing_ok option to the SQL functions for reading files. · cb2acb10
      Heikki Linnakangas authored
      This makes it possible to use the functions without getting errors, if there
      is a chance that the file might be removed or renamed concurrently.
      pg_rewind needs to do just that, although this could be useful for other
      purposes too. (The changes to pg_rewind to use these functions will come in
      a separate commit.)
      
      The read_binary_file() function isn't very well-suited for extensions.c's
      purposes anymore, if it ever was. So bite the bullet and make a copy of it
      in extension.c, tailored for that use case. This seems better than the
      accidental code reuse, even if it's a some more lines of code.
      
      Michael Paquier, with plenty of kibitzing by me.
      cb2acb10
    • Kevin Grittner's avatar
      Fix comment for GetCurrentIntegerTimestamp(). · cca8ba95
      Kevin Grittner authored
      The unit of measure is microseconds, not milliseconds.
      
      Backpatch to 9.3 where the function and its comment were added.
      cca8ba95
    • Tatsuo Ishii's avatar
  2. 27 Jun, 2015 4 commits
    • Tom Lane's avatar
      Avoid passing NULL to memcmp() in lookups of zero-argument functions. · 0a52d378
      Tom Lane authored
      A few places assumed they could pass NULL for the argtypes array when
      looking up functions known to have zero arguments.  At first glance
      it seems that this should be safe enough, since memcmp() is surely not
      allowed to fetch any bytes if its count argument is zero.  However,
      close reading of the C standard says that such calls have undefined
      behavior, so we'd probably best avoid it.
      
      Since the number of places doing this is quite small, and some other
      places looking up zero-argument functions were already passing dummy
      arrays, let's standardize on the latter solution rather than hacking
      the function lookup code to avoid calling memcmp() in these cases.
      I also added Asserts to catch any future violations of the new rule.
      
      Given the utter lack of any evidence that this actually causes any
      problems in the field, I don't feel a need to back-patch this change.
      
      Per report from Piotr Stefaniak, though this is not his patch.
      0a52d378
    • Andres Freund's avatar
      Fix test_decoding's handling of nonexistant columns in old tuple versions. · d47a1136
      Andres Freund authored
      test_decoding used fastgetattr() to extract column values. That's wrong
      when decoding updates and deletes if a table's replica identity is set
      to FULL and new columns have been added since the old version of the
      tuple was created. Due to the lack of a crosscheck with the datum's
      natts values an invalid value will be output, leading to errors or
      worse.
      
      Bug: #13470
      Reported-By: Krzysztof Kotlarski
      Discussion: 20150626100333.3874.90852@wrigleys.postgresql.org
      
      Backpatch to 9.4, where the feature, including the bug, was added.
      d47a1136
    • Kevin Grittner's avatar
      Add opaque declaration of HTAB to tqual.h. · 604e9939
      Kevin Grittner authored
      Commit b89e1510 added the
      ResolveCminCmaxDuringDecoding declaration to tqual.h, which uses an
      HTAB parameter, without declaring HTAB.  It accidentally fails to
      fail to build with current sources because a declaration happens to
      be included, directly or indirectly, in all source files that
      currently use tqual.h before tqual.h is first included, but we
      shouldn't count on that.  Since an opaque declaration is enough
      here, just use that, as was done in snapmgr.h.
      
      Backpatch to 9.4, where the HTAB reference was added to tqual.h.
      604e9939
    • Heikki Linnakangas's avatar
      Fix typo in comment · 7845db2a
      Heikki Linnakangas authored
      Etsuro Fujita
      7845db2a
  3. 26 Jun, 2015 13 commits
    • Simon Riggs's avatar
      Avoid hot standby cancels from VAC FREEZE · 66fbcb0d
      Simon Riggs authored
      VACUUM FREEZE generated false cancelations of standby queries on an
      otherwise idle master. Caused by an off-by-one error on cutoff_xid
      which goes back to original commit.
      
      Backpatch to all versions 9.0+
      
      Analysis and report by Marco Nenciarini
      
      Bug fix by Simon Riggs
      66fbcb0d
    • Alvaro Herrera's avatar
      Fix DDL command collection for TRANSFORM · 7d60b2af
      Alvaro Herrera authored
      Commit b488c580, which added the DDL command collection feature,
      neglected to update the code that commit cac76582 had previously
      added two weeks earlier for the TRANSFORM feature.
      
      Reported by Michael Paquier.
      7d60b2af
    • Alvaro Herrera's avatar
      Fix BRIN xlog replay · 40282224
      Alvaro Herrera authored
      There was a confusion about which block number to use when storing an
      item's pointer in the revmap -- the revmap page's blkno was being used,
      not the data page's blkno.
      
      Spotted-by: Jeff Janes
      40282224
    • Robert Haas's avatar
      Fix grammar. · 7c02d48e
      Robert Haas authored
      Reported by Peter Geoghegan.
      7c02d48e
    • Robert Haas's avatar
      Be more conservative about removing tablespace "symlinks". · 8f15f74a
      Robert Haas authored
      Don't apply rmtree(), which will gleefully remove an entire subtree,
      and don't even apply unlink() unless it's symlink or a directory,
      the only things that we expect to find.
      
      Amit Kapila, with minor tweaks by me, per extensive discussions
      involving Andrew Dunstan, Fujii Masao, and Heikki Linnakangas,
      at least some of whom also reviewed the code.
      8f15f74a
    • Robert Haas's avatar
      release notes: Add entry for commit 5ea86e6e. · c66bc72e
      Robert Haas authored
      Peter Geoghegan and Robert Haas
      c66bc72e
    • Robert Haas's avatar
      Remove unnecessary NULL test. · 8a8c581a
      Robert Haas authored
      Spotted by Coverity and reported by Michael Paquier.  Per discussion,
      we don't necessarily care about making Coverity happy in all such
      instances, but we can go ahead and change them where it otherwise
      seems to improve the code.
      8a8c581a
    • Robert Haas's avatar
      release notes: Combine items for pg_upgrade and pg_upgrade_support moves. · 31c018ec
      Robert Haas authored
      Per suggestions from Amit Langote and Álvaro Herrera.
      31c018ec
    • Robert Haas's avatar
      Don't warn about creating temporary or unlogged hash indexes. · 9043ef39
      Robert Haas authored
      Warning people that no WAL-logging will be done doesn't make sense
      in this case.
      
      Michael Paquier
      9043ef39
    • Robert Haas's avatar
      Reduce log level for background worker events from LOG to DEBUG1. · 91118f1a
      Robert Haas authored
      Per discussion, LOG is just too chatty for something that will happen
      as routinely as this.
      
      Pavel Stehule
      91118f1a
    • Andres Freund's avatar
      Fix the fallback memory barrier implementation to be reentrant. · 1b468a13
      Andres Freund authored
      This was essentially "broken" since 0c8eda62; but until more
      recently (14e8803f) barriers usage in signal handlers was infrequent.
      
      The failure to be reentrant was noticed because the test_shm_mq, which
      uses memory barriers at a high frequency, occasionally got stuck on some
      solaris buildfarm animals. Turns out, those machines use sun studio
      12.1, which doesn't yet have efficient memory barrier support. A machine
      with a newer sun studio did not fail.  Forcing the barrier fallback to
      be used on x86 allows to reproduce the problem.
      
      The new fallback is to use kill(PostmasterPid, 0) based on the theory
      that that'll always imply a barrier due to checking the liveliness of
      PostmasterPid on systems old enough to need fallback support. It's hard
      to come up with a good and performant fallback.
      
      I'm not backpatching this for now - the problem isn't active in the back
      branches, and we haven't backpatched barrier changes for
      now. Additionally master looks entirely different than the back branches
      due to the new atomics abstraction. It seems better to let this rest in
      master, where the non-reentrancy actively causes a problem, and then
      consider backpatching.
      
      Found-By: Robert Haas
      Discussion: 55626265.3060800@dunslane.net
      1b468a13
    • Robert Haas's avatar
      Improve handling of CustomPath/CustomPlan(State) children. · 5ca61184
      Robert Haas authored
      Allow CustomPath to have a list of paths, CustomPlan a list of plans,
      and CustomPlanState a list of planstates known to the core system, so
      that custom path/plan providers can more reasonably use this
      infrastructure for nodes with multiple children.
      
      KaiGai Kohei, per a design suggestion from Tom Lane, with some
      further kibitzing by me.
      5ca61184
    • Heikki Linnakangas's avatar
      Fix a couple of bugs with wal_log_hints. · 4b8e24b9
      Heikki Linnakangas authored
      1. Replay of the WAL record for setting a bit in the visibility map
      contained an assertion that a full-page image of that record type can only
      occur with checksums enabled. But it can also happen with wal_log_hints, so
      remove the assertion. Unlike checksums, wal_log_hints can be changed on the
      fly, so it would be complicated to figure out if it was enabled at the time
      that the WAL record was generated.
      
      2. wal_log_hints has the same effect on the locking needed to read the LSN
      of a page as data checksums. BufferGetLSNAtomic() didn't get the memo.
      
      Backpatch to 9.4, where wal_log_hints was added.
      4b8e24b9
  4. 25 Jun, 2015 3 commits
    • Robert Haas's avatar
      Allow background workers to connect to no particular database. · f7bb7f06
      Robert Haas authored
      The documentation claims that this is supported, but it didn't
      actually work.  Fix that.
      
      Reported by Pavel Stehule; patch by me.
      f7bb7f06
    • Tom Lane's avatar
      Fix the logic for putting relations into the relcache init file. · 5d1ff6bd
      Tom Lane authored
      Commit f3b5565d was a couple of bricks shy
      of a load; specifically, it missed putting pg_trigger_tgrelid_tgname_index
      into the relcache init file, because that index is not used by any
      syscache.  However, we have historically nailed that index into cache for
      performance reasons.  The upshot was that load_relcache_init_file always
      decided that the init file was busted and silently ignored it, resulting
      in a significant hit to backend startup speed.
      
      To fix, reinstantiate RelationIdIsInInitFile() as a wrapper around
      RelationSupportsSysCache(), which can know about additional relations
      that should be in the init file despite being unknown to syscache.c.
      
      Also install some guards against future mistakes of this type: make
      write_relcache_init_file Assert that all nailed relations get written to
      the init file, and make load_relcache_init_file emit a WARNING if it takes
      the "wrong number of nailed relations" exit path.  Now that we remove the
      init files during postmaster startup, that case should never occur in the
      field, even if we are starting a minor-version update that added or removed
      rels from the nailed set.  So the warning shouldn't ever be seen by end
      users, but it will show up in the regression tests if somebody breaks this
      logic.
      
      Back-patch to all supported branches, like the previous commit.
      5d1ff6bd
    • Tom Lane's avatar
      Docs: fix claim that to_char('FM') removes trailing zeroes. · d759b7eb
      Tom Lane authored
      Of course, what it removes is leading zeroes.  Seems to have been a thinko
      in commit ffe92d15.  Noted by Hubert Depesz
      Lubaczewski.
      d759b7eb
  5. 24 Jun, 2015 1 commit
  6. 23 Jun, 2015 4 commits
  7. 22 Jun, 2015 3 commits
    • Tom Lane's avatar
      Improve inheritance_planner()'s performance for large inheritance sets. · 2cb9ec1b
      Tom Lane authored
      Commit c03ad560 introduced a planner
      performance regression for UPDATE/DELETE on large inheritance sets.
      It required copying the append_rel_list (which is of size proportional to
      the number of inherited tables) once for each inherited table, thus
      resulting in O(N^2) time and memory consumption.  While it's difficult to
      avoid that in general, the extra work only has to be done for
      append_rel_list entries that actually reference subquery RTEs, which
      inheritance-set entries will not.  So we can buy back essentially all of
      the loss in cases without subqueries in FROM; and even for those, the added
      work is mainly proportional to the number of UNION ALL subqueries.
      
      Back-patch to 9.2, like the previous commit.
      
      Tom Lane and Dean Rasheed, per a complaint from Thomas Munro.
      2cb9ec1b
    • Robert Haas's avatar
      psql: Add some tab completion for TABLESAMPLE. · da9ee026
      Robert Haas authored
      Petr Jelinek, reviewed by Brendan Jurd
      da9ee026
    • Noah Misch's avatar
      Truncate strings in tarCreateHeader() with strlcpy(), not sprintf(). · 4318118e
      Noah Misch authored
      This supplements the GNU libc bug #6530 workarounds introduced in commit
      54cd4f04.  On affected systems, a
      tar-format pg_basebackup failed when some filename beneath the data
      directory was not valid character data in the postmaster/walsender
      locale.  Back-patch to 9.1, where pg_basebackup was introduced.  Extant,
      bug-prone conversion specifications receive only ASCII bytes or involve
      low-importance messages.
      4318118e
  8. 21 Jun, 2015 4 commits
    • Alvaro Herrera's avatar
      Add transforms to pg_get_object_address and friends · ad89a5d1
      Alvaro Herrera authored
      This was missed when transforms were added by commit cac76582.
      
      Extracted from a larger patch
      Author: Michael Paquier
      ad89a5d1
    • Andres Freund's avatar
      Improve multixact emergency autovacuum logic. · 667912ae
      Andres Freund authored
      Previously autovacuum was not necessarily triggered if space in the
      members slru got tight. The first problem was that the signalling was
      tied to values in the offsets slru, but members can advance much
      faster. Thats especially a problem if old sessions had been around that
      previously prevented the multixact horizon to increase. Secondly the
      skipping logic doesn't work if the database was restarted after
      autovacuum was triggered - that knowledge is not preserved across
      restart. This is especially a problem because it's a common
      panic-reaction to restart the database if it gets slow to
      anti-wraparound vacuums.
      
      Fix the first problem by separating the logic for members from
      offsets. Trigger autovacuum whenever a multixact crosses a segment
      boundary, as the current member offset increases in irregular values, so
      we can't use a simple modulo logic as for offsets.  Add a stopgap for
      the second problem, by signalling autovacuum whenver ERRORing out
      because of boundaries.
      
      Discussion: 20150608163707.GD20772@alap3.anarazel.de
      
      Backpatch into 9.3, where it became more likely that multixacts wrap
      around.
      667912ae
    • Andres Freund's avatar
      Add missing check for wal_debug GUC. · 90231cd5
      Andres Freund authored
      9a20a9b2 added a new elog(), enabled when WAL_DEBUG is defined. The
      other WAL_DEBUG dependant messages check for the wal_debug GUC, but this
      one did not. While at it replace 'upto' with 'up to'.
      
      Discussion: 20150610110253.GF3832@alap3.anarazel.de
      
      Backpatch to 9.4, the first release containing 9a20a9b2.
      90231cd5
    • Peter Eisentraut's avatar
      103382ab
  9. 20 Jun, 2015 4 commits
    • Noah Misch's avatar
      Fix failure to copy setlocale() return value. · f0a264a3
      Noah Misch authored
      POSIX permits setlocale() calls to invalidate any previous setlocale()
      return values, but commit 5f538ad0
      neglected to account for setlocale(LC_CTYPE, NULL) doing so.  The effect
      was to set the LC_CTYPE environment variable to an unintended value.
      pg_perm_setlocale() sets this variable to assist PL/Perl; without it,
      Perl would undo PostgreSQL's locale settings.  The known-affected
      configurations are 32-bit, release builds using Visual Studio 2012 or
      Visual Studio 2013.  Visual Studio 2010 is unaffected, as were all
      buildfarm-attested configurations.  In principle, this bug could leave
      the wrong LC_CTYPE in effect after PL/Perl use, which could in turn
      facilitate problems like corrupt tsvector datums.  No known platform
      experiences that consequence, because PL/Perl on Windows does not use
      this environment variable.
      
      The bug has been user-visible, as early postmaster failure, on systems
      with Windows ANSI code page set to CP936 for "Chinese (Simplified, PRC)"
      and probably on systems using other multibyte code pages.
      (SetEnvironmentVariable() rejects values containing character data not
      valid under the Windows ANSI code page.)  Back-patch to 9.4, where the
      faulty commit first appeared.
      
      Reported by Didi Hu and 林鹏程.  Reviewed by Tom Lane, though this fix
      strategy was not his first choice.
      f0a264a3
    • Noah Misch's avatar
      Revert "Detect setlocale(LC_CTYPE, NULL) clobbering previous return values." · 1f2a378d
      Noah Misch authored
      This reverts commit b76e76be.  The
      buildfarm yielded no related failures.
      1f2a378d
    • Alvaro Herrera's avatar
      Fix BRIN supported operators table · 1443a165
      Alvaro Herrera authored
      Some of the entries in the inclusion opclasses where missing operators,
      and we had an entry for inet_inclusion_ops instead of
      network_inclusion_ops.  Sort the operators within each opclass by
      strategy number, just to make it easier to spot mistakes.
      
      Also sort the rows by data type name, rather than OID.
      1443a165
    • Alvaro Herrera's avatar
      3c400a3f
  10. 19 Jun, 2015 1 commit
    • Tom Lane's avatar
      In immediate shutdown, postmaster should not exit till children are gone. · 48913db8
      Tom Lane authored
      This adjusts commit 82233ce7 so that the
      postmaster does not exit until all its child processes have exited, even
      if the 5-second timeout elapses and we have to send SIGKILL.  There is no
      great value in having the postmaster process quit sooner, and doing so can
      mislead onlookers into thinking that the cluster is fully terminated when
      actually some child processes still survive.
      
      This effect might explain recent test failures on buildfarm member hamster,
      wherein we failed to restart a cluster just after shutting it down with
      "pg_ctl stop -m immediate".
      
      I also did a bit of code review/beautification, including fixing a faulty
      use of the Max() macro on a volatile expression.
      
      Back-patch to 9.4.  In older branches, the postmaster never waited for
      children to exit during immediate shutdowns, and changing that would be
      too much of a behavioral change.
      48913db8