1. 03 Mar, 2021 4 commits
    • Thomas Munro's avatar
      Add sort_template.h for making sort functions. · 0a1f1d3c
      Thomas Munro authored
      Move our qsort implementation into a header that can be used to define
      specialized functions for better performance and reduced duplication.
      Reviewed-by: default avatarDaniel Gustafsson <daniel@yesql.se>
      Discussion: https://postgr.es/m/CA%2BhUKGJ2-eaDqAum5bxhpMNhvuJmRDZxB_Tow0n-gse%2BHG0Yig%40mail.gmail.com
      0a1f1d3c
    • Amit Kapila's avatar
      Add option to enable two_phase commits via pg_create_logical_replication_slot. · 19890a06
      Amit Kapila authored
      Commit 0aa8a01d extends the output plugin API to allow decoding of
      prepared xacts and allowed the user to enable/disable the two-phase option
      via pg_logical_slot_get_changes(). This can lead to a problem such that
      the first time when it gets changes via pg_logical_slot_get_changes()
      without two_phase option enabled it will not get the prepared even though
      prepare is after consistent snapshot. Now next time during getting changes,
      if the two_phase option is enabled it can skip prepare because by that
      time start decoding point has been moved. So the user will only get commit
      prepared.
      
      Allow to enable/disable this option at the create slot time and default
      will be false. It will break the existing slots which is fine in a major
      release.
      
      Author: Ajin Cherian
      Reviewed-by: Amit Kapila and Vignesh C
      Discussion: https://postgr.es/m/d0f60d60-133d-bf8d-bd70-47784d8fabf3@enterprisedb.com
      19890a06
    • Tom Lane's avatar
      Extend the abilities of libpq's target_session_attrs parameter. · ee28cacf
      Tom Lane authored
      In addition to the existing options of "any" and "read-write", we
      now support "read-only", "primary", "standby", and "prefer-standby".
      "read-write" retains its previous meaning of "transactions are
      read-write by default", and "read-only" inverts that.  The other
      three modes test specifically for hot-standby status, which is not
      quite the same thing.  (Setting default_transaction_read_only on
      a primary server renders it read-only to this logic, but not a
      standby.)
      
      Furthermore, if talking to a v14 or later server, no extra network
      round trip is needed to detect the session's status; the GUC_REPORT
      variables delivered by the server are enough.  When talking to an
      older server, a SHOW or SELECT query is issued to detect session
      read-only-ness or server hot-standby state, as needed.
      
      Haribabu Kommi, Greg Nancarrow, Vignesh C, Tom Lane; reviewed at
      various times by Laurenz Albe, Takayuki Tsunakawa, Peter Smith.
      
      Discussion: https://postgr.es/m/CAF3+xM+8-ztOkaV9gHiJ3wfgENTq97QcjXQt+rbFQ6F7oNzt9A@mail.gmail.com
      ee28cacf
    • Michael Paquier's avatar
      Add --tablespace option to reindexdb · 57e6db70
      Michael Paquier authored
      This option provides REINDEX (TABLESPACE) for reindexdb, applying the
      tablespace value given by the caller to all the REINDEX queries
      generated.
      
      While on it, this commit adds some tests for REINDEX TABLESPACE, with
      and without CONCURRENTLY, when run on toast indexes and tables.  Such
      operations are not allowed, and toast relation names are not stable
      enough to be part of the main regression test suite (even if using a PL
      function with a TRY/CATCH logic, as CONCURRENTLY could not be tested).
      
      Author: Michael Paquier
      Reviewed-by: Mark Dilger, Daniel Gustafsson
      Discussion: https://postgr.es/m/YDiaDMnzLICqeukl@paquier.xyz
      57e6db70
  2. 02 Mar, 2021 11 commits
    • Peter Geoghegan's avatar
      nbtree page deletion: Add leaftopparent assertion. · 5b2f2af3
      Peter Geoghegan authored
      Add documenting assertion.  This makes it easier to follow how we
      maintain the top parent link in target subtree's half-dead/leaf level
      page.
      5b2f2af3
    • Peter Geoghegan's avatar
      Fix nbtree page deletion error messages. · 3d8d5787
      Peter Geoghegan authored
      Adjust some "can't happen" error messages that assumed that the page
      deletion target page must be a half-dead page.  This assumption was
      wrong in the case of an internal target page.  Simply refer to these
      pages as the target page instead.
      
      Internal pages are never marked half-dead.  There is exactly one
      half-dead page for each subtree undergoing deletion.  The half-dead page
      is also the target subtree's leaf-level page.  This has been the case
      since commit efada2b8, which totally overhauled nbtree page deletion.
      3d8d5787
    • Tom Lane's avatar
      Mark default_transaction_read_only as GUC_REPORT. · d16f8c8e
      Tom Lane authored
      This allows clients to find out the setting at connection time without
      having to expend a query round trip to do so; which is helpful when
      trying to identify read/write servers.  (One must also look at
      in_hot_standby, but that's already GUC_REPORT, cf bf8a662c.)
      Modifying libpq to make use of this will come soon, but I felt it
      cleaner to push the server change separately.
      
      Haribabu Kommi, Greg Nancarrow, Vignesh C; reviewed at various times
      by Laurenz Albe, Takayuki Tsunakawa, Peter Smith.
      
      Discussion: https://postgr.es/m/CAF3+xM+8-ztOkaV9gHiJ3wfgENTq97QcjXQt+rbFQ6F7oNzt9A@mail.gmail.com
      d16f8c8e
    • Alvaro Herrera's avatar
      Use native path separators to pg_ctl in initdb · 75dbfe4c
      Alvaro Herrera authored
      On Windows, CMD.EXE allegedly does not run a command that uses forward slashes,
      so let's convert the path to use backslashes instead.
      
      Backpatch to 10.
      
      Author: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
      Reviewed-by: default avatarJuan José Santamaría Flecha <juanjo.santamaria@gmail.com>
      Discussion: https://postgr.es/m/CAMm1aWaNDuaPYFYMAqDeJrZmPtNvLcJRS++CcZWY8LT6KcoBZw@mail.gmail.com
      75dbfe4c
    • Tom Lane's avatar
      Suppress unnecessary regex subre nodes in a couple more cases. · 4604f83f
      Tom Lane authored
      This extends the changes made in commit cebc1d34, teaching
      parseqatom() to generate fewer or cheaper subre nodes in some edge
      cases.  The case of interest here is a quantified atom that is "messy"
      only because it has greediness opposite to what preceded it (whereas
      captures and backrefs are intrinsically messy).  In this case we don't
      need an iteration node, since we don't care where the sub-matches of
      the quantifier are; and we might also not need a second concatenation
      node.  This seems of only marginal real-world use according to my
      testing, but I wanted to get it in before wrapping up this series of
      regex performance fixes.
      
      Discussion: https://postgr.es/m/1340281.1613018383@sss.pgh.pa.us
      4604f83f
    • Tom Lane's avatar
      Improve performance of regular expression back-references. · 0c3405cf
      Tom Lane authored
      In some cases, at the time that we're doing an NFA-based precheck
      of whether a backref subexpression can match at a particular place
      in the string, we already know which substring the referenced
      subexpression matched.  If so, we might as well forget about the NFA
      and just compare the substring; this is faster and it gives an exact
      rather than approximate answer.
      
      In general, this optimization can help while we are prechecking within
      the second child expression of a concat node, while the capture was
      within the first child expression; then the substring was saved during
      cdissect() of the first child and will be available to NFA checks done
      while cdissect() recurses into the second child.  It can help quite a
      lot if the tree looks like
      
                    concat
                   /      \
            capture        concat
                          /      \
           expensive stuff        backref
      
      as we will be able to avoid recursively dissecting the "expensive
      stuff" before discovering that the backref isn't satisfied with a
      particular midpoint that the lower concat node is testing.  This
      doesn't help if the concat tree is left-deep, as the capture node
      won't get set soon enough (and it's hard to fix that without changing
      the engine's match behavior).  Fortunately, right-deep concat trees
      are the common case.
      
      Patch by me, reviewed by Joel Jacobson
      
      Discussion: https://postgr.es/m/661609.1614560029@sss.pgh.pa.us
      0c3405cf
    • Tom Lane's avatar
      Fix semantics of regular expression back-references. · 4aea704a
      Tom Lane authored
      POSIX defines the behavior of back-references thus:
      
          The back-reference expression '\n' shall match the same (possibly
          empty) string of characters as was matched by a subexpression
          enclosed between "\(" and "\)" preceding the '\n'.
      
      As far as I can see, the back-reference is supposed to consider only
      the data characters matched by the referenced subexpression.  However,
      because our engine copies the NFA constructed from the referenced
      subexpression, it effectively enforces any constraints therein, too.
      As an example, '(^.)\1' ought to match 'xx', or any other string
      starting with two occurrences of the same character; but in our code
      it does not, and indeed can't match anything, because the '^' anchor
      constraint is included in the backref's copied NFA.  If POSIX intended
      that, you'd think they'd mention it.  Perl for one doesn't act that
      way, so it's hard to conclude that this isn't a bug.
      
      Fix by modifying the backref's NFA immediately after it's copied from
      the reference, replacing all constraint arcs by EMPTY arcs so that the
      constraints are treated as automatically satisfied.  This still allows
      us to enforce matching rules that depend only on the data characters;
      for example, in '(^\d+).*\1' the NFA matching step will still know
      that the backref can only match strings of digits.
      
      Perhaps surprisingly, this change does not affect the results of any
      of a rather large corpus of real-world regexes.  Nonetheless, I would
      not consider back-patching it, since it's a clear compatibility break.
      
      Patch by me, reviewed by Joel Jacobson
      
      Discussion: https://postgr.es/m/661609.1614560029@sss.pgh.pa.us
      4aea704a
    • Michael Paquier's avatar
      Fix duplicated test case in TAP tests of reindexdb · c5530d84
      Michael Paquier authored
      The same test for REINDEX (VERBOSE) was done twice, while it is clear
      that the second test should use --concurrently.  Issue introduced in
      5dc92b84, for what looks like a copy-paste mistake.
      
      Reviewed-by: Mark Dilger
      Discussion: https://postgr.es/m/A7AE97EA-F4B0-4CAB-8FFF-3FECD31F9D63@enterprisedb.com
      Backpatch-through: 12
      c5530d84
    • Michael Paquier's avatar
      Simplify code to switch pg_class.relrowsecurity in tablecmds.c · fabde52f
      Michael Paquier authored
      The same code pattern was repeated twice to enable or disable ROW LEVEL
      SECURITY with an ALTER TABLE command.  This makes the code slightly
      cleaner.
      
      Author: Justin Pryzby
      Reviewed-by: Zhihong Yu
      Discussion: https://postgr.es/m/20210228211854.GC20769@telsasoft.com
      fabde52f
    • Michael Paquier's avatar
      doc: Improve description of data checksums · bd1b8d0e
      Michael Paquier authored
      This partially reverts bcf2667b that got incorrectly merged, and this
      improves the wording of the documentation that existed before that.
      
      Per discussion with Justin Pryzby.
      
      Discussion: https://postgr.es/m/20210301004647.GF20769@telsasoft.com
      bd1b8d0e
    • Michael Paquier's avatar
      doc: Mention archive_command failure handling on signals · 8c1b6a18
      Michael Paquier authored
      The behavior is similar to restore_command, which was already documented
      for the restore part, but not the archive part.
      
      Author: Benoit Lobréau
      Reviewed-by: Julien Rouhaud
      Discussion: https://postgr.es/m/CAPE8EZ7akCzc1hWohA4AcbmKtHh9rcWAB5MStOeZD2+9jC+hLQ@mail.gmail.com
      8c1b6a18
  3. 01 Mar, 2021 12 commits
  4. 28 Feb, 2021 3 commits
  5. 27 Feb, 2021 6 commits
  6. 26 Feb, 2021 4 commits
    • Tom Lane's avatar
      Doc: further clarify libpq's description of connection string URIs. · 4e90052c
      Tom Lane authored
      Break the synopsis into named parts to make it less confusing.
      Make more than zero effort at applying SGML markup.  Do a bit
      of copy-editing of nearby text.
      
      The synopsis revision is by Alvaro Herrera and Paul Förster,
      the rest is my fault.  Back-patch to v10 where multi-host
      connection strings appeared.
      
      Discussion: https://postgr.es/m/6E752D6B-487C-463E-B6E2-C32E7FB007EA@gmail.com
      4e90052c
    • Tom Lane's avatar
      Improve memory management in regex compiler. · 0fc1af17
      Tom Lane authored
      The previous logic here created a separate pool of arcs for each
      state, so that the out-arcs of each state were physically stored
      within it.  Perhaps this choice was driven by trying to not include
      a "from" pointer within each arc; but Spencer gave up on that idea
      long ago, and it's hard to see what the value is now.  The approach
      turns out to be fairly disastrous in terms of memory consumption,
      though.  In the first place, NFAs built by this engine seem to have
      about 4 arcs per state on average, with a majority having only one
      or two out-arcs.  So pre-allocating 10 out-arcs for each state is
      already cause for a factor of two or more bloat.  Worse, the NFA
      optimization phase moves arcs around with abandon.  In a large NFA,
      some of the states will have hundreds of out-arcs, so towards the
      end of the optimization phase we have a significant number of states
      whose arc pools have room for hundreds of arcs each, even though only
      a few of those arcs are in use.  We have seen real-world regexes in
      which this effect bloats the memory requirement by 25X or even more.
      
      Hence, get rid of the per-state arc pools in favor of a single arc
      pool for the whole NFA, with variable-sized allocation batches
      instead of always asking for 10 at a time.  While we're at it,
      let's batch the allocations of state structs too, to further reduce
      the malloc traffic.
      
      This incidentally allows moveouts() to be optimized in a similar
      way to moveins(): when moving an arc to another state, it's now
      valid to just re-link the same arc struct into a different outchain,
      where before the code invariants required us to make a physically
      new arc and then free the old one.
      
      These changes reduce the regex compiler's typical space consumption
      for average-size regexes by about a factor of two, and much more for
      large or complicated regexes.  In a large test set of real-world
      regexes, we formerly had half a dozen cases that failed with "regular
      expression too complex" due to exceeding the REG_MAX_COMPILE_SPACE
      limit (about 150MB); we would have had to raise that limit to
      something close to 400MB to make them work with the old code.  Now,
      none of those cases need more than 13MB to compile.  Furthermore,
      the test set is about 10% faster overall due to less malloc traffic.
      
      Discussion: https://postgr.es/m/168861.1614298592@sss.pgh.pa.us
      0fc1af17
    • Peter Eisentraut's avatar
      Extend a test case a little · b3a9e989
      Peter Eisentraut authored
      This will possibly help a subsequent patch by making sure the notice
      messages are distinct so that it's clear that they come out in the
      right order.
      
      Author: Fabien COELHO <coelho@cri.ensmp.fr>
      Discussion: https://www.postgresql.org/message-id/alpine.DEB.2.21.1904240654120.3407%40lancre
      b3a9e989
    • Michael Paquier's avatar
      doc: Improve {archive,restore}_command for compressed logs · 329784e1
      Michael Paquier authored
      The commands mentioned in the docs with gzip and gunzip did not prefix
      the archives with ".gz" and used inconsistent paths for the archives,
      which can be confusing.
      
      Reported-by: Philipp Gramzow
      Reviewed-by: Fujii Masao
      Discussion: https://postgr.es/m/161397938841.15451.13129264141285167267@wrigleys.postgresql.org
      329784e1