Skip to content
Snippets Groups Projects
  1. Jan 17, 2017
  2. 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
  3. Jan 12, 2017
  4. 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
  5. Jan 05, 2017
  6. Jan 03, 2017
  7. Dec 22, 2016
  8. 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
  9. 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
  10. Dec 12, 2016
  11. 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
  12. 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
  13. 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
  14. Nov 29, 2016
  15. Nov 22, 2016
  16. Nov 14, 2016
  17. Nov 13, 2016
  18. 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
  19. 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
  20. Nov 07, 2016
  21. Nov 05, 2016
    • Tom Lane's avatar
      Provide DLLEXPORT markers for C functions via PG_FUNCTION_INFO_V1 macro. · c8ead2a3
      Tom Lane authored
      Second try at the change originally made in commit 8518583c;
      this time with contrib updates so that manual extern declarations
      are also marked with PGDLLEXPORT.  The release notes should point
      this out as a significant source-code change for extension authors,
      since they'll have to make similar additions to avoid trouble on Windows.
      
      Laurenz Albe, doc change by me
      
      Patch: <A737B7A37273E048B164557ADEF4A58B53962ED8@ntex2010a.host.magwien.gv.at>
      c8ead2a3
  22. Nov 04, 2016
    • Tom Lane's avatar
      Delete contrib/xml2's legacy implementation of xml_is_well_formed(). · 20540710
      Tom Lane authored
      This function is unreferenced in modern usage; it was superseded in 9.1
      by a core function of the same name.  It has been left in place in the C
      code only so that pre-9.1 SQL definitions of the contrib/xml2 functions
      would continue to work.  Six years seems like enough time for people to
      have updated to the extension-style version of the xml2 module, so let's
      drop this.
      
      The key reason for not keeping it any longer is that we want to stick
      an explicit PGDLLEXPORT into PG_FUNCTION_INFO_V1(), and the similarity
      of name to the core function creates a conflict that compilers will
      complain about.
      
      Extracted from a larger patch for that purpose.  I'm committing this
      change separately to give it more visibility in the commit logs.
      
      While at it, remove the documentation entry that claimed that
      xml_is_well_formed() is a function provided by contrib/xml2, and
      instead mention the even more ancient alias xml_valid().
      
      Laurenz Albe, doc change by me
      
      Patch: <A737B7A37273E048B164557ADEF4A58B53962ED8@ntex2010a.host.magwien.gv.at>
      20540710
    • Tom Lane's avatar
      Fix gin_leafpage_items(). · 367b99bb
      Tom Lane authored
      On closer inspection, commit 84ad68d6 broke gin_leafpage_items(),
      because the aligned copy of the page got palloc'd in a short-lived
      context whereas it needs to be in the SRF's multi_call_memory_ctx.
      This was not exposed by the regression test, because the regression
      test doesn't actually exercise the function in a meaningful way.
      Fix the code bug, and extend the test in what I hope is a portable
      fashion.
      367b99bb
    • Peter Eisentraut's avatar
      pageinspect: Fix unaligned struct access in GIN functions · 84ad68d6
      Peter Eisentraut authored
      The raw page data that is passed into the functions will not be aligned
      at 8-byte boundaries.  Casting that to a struct and accessing int64
      fields will result in unaligned access.  On most platforms, you get away
      with it, but it will result on a crash on pickier platforms such as ia64
      and sparc64.
      84ad68d6
    • Robert Haas's avatar
      postgres_fdw: Fix typo in comment. · 7016e4c4
      Robert Haas authored
      Etsuro Fujita
      7016e4c4
  23. Nov 03, 2016
Loading