1. 23 Jan, 2018 4 commits
  2. 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
  3. 21 Jan, 2018 3 commits
    • Magnus Hagander's avatar
      Support huge pages on Windows · 1cc4f536
      Magnus Hagander authored
      Add support for huge pages (called large pages on Windows) to the
      Windows build.
      
      This (probably) breaks compatibility with Windows versions prior to
      Windows 2003 or Windows Vista.
      
      Authors: Takayuki Tsunakawa and Thomas Munro
      Reviewed by: Magnus Hagander, Amit Kapila
      1cc4f536
    • Magnus Hagander's avatar
      Fix wording of "hostaddrs" · 5c15a54e
      Magnus Hagander authored
      The field is still called "hostaddr", so make sure references use
      "hostaddr values" instead.
      
      Author: Michael Paquier <michael.paquier@gmail.com>
      5c15a54e
    • Bruce Momjian's avatar
      doc: update intermediate certificate instructions · 815f84aa
      Bruce Momjian authored
      Document how to properly create root and intermediate certificates using
      v3_ca extensions and where to place intermediate certificates so they
      are properly transferred to the remote side with the leaf certificate to
      link to the remote root certificate.  This corrects docs that used to
      say that intermediate certificates must be stored with the root
      certificate.
      
      Also add instructions on how to create root, intermediate, and leaf
      certificates.
      
      Discussion: https://postgr.es/m/20180116002238.GC12724@momjian.us
      
      Reviewed-by: Michael Paquier
      
      Backpatch-through: 9.3
      815f84aa
  4. 20 Jan, 2018 2 commits
  5. 19 Jan, 2018 12 commits
  6. 18 Jan, 2018 4 commits
  7. 17 Jan, 2018 6 commits
    • Bruce Momjian's avatar
      Reorder C includes · f033462d
      Bruce Momjian authored
      Reorder header files in joinrels.c and pathnode.c in alphabetical order,
      removing unnecessary ones.
      
      Author: Etsuro Fujita
      f033462d
    • Robert Haas's avatar
      postgres_fdw: Avoid 'outer pathkeys do not match mergeclauses' error. · 4bbf6edf
      Robert Haas authored
      When pushing down a join to a foreign server, postgres_fdw constructs
      an alternative plan to be used for any EvalPlanQual rechecks that
      prove to be necessary.  This plan is stored as the outer subplan of
      the Foreign Scan implementing the pushed-down join.  Previously, this
      alternative plan could have a different nominal sort ordering than its
      parent, which seemed OK since there will only be one tuple per base
      table anyway in the case of an EvalPlanQual recheck.  Actually,
      though, it caused a problem if that path was used as a building block
      for the EvalPlanQual recheck plan of a higher-level foreign join,
      because we could end up with a merge join one of whose inputs was not
      labelled with the correct sort order.  Repair by injecting an extra
      Sort node into the EvalPlanQual recheck plan whenever it would
      otherwise fail to be sorted at least as well as its parent Foreign
      Scan.
      
      Report by Jeff Janes.  Patch by me, reviewed by Tom Lane, who also
      provided the test case and comment text.
      
      Discussion: http://postgr.es/m/CAMkU=1y2G8VOVBHv3iXU2TMAj7-RyBFFW1uhkr5sm9LQ2=X35g@mail.gmail.com
      4bbf6edf
    • Tom Lane's avatar
      Remove useless lookup of root partitioned rel in ExecInitModifyTable(). · dca48d14
      Tom Lane authored
      node->partitioned_rels is only set in UPDATE/DELETE cases, but
      ExecInitModifyTable only uses its "rel" variable in INSERT cases,
      so the extra logic to find the root rel is just a waste of complexity
      and cycles.
      
      Etsuro Fujita, reviewed by Amit Langote
      
      Discussion: https://postgr.es/m/93cf9816-2f7d-0f67-8ed2-4a4e497a6ab8@lab.ntt.co.jp
      dca48d14
    • Simon Riggs's avatar
      Ability to advance replication slots · 9c7d06d6
      Simon Riggs authored
      Ability to advance both physical and logical replication slots using a
      new user function pg_replication_slot_advance().
      
      For logical advance that means records are consumed as fast as possible
      and changes are not given to output plugin for sending. Makes 2nd phase
      (after we reached SNAPBUILD_FULL_SNAPSHOT) of replication slot creation
      faster, especially when there are big transactions as the reorder buffer
      does not have to deal with data changes and does not have to spill to
      disk.
      
      Author: Petr Jelinek
      Reviewed-by: Simon Riggs
      9c7d06d6
    • Andrew Dunstan's avatar
      585e166e
    • Andrew Dunstan's avatar
      Centralize json and jsonb handling of datetime types · cc4feded
      Andrew Dunstan authored
      The creates a single function JsonEncodeDateTime which will format these
      data types in an efficient and consistent manner. This will be all the
      more important when we come to jsonpath so we don't have to implement yet
      more code doing the same thing in two more places.
      
      This also extends the code to handle time and timetz types which were
      not previously handled specially. This requires exposing the time2tm and
      timetz2tm functions.
      
      Patch from Nikita Glukhov
      cc4feded
  8. 16 Jan, 2018 1 commit
  9. 13 Jan, 2018 1 commit
  10. 12 Jan, 2018 1 commit