Skip to content
Snippets Groups Projects
  1. Feb 01, 2017
    • Heikki Linnakangas's avatar
      Replace isMD5() with a more future-proof way to check if pw is encrypted. · dbd69118
      Heikki Linnakangas authored
      The rule is that if pg_authid.rolpassword begins with "md5" and has the
      right length, it's an MD5 hash, otherwise it's a plaintext password. The
      idiom has been to use isMD5() to check for that, but that gets awkward,
      when we add new kinds of verifiers, like the verifiers for SCRAM
      authentication in the pending SCRAM patch set. Replace isMD5() with a new
      get_password_type() function, so that when new verifier types are added, we
      don't need to remember to modify every place that currently calls isMD5(),
      to also recognize the new kinds of verifiers.
      
      Also, use the new plain_crypt_verify function in passwordcheck, so that it
      doesn't need to know about MD5, or in the future, about other kinds of
      hashes or password verifiers.
      
      Reviewed by Michael Paquier and Peter Eisentraut.
      
      Discussion: https://www.postgresql.org/message-id/2d07165c-1793-e243-a2a9-e45b624c7580@iki.fi
      dbd69118
  2. Jan 27, 2017
  3. Jan 25, 2017
  4. Jan 24, 2017
  5. Jan 21, 2017
  6. Jan 19, 2017
  7. Jan 18, 2017
  8. Jan 17, 2017
  9. Jan 14, 2017
    • Tom Lane's avatar
      Teach contrib/pg_stat_statements to handle multi-statement commands better. · 83f2061d
      Tom Lane authored
      Make use of the statement boundary info added by commit ab1f0c82
      to let pg_stat_statements behave more sanely when multiple SQL queries
      are jammed into one query string.  It now records just the relevant
      part of the source string, not the whole thing, for each individual
      query.
      
      Even when no multi-statement strings are involved, users may notice small
      changes in the output: leading and trailing whitespace and semicolons will
      be stripped from statements, which did not happen before.
      
      Also, significantly expand pg_stat_statements' regression test script.
      
      Fabien Coelho, reviewed by Craig Ringer and Kyotaro Horiguchi,
      some mods by me
      
      Discussion: https://postgr.es/m/alpine.DEB.2.20.1612200926310.29821@lancre
      83f2061d
    • Tom Lane's avatar
      Change representation of statement lists, and add statement location info. · ab1f0c82
      Tom Lane authored
      This patch makes several changes that improve the consistency of
      representation of lists of statements.  It's always been the case
      that the output of parse analysis is a list of Query nodes, whatever
      the types of the individual statements in the list.  This patch brings
      similar consistency to the outputs of raw parsing and planning steps:
      
      * The output of raw parsing is now always a list of RawStmt nodes;
      the statement-type-dependent nodes are one level down from that.
      
      * The output of pg_plan_queries() is now always a list of PlannedStmt
      nodes, even for utility statements.  In the case of a utility statement,
      "planning" just consists of wrapping a CMD_UTILITY PlannedStmt around
      the utility node.  This list representation is now used in Portal and
      CachedPlan plan lists, replacing the former convention of intermixing
      PlannedStmts with bare utility-statement nodes.
      
      Now, every list of statements has a consistent head-node type depending
      on how far along it is in processing.  This allows changing many places
      that formerly used generic "Node *" pointers to use a more specific
      pointer type, thus reducing the number of IsA() tests and casts needed,
      as well as improving code clarity.
      
      Also, the post-parse-analysis representation of DECLARE CURSOR is changed
      so that it looks more like EXPLAIN, PREPARE, etc.  That is, the contained
      SELECT remains a child of the DeclareCursorStmt rather than getting flipped
      around to be the other way.  It's now true for both Query and PlannedStmt
      that utilityStmt is non-null if and only if commandType is CMD_UTILITY.
      That allows simplifying a lot of places that were testing both fields.
      (I think some of those were just defensive programming, but in many places,
      it was actually necessary to avoid confusing DECLARE CURSOR with SELECT.)
      
      Because PlannedStmt carries a canSetTag field, we're also able to get rid
      of some ad-hoc rules about how to reconstruct canSetTag for a bare utility
      statement; specifically, the assumption that a utility is canSetTag if and
      only if it's the only one in its list.  While I see no near-term need for
      relaxing that restriction, it's nice to get rid of the ad-hocery.
      
      The API of ProcessUtility() is changed so that what it's passed is the
      wrapper PlannedStmt not just the bare utility statement.  This will affect
      all users of ProcessUtility_hook, but the changes are pretty trivial; see
      the affected contrib modules for examples of the minimum change needed.
      (Most compilers should give pointer-type-mismatch warnings for uncorrected
      code.)
      
      There's also a change in the API of ExplainOneQuery_hook, to pass through
      cursorOptions instead of expecting hook functions to know what to pick.
      This is needed because of the DECLARE CURSOR changes, but really should
      have been done in 9.6; it's unlikely that any extant hook functions
      know about using CURSOR_OPT_PARALLEL_OK.
      
      Finally, teach gram.y to save statement boundary locations in RawStmt
      nodes, and pass those through to Query and PlannedStmt nodes.  This allows
      more intelligent handling of cases where a source query string contains
      multiple statements.  This patch doesn't actually do anything with the
      information, but a follow-on patch will.  (Passing this information through
      cleanly is the true motivation for these changes; while I think this is all
      good cleanup, it's unlikely we'd have bothered without this end goal.)
      
      catversion bump because addition of location fields to struct Query
      affects stored rules.
      
      This patch is by me, but it owes a good deal to Fabien Coelho who did
      a lot of preliminary work on the problem, and also reviewed the patch.
      
      Discussion: https://postgr.es/m/alpine.DEB.2.20.1612200926310.29821@lancre
      ab1f0c82
    • Peter Eisentraut's avatar
      pg_ctl: Change default to wait for all actions · 05cd12ed
      Peter Eisentraut authored
      
      The different actions in pg_ctl had different defaults for -w and -W,
      mostly for historical reasons.  Most users will want the -w behavior, so
      make that the default.
      
      Remove the -w option in most example and test code, so avoid confusion
      and reduce verbosity.  pg_upgrade is not touched, so it can continue to
      work with older installations.
      
      Reviewed-by: default avatarBeena Emerson <memissemerson@gmail.com>
      Reviewed-by: default avatarRyan Murphy <ryanfmurphy@gmail.com>
      05cd12ed
    • Peter Eisentraut's avatar
      Updates to reflect that pg_ctl stop -m fast is the default · e574f15d
      Peter Eisentraut authored
      Various example and test code used -m fast explicitly, but since it's
      the default, this can be omitted now or should be replaced by a better
      example.
      
      pg_upgrade is not touched, so it can continue to operate with older
      installations.
      e574f15d
  10. Jan 12, 2017
  11. Jan 06, 2017
    • Tom Lane's avatar
      Invalidate cached plans on FDW option changes. · c52d37c8
      Tom Lane authored
      This fixes problems where a plan must change but fails to do so,
      as seen in a bug report from Rajkumar Raghuwanshi.
      
      For ALTER FOREIGN TABLE OPTIONS, do this through the standard method of
      forcing a relcache flush on the table.  For ALTER FOREIGN DATA WRAPPER
      and ALTER SERVER, just flush the whole plan cache on any change in
      pg_foreign_data_wrapper or pg_foreign_server.  That matches the way
      we handle some other low-probability cases such as opclass changes, and
      it's unclear that the case arises often enough to be worth working harder.
      Besides, that gives a patch that is simple enough to back-patch with
      confidence.
      
      Back-patch to 9.3.  In principle we could apply the code change to 9.2 as
      well, but (a) we lack postgres_fdw to test it with, (b) it's doubtful that
      anyone is doing anything exciting enough with FDWs that far back to need
      this desperately, and (c) the patch doesn't apply cleanly.
      
      Patch originally by Amit Langote, reviewed by Etsuro Fujita and Ashutosh
      Bapat, who each contributed substantial changes as well.
      
      Discussion: https://postgr.es/m/CAKcux6m5cA6rRPTKkqVdJ-R=KKDfe35Q_ZuUqxDSV_4hwga=og@mail.gmail.com
      c52d37c8
  12. Jan 05, 2017
  13. Jan 03, 2017
  14. Dec 22, 2016
  15. Dec 18, 2016
    • Tom Lane's avatar
      In contrib/uuid-ossp, #include headers needed for ntohl() and ntohs(). · 4a0a34b5
      Tom Lane authored
      Oversight in commit b8cc8f94.  I just noticed this causes compiler
      warnings on FreeBSD, and it really ought to cause warnings elsewhere too:
      all references I can find say that <arpa/inet.h> is required for these.
      We have a lot of code elsewhere that thinks that both <netinet/in.h>
      and <arpa/inet.h> should be included for these functions, so do it that
      way here too, even though <arpa/inet.h> ought to be sufficient according
      to the references I consulted.
      
      Back-patch to 9.4 where the previous commit landed.
      4a0a34b5
  16. Dec 15, 2016
    • Peter Eisentraut's avatar
      Various temporary slots test improvements · fdf71389
      Peter Eisentraut authored
      Fix the tests on slow machines (per buildfarm).
      
      Add test for dropping on error.  And also try to consume real changes
      from temporary slots.
      
      From: Petr Jelinek <petr.jelinek@2ndquadrant.com>
      fdf71389
  17. Dec 12, 2016
  18. Dec 08, 2016
    • Robert Haas's avatar
      Log the creation of an init fork unconditionally. · fa0f466d
      Robert Haas authored
      Previously, it was thought that this only needed to be done for the
      benefit of possible standbys, so wal_level = minimal skipped it.
      But that's not safe, because during crash recovery we might replay
      XLOG_DBASE_CREATE or XLOG_TBLSPC_CREATE record which recursively
      removes the directory that contains the new init fork.  So log it
      always.
      
      The user-visible effect of this bug is that if you create a database
      or tablespace, then create an unlogged table, then crash without
      checkpointing, then restart, accessing the table will fail, because
      the it won't have been properly reset.  This commit fixes that.
      
      Michael Paquier, per a report from Konstantin Knizhnik.  Wording of
      the comments per a suggestion from me.
      fa0f466d
  19. Dec 05, 2016
    • Heikki Linnakangas's avatar
      Replace PostmasterRandom() with a stronger source, second attempt. · fe0a0b59
      Heikki Linnakangas authored
      This adds a new routine, pg_strong_random() for generating random bytes,
      for use in both frontend and backend. At the moment, it's only used in
      the backend, but the upcoming SCRAM authentication patches need strong
      random numbers in libpq as well.
      
      pg_strong_random() is based on, and replaces, the existing implementation
      in pgcrypto. It can acquire strong random numbers from a number of sources,
      depending on what's available:
      
      - OpenSSL RAND_bytes(), if built with OpenSSL
      - On Windows, the native cryptographic functions are used
      - /dev/urandom
      
      Unlike the current pgcrypto function, the source is chosen by configure.
      That makes it easier to test different implementations, and ensures that
      we don't accidentally fall back to a less secure implementation, if the
      primary source fails. All of those methods are quite reliable, it would be
      pretty surprising for them to fail, so we'd rather find out by failing
      hard.
      
      If no strong random source is available, we fall back to using erand48(),
      seeded from current timestamp, like PostmasterRandom() was. That isn't
      cryptographically secure, but allows us to still work on platforms that
      don't have any of the above stronger sources. Because it's not very secure,
      the built-in implementation is only used if explicitly requested with
      --disable-strong-random.
      
      This replaces the more complicated Fortuna algorithm we used to have in
      pgcrypto, which is unfortunate, but all modern platforms have /dev/urandom,
      so it doesn't seem worth the maintenance effort to keep that. pgcrypto
      functions that require strong random numbers will be disabled with
      --disable-strong-random.
      
      Original patch by Magnus Hagander, tons of further work by Michael Paquier
      and me.
      
      Discussion: https://www.postgresql.org/message-id/CAB7nPqRy3krN8quR9XujMVVHYtXJ0_60nqgVc6oUk8ygyVkZsA@mail.gmail.com
      Discussion: https://www.postgresql.org/message-id/CAB7nPqRWkNYRRPJA7-cF+LfroYV10pvjdz6GNvxk-Eee9FypKA@mail.gmail.com
      fe0a0b59
  20. Nov 30, 2016
    • Heikki Linnakangas's avatar
      Remove dead stuff from pgcrypto. · b2cc748b
      Heikki Linnakangas authored
      pgp-pubkey-DISABLED test has been unused since 2006, when support for
      built-in bignum math was added (commit 1abf76e8). pgp-encrypt-DISABLED has
      been unused forever, AFAICS.
      
      Also remove a couple of unused error codes.
      b2cc748b
  21. Nov 29, 2016
  22. Nov 22, 2016
  23. Nov 14, 2016
  24. Nov 13, 2016
  25. Nov 12, 2016
    • Andres Freund's avatar
      Add minimal set of regression tests for pg_stat_statements. · 9be244db
      Andres Freund authored
      While the set of covered functionality is fairly small, the added tests
      still are useful to get some basic buildfarm testing of
      pg_stat_statements itself, but also to exercise the lwlock tranch code
      on the buildfarm.
      
      Author: Amit Kapila, slightly editorialized by me
      Reviewed-By: Ashutosh Sharma, Andres Freund
      Discussion: <CAA4eK1JOjkdXYtHxh=2aDK4VgDtN-LNGKY_YqX0N=YEvuzQVWg@mail.gmail.com>
      9be244db
  26. Nov 08, 2016
    • Tom Lane's avatar
      Replace uses of SPI_modifytuple that intend to allocate in current context. · 9257f078
      Tom Lane authored
      Invent a new function heap_modify_tuple_by_cols() that is functionally
      equivalent to SPI_modifytuple except that it always allocates its result
      by simple palloc.  I chose however to make the API details a bit more
      like heap_modify_tuple: pass a tupdesc rather than a Relation, and use
      bool convention for the isnull array.
      
      Use this function in place of SPI_modifytuple at all call sites where the
      intended behavior is to allocate in current context.  (There actually are
      only two call sites left that depend on the old behavior, which makes me
      wonder if we should just drop this function rather than keep it.)
      
      This new function is easier to use than heap_modify_tuple() for purposes
      of replacing a single column (or, really, any fixed number of columns).
      There are a number of places where it would simplify the code to change
      over, but I resisted that temptation for the moment ... everywhere except
      in plpgsql's exec_assign_value(); changing that might offer some small
      performance benefit, so I did it.
      
      This is on the way to removing SPI_push/SPI_pop, but it seems like
      good code cleanup in its own right.
      
      Discussion: <9633.1478552022@sss.pgh.pa.us>
      9257f078
    • Tom Lane's avatar
      Make SPI_fnumber() reject dropped columns. · 6d30fb1f
      Tom Lane authored
      There's basically no scenario where it's sensible for this to match
      dropped columns, so put a test for dropped-ness into SPI_fnumber()
      itself, and excise the test from the small number of callers that
      were paying attention to the case.  (Most weren't :-(.)
      
      In passing, normalize tests at call sites: always reject attnum <= 0
      if we're disallowing system columns.  Previously there was a mixture
      of "< 0" and "<= 0" tests.  This makes no practical difference since
      SPI_fnumber() never returns 0, but I'm feeling pedantic today.
      
      Also, in the places that are actually live user-facing code and not
      legacy cruft, distinguish "column not found" from "can't handle
      system column".
      
      Per discussion with Jim Nasby; thi supersedes his original patch
      that just changed the behavior at one call site.
      
      Discussion: <b2de8258-c4c0-1cb8-7b97-e8538e5c975c@BlueTreble.com>
      6d30fb1f
Loading