1. 16 Jan, 2021 3 commits
    • Noah Misch's avatar
      Fix pg_dump for GRANT OPTION among initial privileges. · f713ff7c
      Noah Misch authored
      The context is an object that no longer bears some aclitem that it bore
      initially.  (A user issued REVOKE or GRANT statements upon the object.)
      pg_dump is forming SQL to reproduce the object ACL.  Since initdb
      creates no ACL bearing GRANT OPTION, reaching this bug requires an
      extension where the creation script establishes such an ACL.  No PGXN
      extension does that.  If an installation did reach the bug, pg_dump
      would have omitted a semicolon, causing a REVOKE and the next SQL
      statement to fail.  Separately, since the affected code exists to
      eliminate an entire aclitem, it wants plain REVOKE, not REVOKE GRANT
      OPTION FOR.  Back-patch to 9.6, where commit
      23f34fa4 first appeared.
      
      Discussion: https://postgr.es/m/20210109102423.GA160022@rfd.leadboat.com
      f713ff7c
    • Noah Misch's avatar
      Prevent excess SimpleLruTruncate() deletion. · 6db99283
      Noah Misch authored
      Every core SLRU wraps around.  With the exception of pg_notify, the wrap
      point can fall in the middle of a page.  Account for this in the
      PagePrecedes callback specification and in SimpleLruTruncate()'s use of
      said callback.  Update each callback implementation to fit the new
      specification.  This changes SerialPagePrecedesLogically() from the
      style of asyncQueuePagePrecedes() to the style of CLOGPagePrecedes().
      (Whereas pg_clog and pg_serial share a key space, pg_serial is nothing
      like pg_notify.)  The bug fixed here has the same symptoms and user
      followup steps as 592a589a04bd456410b853d86bd05faa9432cbbb.  Back-patch
      to 9.5 (all supported versions).
      
      Reviewed by Andrey Borodin and (in earlier versions) by Tom Lane.
      
      Discussion: https://postgr.es/m/20190202083822.GC32531@gust.leadboat.com
      6db99283
    • Amit Kapila's avatar
      Remove unnecessary pstrdup in fetch_table_list. · c95765f4
      Amit Kapila authored
      The result of TextDatumGetCString is already palloc'ed so we don't need to
      allocate memory for it again. We decide not to backpatch it as there
      doesn't seem to be any case where it can create a meaningful leak.
      
      Author: Zhijie Hou
      Reviewed-by: Daniel Gustafsson
      Discussion: https://postgr.es/m/229fed2eb8c54c71a96ccb99e516eb12@G08CNEXMBPEKD05.g08.fujitsu.local
      c95765f4
  2. 15 Jan, 2021 7 commits
  3. 14 Jan, 2021 7 commits
    • Tom Lane's avatar
      pg_dump: label PUBLICATION TABLE ArchiveEntries with an owner. · 8e396a77
      Tom Lane authored
      This is the same fix as commit 9eabfe30 applied to INDEX ATTACH
      entries, but for table-to-publication attachments.  As in that
      case, even though the backend doesn't record "ownership" of the
      attachment, we still ought to label it in the dump archive with
      the role name that should run the ALTER PUBLICATION command.
      The existing behavior causes the ALTER to be done by the original
      role that started the restore; that will usually work fine, but
      there may be corner cases where it fails.
      
      The bulk of the patch is concerned with changing struct
      PublicationRelInfo to include a pointer to the associated
      PublicationInfo object, so that we can get the owner's name
      out of that when the time comes.  While at it, I rewrote
      getPublicationTables() to do just one query of pg_publication_rel,
      not one per table.
      
      Back-patch to v10 where this code was introduced.
      
      Discussion: https://postgr.es/m/1165710.1610473242@sss.pgh.pa.us
      8e396a77
    • Alvaro Herrera's avatar
      Prevent drop of tablespaces used by partitioned relations · ebfe2dbd
      Alvaro Herrera authored
      When a tablespace is used in a partitioned relation (per commits
      ca410302 in pg12 for tables and 33e6c34c3267 in pg11 for indexes),
      it is possible to drop the tablespace, potentially causing various
      problems.  One such was reported in bug #16577, where a rewriting ALTER
      TABLE causes a server crash.
      
      Protect against this by using pg_shdepend to keep track of tablespaces
      when used for relations that don't keep physical files; we now abort a
      tablespace if we see that the tablespace is referenced from any
      partitioned relations.
      
      Backpatch this to 11, where this problem has been latent all along.  We
      don't try to create pg_shdepend entries for existing partitioned
      indexes/tables, but any ones that are modified going forward will be
      protected.
      
      Note slight behavior change: when trying to drop a tablespace that
      contains both regular tables as well as partitioned ones, you'd
      previously get ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE and now you'll
      get ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST.  Arguably, the latter is more
      correct.
      
      It is possible to add protecting pg_shdepend entries for existing
      tables/indexes, by doing
        ALTER TABLE ONLY some_partitioned_table SET TABLESPACE pg_default;
        ALTER TABLE ONLY some_partitioned_table SET TABLESPACE original_tablespace;
      for each partitioned table/index that is not in the database default
      tablespace.  Because these partitioned objects do not have storage, no
      file needs to be actually moved, so it shouldn't take more time than
      what's required to acquire locks.
      
      This query can be used to search for such relations:
      SELECT ... FROM pg_class WHERE relkind IN ('p', 'I') AND reltablespace <> 0
      Reported-by: default avatarAlexander Lakhin <exclusion@gmail.com>
      Discussion: https://postgr.es/m/16577-881633a9f9894fd5@postgresql.org
      Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
      Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
      ebfe2dbd
    • Fujii Masao's avatar
      Stabilize timeline switch regression test. · 424d7a9b
      Fujii Masao authored
      Commit fef5b47f added the regression test to check whether a standby is
      able to follow a primary on a newer timeline when WAL archiving is enabled.
      But the buildfarm member florican reported that this test failed because
      the requested WAL segment was removed and replication failed. This is a
      timing issue. Since neither replication slot is used nor wal_keep_size is set
      in the test, checkpoint could remove the WAL segment that's still necessary
      for replication.
      
      This commit stabilizes the test by setting wal_keep_size.
      
      Back-patch to v13 where the regression test that this commit stabilizes
      was added.
      
      Author: Fujii Masao
      Discussion: https://postgr.es/m/X//PsenxcC50jDzX@paquier.xyz
      424d7a9b
    • Fujii Masao's avatar
      Improve tab-completion for CLOSE, DECLARE, FETCH and MOVE. · 3f238b88
      Fujii Masao authored
      This commit makes CLOSE, FETCH and MOVE commands tab-complete the list of
      cursors. Also this commit makes DECLARE command tab-complete the options.
      
      Author: Shinya Kato, Sawada Masahiko, tweaked by Fujii Masao
      Reviewed-by: Shinya Kato, Sawada Masahiko, Fujii Masao
      Discussion: https://postgr.es/m/b0e4c5c53ef84c5395524f5056fc71f0@MP-MSGSS-MBX001.msg.nttdata.co.jp
      3f238b88
    • Thomas Munro's avatar
      Minor header cleanup for the new iovec code. · fb29ab26
      Thomas Munro authored
      Remove redundant function declaration and improve header comment in
      pg_iovec.h.  Move the new declaration in fd.h next to a group of more
      similar functions.
      fb29ab26
    • Fujii Masao's avatar
      Ensure that a standby is able to follow a primary on a newer timeline. · fef5b47f
      Fujii Masao authored
      Commit 709d003f refactored WAL-reading code, but accidentally caused
      WalSndSegmentOpen() to fail to follow a timeline switch while reading from
      a historic timeline. This issue caused a standby to fail to follow a primary
      on a newer timeline when WAL archiving is enabled.
      
      If there is a timeline switch within the segment, WalSndSegmentOpen() should
      read from the WAL segment belonging to the new timeline. But previously
      since it failed to follow a timeline switch, it tried to read the WAL segment
      with old timeline. When WAL archiving is enabled, that WAL segment with
      old timeline doesn't exist because it's renamed to .partial. This leads
      a primary to have tried to read non-existent WAL segment, and which caused
      replication to faill with the error "ERROR:  requested WAL segment ... has
       already been removed".
      
      This commit fixes WalSndSegmentOpen() so that it's able to follow a timeline
      switch, to ensure that a standby is able to follow a primary on a newer
      timeline even when WAL archiving is enabled.
      
      This commit also adds the regression test to check whether a standby is
      able to follow a primary on a newer timeline when WAL archiving is enabled.
      
      Back-patch to v13 where the bug was introduced.
      
      Reported-by: Kyotaro Horiguchi
      Author: Kyotaro Horiguchi, tweaked by Fujii Masao
      Reviewed-by:  Alvaro Herrera, Fujii Masao
      Discussion: https://postgr.es/m/20201209.174314.282492377848029776.horikyota.ntt@gmail.com
      fef5b47f
    • Michael Paquier's avatar
      Rework refactoring of hex and encoding routines · aef8948f
      Michael Paquier authored
      This commit addresses some issues with c3826f83 that moved the hex
      decoding routine to src/common/:
      - The decoding function lacked overflow checks, so when used for
      security-related features it was an open door to out-of-bound writes if
      not carefully used that could remain undetected.  Like the base64
      routines already in src/common/ used by SCRAM, this routine is reworked
      to check for overflows by having the size of the destination buffer
      passed as argument, with overflows checked before doing any writes.
      - The encoding routine was missing.  This is moved to src/common/ and
      it gains the same overflow checks as the decoding part.
      
      On failure, the hex routines of src/common/ issue an error as per the
      discussion done to make them usable by frontend tools, but not by shared
      libraries.  Note that this is why ECPG is left out of this commit, and
      it still includes a duplicated logic doing hex encoding and decoding.
      
      While on it, this commit uses better variable names for the source and
      destination buffers in the existing escape and base64 routines in
      encode.c and it makes them more robust to overflow detection.  The
      previous core code issued a FATAL after doing out-of-bound writes if
      going through the SQL functions, which would be enough to detect
      problems when working on changes that impacted this area of the
      code.  Instead, an error is issued before doing an out-of-bound write.
      The hex routines were being directly called for bytea conversions and
      backup manifests without such sanity checks.  The current calls happen
      to not have any problems, but careless uses of such APIs could easily
      lead to CVE-class bugs.
      
      Author: Bruce Momjian, Michael Paquier
      Reviewed-by: Sehrope Sarkuni
      Discussion: https://postgr.es/m/20201231003557.GB22199@momjian.us
      aef8948f
  4. 13 Jan, 2021 18 commits
  5. 12 Jan, 2021 5 commits