1. 20 Mar, 2020 1 commit
    • Amit Kapila's avatar
      Allow relation extension lock to conflict among parallel group members. · 85f6b49c
      Amit Kapila authored
      This is required as it is no safer for two related processes to extend the
      same relation at a time than for unrelated processes to do the same.  We
      don't acquire a heavyweight lock on any other object after relation
      extension lock which means such a lock can never participate in the
      deadlock cycle.  So, avoid checking wait edges from this lock.
      
      This provides an infrastructure to allow parallel operations like insert,
      copy, etc. which were earlier not possible as parallel group members won't
      conflict for relation extension lock.
      
      Author: Dilip Kumar, Amit Kapila
      Reviewed-by: Amit Kapila, Kuntal Ghosh and Sawada Masahiko
      Discussion: https://postgr.es/m/CAD21AoCmT3cFQUN4aVvzy5chw7DuzXrJCbrjTU05B+Ss=Gn1LA@mail.gmail.com
      85f6b49c
  2. 19 Mar, 2020 11 commits
    • Peter Geoghegan's avatar
      nbtree: Remove obsolete _bt_pgaddtup() comments. · b27e1b34
      Peter Geoghegan authored
      Remove comments that are a throw back to a time when nbtree cared about
      write-ordering dependencies.  The comments are similar to those removed
      by commit 9ee7414e, among others.
      b27e1b34
    • Jeff Davis's avatar
      Revert "Specialize MemoryContextMemAllocated()." · 2fd6a44a
      Jeff Davis authored
      This reverts commit e00912e1.
      2fd6a44a
    • Bruce Momjian's avatar
      pg_upgrade: make get_major_server_version() err msg consistent · 2247a1ea
      Bruce Momjian authored
      This patch fixes the error message in get_major_server_version() to be
      "could not parse version file", and uses the full file path name, rather
      than just the data directory path.
      
      Also, commit 4109bb5d added the cause of the failure to the  "could
      not open" error message, and improved quoting.  This patch backpatches
      the "could not open" cause to PG 12, where it was first widely used, and
      backpatches the quoting fix in that patch to all supported releases.
      
      Reported-by: Tom Lane
      
      Discussion: https://postgr.es/m/87pne2w98h.fsf@wibble.ilmari.org
      
      Author: Dagfinn Ilmari Mannsåker
      
      Backpatch-through: 9.5
      2247a1ea
    • Alexander Korotkov's avatar
    • Tom Lane's avatar
      Introduce "anycompatible" family of polymorphic types. · 24e2885e
      Tom Lane authored
      This patch adds the pseudo-types anycompatible, anycompatiblearray,
      anycompatiblenonarray, and anycompatiblerange.  They work much like
      anyelement, anyarray, anynonarray, and anyrange respectively, except
      that the actual input values need not match precisely in type.
      Instead, if we can find a common supertype (using the same rules
      as for UNION/CASE type resolution), then the parser automatically
      promotes the input values to that type.  For example,
      "myfunc(anycompatible, anycompatible)" can match a call with one
      integer and one bigint argument, with the integer automatically
      promoted to bigint.  With anyelement in the definition, the user
      would have had to cast the integer explicitly.
      
      The new types also provide a second, independent set of type variables
      for function matching; thus with "myfunc(anyelement, anyelement,
      anycompatible) returns anycompatible" the first two arguments are
      constrained to be the same type, but the third can be some other
      type, and the result has the type of the third argument.  The need
      for more than one set of type variables was foreseen back when we
      first invented the polymorphic types, but we never did anything
      about it.
      
      Pavel Stehule, revised a bit by me
      
      Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
      24e2885e
    • Fujii Masao's avatar
      Make pg_basebackup ask the server to estimate the total backup size, by default. · fab13dc5
      Fujii Masao authored
      This commit changes pg_basebackup so that it specifies PROGRESS option in
      BASE_BACKUP replication command whether --progress is specified or not.
      This causes the server to estimate the total backup size and report it in
      pg_stat_progress_basebackup.backup_total, by default. This is reasonable
      default because the time required for the estimation would not be so large
      in most cases.
      
      Also this commit adds new option --no-estimate-size to pg_basebackup.
      This option prevents the server from the estimation, and so is useful to
      avoid such estimation time if it's too long.
      
      Author: Fujii Masao
      Reviewed-by: Magnus Hagander, Amit Langote
      Discussion: https://postgr.es/m/CABUevEyDPPSjP7KRvfTXPdqOdY5aWNkqsB5aAXs3bco5ZwtGHg@mail.gmail.com
      fab13dc5
    • Peter Eisentraut's avatar
      Prepare to support non-tables in publications · c314c147
      Peter Eisentraut authored
      This by itself doesn't change any functionality but prepares the way
      for having relations other than base tables in publications.
      
      Make arrangements for COPY handling the initial table sync.  For
      non-tables we have to use COPY (SELECT ...) instead of directly
      copying from the table, but then we have to take care to omit
      generated columns from the column list.
      
      Also, remove a hardcoded reference to relkind = 'r' and rely on the
      publisher to send only what it can actually publish, which will be
      correct even in future cross-version scenarios.
      Reviewed-by: default avatarAmit Langote <amitlangote09@gmail.com>
      Discussion: https://www.postgresql.org/message-id/flat/CA+HiwqH=Y85vRK3mOdjEkqFK+E=ST=eQiHdpj43L=_eJMOOznQ@mail.gmail.com
      c314c147
    • Fujii Masao's avatar
      Rename the recovery-related wait events. · 1d253bae
      Fujii Masao authored
      This commit renames RecoveryWalAll and RecoveryWalStream wait events to
      RecoveryWalStream and RecoveryRetrieveRetryInterval, respectively,
      in order to make the names and what they are more consistent. For example,
      previously RecoveryWalAll was reported as a wait event while the recovery
      was waiting for WAL from a stream, and which was confusing because the name
      was very different from the situation where the wait actually could happen.
      
      The names of macro variables for those wait events also are renamed
      accordingly.
      
      This commit also changes the category of RecoveryRetrieveRetryInterval to
      Timeout from Activity because the wait event is reported while waiting based
      on wal_retrieve_retry_interval.
      
      Author: Fujii Masao
      Reviewed-by: Kyotaro Horiguchi, Atsushi Torikoshi
      Discussion: https://postgr.es/m/124997ee-096a-5d09-d8da-2c7a57d0816e@oss.nttdata.com
      1d253bae
    • Amit Kapila's avatar
      Add assert to ensure that page locks don't participate in deadlock cycle. · 72e78d83
      Amit Kapila authored
      Assert that we don't acquire any other heavyweight lock while holding the
      page lock except for relation extension.  However, these locks are never
      taken in reverse order which implies that page locks will never
      participate in the deadlock cycle.
      
      Similar to relation extension, page locks are also held for a short
      duration, so imposing such a restriction won't hurt.
      
      Author: Dilip Kumar, with few changes by Amit Kapila
      Reviewed-by: Amit Kapila, Kuntal Ghosh and Sawada Masahiko
      Discussion: https://postgr.es/m/CAD21AoCmT3cFQUN4aVvzy5chw7DuzXrJCbrjTU05B+Ss=Gn1LA@mail.gmail.com
      72e78d83
    • Peter Geoghegan's avatar
      nbtree: Use raw PageAddItem() for retail inserts. · 6312c08a
      Peter Geoghegan authored
      Only internal page splits need to call _bt_pgaddtup() instead of
      PageAddItem(), and only for data items, one of which will end up at the
      first offset (or first offset after the high key offset) on the new
      right page.  This data item alone will need to be truncated in
      _bt_pgaddtup().
      
      Since there is no reason why retail inserts ever need to truncate the
      incoming item, use a raw PageAddItem() call there instead.  Even
      _bt_split() uses raw PageAddItem() calls for left page and right page
      high keys.  Clearly the _bt_pgaddtup() shim function wasn't really
      encapsulating anything.  _bt_pgaddtup() should now be thought of as a
      _bt_split() helper function.
      
      Note that the assertions from commit d1e241c2 verify that retail inserts
      never insert an item at an internal page's negative infinity offset.
      This invariant could only ever be violated as a result of a basic logic
      error in nbtinsert.c.
      6312c08a
    • Michael Paquier's avatar
      Fix comment related to concurrent index swapping in index.c · d41202f3
      Michael Paquier authored
      A comment about switching indisvalid of the new and old indexes swapped
      in REINDEX CONCURRENTLY got this backwards.
      
      Issue introduced by 5dc92b84, the original commit of REINDEX
      CONCURRENTLY.
      
      Author: Julien Rouhaud
      Discussion: https://postgr.es/m/20200318143340.GA46897@nol
      Backpatch-through: 12
      d41202f3
  3. 18 Mar, 2020 17 commits
  4. 17 Mar, 2020 11 commits
    • Tom Lane's avatar
      Refactor our checks for valid function and aggregate signatures. · e6c178b5
      Tom Lane authored
      pg_proc.c and pg_aggregate.c had near-duplicate copies of the logic
      to decide whether a function or aggregate's signature is legal.
      This seems like a bad thing even without the problem that the
      upcoming "anycompatible" patch would roughly double the complexity
      of that logic.  Hence, refactor so that the rules are localized
      in new subroutines supplied by parse_coerce.c.  (One could quibble
      about just where to add that code, but putting it beside
      enforce_generic_type_consistency seems not totally unreasonable.)
      
      The fact that the rules are about to change would mandate some
      changes in the wording of the associated error messages in any case.
      I ended up spelling things out in a fairly literal fashion in the
      errdetail messages, eg "A result of type anyelement requires at
      least one input of type anyelement, anyarray, anynonarray, anyenum,
      or anyrange."  Perhaps this is overkill, but once there's more than
      one subgroup of polymorphic types, people might get confused by
      more-abstract messages.
      
      Discussion: https://postgr.es/m/24137.1584139352@sss.pgh.pa.us
      e6c178b5
    • Peter Geoghegan's avatar
      Doc: Correct deduplicate_items varlistentry id. · dbbb5538
      Peter Geoghegan authored
      Use a varlistentry id for the deduplicate_items storage parameter that
      is derived from the name of the parameter itself.
      
      This oversight happened because the storage parameter was renamed
      relatively late during the development of the patch that became commit
      0d861bbb.
      dbbb5538
    • Tom Lane's avatar
      Adjust handling of an ANYARRAY actual input for an ANYARRAY argument. · 77ec5aff
      Tom Lane authored
      Ordinarily it's impossible for an actual input of a function to have
      declared type ANYARRAY, since we'd resolve that to a concrete array
      type before doing argument type resolution for the function.  But an
      exception arises for functions applied to certain columns of pg_statistic
      or pg_stats, since we abuse the "anyarray" pseudotype by using it to
      declare those columns.  So parse_coerce.c has to deal with the case.
      
      Previously we allowed an ANYARRAY actual input to match an ANYARRAY
      polymorphic argument, but only if no other argument or result was
      declared ANYELEMENT.  When that logic was written, those were the only
      two polymorphic types, and I fear nobody thought carefully about how it
      ought to extend to the other ones that came along later.  But actually
      it was wrong even then, because if a function has two ANYARRAY
      arguments, it should be able to expect that they have identical element
      types, and we'd not be able to ensure that.
      
      The correct generalization is that we can match an ANYARRAY actual input
      to an ANYARRAY polymorphic argument only if no other argument or result
      is of any polymorphic type, so that no promises are being made about
      element type compatibility.  check_generic_type_consistency can't test
      that condition, but it seems better anyway to accept such matches there
      and then throw an error if needed in enforce_generic_type_consistency.
      That way we can produce a specific error message rather than an
      unintuitive "function does not exist" complaint.  (There's some risk
      perhaps of getting new ambiguous-function complaints, but I think that
      any set of functions for which that could happen would be ambiguous
      against ordinary array columns as well.)  While we're at it, we can
      improve the message that's produced in cases that the code did already
      object to, as shown in the regression test changes.
      
      Also, remove a similar test that got cargo-culted in for ANYRANGE;
      there are no catalog columns of type ANYRANGE, and I hope we never
      create any, so that's not needed.  (It was incomplete anyway.)
      
      While here, update some comments and rearrange the code a bit in
      preparation for upcoming additions of more polymorphic types.
      
      In practical situations I believe this is just exchanging one error
      message for another, hopefully better, one.  So it doesn't seem
      needful to back-patch, even though the mistake is ancient.
      
      Discussion: https://postgr.es/m/21569.1584314271@sss.pgh.pa.us
      77ec5aff
    • Alvaro Herrera's avatar
      Remove logical_read_local_xlog_page · 5d0c2d5e
      Alvaro Herrera authored
      It devolved into a content-less wrapper over read_local_xlog_page, with
      nothing to add, plus it's easily confused with walsender's
      logical_read_xlog_page.  There doesn't seem to be any reason for it to
      stay.
      
      src/include/replication/logicalfuncs.h becomes empty, so remove it too.
      The prototypes it initially had were absorbed by generated fmgrprotos.h.
      
      Discussion: https://postgr.es/m/20191115214102.GA15616@alvherre.pgsql
      5d0c2d5e
    • Alvaro Herrera's avatar
      Fix consistency issues with replication slot copy · bcd1c363
      Alvaro Herrera authored
      Commit 9f06d79e's replication slot copying failed to
      properly reserve the WAL that the slot is expecting to see
      during DecodingContextFindStartpoint (to set the confirmed_flush
      LSN), so concurrent activity could remove that WAL and cause the
      copy process to error out.  But it doesn't actually *need* that
      WAL anyway: instead of running decode to find confirmed_flush, it
      can be copied from the source slot. Fix this by rearranging things
      to avoid DecodingContextFindStartpoint() (leaving the target slot's
      confirmed_flush_lsn to invalid), and set that up afterwards by copying
      from the target slot's value.
      
      Also ensure the source slot's confirmed_flush_lsn is valid.
      
      Reported-by: Arseny Sher
      Author: Masahiko Sawada, Arseny Sher
      Discussion: https://postgr.es/m/871rr3ohbo.fsf@ars-thinkpad
      bcd1c363
    • Tom Lane's avatar
      Doc: clarify behavior of "anyrange" pseudo-type. · 31d846e0
      Tom Lane authored
      I noticed that we completely failed to document the restriction
      that an "anyrange" result type has to be inferred from an "anyrange"
      input.  The docs also were less clear than they could be about the
      relationship between "anyrange" and "anyarray".
      
      It's been like this all along, so back-patch.
      31d846e0
    • Tom Lane's avatar
      Remove bogus assertion about polymorphic SQL function result. · 9d9784c8
      Tom Lane authored
      It is possible to reach check_sql_fn_retval() with an unresolved
      polymorphic rettype, resulting in an assertion failure as demonstrated
      by one of the added test cases.  However, the code following that
      throws what seems an acceptable error message, so just remove the
      Assert and adjust commentary.
      
      While here, I thought it'd be a good idea to provide some parallel
      tests of SQL-function and PL/pgSQL-function polymorphism behavior.
      Some of these cases are perhaps duplicative of tests elsewhere,
      but we hadn't any organized coverage of the topic AFAICS.
      
      Although that assertion's been wrong all along, it won't have any
      effect in production builds, so I'm not bothering to back-patch.
      
      Discussion: https://postgr.es/m/21569.1584314271@sss.pgh.pa.us
      9d9784c8
    • Tom Lane's avatar
      Use pkg-config, if available, to locate libxml2 during configure. · 0bc8cebd
      Tom Lane authored
      If pkg-config is installed and knows about libxml2, use its information
      rather than asking xml2-config.  Otherwise proceed as before.  This
      patch allows "configure --with-libxml" to succeed on platforms that
      have pkg-config but not xml2-config, which is likely to soon become
      a typical situation.
      
      The old mechanism can be forced by setting XML2_CONFIG explicitly
      (hence, build processes that were already doing so will certainly
      not need adjustment).  Also, it's now possible to set XML2_CFLAGS
      and XML2_LIBS explicitly to override both programs.
      
      There is a small risk of this breaking existing build processes,
      if there are multiple libxml2 installations on the machine and
      pkg-config disagrees with xml2-config about which to use.  The
      only case where that seems really likely is if a builder has tried
      to select a non-default xml2-config by putting it early in his PATH
      rather than setting XML2_CONFIG.  Plan to warn against that in the
      minor release notes.
      
      Back-patch to v10; before that we had no pkg-config infrastructure,
      and it doesn't seem worth adding it for this.
      
      Hugh McMaster and Tom Lane; Peter Eisentraut also made an earlier
      attempt at this, from which I lifted most of the docs changes.
      
      Discussion: https://postgr.es/m/CAN9BcdvfUwc9Yx5015bLH2TOiQ-M+t_NADBSPhMF7dZ=pLa_iw@mail.gmail.com
      0bc8cebd
    • Fujii Masao's avatar
    • Fujii Masao's avatar
      Fix comment in xlog.c. · 1429d3f7
      Fujii Masao authored
      This commit fixes the comment about SharedHotStandbyActive variable.
      The comment was apparently copy-and-pasted.
      
      Author: Atsushi Torikoshi
      Discussion: https://postgr.es/m/CACZ0uYEjpqZB9wN2Rwc_RMvDybyYqdbkPuDr1NyxJg4f9yGfMw@mail.gmail.com
      1429d3f7
    • Tom Lane's avatar
      Remove useless pfree()s at the ends of various ValuePerCall SRFs. · 41b45576
      Tom Lane authored
      We don't need to manually clean up allocations in a SRF's
      multi_call_memory_ctx, because the SRF_RETURN_DONE infrastructure
      takes care of that (and also ensures that it will happen even if the
      function never gets a final call, which simple manual cleanup cannot
      do).
      
      Hence, the code removed by this patch is a waste of code and cycles.
      Worse, it gives the impression that cleaning up manually is a thing,
      which can lead to more serious errors such as those fixed in
      commits 085b6b66 and b4570d33.  So we should get rid of it.
      
      These are not quite actual bugs though, so I couldn't muster the
      enthusiasm to back-patch.  Fix in HEAD only.
      
      Justin Pryzby
      
      Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com
      41b45576