1. 05 Dec, 2013 3 commits
    • Alvaro Herrera's avatar
      Fix improper abort during update chain locking · 312bde3d
      Alvaro Herrera authored
      In 247c76a9, I added some code to do fine-grained checking of
      MultiXact status of locking/updating transactions when traversing an
      update chain.  There was a thinko in that patch which would have the
      traversing abort, that is return HeapTupleUpdated, when the other
      transaction is a committed lock-only.  In this case we should ignore it
      and return success instead.  Of course, in the case where there is a
      committed update, HeapTupleUpdated is the correct return value.
      
      A user-visible symptom of this bug is that in REPEATABLE READ and
      SERIALIZABLE transaction isolation modes spurious serializability errors
      can occur:
        ERROR:  could not serialize access due to concurrent update
      
      In order for this to happen, there needs to be a tuple that's key-share-
      locked and also updated, and the update must abort; a subsequent
      transaction trying to acquire a new lock on that tuple would abort with
      the above error.  The reason is that the initial FOR KEY SHARE is seen
      as committed by the new locking transaction, which triggers this bug.
      (If the UPDATE commits, then the serialization error is correctly
      reported.)
      
      When running a query in READ COMMITTED mode, what happens is that the
      locking is aborted by the HeapTupleUpdated return value, then
      EvalPlanQual fetches the newest version of the tuple, which is then the
      only version that gets locked.  (The second time the tuple is checked
      there is no misbehavior on the committed lock-only, because it's not
      checked by the code that traverses update chains; so no bug.) Only the
      newest version of the tuple is locked, not older ones, but this is
      harmless.
      
      The isolation test added by this commit illustrates the desired
      behavior, including the proper serialization errors that get thrown.
      
      Backpatch to 9.3.
      312bde3d
    • Tom Lane's avatar
      Clear retry flags properly in replacement OpenSSL sock_write function. · 74242c23
      Tom Lane authored
      Current OpenSSL code includes a BIO_clear_retry_flags() step in the
      sock_write() function.  Either we failed to copy the code correctly, or
      they added this since we copied it.  In any case, lack of the clear step
      appears to be the cause of the server lockup after connection loss reported
      in bug #8647 from Valentine Gogichashvili.  Assume that this is correct
      coding for all OpenSSL versions, and hence back-patch to all supported
      branches.
      
      Diagnosis and patch by Alexander Kukushkin.
      74242c23
    • Alvaro Herrera's avatar
      Avoid resetting Xmax when it's a multi with an aborted update · 07aeb1fe
      Alvaro Herrera authored
      HeapTupleSatisfiesUpdate can very easily "forget" tuple locks while
      checking the contents of a multixact and finding it contains an aborted
      update, by setting the HEAP_XMAX_INVALID bit.  This would lead to
      concurrent transactions not noticing any previous locks held by
      transactions that might still be running, and thus being able to acquire
      subsequent locks they wouldn't be normally able to acquire.
      
      This bug was introduced in commit 1ce150b7; backpatch this fix to 9.3,
      like that commit.
      
      This change reverts the change to the delete-abort-savept isolation test
      in 1ce150b7, because that behavior change was caused by this bug.
      
      Noticed by Andres Freund while investigating a different issue reported
      by Noah Misch.
      07aeb1fe
  2. 04 Dec, 2013 3 commits
  3. 03 Dec, 2013 8 commits
  4. 02 Dec, 2013 8 commits
  5. 01 Dec, 2013 3 commits
  6. 30 Nov, 2013 10 commits
    • Tom Lane's avatar
      Editorial corrections to the October 2013 minor-release notes. · 47960354
      Tom Lane authored
      This is mostly to fix incorrect migration instructions: since the preceding
      minor releases advised reindexing some GIST indexes, it's important that
      we back-link to that advice rather than earlier instances.
      
      Also improve some bug descriptions and fix a few typos.
      
      No back-patch yet; these files will get copied into the back branches
      later in the release process.
      47960354
    • Bruce Momjian's avatar
      pg_upgrade: Handle default_transaction_read_only settings · e7d56aee
      Bruce Momjian authored
      Setting default_transaction_read_only=true could prevent pg_upgrade from
      completing, so prepend default_transaction_read_only=false to
      PGOPTIONS.
      e7d56aee
    • Kevin Grittner's avatar
      Fix pg_dumpall to work for databases flagged as read-only. · 4bd371f6
      Kevin Grittner authored
      pg_dumpall's charter is to be able to recreate a database cluster's
      contents in a virgin installation, but it was failing to honor that
      contract if the cluster had any ALTER DATABASE SET
      default_transaction_read_only settings.  By including a SET command
      for the connection for each connection opened by pg_dumpall output,
      errors are avoided and the source cluster is successfully
      recreated.
      
      There was discussion of whether to also set this for the connection
      applying pg_dump output, but it was felt that it was both less
      appropriate in that context, and far easier to work around.
      
      Backpatch to all supported branches.
      4bd371f6
    • Peter Eisentraut's avatar
      Remove use of obsolescent Autoconf macros · 34fa72ec
      Peter Eisentraut authored
      Remove the use of the following macros, which are obsolescent according
      to the Autoconf documentation:
      
      - AC_C_CONST
      - AC_C_STRINGIZE
      - AC_C_VOLATILE
      - AC_FUNC_MEMCMP
      34fa72ec
    • Peter Eisentraut's avatar
      doc: Simplify handling of variablelists in XSLT build · 1eafea5d
      Peter Eisentraut authored
      The previously used custom template is no longer necessary because
      parameters provided by the standard style sheet can achieve the same
      outcome.
      1eafea5d
    • Alvaro Herrera's avatar
      Fix a couple of bugs in MultiXactId freezing · 2393c7d1
      Alvaro Herrera authored
      Both heap_freeze_tuple() and heap_tuple_needs_freeze() neglected to look
      into a multixact to check the members against cutoff_xid.  This means
      that a very old Xid could survive hidden within a multi, possibly
      outliving its CLOG storage.  In the distant future, this would cause
      clog lookup failures:
      ERROR:  could not access status of transaction 3883960912
      DETAIL:  Could not open file "pg_clog/0E78": No such file or directory.
      
      This mostly was problematic when the updating transaction aborted, since
      in that case the row wouldn't get pruned away earlier in vacuum and the
      multixact could possibly survive for a long time.  In many cases, data
      that is inaccessible for this reason way can be brought back
      heuristically.
      
      As a second bug, heap_freeze_tuple() didn't properly handle multixacts
      that need to be frozen according to cutoff_multi, but whose updater xid
      is still alive.  Instead of preserving the update Xid, it just set Xmax
      invalid, which leads to both old and new tuple versions becoming
      visible.  This is pretty rare in practice, but a real threat
      nonetheless.  Existing corrupted rows, unfortunately, cannot be repaired
      in an automated fashion.
      
      Existing physical replicas might have already incorrectly frozen tuples
      because of different behavior than in master, which might only become
      apparent in the future once pg_multixact/ is truncated; it is
      recommended that all clones be rebuilt after upgrading.
      
      Following code analysis caused by bug report by J Smith in message
      CADFUPgc5bmtv-yg9znxV-vcfkb+JPRqs7m2OesQXaM_4Z1JpdQ@mail.gmail.com
      and privately by F-Secure.
      
      Backpatch to 9.3, where freezing of MultiXactIds was introduced.
      
      Analysis and patch by Andres Freund, with some tweaks by Álvaro.
      2393c7d1
    • Alvaro Herrera's avatar
      Don't TransactionIdDidAbort in HeapTupleGetUpdateXid · 1ce150b7
      Alvaro Herrera authored
      It is dangerous to do so, because some code expects to be able to see what's
      the true Xmax even if it is aborted (particularly while traversing HOT
      chains).  So don't do it, and instead rely on the callers to verify for
      abortedness, if necessary.
      
      Several race conditions and bugs fixed in the process.  One isolation test
      changes the expected output due to these.
      
      This also reverts commit c235a6a5, which is no longer necessary.
      
      Backpatch to 9.3, where this function was introduced.
      
      Andres Freund
      1ce150b7
    • Alvaro Herrera's avatar
      Truncate pg_multixact/'s contents during crash recovery · 1df0122d
      Alvaro Herrera authored
      Commit 9dc842f0 of 8.2 era prevented MultiXact truncation during crash
      recovery, because there was no guarantee that enough state had been
      setup, and because it wasn't deemed to be a good idea to remove data
      during crash recovery anyway.  Since then, due to Hot-Standby, streaming
      replication and PITR, the amount of time a cluster can spend doing crash
      recovery has increased significantly, to the point that a cluster may
      even never come out of it.  This has made not truncating the content of
      pg_multixact/ not defensible anymore.
      
      To fix, take care to setup enough state for multixact truncation before
      crash recovery starts (easy since checkpoints contain the required
      information), and move the current end-of-recovery actions to a new
      TrimMultiXact() function, analogous to TrimCLOG().
      
      At some later point, this should probably done similarly to the way
      clog.c is doing it, which is to just WAL log truncations, but we can't
      do that for the back branches.
      
      Back-patch to 9.0.  8.4 also has the problem, but since there's no hot
      standby there, it's much less pressing.  In 9.2 and earlier, this patch
      is simpler than in newer branches, because multixact access during
      recovery isn't required.  Add appropriate checks to make sure that's not
      happening.
      
      Andres Freund
      1df0122d
    • Alvaro Herrera's avatar
      Fix full-table-vacuum request mechanism for MultiXactIds · f54106f7
      Alvaro Herrera authored
      While autovacuum dutifully launched anti-multixact-wraparound vacuums
      when the multixact "age" was reached, the vacuum code was not aware that
      it needed to make them be full table vacuums.  As the resulting
      partial-table vacuums aren't capable of actually increasing relminmxid,
      autovacuum continued to launch anti-wraparound vacuums that didn't have
      the intended effect, until age of relfrozenxid caused the vacuum to
      finally be a full table one via vacuum_freeze_table_age.
      
      To fix, introduce logic for multixacts similar to that for plain
      TransactionIds, using the same GUCs.
      
      Backpatch to 9.3, where permanent MultiXactIds were introduced.
      
      Andres Freund, some cleanup by Álvaro
      f54106f7
    • Alvaro Herrera's avatar
      Replace hardcoded 200000000 with autovacuum_freeze_max_age · 76a31c68
      Alvaro Herrera authored
      Parts of the code used autovacuum_freeze_max_age to determine whether
      anti-multixact-wraparound vacuums are necessary, while others used a
      hardcoded 200000000 value.  This leads to problems when
      autovacuum_freeze_max_age is set to a non-default value.  Use the latter
      everywhere.
      
      Backpatch to 9.3, where vacuuming of multixacts was introduced.
      
      Andres Freund
      76a31c68
  7. 29 Nov, 2013 5 commits
    • Tom Lane's avatar
      Fix assorted issues in pg_ctl's pgwin32_CommandLine(). · 79193c75
      Tom Lane authored
      Ensure that the invocation command for postgres or pg_ctl runservice
      double-quotes the executable's pathname; failure to do this leads to
      trouble when the path contains spaces.
      
      Also, ensure that the path ends in ".exe" in both cases and uses
      backslashes rather than slashes as directory separators.  The latter issue
      is reported to confuse some third-party tools such as Symantec Backup Exec.
      
      Also, rewrite the function to avoid buffer overrun issues by using a
      PQExpBuffer instead of a fixed-size static buffer.  Combinations of
      very long executable pathnames and very long data directory pathnames
      could have caused trouble before, for example.
      
      Back-patch to all active branches, since this code has been like this
      for a long while.
      
      Naoya Anzai and Tom Lane, reviewed by Rajeev Rastogi
      79193c75
    • Tom Lane's avatar
      Be sure to release proc->backendLock after SetupLockInTable() failure. · 8b151558
      Tom Lane authored
      The various places that transferred fast-path locks to the main lock table
      neglected to release the PGPROC's backendLock if SetupLockInTable failed
      due to being out of shared memory.  In most cases this is no big deal since
      ensuing error cleanup would release all held LWLocks anyway.  But there are
      some hot-standby functions that don't consider failure of
      FastPathTransferRelationLocks to be a hard error, and in those cases this
      oversight could lead to system lockup.  For consistency, make all of these
      places look the same as FastPathTransferRelationLocks.
      
      Noted while looking for the cause of Dan Wood's bugs --- this wasn't it,
      but it's a bug anyway.
      8b151558
    • Tom Lane's avatar
      Fix assorted race conditions in the new timeout infrastructure. · 16e1b7a1
      Tom Lane authored
      Prevent handle_sig_alarm from losing control partway through due to a query
      cancel (either an asynchronous SIGINT, or a cancel triggered by one of the
      timeout handler functions).  That would at least result in failure to
      schedule any required future interrupt, and might result in actual
      corruption of timeout.c's data structures, if the interrupt happened while
      we were updating those.
      
      We could still lose control if an asynchronous SIGINT arrives just as the
      function is entered.  This wouldn't break any data structures, but it would
      have the same effect as if the SIGALRM interrupt had been silently lost:
      we'd not fire any currently-due handlers, nor schedule any new interrupt.
      To forestall that scenario, forcibly reschedule any pending timer interrupt
      during AbortTransaction and AbortSubTransaction.  We can avoid any extra
      kernel call in most cases by not doing that until we've allowed
      LockErrorCleanup to kill the DEADLOCK_TIMEOUT and LOCK_TIMEOUT events.
      
      Another hazard is that some platforms (at least Linux and *BSD) block a
      signal before calling its handler and then unblock it on return.  When we
      longjmp out of the handler, the unblock doesn't happen, and the signal is
      left blocked indefinitely.  Again, we can fix that by forcibly unblocking
      signals during AbortTransaction and AbortSubTransaction.
      
      These latter two problems do not manifest when the longjmp reaches
      postgres.c, because the error recovery code there kills all pending timeout
      events anyway, and it uses sigsetjmp(..., 1) so that the appropriate signal
      mask is restored.  So errors thrown outside any transaction should be OK
      already, and cleaning up in AbortTransaction and AbortSubTransaction should
      be enough to fix these issues.  (We're assuming that any code that catches
      a query cancel error and doesn't re-throw it will do at least a
      subtransaction abort to clean up; but that was pretty much required already
      by other subsystems.)
      
      Lastly, ProcSleep should not clear the LOCK_TIMEOUT indicator flag when
      disabling that event: if a lock timeout interrupt happened after the lock
      was granted, the ensuing query cancel is still going to happen at the next
      CHECK_FOR_INTERRUPTS, and we want to report it as a lock timeout not a user
      cancel.
      
      Per reports from Dan Wood.
      
      Back-patch to 9.3 where the new timeout handling infrastructure was
      introduced.  We may at some point decide to back-patch the signal
      unblocking changes further, but I'll desist from that until we hear
      actual field complaints about it.
      16e1b7a1
    • Peter Eisentraut's avatar
    • Peter Eisentraut's avatar