1. 22 Mar, 2021 9 commits
    • Tom Lane's avatar
      Mostly-cosmetic adjustments of TOAST-related macros. · aeb1631e
      Tom Lane authored
      The authors of bbe0a81d hadn't quite got the idea that macros named
      like SOMETHING_4B_C were only meant for internal endianness-related
      details in postgres.h.  Choose more legible names for macros that are
      intended to be used elsewhere.  Rearrange postgres.h a bit to clarify
      the separation between those internal macros and ones intended for
      wider use.
      
      Also, avoid using the term "rawsize" for true decompressed size;
      we've used "extsize" for that, because "rawsize" generally denotes
      total Datum size including header.  This choice seemed particularly
      unfortunate in tests that were comparing one of these meanings to
      the other.
      
      This patch includes a couple of not-purely-cosmetic changes: be
      sure that the shifts aligning compression methods are unsigned
      (not critical today, but will be when compression method 2 exists),
      and fix broken definition of VARATT_EXTERNAL_GET_COMPRESSION (now
      VARATT_EXTERNAL_GET_COMPRESS_METHOD), whose callers worked only
      accidentally.
      
      Discussion: https://postgr.es/m/574197.1616428079@sss.pgh.pa.us
      aeb1631e
    • Tom Lane's avatar
      Remove useless configure probe for <lz4/lz4.h>. · 2c75f8a6
      Tom Lane authored
      This seems to have been just copied-and-pasted from some other
      header checks.  But our C code is entirely unprepared to support
      such a header name, so it's only wasting cycles to look for it.
      If we did need to support it, some #ifdefs would be required.
      
      (A quick trawl at codesearch.debian.net finds some packages that
      reference lz4/lz4.h; but they use *only* that spelling, and
      appear to be intending to reference their own copy rather than
      a system-level installation of liblz4.  There's no evidence of
      freestanding installations that require this spelling.)
      
      Discussion: https://postgr.es/m/457962.1616362509@sss.pgh.pa.us
      2c75f8a6
    • Robert Haas's avatar
      Error on invalid TOAST compression in CREATE or ALTER TABLE. · a4d5284a
      Robert Haas authored
      The previous coding treated an invalid compression method name as
      equivalent to the default, which is certainly not right.
      
      Justin Pryzby
      
      Discussion: http://postgr.es/m/20210321235544.GD4203@telsasoft.com
      a4d5284a
    • Robert Haas's avatar
      docs: Fix omissions related to configurable TOAST compression. · 24f0e395
      Robert Haas authored
      Previously, the default_toast_compression GUC was not documented,
      and neither was pg_dump's new --no-toast-compression option.
      
      Justin Pryzby and Robert Haas
      
      Discussion: http://postgr.es/m/20210321235544.GD4203@telsasoft.com
      24f0e395
    • Robert Haas's avatar
      More code cleanup for configurable TOAST compression. · 226e2be3
      Robert Haas authored
      Remove unused macro. Fix confusion about whether a TOAST compression
      method is identified by an OID or a char.
      
      Justin Pryzby
      
      Discussion: http://postgr.es/m/20210321235544.GD4203@telsasoft.com
      226e2be3
    • Michael Paquier's avatar
      Fix concurrency issues with WAL segment recycling on Windows · 909b449e
      Michael Paquier authored
      This commit is mostly a revert of aaa3aedd, that switched the routine
      doing the internal renaming of recycled WAL segments to use on Windows a
      combination of CreateHardLinkA() plus unlink() instead of rename().  As
      reported by several users of Postgres 13, this is causing concurrency
      issues when manipulating WAL segments, mostly in the shape of the
      following error:
      LOG:  could not rename file "pg_wal/000000XX000000YY000000ZZ":
      Permission denied
      
      This moves back to a logic where a single rename() (well, pgrename() for
      Windows) is used.  This issue has proved to be hard to hit when I tested
      it, facing it only once with an archive_command that was not able to do
      its work, so it is environment-sensitive.  The reporters of this issue
      have been able to confirm that the situation improved once we switched
      back to a single rename().  In order to check things, I have provided to
      the reporters a patched build based on 13.2 with aaa3aedd reverted, to
      test if the error goes away, and an unpatched build of 13.2 to test if
      the error still showed up (just to make sure that I did not mess up my
      build process).
      
      Extra thanks to Fujii Masao for pointing out what looked like the
      culprit commit, and to all the reporters for taking the time to test
      what I have sent them.
      
      Reported-by: Andrus, Guy Burgess, Yaroslav Pashinsky, Thomas Trenz
      Reviewed-by: Tom Lane, Andres Freund
      Discussion: https://postgr.es/m/3861ff1e-0923-7838-e826-094cc9bef737@hot.ee
      Discussion: https://postgr.es/m/16874-c3eecd319e36a2bf@postgresql.org
      Discussion: https://postgr.es/m/095ccf8d-7f58-d928-427c-b17ace23cae6@burgess.co.nz
      Discussion: https://postgr.es/m/16927-67c570d968c99567%40postgresql.org
      Discussion: https://postgr.es/m/YFBcRbnBiPdGZvfW@paquier.xyz
      Backpatch-through: 13
      909b449e
    • Fujii Masao's avatar
      pgbench: Improve error-handling in \sleep command. · 8c6eda2d
      Fujii Masao authored
      This commit improves pgbench \sleep command so that it handles
      the following three cases more properly.
      
      (1) When only one argument was specified in \sleep command and
          it's not a number, previously pgbench reported a confusing error
          message like "unrecognized time unit, must be us, ms or s".
          This commit fixes this so that more proper error message like
          "invalid sleep time, must be an integer" is reported.
      
      (2) When two arguments were specified in \sleep command and
          the first argument was not a number, previously pgbench treated
          that argument as the sleep time 0. No error was reported in this
          case. This commit fixes this so that an error is thrown in this
          case.
      
      (3) When a variable was specified as the first argument in \sleep
          command and the variable stored non-digit value, previously
          pgbench treated that argument as the sleep time 0. No error
          was reported in this case. This commit fixes this so that
          an error is thrown in this case.
      
      Author: Kota Miyake
      Reviewed-by: Hayato Kuroda, Alvaro Herrera, Fujii Masao
      Discussion: https://postgr.es/m/23b254daf20cec4332a2d9168505dbc9@oss.nttdata.com
      8c6eda2d
    • Noah Misch's avatar
      Make a test endure log_error_verbosity=verbose. · e3f4aec0
      Noah Misch authored
      Back-patch to v13, which introduced the test code in question.
      e3f4aec0
    • Michael Paquier's avatar
      Fix new TAP test for 2PC transactions and PITRs on Windows · 992d353a
      Michael Paquier authored
      The test added by 595b9cba forgot that on Windows it is necessary to set
      up pg_hba.conf (see PostgresNode::set_replication_conf) with a specific
      entry or base backups fail.  Any node that requires to support
      replication just needs to pass down allows_streaming at initialization.
      This updates the test to do so.  Simplify things a bit while on it.
      
      Per buildfarm member fairywren.  Any Windows hosts running this test
      would have failed, and I have reproduced the problem as well.
      
      Backpatch-through: 10
      992d353a
  2. 21 Mar, 2021 11 commits
    • Michael Paquier's avatar
      Simplify TAP tests of kerberos with expected log file contents · 11e1577a
      Michael Paquier authored
      The TAP tests of kerberos rely on the logs generated by the backend to
      check various connection scenarios.  In order to make sure that a given
      test does not overlap with the log contents generated by a previous
      test, the test suite relied on a logic with the logging collector and a
      rotation of the log files to ensure the uniqueness of the log generated
      with a wait phase.
      
      Parsing the log contents for expected patterns is a problem that has
      been solved in a simpler way by PostgresNode::issues_sql_like() where
      the log file is truncated before checking for the contents generated,
      with the backend sending its output to a log file given by pg_ctl
      instead.  This commit switches the kerberos test suite to use such a
      method, removing any wait phase and simplifying the whole logic,
      resulting in less code.  If a failure happens in the tests, the contents
      of the logs are still showed to the user at the moment of the failure
      thanks to like(), so this has no impact on debugging capabilities.
      
      I have bumped into this issue while reviewing a different patch set
      aiming at extending the kerberos test suite to check for multiple
      log patterns instead of one now.
      
      Author: Michael Paquier
      Reviewed-by: Stephen Frost, Bharath Rupireddy
      Discussion: https://postgr.es/m/YFXcq2vBTDGQVBNC@paquier.xyz
      11e1577a
    • Michael Paquier's avatar
      Fix timeline assignment in checkpoints with 2PC transactions · 595b9cba
      Michael Paquier authored
      Any transactions found as still prepared by a checkpoint have their
      state data read from the WAL records generated by PREPARE TRANSACTION
      before being moved into their new location within pg_twophase/.  While
      reading such records, the WAL reader uses the callback
      read_local_xlog_page() to read a page, that is shared across various
      parts of the system.  This callback, since 1148e22a, has introduced an
      update of ThisTimeLineID when reading a record while in recovery, which
      is potentially helpful in the context of cascading WAL senders.
      
      This update of ThisTimeLineID interacts badly with the checkpointer if a
      promotion happens while some 2PC data is read from its record, as, by
      changing ThisTimeLineID, any follow-up WAL records would be written to
      an timeline older than the promoted one.  This results in consistency
      issues.  For instance, a subsequent server restart would cause a failure
      in finding a valid checkpoint record, resulting in a PANIC, for
      instance.
      
      This commit changes the code reading the 2PC data to reset the timeline
      once the 2PC record has been read, to prevent messing up with the static
      state of the checkpointer.  It would be tempting to do the same thing
      directly in read_local_xlog_page().  However, based on the discussion
      that has led to 1148e22a, users may rely on the updates of
      ThisTimeLineID when a WAL record page is read in recovery, so changing
      this callback could break some cases that are working currently.
      
      A TAP test reproducing the issue is added, relying on a PITR to
      precisely trigger a promotion with a prepared transaction still
      tracked.
      
      Per discussion with Heikki Linnakangas, Kyotaro Horiguchi, Fujii Masao
      and myself.
      
      Author: Soumyadeep Chakraborty, Jimmy Yih, Kevin Yeap
      Discussion: https://postgr.es/m/CAE-ML+_EjH_fzfq1F3RJ1=XaaNG=-Jz-i3JqkNhXiLAsM3z-Ew@mail.gmail.com
      Backpatch-through: 10
      595b9cba
    • Tom Lane's avatar
      Fix assorted silliness in ATExecSetCompression(). · ac897c48
      Tom Lane authored
      It's not okay to scribble directly on a syscache entry.
      Nor to continue accessing said entry after releasing it.
      
      Also get rid of not-used local variables.
      
      Per valgrind testing.
      ac897c48
    • Peter Geoghegan's avatar
      Recycle nbtree pages deleted during same VACUUM. · 9dd963ae
      Peter Geoghegan authored
      Maintain a simple array of metadata about pages that were deleted during
      nbtree VACUUM's current btvacuumscan() call.  Use this metadata at the
      end of btvacuumscan() to attempt to place newly deleted pages in the FSM
      without further delay.  It might not yet be safe to place any of the
      pages in the FSM by then (they may not be deemed recyclable), but we
      have little to lose and plenty to gain by trying.  In practice there is
      a very good chance that this will work out when vacuuming larger
      indexes, where scanning the index naturally takes quite a while.
      
      This commit doesn't change the page recycling invariants; it merely
      improves the efficiency of page recycling within the confines of the
      existing design.  Recycle safety is a part of nbtree's implementation of
      what Lanin & Shasha call "the drain technique".  The design happens to
      use transaction IDs (they're stored in deleted pages), but that in
      itself doesn't align the cutoff for recycle safety to any of the
      XID-based cutoffs used by VACUUM (e.g., OldestXmin).  All that matters
      is whether or not _other_ backends might be able to observe various
      inconsistencies in the tree structure (that they cannot just detect and
      recover from by moving right).  Recycle safety is purely a question of
      maintaining the consistency (or the apparent consistency) of a physical
      data structure.
      
      Note that running a simple serial test case involving a large range
      DELETE followed by a VACUUM VERBOSE will probably show that any newly
      deleted nbtree pages are not yet reusable/recyclable.  This is expected
      in the absence of even one concurrent XID assignment.  It is an old
      implementation restriction.  In practice it's unlikely to be the thing
      that makes recycling remain unsafe, at least with larger indexes, where
      recycling newly deleted pages during the same VACUUM actually matters.
      
      An important high-level goal of this commit (as well as related recent
      commits e5d8a999 and 9f3665fb) is to make expensive deferred cleanup
      operations in index AMs rare in general.  If index vacuuming frequently
      depends on the next VACUUM operation finishing off work that the current
      operation started, then the general behavior of index vacuuming is hard
      to predict.  This is relevant to ongoing work that adds a vacuumlazy.c
      mechanism to skip index vacuuming in certain cases.  Anything that makes
      the real world behavior of index vacuuming simpler and more linear will
      also make top-down modeling in vacuumlazy.c more robust.
      
      Author: Peter Geoghegan <pg@bowt.ie>
      Reviewed-By: default avatarMasahiko Sawada <sawada.mshk@gmail.com>
      Discussion: https://postgr.es/m/CAH2-Wzk76_P=67iUscb1UN44-gyZL-KgpsXbSxq_bdcMa7Q+wQ@mail.gmail.com
      9dd963ae
    • Tom Lane's avatar
      Bring configure support for LZ4 up to snuff. · 4d399a6f
      Tom Lane authored
      It's not okay to just shove the pkg_config results right into our
      build flags, for a couple different reasons:
      
      * This fails to maintain the separation between CPPFLAGS and CFLAGS,
      as well as that between LDFLAGS and LIBS.  (The CPPFLAGS angle is,
      I believe, the reason for warning messages reported when building
      with MacPorts' liblz4.)
      
      * If pkg_config emits anything other than -I/-D/-L/-l switches,
      it's highly unlikely that we want to absorb those.  That'd be more
      likely to break the build than do anything helpful.  (Even the -D
      case is questionable; but we're doing that for libxml2, so I kept it.)
      
      Also, it's not okay to skip doing an AC_CHECK_LIB probe, as
      evidenced by recent build failure on topminnow; that should
      have been caught at configure time.
      
      Model fixes for this on configure's libxml2 support.
      
      It appears that somebody overlooked an autoheader run, too.
      
      Discussion: https://postgr.es/m/20210119190720.GL8560@telsasoft.com
      4d399a6f
    • Tom Lane's avatar
      Make compression.sql regression test independent of default. · fd1ac9a5
      Tom Lane authored
      This test will fail in "make installcheck" if the installation's
      default_toast_compression setting is not 'pglz'.  Make it robust
      against that situation.
      
      Dilip Kumar
      
      Discussion: https://postgr.es/m/CAFiTN-t0w+Rc2U3S+y=7KWcLuOYNB5MfWeGdNa7+pg0UovVdcQ@mail.gmail.com
      fd1ac9a5
    • Andrew Dunstan's avatar
      Don't run recover crash_temp_files test in Windows perl · ef823873
      Andrew Dunstan authored
      This reverts commit 677271a3.
      "Unbreak recovery test on Windows"
      
      The test hangs on Windows, and attempts to remedy the problem have
      proved fragile at best. So we simply disable the test on Windows perl.
      (Msys perl seems perfectly happy).
      
      Discussion: https://postgr.es/m/5b748470-7335-5439-e876-6a88c951e1c5@dunslane.net
      ef823873
    • Alvaro Herrera's avatar
      Fix new memory leaks in libpq · 2b526ed2
      Alvaro Herrera authored
      My oversight in commit 9aa491ab.
      
      Per coverity.
      2b526ed2
    • Andrew Dunstan's avatar
      Unbreak recovery test on Windows · 677271a3
      Andrew Dunstan authored
      On Windows we need to send explicit quit messages to psql or the TAP tests
      can hang.
      677271a3
    • Tom Lane's avatar
      Suppress various new compiler warnings. · 9fb9691a
      Tom Lane authored
      Compilers that don't understand that elog(ERROR) doesn't return
      issued warnings here.  In the cases in libpq_pipeline.c, we were
      not exactly helping things by failing to mark pg_fatal() as noreturn.
      
      Per buildfarm.
      9fb9691a
    • Peter Eisentraut's avatar
      Move lwlock-release probe back where it belongs · 96ae658e
      Peter Eisentraut authored
      The documentation specifically states that lwlock-release fires before
      any released waiters have been awakened.  It worked that way until
      ab5194e6, where is seems to have been
      misplaced accidentally.  Move it back where it belongs.
      
      Author: Craig Ringer <craig.ringer@enterprisedb.com>
      Discussion: https://www.postgresql.org/message-id/CAGRY4nwxKUS_RvXFW-ugrZBYxPFFM5kjwKT5O+0+Stuga5b4+Q@mail.gmail.com
      96ae658e
  3. 20 Mar, 2021 4 commits
    • Tomas Vondra's avatar
      Use valid compression method in brin_form_tuple · 882b2cdc
      Tomas Vondra authored
      When compressing the BRIN summary, we can't simply use the compression
      method from the indexed attribute.  The summary may use a different data
      type, e.g. fixed-length attribute may have varlena summary, leading to
      compression failures.  For the built-in BRIN opclasses this happens to
      work, because the summary uses the same data type as the attribute.
      
      When the data types match, we can inherit use the compression method
      specified for the attribute (it's copied into the index descriptor).
      Otherwise we don't have much choice and have to use the default one.
      
      Author: Tomas Vondra
      Reviewed-by: default avatarJustin Pryzby <pryzby@telsasoft.com>
      Discussion: https://postgr.es/m/e0367f27-392c-321a-7411-a58e1a7e4817%40enterprisedb.com
      882b2cdc
    • Tom Lane's avatar
      Fix up pg_dump's handling of per-attribute compression options. · aa25d108
      Tom Lane authored
      The approach used in commit bbe0a81d would've been disastrous for
      portability of dumps.  Instead handle non-default compression options
      in separate ALTER TABLE commands.  This reduces chatter for the
      common case where most columns are compressed the same way, and it
      makes it possible to restore the dump to a server that lacks any
      knowledge of per-attribute compression options (so long as you're
      willing to ignore syntax errors from the ALTER TABLE commands).
      
      There's a whole lot left to do to mop up after bbe0a81d, but
      I'm fast-tracking this part because we need to see if it's
      enough to make the buildfarm's cross-version-upgrade tests happy.
      
      Justin Pryzby and Tom Lane
      
      Discussion: https://postgr.es/m/20210119190720.GL8560@telsasoft.com
      aa25d108
    • Tom Lane's avatar
      Fix memory leak when rejecting bogus DH parameters. · e835e89a
      Tom Lane authored
      While back-patching e0e569e1, I noted that there were some other
      places where we ought to be applying DH_free(); namely, where we
      load some DH parameters from a file and then reject them as not
      being sufficiently secure.  While it seems really unlikely that
      anybody would hit these code paths in production, let alone do
      so repeatedly, let's fix it for consistency.
      
      Back-patch to v10 where this code was introduced.
      
      Discussion: https://postgr.es/m/16160-18367e56e9a28264@postgresql.org
      e835e89a
    • Tom Lane's avatar
      Avoid leaking memory in RestoreGUCState(), and improve comments. · f0c2a5bb
      Tom Lane authored
      RestoreGUCState applied InitializeOneGUCOption to already-live
      GUC entries, causing any malloc'd subsidiary data to be forgotten.
      We do want the effect of resetting the GUC to its compiled-in
      default, and InitializeOneGUCOption seems like the best way to do
      that, so add code to free any existing subsidiary data beforehand.
      
      The interaction between can_skip_gucvar, SerializeGUCState, and
      RestoreGUCState is way more subtle than their opaque comments
      would suggest to an unwary reader.  Rewrite and enlarge the
      comments to try to make it clearer what's happening.
      
      Remove a long-obsolete assertion in read_nondefault_variables: the
      behavior of set_config_option hasn't depended on IsInitProcessingMode
      since f5d9698a installed a better way of controlling it.
      
      Although this is fixing a clear memory leak, the leak is quite unlikely
      to involve any large amount of data, and it can only happen once in the
      lifetime of a worker process.  So it seems unnecessary to take any
      risk of back-patching.
      
      Discussion: https://postgr.es/m/4105247.1616174862@sss.pgh.pa.us
      f0c2a5bb
  4. 19 Mar, 2021 14 commits
    • Thomas Munro's avatar
      Provide recovery_init_sync_method=syncfs. · 61752afb
      Thomas Munro authored
      Since commit 2ce439f3 we have opened every file in the data directory
      and called fsync() at the start of crash recovery.  This can be very
      slow if there are many files, leading to field complaints of systems
      taking minutes or even hours to begin crash recovery.
      
      Provide an alternative method, for Linux only, where we call syncfs() on
      every possibly different filesystem under the data directory.  This is
      equivalent, but avoids faulting in potentially many inodes from
      potentially slow storage.
      
      The new mode comes with some caveats, described in the documentation, so
      the default value for the new setting is "fsync", preserving the older
      behavior.
      Reported-by: default avatarMichael Brown <michael.brown@discourse.org>
      Reviewed-by: default avatarFujii Masao <masao.fujii@oss.nttdata.com>
      Reviewed-by: default avatarPaul Guo <guopa@vmware.com>
      Reviewed-by: default avatarBruce Momjian <bruce@momjian.us>
      Reviewed-by: default avatarJustin Pryzby <pryzby@telsasoft.com>
      Reviewed-by: default avatarDavid Steele <david@pgmasters.net>
      Discussion: https://postgr.es/m/11bc2bb7-ecb5-3ad0-b39f-df632734cd81%40discourse.org
      Discussion: https://postgr.es/m/CAEET0ZHGnbXmi8yF3ywsDZvb3m9CbdsGZgfTXscQ6agcbzcZAw%40mail.gmail.com
      61752afb
    • Tomas Vondra's avatar
      Use lfirst_int in cmp_list_len_contents_asc · b822ae13
      Tomas Vondra authored
      The function added in be45be9c is comparing integer lists (IntList) by
      length and contents, but there were two bugs.  Firstly, it used intVal()
      to extract the value, but that's for Value nodes, not for extracting int
      values from IntList.  Secondly, it called it directly on the ListCell,
      without doing lfirst().  So just do lfirst_int() instead.
      
      Interestingly enough, this did not cause any crashes on the buildfarm,
      but valgrind rightfully complained about it.
      
      Discussion: https://postgr.es/m/bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org
      b822ae13
    • Robert Haas's avatar
      Fix use-after-ReleaseSysCache problem in ATExecAlterColumnType. · d00fbdc4
      Robert Haas authored
      Introduced by commit bbe0a81d.
      
      Per buildfarm member prion.
      d00fbdc4
    • Robert Haas's avatar
      Allow configurable LZ4 TOAST compression. · bbe0a81d
      Robert Haas authored
      There is now a per-column COMPRESSION option which can be set to pglz
      (the default, and the only option in up until now) or lz4. Or, if you
      like, you can set the new default_toast_compression GUC to lz4, and
      then that will be the default for new table columns for which no value
      is specified. We don't have lz4 support in the PostgreSQL code, so
      to use lz4 compression, PostgreSQL must be built --with-lz4.
      
      In general, TOAST compression means compression of individual column
      values, not the whole tuple, and those values can either be compressed
      inline within the tuple or compressed and then stored externally in
      the TOAST table, so those properties also apply to this feature.
      
      Prior to this commit, a TOAST pointer has two unused bits as part of
      the va_extsize field, and a compessed datum has two unused bits as
      part of the va_rawsize field. These bits are unused because the length
      of a varlena is limited to 1GB; we now use them to indicate the
      compression type that was used. This means we only have bit space for
      2 more built-in compresison types, but we could work around that
      problem, if necessary, by introducing a new vartag_external value for
      any further types we end up wanting to add. Hopefully, it won't be
      too important to offer a wide selection of algorithms here, since
      each one we add not only takes more coding but also adds a build
      dependency for every packager. Nevertheless, it seems worth doing
      at least this much, because LZ4 gets better compression than PGLZ
      with less CPU usage.
      
      It's possible for LZ4-compressed datums to leak into composite type
      values stored on disk, just as it is for PGLZ. It's also possible for
      LZ4-compressed attributes to be copied into a different table via SQL
      commands such as CREATE TABLE AS or INSERT .. SELECT.  It would be
      expensive to force such values to be decompressed, so PostgreSQL has
      never done so. For the same reasons, we also don't force recompression
      of already-compressed values even if the target table prefers a
      different compression method than was used for the source data.  These
      architectural decisions are perhaps arguable but revisiting them is
      well beyond the scope of what seemed possible to do as part of this
      project.  However, it's relatively cheap to recompress as part of
      VACUUM FULL or CLUSTER, so this commit adjusts those commands to do
      so, if the configured compression method of the table happens not to
      match what was used for some column value stored therein.
      
      Dilip Kumar. The original patches on which this work was based were
      written by Ildus Kurbangaliev, and those were patches were based on
      even earlier work by Nikita Glukhov, but the design has since changed
      very substantially, since allow a potentially large number of
      compression methods that could be added and dropped on a running
      system proved too problematic given some of the architectural issues
      mentioned above; the choice of which specific compression method to
      add first is now different; and a lot of the code has been heavily
      refactored.  More recently, Justin Przyby helped quite a bit with
      testing and reviewing and this version also includes some code
      contributions from him. Other design input and review from Tomas
      Vondra, Álvaro Herrera, Andres Freund, Oleg Bartunov, Alexander
      Korotkov, and me.
      
      Discussion: http://postgr.es/m/20170907194236.4cefce96%40wp.localdomain
      Discussion: http://postgr.es/m/CAFiTN-uUpX3ck%3DK0mLEk-G_kUQY%3DSNOTeqdaNRR9FMdQrHKebw%40mail.gmail.com
      bbe0a81d
    • Tomas Vondra's avatar
      Fix race condition in remove_temp_files_after_crash TAP test · e589c489
      Tomas Vondra authored
      The TAP test was written so that it was not waiting for the correct SQL
      command, but for output from the preceding one.  This resulted in race
      conditions, allowing the commands to run in a different order, not block
      as expected and so on.  This fixes it by inverting the order of commands
      where possible, so that observing the output guarantees the data was
      inserted properly, and waiting for a lock to appear in pg_locks.
      
      Discussion: https://postgr.es/m/CAH503wDKdYzyq7U-QJqGn%3DGm6XmoK%2B6_6xTJ-Yn5WSvoHLY1Ww%40mail.gmail.com
      e589c489
    • Tom Lane's avatar
      Blindly try to fix test script's tar invocation for MSYS. · 27ab1981
      Tom Lane authored
      Buildfarm member fairywren doesn't like the test case I added
      in commit 081876d7.  I'm guessing the reason is that I shouldn't
      be using a perl2host-ified path in the tar command line.
      27ab1981
    • Fujii Masao's avatar
      Fix comments in postmaster.c. · fd312140
      Fujii Masao authored
      Commit 86c23a6e changed the option to specify that postgres will
      stop all other server processes by sending the signal SIGSTOP,
      from -s to -T. But previously there were comments incorrectly
      explaining that SIGSTOP behavior is set by -s option. This commit
      fixes them.
      
      Author: Kyotaro Horiguchi
      Reviewed-by: Fujii Masao
      Discussion: https://postgr.es/m/20210316.165141.1400441966284654043.horikyota.ntt@gmail.com
      fd312140
    • Tom Lane's avatar
      Don't leak malloc'd error string in libpqrcv_check_conninfo(). · 9bacdf9f
      Tom Lane authored
      We leaked the error report from PQconninfoParse, when there was
      one.  It seems unlikely that real usage patterns would repeat
      the failure often enough to create serious bloat, but let's
      back-patch anyway to keep the code similar in all branches.
      
      Found via valgrind testing.
      Back-patch to v10 where this code was added.
      
      Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
      9bacdf9f
    • Tom Lane's avatar
      Don't leak malloc'd strings when a GUC setting is rejected. · 377b7a83
      Tom Lane authored
      Because guc.c prefers to keep all its string values in malloc'd
      not palloc'd storage, it has to be more careful than usual to
      avoid leaks.  Error exits out of string GUC hook checks failed
      to clear the proposed value string, and error exits out of
      ProcessGUCArray() failed to clear the malloc'd results of
      ParseLongOption().
      
      Found via valgrind testing.
      This problem is ancient, so back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
      377b7a83
    • Tom Lane's avatar
      Don't leak compiled regex(es) when an ispell cache entry is dropped. · d303849b
      Tom Lane authored
      The text search cache mechanisms assume that we can clean up
      an invalidated dictionary cache entry simply by resetting the
      associated long-lived memory context.  However, that does not work
      for ispell affixes that make use of regular expressions, because
      the regex library deals in plain old malloc.  Hence, we leaked
      compiled regex(es) any time we dropped such a cache entry.  That
      could quickly add up, since even a fairly trivial regex can use up
      tens of kB, and a large one can eat megabytes.  Add a memory context
      callback to ensure that a regex gets freed when its owning cache
      entry is cleared.
      
      Found via valgrind testing.
      This problem is ancient, so back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
      d303849b
    • Tom Lane's avatar
      Don't run RelationInitTableAccessMethod in a long-lived context. · 415ffdc2
      Tom Lane authored
      Some code paths in this function perform syscache lookups, which
      can lead to table accesses and possibly leakage of cruft into
      the caller's context.  If said context is CacheMemoryContext,
      we eventually will have visible bloat.  But fixing this is no
      harder than moving one memory context switch step.  (The other
      callers don't have a problem.)
      
      Andres Freund and I independently found this via valgrind testing.
      Back-patch to v12 where this code was added.
      
      Discussion: https://postgr.es/m/20210317023101.anvejcfotwka6gaa@alap3.anarazel.de
      Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
      415ffdc2
    • Tom Lane's avatar
      Don't leak rd_statlist when a relcache entry is dropped. · 28644fac
      Tom Lane authored
      Although these lists are usually NIL, and even when not empty
      are unlikely to be large, constant relcache update traffic could
      eventually result in visible bloat of CacheMemoryContext.
      
      Found via valgrind testing.
      Back-patch to v10 where this field was added.
      
      Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
      28644fac
    • Tomas Vondra's avatar
      Fix TAP test for remove_temp_files_after_crash · a16b2b96
      Tomas Vondra authored
      The test included in cd91de0d had two simple flaws.
      
      Firstly, the number of rows was low and on some platforms (e.g. 32-bit)
      the sort did not require on-disk sort, so on those machines it was not
      testing the automatic removal.  The test was however failing, because
      without any temporary files the base/pgsql_tmp directory was not even
      created.  Fixed by increasing the rowcount to 5000, which should be high
      engough on any platform.
      
      Secondly, the test used a simple sleep to wait for the temporary file to
      be created.  This is obviously problematic, because on slow machines (or
      with valgrind, CLOBBER_CACHE_ALWAYS etc.) it may take a while to create
      the temporary file.  But we also want the tests run reasonably fast.
      Fixed by instead relying on a UNIQUE constraint, blocking the query that
      created the temporary file.
      
      Author: Euler Taveira
      Reviewed-by: Tomas Vondra
      Discussion: https://postgr.es/m/CAH503wDKdYzyq7U-QJqGn%3DGm6XmoK%2B6_6xTJ-Yn5WSvoHLY1Ww%40mail.gmail.com
      a16b2b96
    • Michael Paquier's avatar
      Improve tab completion of IMPORT FOREIGN SCHEMA with \h in psql · 5b2266e3
      Michael Paquier authored
      Only "IMPORT" was showing as result of the completion, while IMPORT
      FOREIGN SCHEMA is the only command using this keyword in first
      position.  This changes the completion to show the full command name
      instead of just "IMPORT".
      
      Reviewed-by: Georgios Kokolatos, Julien Rouhaud
      Discussion: https://postgr.es/m/YFL6JneBiuMWYyoh@paquier.xyz
      5b2266e3
  5. 18 Mar, 2021 2 commits
    • Tom Lane's avatar
      Fix misuse of foreach_delete_current(). · 1d581ce7
      Tom Lane authored
      Our coding convention requires this macro's result to be assigned
      back to the original List variable.  In this usage, since the
      List could not become empty, there was no actual bug --- but
      some compilers warned about it.  Oversight in be45be9c.
      
      Discussion: https://postgr.es/m/35077b31-2d62-1e31-0e2e-ddb52d590b73@enterprisedb.com
      1d581ce7
    • Tomas Vondra's avatar
      Implement GROUP BY DISTINCT · be45be9c
      Tomas Vondra authored
      With grouping sets, it's possible that some of the grouping sets are
      duplicate.  This is especially common with CUBE and ROLLUP clauses. For
      example GROUP BY CUBE (a,b), CUBE (b,c) is equivalent to
      
        GROUP BY GROUPING SETS (
          (a, b, c),
          (a, b, c),
          (a, b, c),
          (a, b),
          (a, b),
          (a, b),
          (a),
          (a),
          (a),
          (c, a),
          (c, a),
          (c, a),
          (c),
          (b, c),
          (b),
          ()
        )
      
      Some of the grouping sets are calculated multiple times, which is mostly
      unnecessary.  This commit implements a new GROUP BY DISTINCT feature, as
      defined in the SQL standard, which eliminates the duplicate sets.
      
      Author: Vik Fearing
      Reviewed-by: Erik Rijkers, Georgios Kokolatos, Tomas Vondra
      Discussion: https://postgr.es/m/bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org
      be45be9c