Skip to content
Snippets Groups Projects
  1. Jan 07, 2014
    • Magnus Hagander's avatar
      Move permissions check from do_pg_start_backup to pg_start_backup · 61d4d14e
      Magnus Hagander authored
      And the same for do_pg_stop_backup. The code in do_pg_* is not allowed
      to access the catalogs. For manual base backups, the permissions
      check can be handled in the calling function, and for streaming
      base backups only users with the required permissions can get past
      the authentication step in the first place.
      
      Reported by Antonin Houska, diagnosed by Andres Freund
      61d4d14e
    • Magnus Hagander's avatar
      Avoid including tablespaces inside PGDATA twice in base backups · 2edf3e82
      Magnus Hagander authored
      If a tablespace was crated inside PGDATA it was backed up both as part
      of the PGDATA backup and as the backup of the tablespace. Avoid this
      by skipping any directory inside PGDATA that contains one of the active
      tablespaces.
      
      Dimitri Fontaine and Magnus Hagander
      2edf3e82
  2. Jan 04, 2014
    • Tom Lane's avatar
      Fix translatability markings in psql, and add defenses against future bugs. · fa28f9cb
      Tom Lane authored
      Several previous commits have added columns to various \d queries without
      updating their translate_columns[] arrays, leading to potentially incorrect
      translations in NLS-enabled builds.  Offenders include commit 89368676
      (added prosecdef to \df+), c9ac00e6 (added description to \dc+) and
      3b17efdf (added description to \dC+).  Fix those cases back to 9.3 or
      9.2 as appropriate.
      
      Since this is evidently more easily missed than one would like, in HEAD
      also add an Assert that the supplied array is long enough.  This requires
      an API change for printQuery(), so it seems inappropriate for back
      branches, but presumably all future changes will be tested in HEAD anyway.
      
      In HEAD and 9.3, also clean up a whole lot of sloppiness in the emitted
      SQL for \dy (event triggers): lack of translatability due to failing to
      pass words-to-be-translated through gettext_noop(), inadequate schema
      qualification, and sloppy formatting resulting in unnecessarily ugly
      -E output.
      
      Peter Eisentraut and Tom Lane, per bug #8702 from Sergey Burladyan
      fa28f9cb
  3. Jan 01, 2014
  4. Dec 29, 2013
    • Kevin Grittner's avatar
      Don't attempt to limit target database for pg_restore. · df090b39
      Kevin Grittner authored
      There was an apparent attempt to limit the target database for
      pg_restore to version 7.1.0 or later.  Due to a leading zero this
      was interpreted as an octal number, which allowed targets with
      version numbers down to 2.87.36.  The lowest actual release above
      that was 6.0.0, so that was effectively the limit.
      
      Since the success of the restore attempt will depend primarily on
      on what statements were generated by the dump run, we don't want
      pg_restore trying to guess whether a given target should be allowed
      based on version number.  Allow a connection to any version.  Since
      it is very unlikely that anyone would be using a recent version of
      pg_restore to restore to a pre-6.0 database, this has little to no
      practical impact, but it makes the code less confusing to read.
      
      Issue reported and initial patch suggestion from Joel Jacobson
      based on an article by Andrey Karpov reporting on issues found by
      PVS-Studio static code analyzer.  Final patch based on analysis by
      Tom Lane.  Back-patch to all supported branches.
      df090b39
  5. Dec 27, 2013
    • Andrew Dunstan's avatar
      Properly detect invalid JSON numbers when generating JSON. · 4825a9e9
      Andrew Dunstan authored
      Instead of looking for characters that aren't valid in JSON numbers, we
      simply pass the output string through the JSON number parser, and if it
      fails the string is quoted. This means among other things that money and
      domains over money will be quoted correctly and generate valid JSON.
      
      Fixes bug #8676 reported by Anderson Cristian da Silva.
      
      Backpatched to 9.2 where JSON generation was introduced.
      4825a9e9
    • Kevin Grittner's avatar
      Fix misplaced right paren bugs in pgstatfuncs.c. · 150a30e1
      Kevin Grittner authored
      The bug would only show up if the C sockaddr structure contained
      zero in the first byte for a valid address; otherwise it would
      fail to fail, which is probably why it went unnoticed for so long.
      
      Patch submitted by Joel Jacobson after seeing an article by Andrey
      Karpov in which he reports finding this through static code
      analysis using PVS-Studio.  While I was at it I moved a definition
      of a local variable referenced in the buggy code to a more local
      context.
      
      Backpatch to all supported branches.
      150a30e1
  6. Dec 15, 2013
    • Tatsuo Ishii's avatar
      Add "SHIFT_JIS" as an accepted encoding name for locale checking. · 0c07ef1a
      Tatsuo Ishii authored
      When locale is "ja_JP.SJIS", nl_langinfo(CODESET) returns "SHIFT_JIS"
      on some platforms, at least on RedHat Linux. So the encoding/locale
      match table (encoding_match_list) needs the entry. Otherwise client
      encoding is set to SQL_ASCII.
      
      Back patch to all supported branches.
      0c07ef1a
  7. Dec 14, 2013
    • Tom Lane's avatar
      Fix inherited UPDATE/DELETE with UNION ALL subqueries. · 5d545b7e
      Tom Lane authored
      Fix an oversight in commit b3aaf908: we do
      indeed need to process the planner's append_rel_list when copying RTE
      subqueries, because if any of them were flattenable UNION ALL subqueries,
      the append_rel_list shows which subquery RTEs were pulled up out of which
      other ones.  Without this, UNION ALL subqueries aren't correctly inserted
      into the update plans for inheritance child tables after the first one,
      typically resulting in no update happening for those child table(s).
      Per report from Victor Yegorov.
      
      Experimentation with this case also exposed a fault in commit
      a7b96538: if an inherited UPDATE/DELETE
      was proven totally dummy by constraint exclusion, we might arrive at
      add_rtes_to_flat_rtable with root->simple_rel_array being NULL.  This
      should be interpreted as not having any RelOptInfos.  I chose to code
      the guard as a check against simple_rel_array_size, so as to also
      provide some protection against indexing off the end of the array.
      
      Back-patch to 9.2 where the faulty code was added.
      5d545b7e
  8. Dec 13, 2013
    • Tom Lane's avatar
      Add HOLD/RESUME_INTERRUPTS in HandleCatchupInterrupt/HandleNotifyInterrupt. · d20eec82
      Tom Lane authored
      This prevents a possible longjmp out of the signal handler if a timeout
      or SIGINT occurs while something within the handler has transiently set
      ImmediateInterruptOK.  For safety we must hold off the timeout or cancel
      error until we're back in mainline, or at least till we reach the end of
      the signal handler when ImmediateInterruptOK was true at entry.  This
      syncs these functions with the logic now present in handle_sig_alarm.
      
      AFAICT there is no live bug here in 9.0 and up, because I don't think we
      currently can wait for any heavyweight lock inside these functions, and
      there is no other code (except read-from-client) that will turn on
      ImmediateInterruptOK.  However, that was not true pre-9.0: in older
      branches ProcessIncomingNotify might block trying to lock pg_listener, and
      then a SIGINT could lead to undesirable control flow.  It might be all
      right anyway given the relatively narrow code ranges in which NOTIFY
      interrupts are enabled, but for safety's sake I'm back-patching this.
      d20eec82
  9. Dec 12, 2013
  10. Dec 11, 2013
    • Tom Lane's avatar
      Tweak placement of explicit ANALYZE commands in the regression tests. · 9c9a1f2e
      Tom Lane authored
      Make the COPY test, which loads most of the large static tables used in
      the tests, also explicitly ANALYZE those tables.  This allows us to get
      rid of various ad-hoc, and rather redundant, ANALYZE commands that had
      gotten stuck into various test scripts over time to ensure we got
      consistent plan choices.  (We could have done a database-wide ANALYZE,
      but that would cause stats to get attached to the small static tables
      too, which results in plan changes compared to the historical behavior.
      I'm not sure that's a good idea, so not going that far for now.)
      
      Back-patch to 9.0, since 9.0 and 9.1 are currently sometimes failing
      regression tests for lack of an "ANALYZE tenk1" in the subselect test.
      There's no need for this in 8.4 since we didn't print any plans back
      then.
      9c9a1f2e
  11. Dec 10, 2013
    • Tom Lane's avatar
      Fix possible crash with nested SubLinks. · f5d9fdcc
      Tom Lane authored
      An expression such as WHERE (... x IN (SELECT ...) ...) IN (SELECT ...)
      could produce an invalid plan that results in a crash at execution time,
      if the planner attempts to flatten the outer IN into a semi-join.
      This happens because convert_testexpr() was not expecting any nested
      SubLinks and would wrongly replace any PARAM_SUBLINK Params belonging
      to the inner SubLink.  (I think the comment denying that this case could
      happen was wrong when written; it's certainly been wrong for quite a long
      time, since very early versions of the semijoin flattening logic.)
      
      Per report from Teodor Sigaev.  Back-patch to all supported branches.
      f5d9fdcc
  12. Dec 08, 2013
    • Joe Conway's avatar
      Fix performance regression in dblink connection speed. · 7f4ef622
      Joe Conway authored
      Previous commit e5de6012 modified dblink
      to ensure client encoding matched the server. However the added
      PQsetClientEncoding() call added significant overhead. Restore original
      performance in the common case where client encoding already matches
      server encoding by doing nothing in that case. Applies to all active
      branches.
      
      Issue reported and work sponsored by Zonar Systems.
      7f4ef622
  13. Dec 05, 2013
    • Tom Lane's avatar
      Clear retry flags properly in replacement OpenSSL sock_write function. · 41042970
      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.
      41042970
  14. Dec 03, 2013
    • Heikki Linnakangas's avatar
      Fix full-page writes of internal GIN pages. · 06df57ac
      Heikki Linnakangas authored
      Insertion to a non-leaf GIN page didn't make a full-page image of the page,
      which is wrong. The code used to do it correctly, but was changed (commit
      853d1c31) because the redo-routine didn't
      track incomplete splits correctly when the page was restored from a full
      page image. Of course, that was not right way to fix it, the redo routine
      should've been fixed instead. The redo-routine was surreptitiously fixed
      in 2010 (commit 4016bdef), so all we need
      to do now is revert the code that creates the record to its original form.
      
      This doesn't change the format of the WAL record.
      
      Backpatch to all supported versions.
      06df57ac
    • Tom Lane's avatar
      Fix crash in assign_collations_walker for EXISTS with empty SELECT list. · 6698782f
      Tom Lane authored
      We (I think I, actually) forgot about this corner case while coding
      collation resolution.  Per bug #8648 from Arjen Nienhuis.
      6698782f
  15. Dec 02, 2013
  16. Dec 01, 2013
  17. Nov 30, 2013
    • Kevin Grittner's avatar
      Fix pg_dumpall to work for databases flagged as read-only. · 27b33245
      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.
      27b33245
    • Alvaro Herrera's avatar
      Truncate pg_multixact/'s contents during crash recovery · 8f8c6661
      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
      8f8c6661
    • Tom Lane's avatar
      Fix assorted issues in pg_ctl's pgwin32_CommandLine(). · 19af7d4f
      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
      19af7d4f
  18. Nov 29, 2013
    • Tom Lane's avatar
      Be sure to release proc->backendLock after SetupLockInTable() failure. · f0e3e05d
      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.
      f0e3e05d
  19. Nov 28, 2013
    • Tom Lane's avatar
      Fix latent(?) race condition in LockReleaseAll. · 9457508f
      Tom Lane authored
      We have for a long time checked the head pointer of each of the backend's
      proclock lists and skipped acquiring the corresponding locktable partition
      lock if the head pointer was NULL.  This was safe enough in the days when
      proclock lists were changed only by the owning backend, but it is pretty
      questionable now that the fast-path patch added cases where backends add
      entries to other backends' proclock lists.  However, we don't really wish
      to revert to locking each partition lock every time, because in simple
      transactions that would add a lot of useless lock/unlock cycles on
      already-heavily-contended LWLocks.  Fortunately, the only way that another
      backend could be modifying our proclock list at this point would be if it
      was promoting a formerly fast-path lock of ours; and any such lock must be
      one that we'd decided not to delete in the previous loop over the locallock
      table.  So it's okay if we miss seeing it in this loop; we'd just decide
      not to delete it again.  However, once we've detected a non-empty list,
      we'd better re-fetch the list head pointer after acquiring the partition
      lock.  This guards against possibly fetching a corrupt-but-non-null pointer
      if pointer fetch/store isn't atomic.  It's not clear if any practical
      architectures are like that, but we've never assumed that before and don't
      wish to start here.  In any case, the situation certainly deserves a code
      comment.
      
      While at it, refactor the partition traversal loop to use a for() construct
      instead of a while() loop with goto's.
      
      Back-patch, just in case the risk is real and not hypothetical.
      9457508f
    • Peter Eisentraut's avatar
      doc: Put data types in alphabetical order · 62e69cb6
      Peter Eisentraut authored
      From: Andreas Karlsson <andreas@proxel.se>
      62e69cb6
    • Tom Lane's avatar
      Fix stale-pointer problem in fast-path locking logic. · 024edb45
      Tom Lane authored
      When acquiring a lock in fast-path mode, we must reset the locallock
      object's lock and proclock fields to NULL.  They are not necessarily that
      way to start with, because the locallock could be left over from a failed
      lock acquisition attempt earlier in the transaction.  Failure to do this
      led to all sorts of interesting misbehaviors when LockRelease tried to
      clean up no-longer-related lock and proclock objects in shared memory.
      Per report from Dan Wood.
      
      In passing, modify LockRelease to elog not just Assert if it doesn't find
      lock and proclock objects for a formerly fast-path lock, matching the code
      in FastPathGetRelationLockEntry and LockRefindAndRelease.  This isn't a
      bug but it will help in diagnosing any future bugs in this area.
      
      Also, modify FastPathTransferRelationLocks and FastPathGetRelationLockEntry
      to break out of their loops over the fastpath array once they've found the
      sole matching entry.  This was inconsistently done in some search loops
      and not others.
      
      Improve assorted related comments, too.
      
      Back-patch to 9.2 where the fast-path mechanism was introduced.
      024edb45
  20. Nov 27, 2013
    • Heikki Linnakangas's avatar
      Don't update relfrozenxid if any pages were skipped. · 0b132b90
      Heikki Linnakangas authored
      Vacuum recognizes that it can update relfrozenxid by checking whether it has
      processed all pages of a relation. Unfortunately it performed that check
      after truncating the dead pages at the end of the relation, and used the new
      number of pages to decide whether all pages have been scanned. If the new
      number of pages happened to be smaller or equal to the number of pages
      scanned, it incorrectly decided that all pages were scanned.
      
      This can lead to relfrozenxid being updated, even though some pages were
      skipped that still contain old XIDs. That can lead to data loss due to xid
      wraparounds with some rows suddenly missing. This likely has escaped notice
      so far because it takes a large number (~2^31) of xids being used to see the
      effect, while a full-table vacuum before that would fix the issue.
      
      The incorrect logic was introduced by commit
      b4b6923e. Backpatch this fix down to 8.4,
      like that commit.
      
      Andres Freund, with some modifications by me.
      0b132b90
    • Michael Meskes's avatar
      ECPG: Fix searching for quoted cursor names case-sensitively. · 0cedfa76
      Michael Meskes authored
      Patch by Böszörményi Zoltán <zb@cybertec.at>
      0cedfa76
    • Michael Meskes's avatar
      Documentation fix for ecpg. · 6bb2972c
      Michael Meskes authored
      The latest fixes removed a limitation that was still in the docs, so Zoltan updated the docs, too.
      6bb2972c
    • Fujii Masao's avatar
      Fix typo in release note. · 744fa4d8
      Fujii Masao authored
      Backpatch to 9.1.
      
      Josh Kupershmidt
      744fa4d8
  21. Nov 26, 2013
    • Michael Meskes's avatar
      ECPG: Make the preprocessor emit ';' if the variable type for a list of · b05c415c
      Michael Meskes authored
      variables is varchar. This fixes this test case:
      
      int main(void)
      {
          exec sql begin declare section;
          varchar a[50], b[50];
          exec sql end declare section;
      
          return 0;
      }
      
      Since varchars are internally turned into custom structs and
      the type name is emitted for these variable declarations,
      the preprocessed code previously had:
      
      struct varchar_1  { ... }  a _,_  struct varchar_2  { ... }  b ;
      
      The comma in the generated C file was a syntax error.
      
      There are no regression test changes since it's not exercised.
      
      Patch by Boszormenyi Zoltan <zb@cybertec.at>
      b05c415c
    • Michael Meskes's avatar
      ECPG: Fix offset to NULL/size indicator array. · 0aec900b
      Michael Meskes authored
      Patch by Boszormenyi Zoltan <zb@cybertec.at>
      0aec900b
  22. Nov 24, 2013
    • Tom Lane's avatar
      Defend against bad trigger definitions in contrib/lo's lo_manage() trigger. · b6da09fc
      Tom Lane authored
      This function formerly crashed if called as a statement-level trigger,
      or if a column-name argument wasn't given.
      
      In passing, add the trigger name to all error messages from the function.
      (None of them are expected cases, so this shouldn't pose any compatibility
      risk.)
      
      Marc Cousin, reviewed by Sawada Masahiko
      b6da09fc
    • Tom Lane's avatar
      Fix array slicing of int2vector and oidvector values. · 96ac8b51
      Tom Lane authored
      The previous coding labeled expressions such as pg_index.indkey[1:3] as
      being of int2vector type; which is not right because the subscript bounds
      of such a result don't, in general, satisfy the restrictions of int2vector.
      To fix, implicitly promote the result of slicing int2vector to int2[],
      or oidvector to oid[].  This is similar to what we've done with domains
      over arrays, which is a good analogy because these types are very much
      like restricted domains of the corresponding regular-array types.
      
      A side-effect is that we now also forbid array-element updates on such
      columns, eg while "update pg_index set indkey[4] = 42" would have worked
      before if you were superuser (and corrupted your catalogs irretrievably,
      no doubt) it's now disallowed.  This seems like a good thing since, again,
      some choices of subscripting would've led to results not satisfying the
      restrictions of int2vector.  The case of an array-slice update was
      rejected before, though with a different error message than you get now.
      We could make these cases work in future if we added a cast from int2[]
      to int2vector (with a cast function checking the subscript restrictions)
      but it seems unlikely that there's any value in that.
      
      Per report from Ronan Dunklau.  Back-patch to all supported branches
      because of the crash risks involved.
      96ac8b51
    • Tom Lane's avatar
      Ensure _dosmaperr() actually sets errno correctly. · e86f2a05
      Tom Lane authored
      If logging is enabled, either ereport() or fprintf() might stomp on errno
      internally, causing this function to return the wrong result.  That might
      only end in a misleading error report, but in any code that's examining
      errno to decide what to do next, the consequences could be far graver.
      
      This has been broken since the very first version of this file in 2006
      ... it's a bit astonishing that we didn't identify this long ago.
      
      Reported by Amit Kapila, though this isn't his proposed fix.
      e86f2a05
  23. Nov 23, 2013
    • Peter Eisentraut's avatar
      Avoid potential buffer overflow crash · 654e006b
      Peter Eisentraut authored
      A pointer to a C string was treated as a pointer to a "name" datum and
      passed to SPI_execute_plan().  This pointer would then end up being
      passed through datumCopy(), which would try to copy the entire 64 bytes
      of name data, thus running past the end of the C string.  Fix by
      converting the string to a proper name structure.
      
      Found by LLVM AddressSanitizer.
      654e006b
Loading