1. 26 Jan, 2018 7 commits
    • Tom Lane's avatar
      Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. · fb8697b3
      Tom Lane authored
      We have a lot of code in which option names, which from the user's
      viewpoint are logically keywords, are passed through the grammar as plain
      identifiers, and then matched to string literals during command execution.
      This approach avoids making words into lexer keywords unnecessarily.  Some
      places matched these strings using plain strcmp, some using pg_strcasecmp.
      But the latter should be unnecessary since identifiers would have been
      downcased on their way through the parser.  Aside from any efficiency
      concerns (probably not a big factor), the lack of consistency in this area
      creates a hazard of subtle bugs due to different places coming to different
      conclusions about whether two option names are the same or different.
      Hence, standardize on using strcmp() to match any option names that are
      expected to have been fed through the parser.
      
      This does create a user-visible behavioral change, which is that while
      formerly all of these would work:
      	alter table foo set (fillfactor = 50);
      	alter table foo set (FillFactor = 50);
      	alter table foo set ("fillfactor" = 50);
      	alter table foo set ("FillFactor" = 50);
      now the last case will fail because that double-quoted identifier is
      different from the others.  However, none of our documentation says that
      you can use a quoted identifier in such contexts at all, and we should
      discourage doing so since it would break if we ever decide to parse such
      constructs as true lexer keywords rather than poor man's substitutes.
      So this shouldn't create a significant compatibility issue for users.
      
      Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
      
      Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
      fb8697b3
    • Robert Haas's avatar
      Factor some code out of create_grouping_paths. · 9fd8b7d6
      Robert Haas authored
      This is preparatory refactoring to prepare the way for partition-wise
      aggregate, which will reuse the new subroutines for child grouping
      rels.  It also does not seem like a bad idea on general principle,
      as the function was getting pretty long.
      
      Jeevan Chalke.  The larger patch series of which this patch is a part
      was reviewed and tested by Antonin Houska, Rajkumar Raghuwanshi,
      Ashutosh Bapat, David Rowley, Dilip Kumar, Konstantin Knizhnik,
      Pascal Legrand, and me.  Some cosmetic changes by me.
      
      Discussion: http://postgr.es/m/CAM2+6=V64_xhstVHie0Rz=KPEQnLJMZt_e314P0jaT_oJ9MR8A@mail.gmail.com
      9fd8b7d6
    • Tom Lane's avatar
      Remove the obsolete WITH clause of CREATE FUNCTION. · 4971d2a3
      Tom Lane authored
      This clause was superseded by SQL-standard syntax back in 7.3.
      We've kept it around for backwards-compatibility purposes ever since;
      but 15 years seems like long enough for that, especially seeing that
      there are undocumented weirdnesses in how it interacts with the
      SQL-standard syntax for specifying the same options.
      
      Michael Paquier, per an observation by Daniel Gustafsson;
      some small cosmetic adjustments to nearby code by me.
      
      Discussion: https://postgr.es/m/20180115022748.GB1724@paquier.xyz
      4971d2a3
    • Robert Haas's avatar
      pageinspect: Fix use of wrong memory context by hash_page_items. · b0313f9c
      Robert Haas authored
      This can cause it to produce incorrect output.
      
      Report and patch by Masahiko Sawada.
      
      Discussion: http://postgr.es/m/CAD21AoBc5Asx7pXdUWu6NqU_g=Ysn95EGL9SMeYhLLduYoO_OA@mail.gmail.com
      b0313f9c
    • Peter Eisentraut's avatar
      Use abstracted SSL API in server connection log messages · c1869542
      Peter Eisentraut authored
      The existing "connection authorized" server log messages used OpenSSL
      API calls directly, even though similar abstracted API calls exist.
      Change to use the latter instead.
      
      Change the function prototype for the functions that return the TLS
      version and the cipher to return const char * directly instead of
      copying into a buffer.  That makes them slightly easier to use.
      
      Add bits= to the message.  psql shows that, so we might as well show the
      same information on the client and server.
      Reviewed-by: default avatarDaniel Gustafsson <daniel@yesql.se>
      Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
      c1869542
    • Peter Eisentraut's avatar
      Remove byte-masking macros for Datum conversion macros · a6ef00b5
      Peter Eisentraut authored
      As the comment there stated, these were needed for old-style
      user-defined functions, but since we removed support for those, we don't
      need this anymore.
      Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
      a6ef00b5
    • Bruce Momjian's avatar
      Fix C comment typo · 6588a43b
      Bruce Momjian authored
      Reported-by: Masahiko Sawada
      
      Discussion: https://postgr.es/m/CAD21AoBgnHy2YKAUuB6iVG4ibvLYepHr+RDRkr1arqWwc1AHCw@mail.gmail.com
      
      Author: Masahiko Sawada
      6588a43b
  2. 25 Jan, 2018 8 commits
    • Tom Lane's avatar
      Support --no-comments in pg_dump, pg_dumpall, pg_restore. · 1368e92e
      Tom Lane authored
      We have switches already to suppress other subsidiary object properties,
      such as ACLs, security labels, ownership, and tablespaces, so just on
      the grounds of symmetry we should allow suppressing comments as well.
      Also, commit 0d4e6ed3 added a positive reason to have this feature,
      i.e. to allow obtaining the old behavior of selective pg_restore should
      anyone desire that.
      
      Recent commits have removed the cases where pg_dump emitted comments on
      built-in objects that the restoring user might not have privileges to
      comment on, so the original primary motivation for this feature is gone,
      but it still seems at least somewhat useful in its own right.
      
      Robins Tharakan, reviewed by Fabrízio Mello
      
      Discussion: https://postgr.es/m/CAEP4nAx22Z4ch74oJGzr5RyyjcyUSbpiFLyeYXX8pehfou92ug@mail.gmail.com
      1368e92e
    • Tom Lane's avatar
      Add missing "static" markers. · bb415675
      Tom Lane authored
      Per buildfarm.
      bb415675
    • Tom Lane's avatar
      Clean up some aspects of pg_dump/pg_restore item-selection logic. · 0d4e6ed3
      Tom Lane authored
      Ensure that CREATE DATABASE and related commands are issued when, and
      only when, --create is specified.  Previously there were scenarios
      where using selective-dump switches would prevent --create from having
      any effect.  For example, it would fail to do anything in pg_restore
      if the archive file had been made by a selective dump, because there
      would be no TOC entry for the database.
      
      Since we don't issue \connect either if we don't issue CREATE DATABASE,
      this could result in unexpectedly restoring objects into the wrong
      database.
      
      Also fix pg_restore's selective restore logic so that when an object is
      selected to be restored, we also restore its ACL, comment, and security
      label if any.  Previously there was no way to get the latter properties
      except through tedious mucking about with a -L file.  If, for some
      reason, you don't want these properties, you can match the old behavior
      by adding --no-acl etc.
      
      While at it, try to make _tocEntryRequired() a little better organized
      and better documented.
      
      Discussion: https://postgr.es/m/32668.1516848577@sss.pgh.pa.us
      0d4e6ed3
    • Alvaro Herrera's avatar
      Ignore partitioned indexes where appropriate · 05fb5d66
      Alvaro Herrera authored
      get_relation_info() was too optimistic about opening indexes in
      partitioned tables, which would raise errors when any queries were
      planned on such tables.  Fix by ignoring any indexes of the partitioned
      kind.
      
      CLUSTER (and ALTER TABLE CLUSTER ON) had a similar problem.  Fix by
      disallowing these commands in partitioned tables.
      
      Fallout from 8b08f7d4.
      05fb5d66
    • Tom Lane's avatar
      Improve pg_dump's handling of "special" built-in objects. · 5955d934
      Tom Lane authored
      We had some pretty ad-hoc handling of the public schema and the plpgsql
      extension, which are both presumed to exist in template0 but might be
      modified or deleted in the database being dumped.
      
      Up to now, by default pg_dump would emit a CREATE EXTENSION IF NOT EXISTS
      command as well as a COMMENT command for plpgsql.  The usefulness of the
      former is questionable, and the latter caused annoying errors in
      non-superuser dump/restore scenarios.  Let's instead install a rule that
      built-in extensions (identified by having low-numbered OIDs) are not to be
      dumped.  We were doing it that way already in binary-upgrade mode, so this
      just makes regular mode behave the same.  It remains true that if someone
      has installed a non-default ACL on the plpgsql language, that will get
      dumped thanks to the pg_init_privs mechanism.  This is more consistent with
      the handling of built-in objects of other kinds.
      
      Also, change the very ad-hoc mechanism that was used to avoid dumping
      creation and comment commands for the public schema.  Instead of hardwiring
      a test in _printTocEntry(), make use of the DUMP_COMPONENT_ infrastructure
      to mark that schema up-front about what we want to do with it.  This has
      the visible effect that the public schema won't be mentioned in the output
      at all, except for updating its ACL if it has a non-default ACL.
      Previously, while it was normally not mentioned, --clean mode would drop
      and recreate it, again causing headaches for non-superuser usage.  This
      change likewise makes the public schema less special and more like other
      built-in objects.
      
      If plpgsql, or the public schema, has been removed entirely in the source
      DB, that situation won't be reproduced in the destination ... but that
      was true before.
      
      Discussion: https://postgr.es/m/29048.1516812451@sss.pgh.pa.us
      5955d934
    • Peter Eisentraut's avatar
      Update documentation to mention huge pages on other OSes · 2a5ecb56
      Peter Eisentraut authored
      Previously, the docs implied that only Linux and Windows could use huge
      pages.  That's not quite true: it's just that we only know how to
      request them explicitly on those OSes.  Be more explicit about what
      huge_pages really does and mention that some OSes may use huge pages
      automatically.
      
      Author: Thomas Munro and Catalin Iacob
      Reviewed-By: Justin Pryzby, Peter Eisentraut
      Discussion: https://postgr.es/m/CAEepm=3qzR-hfjepymohuC4XO5phxoSoipOjm6BEhnJHjNR+jg@mail.gmail.com
      2a5ecb56
    • Peter Eisentraut's avatar
      Remove use of byte-masking macros in record_image_cmp · 0b5e33f6
      Peter Eisentraut authored
      These were introduced in 4cbb6463, but
      after further analysis and testing, they should not be necessary and
      probably weren't the part of that commit that fixed anything.
      Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
      0b5e33f6
    • Peter Eisentraut's avatar
      Allow spaces in connection strings in SSL tests · 4a3fdbdf
      Peter Eisentraut authored
      Connection strings can have items with spaces in them, wrapped in
      quotes.  The tests however ran a SELECT '$connstr' upon connection which
      broke on the embedded quotes.  Use dollar quotes on the connstr to
      protect against this.  This was hit during the development of the macOS
      Secure Transport patch, but is independent of it.
      
      Author: Daniel Gustafsson <daniel@yesql.se>
      4a3fdbdf
  3. 24 Jan, 2018 5 commits
  4. 23 Jan, 2018 14 commits
    • Bruce Momjian's avatar
      doc: mention psql -l uses the 'postgres' database by default · e0a0deca
      Bruce Momjian authored
      Reported-by: Mark Wood
      
      Bug: 14912
      
      Discussion: https://postgr.es/m/20171116171735.1474.30450@wrigleys.postgresql.org
      
      Author: David G. Johnston
      
      Backpatch-through: 10
      e0a0deca
    • Tom Lane's avatar
      Teach reparameterize_path() to handle AppendPaths. · bb94ce4d
      Tom Lane authored
      If we're inside a lateral subquery, there may be no unparameterized paths
      for a particular child relation of an appendrel, in which case we *must*
      be able to create similarly-parameterized paths for each other child
      relation, else the planner will fail with "could not devise a query plan
      for the given query".  This means that there are situations where we'd
      better be able to reparameterize at least one path for each child.
      
      This calls into question the assumption in reparameterize_path() that
      it can just punt if it feels like it.  However, the only case that is
      known broken right now is where the child is itself an appendrel so that
      all its paths are AppendPaths.  (I think possibly I disregarded that in
      the original coding on the theory that nested appendrels would get folded
      together --- but that only happens *after* reparameterize_path(), so it's
      not excused from handling a child AppendPath.)  Given that this code's been
      like this since 9.3 when LATERAL was introduced, it seems likely we'd have
      heard of other cases by now if there were a larger problem.
      
      Per report from Elvis Pranskevichus.  Back-patch to 9.3.
      
      Discussion: https://postgr.es/m/5981018.zdth1YWmNy@hammer.magicstack.net
      bb94ce4d
    • Alvaro Herrera's avatar
      Remove unnecessary include · 95be5ce1
      Alvaro Herrera authored
      autovacuum.c no longer needs dsa.h, since commit 31ae1638.
      Author: Masahiko Sawada
      Discussion: https://postgr.es/m/CAD21AoCWvYyXrvdANSHWWWEWJH5TeAWAkJ_2gqrHhukG+OBo1g@mail.gmail.com
      95be5ce1
    • Tom Lane's avatar
      c9707d94
    • Peter Eisentraut's avatar
      pgbench: Remove accidental garbage in test file · f9bbd46a
      Peter Eisentraut authored
      Author: Fabien COELHO <coelho@cri.ensmp.fr>
      f9bbd46a
    • Robert Haas's avatar
      Update obsolete sentence in README.parallel. · 28e04155
      Robert Haas authored
      Since 9.6, heavyweight locking is not an abstract and unhandled
      concern of the parallel machinery, but rather something to which
      we have a specific approach.
      28e04155
    • Robert Haas's avatar
      Report an ERROR if a parallel worker fails to start properly. · 2badb5af
      Robert Haas authored
      Commit 28724fd9 fixed things so that
      if a background worker fails to start due to fork() failure or because
      it is terminated before startup succeeds, BGWH_STOPPED will be
      reported.  However, that only helps if the code that uses the
      background worker machinery notices the change in status, and the code
      in parallel.c did not.
      
      To fix that, do two things.  First, make sure that when a worker
      exits, it triggers the leader to read from error queues.  That way, if
      a worker which has attached to an error queue exits uncleanly, the
      leader is sure to throw some error, either the contents of the
      ErrorResponse sent by the worker, or "lost connection to parallel
      worker" if it exited without sending one.  To cover the case where
      the worker never starts up in the first place or exits before
      attaching to the error queue, the ParallelContext now keeps track
      of which workers have sent at least one message via the error
      queue.  A worker which sends no messages by the time the parallel
      operation finishes will be checked to see whether it exited before
      attaching to the error queue; if so, a new error message, "parallel
      worker failed to initialize", will be reported.  If not, we'll
      continue to wait until it either starts up and exits cleanly, starts
      up and exits uncleanly, or fails to start, and then take the
      appropriate action.
      
      Patch by me, reviewed by Amit Kapila.
      
      Discussion: http://postgr.es/m/CA+TgmoYnBgXgdTu6wk5YPdWhmgabYc9nY_pFLq=tB=FSLYkD8Q@mail.gmail.com
      2badb5af
    • Tom Lane's avatar
      In pg_dump, force reconnection after issuing ALTER DATABASE SET command(s). · 160a4f62
      Tom Lane authored
      The folly of not doing this was exposed by the buildfarm: in some cases,
      the GUC settings applied through ALTER DATABASE SET may be essential to
      interpreting the reloaded data correctly.  Another argument why we can't
      really get away with the scheme proposed in commit b3f84012 is that it
      cannot work for parallel restore: even if the parent process manages to
      hang onto the previous GUC state, worker processes would see the state
      post-ALTER-DATABASE.  (Perhaps we could have dodged that bullet by
      delaying DATABASE PROPERTIES restoration to the end of the run, but
      that does nothing for the data semantics problem.)
      
      This leaves us with no solution for the default_transaction_read_only issue
      that commit 4bd371f6 intended to work around, other than "you gotta remove
      such settings before dumping/upgrading".  However, in view of the fact that
      parallel restore broke that hack years ago and no one has noticed, it's
      fair to question how many people care.  I'm unexcited about adding a large
      dollop of new complexity to handle that corner case.
      
      This would be a one-liner fix, except it turns out that ReconnectToServer
      tries to optimize away "redundant" reconnections.  While that may have been
      valuable when coded, a quick survey of current callers shows that there are
      no cases where that's actually useful, so just remove that check.  While at
      it, remove the function's useless return value.
      
      Discussion: https://postgr.es/m/12453.1516655001@sss.pgh.pa.us
      160a4f62
    • Bruce Momjian's avatar
      doc: simplify intermediate certificate mention in libpq docs · a541dbb6
      Bruce Momjian authored
      Backpatch-through: 9.3
      a541dbb6
    • Peter Eisentraut's avatar
      Extract common bits from OpenSSL implementation · 1c218340
      Peter Eisentraut authored
      Some things in be-secure-openssl.c and fe-secure-openssl.c were not
      actually specific to OpenSSL but could also be used by other
      implementations.  In order to avoid copy-and-pasting, move some of that
      code to common files.
      1c218340
    • Peter Eisentraut's avatar
      Move SSL API comments to header files · f966101d
      Peter Eisentraut authored
      Move the documentation of the SSL API calls are supposed to do into the
      headers files, instead of keeping them in the files for the OpenSSL
      implementation.  That way, they don't have to be duplicated or be
      inconsistent when other implementations are added.
      f966101d
    • Peter Eisentraut's avatar
      Move EDH support to common files · 573bd08b
      Peter Eisentraut authored
      The EDH support is not really specific to the OpenSSL implementation, so
      move the support and documentation comments to common files.
      573bd08b
    • Peter Eisentraut's avatar
      Split out documentation of SSL parameters into their own section · 7404e77c
      Peter Eisentraut authored
      Split the "Authentication and Security" section into two separate
      sections "Authentication" and "SSL".  The latter part has gotten much
      longer over time, and doesn't primarily have to do with authentication.
      
      Also, the row_security parameter was inconsistently categorized, so
      clean that up while we're here.
      7404e77c
    • Peter Eisentraut's avatar
      Add installcheck support to more test suites · f5da5683
      Peter Eisentraut authored
      Several of the test suites under src/test/ were missing an installcheck
      target.
      f5da5683
  5. 22 Jan, 2018 6 commits
    • Tom Lane's avatar
      Move handling of database properties from pg_dumpall into pg_dump. · b3f84012
      Tom Lane authored
      This patch rearranges the division of labor between pg_dump and pg_dumpall
      so that pg_dump itself handles all properties attached to a single
      database.  Notably, a database's ACL (GRANT/REVOKE status) and local GUC
      settings established by ALTER DATABASE SET and ALTER ROLE IN DATABASE SET
      can be dumped and restored by pg_dump.  This is a long-requested
      improvement.
      
      "pg_dumpall -g" will now produce only role- and tablespace-related output,
      nothing about individual databases.  The total output of a regular
      pg_dumpall run remains the same.
      
      pg_dump (or pg_restore) will restore database-level properties only when
      creating the target database with --create.  This applies not only to
      ACLs and GUCs but to the other database properties it already handled,
      that is database comments and security labels.  This is more consistent
      and useful, but does represent an incompatibility in the behavior seen
      without --create.
      
      (This change makes the proposed patch to have pg_dump use "COMMENT ON
      DATABASE CURRENT_DATABASE" unnecessary, since there is no case where
      the command is issued that we won't know the true name of the database.
      We might still want that patch as a feature in its own right, but pg_dump
      no longer needs it.)
      
      pg_dumpall with --clean will now drop and recreate the "postgres" and
      "template1" databases in the target cluster, allowing their locale and
      encoding settings to be changed if necessary, and providing a cleaner
      way to set nondefault tablespaces for them than we had before.  This
      means that such a script must now always be started in the "postgres"
      database; the order of drops and reconnects will not work otherwise.
      Without --clean, the script will not adjust any database-level properties
      of those two databases (including their comments, ACLs, and security
      labels, which it formerly would try to set).
      
      Another minor incompatibility is that the CREATE DATABASE commands in a
      pg_dumpall script will now always specify locale and encoding settings.
      Formerly those would be omitted if they matched the cluster's default.
      While that behavior had some usefulness in some migration scenarios,
      it also posed a significant hazard of unwanted locale/encoding changes.
      To migrate to another locale/encoding, it's now necessary to use pg_dump
      without --create to restore into a database with the desired settings.
      
      Commit 4bd371f6's hack to emit "SET default_transaction_read_only = off"
      is gone: we now dodge that problem by the expedient of not issuing ALTER
      DATABASE SET commands until after reconnecting to the target database.
      Therefore, such settings won't apply during the restore session.
      
      In passing, improve some shaky grammar in the docs, and add a note pointing
      out that pg_dumpall's output can't be expected to load without any errors.
      (Someday we might want to fix that, but this is not that patch.)
      
      Haribabu Kommi, reviewed at various times by Andreas Karlsson,
      Vaishnavi Prabakaran, and Robert Haas; further hacking by me.
      
      Discussion: https://postgr.es/m/CAJrrPGcUurV0eWTeXODwsOYFN=Ekq36t1s0YnFYUNzsmRfdAyA@mail.gmail.com
      b3f84012
    • Tom Lane's avatar
      Reorder code in pg_dump to dump comments etc in a uniform order. · d6c84667
      Tom Lane authored
      Most of the code in pg_dump dumps an object's comment, security label,
      and ACL auxiliary TOC entries, in that order, immediately after the
      object's main TOC entry, and at least dumpComment's API spec says this
      isn't optional.  dumpDatabase was significantly violating that when
      in binary-upgrade mode, by inserting totally unrelated stuff between.
      Also, dumpForeignDataWrapper and dumpForeignServer were being randomly
      inconsistent.  Reorder code so everybody does it the same.
      
      This may be future-proofing us against some code growing a requirement for
      such auxiliary entries to be adjacent to their main entry.  But for now
      it's just neatnik-ism, so I see no need for back-patch.
      
      Discussion: https://postgr.es/m/21714.1516553459@sss.pgh.pa.us
      d6c84667
    • Peter Eisentraut's avatar
      PL/Python: Fix tests for older Python versions · f4987043
      Peter Eisentraut authored
      Commit 8561e484 neglected to handle
      older Python versions that don't support the "with" statement.  So write
      the tests in a way that older versions can handle as well.
      f4987043
    • Tom Lane's avatar
      Make pg_dump's ACL, sec label, and comment entries reliably identifiable. · 2b792ab0
      Tom Lane authored
      _tocEntryRequired() expects that it can identify ACL, SECURITY LABEL,
      and COMMENT TOC entries that are for large objects by seeing whether
      the tag for them starts with "LARGE OBJECT ".  While that works fine
      for actual large objects, which are indeed tagged that way, it's
      subject to false positives unless every such entry's tag starts with an
      appropriate type ID.  And in fact it does not work for ACLs, because
      up to now we customarily tagged those entries with just the bare name
      of the object.  This means that an ACL for an object named
      "LARGE OBJECT something" would be misclassified as data not schema,
      with undesirable results in a schema-only or data-only dump ---
      although pg_upgrade seems unaffected, due to the special case for
      binary-upgrade mode further down in _tocEntryRequired().
      
      We can fix this by changing all the dumpACL calls to use the label
      strings already in use for comments and security labels, which do
      follow the convention of starting with an object type indicator.
      
      Well, mostly they follow it.  dumpDatabase() got it wrong, using
      just the bare database name for those purposes, so that a database
      named "LARGE OBJECT something" would similarly be subject to having
      its comment or security label dropped or included when not wanted.
      Bring that into line too.  (Note that up to now, database ACLs have
      not been processed by pg_dump, so that this issue doesn't affect them.)
      
      _tocEntryRequired() itself is not free of fault: it was overly liberal
      about matching object tags to "LARGE OBJECT " in binary-upgrade mode.
      This looks like it is probably harmless because there would be no data
      component to strip anyway in that mode, but at best it's trouble
      waiting to happen, so tighten that up too.
      
      The possible misclassification of SECURITY LABEL entries for databases is
      in principle a security problem, but the opportunities for actual exploits
      seem too narrow to be interesting.  The other cases seem like just bugs,
      since an object owner can change its ACL or comment for himself, he needn't
      try to trick someone else into doing it by choosing a strange name.
      
      This has been broken since per-large-object TOC entries were introduced
      in 9.0, so back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/21714.1516553459@sss.pgh.pa.us
      2b792ab0
    • Peter Eisentraut's avatar
      Transaction control in PL procedures · 8561e484
      Peter Eisentraut authored
      In each of the supplied procedural languages (PL/pgSQL, PL/Perl,
      PL/Python, PL/Tcl), add language-specific commit and rollback
      functions/commands to control transactions in procedures in that
      language.  Add similar underlying functions to SPI.  Some additional
      cleanup so that transaction commit or abort doesn't blow away data
      structures still used by the procedure call.  Add execution context
      tracking to CALL and DO statements so that transaction control commands
      can only be issued in top-level procedure and block calls, not function
      calls or other procedure or block calls.
      
      - SPI
      
      Add a new function SPI_connect_ext() that is like SPI_connect() but
      allows passing option flags.  The only option flag right now is
      SPI_OPT_NONATOMIC.  A nonatomic SPI connection can execute transaction
      control commands, otherwise it's not allowed.  This is meant to be
      passed down from CALL and DO statements which themselves know in which
      context they are called.  A nonatomic SPI connection uses different
      memory management.  A normal SPI connection allocates its memory in
      TopTransactionContext.  For nonatomic connections we use PortalContext
      instead.  As the comment in SPI_connect_ext() (previously SPI_connect())
      indicates, one could potentially use PortalContext in all cases, but it
      seems safest to leave the existing uses alone, because this stuff is
      complicated enough already.
      
      SPI also gets new functions SPI_start_transaction(), SPI_commit(), and
      SPI_rollback(), which can be used by PLs to implement their transaction
      control logic.
      
      - portalmem.c
      
      Some adjustments were made in the code that cleans up portals at
      transaction abort.  The portal code could already handle a command
      *committing* a transaction and continuing (e.g., VACUUM), but it was not
      quite prepared for a command *aborting* a transaction and continuing.
      
      In AtAbort_Portals(), remove the code that marks an active portal as
      failed.  As the comment there already predicted, this doesn't work if
      the running command wants to keep running after transaction abort.  And
      it's actually not necessary, because pquery.c is careful to run all
      portal code in a PG_TRY block and explicitly runs MarkPortalFailed() if
      there is an exception.  So the code in AtAbort_Portals() is never used
      anyway.
      
      In AtAbort_Portals() and AtCleanup_Portals(), we need to be careful not
      to clean up active portals too much.  This mirrors similar code in
      PreCommit_Portals().
      
      - PL/Perl
      
      Gets new functions spi_commit() and spi_rollback()
      
      - PL/pgSQL
      
      Gets new commands COMMIT and ROLLBACK.
      
      Update the PL/SQL porting example in the documentation to reflect that
      transactions are now possible in procedures.
      
      - PL/Python
      
      Gets new functions plpy.commit and plpy.rollback.
      
      - PL/Tcl
      
      Gets new commands commit and rollback.
      Reviewed-by: default avatarAndrew Dunstan <andrew.dunstan@2ndquadrant.com>
      8561e484
    • Magnus Hagander's avatar
      Fix docs typo · b9ff79b8
      Magnus Hagander authored
      Spotted by Thomas Munro
      b9ff79b8