1. 19 Jul, 2021 1 commit
  2. 28 Jun, 2021 1 commit
  3. 25 Jun, 2021 1 commit
  4. 16 Jun, 2021 1 commit
    • Tom Lane's avatar
      Improve SQLSTATE reporting in some replication-related code. · 6b787d9e
      Tom Lane authored
      I started out with the goal of reporting ERRCODE_CONNECTION_FAILURE
      when walrcv_connect() fails, but as I looked around I realized that
      whoever wrote this code was of the opinion that errcodes are purely
      optional.  That's not my understanding of our project policy.  Hence,
      make sure that an errcode is provided in each ereport that (a) is
      ERROR or higher level and (b) isn't arguably an internal logic error.
      Also fix some very dubious existing errcode assignments.
      
      While this is not per policy, it's also largely cosmetic, since few
      of these cases could get reported to applications.  So I don't
      feel a need to back-patch.
      
      Discussion: https://postgr.es/m/2189704.1623512522@sss.pgh.pa.us
      6b787d9e
  5. 12 May, 2021 1 commit
    • Tom Lane's avatar
      Initial pgindent and pgperltidy run for v14. · def5b065
      Tom Lane authored
      Also "make reformat-dat-files".
      
      The only change worthy of note is that pgindent messed up the formatting
      of launcher.c's struct LogicalRepWorkerId, which led me to notice that
      that struct wasn't used at all anymore, so I just took it out.
      def5b065
  6. 07 May, 2021 1 commit
  7. 06 Apr, 2021 1 commit
  8. 31 Mar, 2021 1 commit
  9. 17 Feb, 2021 1 commit
  10. 15 Feb, 2021 1 commit
  11. 12 Feb, 2021 1 commit
    • Amit Kapila's avatar
      Allow multiple xacts during table sync in logical replication. · ce0fdbfe
      Amit Kapila authored
      For the initial table data synchronization in logical replication, we use
      a single transaction to copy the entire table and then synchronize the
      position in the stream with the main apply worker.
      
      There are multiple downsides of this approach: (a) We have to perform the
      entire copy operation again if there is any error (network breakdown,
      error in the database operation, etc.) while we synchronize the WAL
      position between tablesync worker and apply worker; this will be onerous
      especially for large copies, (b) Using a single transaction in the
      synchronization-phase (where we can receive WAL from multiple
      transactions) will have the risk of exceeding the CID limit, (c) The slot
      will hold the WAL till the entire sync is complete because we never commit
      till the end.
      
      This patch solves all the above downsides by allowing multiple
      transactions during the tablesync phase. The initial copy is done in a
      single transaction and after that, we commit each transaction as we
      receive. To allow recovery after any error or crash, we use a permanent
      slot and origin to track the progress. The slot and origin will be removed
      once we finish the synchronization of the table. We also remove slot and
      origin of tablesync workers if the user performs DROP SUBSCRIPTION .. or
      ALTER SUBSCRIPTION .. REFERESH and some of the table syncs are still not
      finished.
      
      The commands ALTER SUBSCRIPTION ... REFRESH PUBLICATION and
      ALTER SUBSCRIPTION ... SET PUBLICATION ... with refresh option as true
      cannot be executed inside a transaction block because they can now drop
      the slots for which we have no provision to rollback.
      
      This will also open up the path for logical replication of 2PC
      transactions on the subscriber side. Previously, we can't do that because
      of the requirement of maintaining a single transaction in tablesync
      workers.
      
      Bump catalog version due to change of state in the catalog
      (pg_subscription_rel).
      
      Author: Peter Smith, Amit Kapila, and Takamichi Osumi
      Reviewed-by: Ajin Cherian, Petr Jelinek, Hou Zhijie and Amit Kapila
      Discussion: https://postgr.es/m/CAA4eK1KHJxaZS-fod-0fey=0tq3=Gkn4ho=8N4-5HWiCfu0H1A@mail.gmail.com
      ce0fdbfe
  12. 10 Feb, 2021 1 commit
    • Amit Kapila's avatar
      Make pg_replication_origin_drop safe against concurrent drops. · cd142e03
      Amit Kapila authored
      Currently, we get the origin id from the name and then drop the origin by
      taking ExclusiveLock on ReplicationOriginRelationId. So, two concurrent
      sessions can get the id from the name at the same time and then when they
      try to drop the origin, one of the sessions will get the either
      "tuple concurrently deleted" or "cache lookup failed for replication
      origin ..".
      
      To prevent this race condition we do the entire operation under lock. This
      obviates the need for replorigin_drop() API and we have removed it so if
      any extension authors are using it they need to instead use
      replorigin_drop_by_name. See it's usage in pg_replication_origin_drop().
      
      Author: Peter Smith
      Reviewed-by: Amit Kapila, Euler Taveira, Petr Jelinek, and Alvaro
      Herrera
      Discussion: https://www.postgresql.org/message-id/CAHut%2BPuW8DWV5fskkMWWMqzt-x7RPcNQOtJQBp6SdwyRghCk7A%40mail.gmail.com
      cd142e03
  13. 16 Jan, 2021 1 commit
  14. 02 Jan, 2021 1 commit
  15. 03 Sep, 2020 1 commit
    • Amit Kapila's avatar
      Add support for streaming to built-in logical replication. · 46482432
      Amit Kapila authored
      To add support for streaming of in-progress transactions into the
      built-in logical replication, we need to do three things:
      
      * Extend the logical replication protocol, so identify in-progress
      transactions, and allow adding additional bits of information (e.g.
      XID of subtransactions).
      
      * Modify the output plugin (pgoutput) to implement the new stream
      API callbacks, by leveraging the extended replication protocol.
      
      * Modify the replication apply worker, to properly handle streamed
      in-progress transaction by spilling the data to disk and then
      replaying them on commit.
      
      We however must explicitly disable streaming replication during
      replication slot creation, even if the plugin supports it. We
      don't need to replicate the changes accumulated during this phase,
      and moreover we don't have a replication connection open so we
      don't have where to send the data anyway.
      
      Author: Tomas Vondra, Dilip Kumar and Amit Kapila
      Reviewed-by: Amit Kapila, Kuntal Ghosh and Ajin Cherian
      Tested-by: Neha Sharma, Mahendra Singh Thalor and Ajin Cherian
      Discussion: https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com
      46482432
  16. 18 Jul, 2020 1 commit
  17. 06 May, 2020 1 commit
    • Alvaro Herrera's avatar
      Heed lock protocol in DROP OWNED BY · 5be594ca
      Alvaro Herrera authored
      We were acquiring object locks then deleting objects one by one, instead
      of acquiring all object locks first, ignoring those that did not exist,
      and then deleting all objects together.   The latter is the correct
      protocol to use, and what this commits changes to code to do.  Failing
      to follow that leads to "cache lookup failed for relation XYZ" error
      reports when DROP OWNED runs concurrently with other DDL -- for example,
      a session termination that removes some temp tables.
      
      Author: Álvaro Herrera
      Reported-by: Mithun Chicklore Yogendra (Mithun CY)
      Reviewed-by: Ahsan Hadi, Tom Lane
      Discussion: https://postgr.es/m/CADq3xVZTbzK4ZLKq+dn_vB4QafXXbmMgDP3trY-GuLnib2Ai1w@mail.gmail.com
      5be594ca
  18. 10 Mar, 2020 1 commit
  19. 04 Mar, 2020 1 commit
    • Tom Lane's avatar
      Introduce macros for typalign and typstorage constants. · 3ed2005f
      Tom Lane authored
      Our usual practice for "poor man's enum" catalog columns is to define
      macros for the possible values and use those, not literal constants,
      in C code.  But for some reason lost in the mists of time, this was
      never done for typalign/attalign or typstorage/attstorage.  It's never
      too late to make it better though, so let's do that.
      
      The reason I got interested in this right now is the need to duplicate
      some uses of the TYPSTORAGE constants in an upcoming ALTER TYPE patch.
      But in general, this sort of change aids greppability and readability,
      so it's a good idea even without any specific motivation.
      
      I may have missed a few places that could be converted, and it's even
      more likely that pending patches will re-introduce some hard-coded
      references.  But that's not fatal --- there's no expectation that
      we'd actually change any of these values.  We can clean up stragglers
      over time.
      
      Discussion: https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
      3ed2005f
  20. 30 Jan, 2020 1 commit
  21. 11 Jan, 2020 1 commit
  22. 01 Jan, 2020 1 commit
  23. 12 Nov, 2019 1 commit
  24. 01 Nov, 2019 1 commit
  25. 29 Jun, 2019 1 commit
    • Tom Lane's avatar
      Add an enforcement mechanism for global object names in regression tests. · 54100f5c
      Tom Lane authored
      In commit 18555b13 we tentatively established a rule that regression
      tests should use names containing "regression" for databases, and names
      starting with "regress_" for all other globally-visible object names, so
      as to circumscribe the side-effects that "make installcheck" could have
      on an existing installation.
      
      This commit adds a simple enforcement mechanism for that rule: if the code
      is compiled with ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS defined, it
      will emit a warning (not an error) whenever a database, role, tablespace,
      subscription, or replication origin name is created that doesn't obey the
      rule.  Running one or more buildfarm members with that symbol defined
      should be enough to catch new violations, at least in the regular
      regression tests.  Most TAP tests wouldn't notice such warnings, but
      that's actually fine because TAP tests don't execute against an existing
      server anyway.
      
      Since it's already the case that running src/test/modules/ tests in
      installcheck mode is deprecated, we can use that as a home for tests
      that seem unsafe to run against an existing server, such as tests that
      might have side-effects on existing roles.  Document that (though this
      commit doesn't in itself make it any less safe than before).
      
      Update regress.sgml to define these restrictions more clearly, and
      to clean up assorted lack-of-up-to-date-ness in its descriptions of
      the available regression tests.
      
      Discussion: https://postgr.es/m/16638.1468620817@sss.pgh.pa.us
      54100f5c
  26. 28 May, 2019 1 commit
  27. 16 May, 2019 1 commit
  28. 21 Jan, 2019 2 commits
  29. 02 Jan, 2019 1 commit
  30. 21 Nov, 2018 1 commit
    • Andres Freund's avatar
      Remove WITH OIDS support, change oid catalog column visibility. · 578b2297
      Andres Freund authored
      Previously tables declared WITH OIDS, including a significant fraction
      of the catalog tables, stored the oid column not as a normal column,
      but as part of the tuple header.
      
      This special column was not shown by default, which was somewhat odd,
      as it's often (consider e.g. pg_class.oid) one of the more important
      parts of a row.  Neither pg_dump nor COPY included the contents of the
      oid column by default.
      
      The fact that the oid column was not an ordinary column necessitated a
      significant amount of special case code to support oid columns. That
      already was painful for the existing, but upcoming work aiming to make
      table storage pluggable, would have required expanding and duplicating
      that "specialness" significantly.
      
      WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
      Remove it.
      
      Removing includes:
      - CREATE TABLE and ALTER TABLE syntax for declaring the table to be
        WITH OIDS has been removed (WITH (oids[ = true]) will error out)
      - pg_dump does not support dumping tables declared WITH OIDS and will
        issue a warning when dumping one (and ignore the oid column).
      - restoring an pg_dump archive with pg_restore will warn when
        restoring a table with oid contents (and ignore the oid column)
      - COPY will refuse to load binary dump that includes oids.
      - pg_upgrade will error out when encountering tables declared WITH
        OIDS, they have to be altered to remove the oid column first.
      - Functionality to access the oid of the last inserted row (like
        plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
      
      The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
      for CREATE TABLE) is still supported. While that requires a bit of
      support code, it seems unnecessary to break applications / dumps that
      do not use oids, and are explicit about not using them.
      
      The biggest user of WITH OID columns was postgres' catalog. This
      commit changes all 'magic' oid columns to be columns that are normally
      declared and stored. To reduce unnecessary query breakage all the
      newly added columns are still named 'oid', even if a table's column
      naming scheme would indicate 'reloid' or such.  This obviously
      requires adapting a lot code, mostly replacing oid access via
      HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
      
      The bootstrap process now assigns oids for all oid columns in
      genbki.pl that do not have an explicit value (starting at the largest
      oid previously used), only oids assigned later by oids will be above
      FirstBootstrapObjectId. As the oid column now is a normal column the
      special bootstrap syntax for oids has been removed.
      
      Oids are not automatically assigned during insertion anymore, all
      backend code explicitly assigns oids with GetNewOidWithIndex(). For
      the rare case that insertions into the catalog via SQL are called for
      the new pg_nextoid() function can be used (which only works on catalog
      tables).
      
      The fact that oid columns on system tables are now normal columns
      means that they will be included in the set of columns expanded
      by * (i.e. SELECT * FROM pg_class will now include the table's oid,
      previously it did not). It'd not technically be hard to hide oid
      column by default, but that'd mean confusing behavior would either
      have to be carried forward forever, or it'd cause breakage down the
      line.
      
      While it's not unlikely that further adjustments are needed, the
      scope/invasiveness of the patch makes it worthwhile to get merge this
      now. It's painful to maintain externally, too complicated to commit
      after the code code freeze, and a dependency of a number of other
      patches.
      
      Catversion bump, for obvious reasons.
      
      Author: Andres Freund, with contributions by John Naylor
      Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
      578b2297
  31. 16 Nov, 2018 1 commit
    • Andres Freund's avatar
      Introduce notion of different types of slots (without implementing them). · 1a0586de
      Andres Freund authored
      Upcoming work intends to allow pluggable ways to introduce new ways of
      storing table data. Accessing those table access methods from the
      executor requires TupleTableSlots to be carry tuples in the native
      format of such storage methods; otherwise there'll be a significant
      conversion overhead.
      
      Different access methods will require different data to store tuples
      efficiently (just like virtual, minimal, heap already require fields
      in TupleTableSlot). To allow that without requiring additional pointer
      indirections, we want to have different structs (embedding
      TupleTableSlot) for different types of slots.  Thus different types of
      slots are needed, which requires adapting creators of slots.
      
      The slot that most efficiently can represent a type of tuple in an
      executor node will often depend on the type of slot a child node
      uses. Therefore we need to track the type of slot is returned by
      nodes, so parent slots can create slots based on that.
      
      Relatedly, JIT compilation of tuple deforming needs to know which type
      of slot a certain expression refers to, so it can create an
      appropriate deforming function for the type of tuple in the slot.
      
      But not all nodes will only return one type of slot, e.g. an append
      node will potentially return different types of slots for each of its
      subplans.
      
      Therefore add function that allows to query the type of a node's
      result slot, and whether it'll always be the same type (whether it's
      fixed). This can be queried using ExecGetResultSlotOps().
      
      The scan, result, inner, outer type of slots are automatically
      inferred from ExecInitScanTupleSlot(), ExecInitResultSlot(),
      left/right subtrees respectively. If that's not correct for a node,
      that can be overwritten using new fields in PlanState.
      
      This commit does not introduce the actually abstracted implementation
      of different kind of TupleTableSlots, that will be left for a followup
      commit.  The different types of slots introduced will, for now, still
      use the same backing implementation.
      
      While this already partially invalidates the big comment in
      tuptable.h, it seems to make more sense to update it later, when the
      different TupleTableSlot implementations actually exist.
      
      Author: Ashutosh Bapat and Andres Freund, with changes by Amit Khandekar
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      1a0586de
  32. 06 Apr, 2018 1 commit
  33. 16 Mar, 2018 1 commit
  34. 19 Jan, 2018 1 commit
  35. 03 Jan, 2018 1 commit
  36. 13 Dec, 2017 1 commit
    • Tom Lane's avatar
      Rethink MemoryContext creation to improve performance. · 9fa6f00b
      Tom Lane authored
      This patch makes a number of interrelated changes to reduce the overhead
      involved in creating/deleting memory contexts.  The key ideas are:
      
      * Include the AllocSetContext header of an aset.c context in its first
      malloc request, rather than allocating it separately in TopMemoryContext.
      This means that we now always create an initial or "keeper" block in an
      aset, even if it never receives any allocation requests.
      
      * Create freelists in which we can save and recycle recently-destroyed
      asets (this idea is due to Robert Haas).
      
      * In the common case where the name of a context is a constant string,
      just store a pointer to it in the context header, rather than copying
      the string.
      
      The first change eliminates a palloc/pfree cycle per context, and
      also avoids bloat in TopMemoryContext, at the price that creating
      a context now involves a malloc/free cycle even if the context never
      receives any allocations.  That would be a loser for some common
      usage patterns, but recycling short-lived contexts via the freelist
      eliminates that pain.
      
      Avoiding copying constant strings not only saves strlen() and strcpy()
      overhead, but is an essential part of the freelist optimization because
      it makes the context header size constant.  Currently we make no
      attempt to use the freelist for contexts with non-constant names.
      (Perhaps someday we'll need to think harder about that, but in current
      usage, most contexts with custom names are long-lived anyway.)
      
      The freelist management in this initial commit is pretty simplistic,
      and we might want to refine it later --- but in common workloads that
      will never matter because the freelists will never get full anyway.
      
      To create a context with a non-constant name, one is now required to
      call AllocSetContextCreateExtended and specify the MEMCONTEXT_COPY_NAME
      option.  AllocSetContextCreate becomes a wrapper macro, and it includes
      a test that will complain about non-string-literal context name
      parameters on gcc and similar compilers.
      
      An unfortunate side effect of making AllocSetContextCreate a macro is
      that one is now *required* to use the size parameter abstraction macros
      (ALLOCSET_DEFAULT_SIZES and friends) with it; the pre-9.6 habit of
      writing out individual size parameters no longer works unless you
      switch to AllocSetContextCreateExtended.
      
      Internally to the memory-context-related modules, the context creation
      APIs are simplified, removing the rather baroque original design whereby
      a context-type module called mcxt.c which then called back into the
      context-type module.  That saved a bit of code duplication, but not much,
      and it prevented context-type modules from exercising control over the
      allocation of context headers.
      
      In passing, I converted the test-and-elog validation of aset size
      parameters into Asserts to save a few more cycles.  The original thought
      was that callers might compute size parameters on the fly, but in practice
      nobody does that, so it's useless to expend cycles on checking those
      numbers in production builds.
      
      Also, mark the memory context method-pointer structs "const",
      just for cleanliness.
      
      Discussion: https://postgr.es/m/2264.1512870796@sss.pgh.pa.us
      9fa6f00b
  37. 23 Sep, 2017 1 commit
  38. 18 Sep, 2017 1 commit
    • Peter Eisentraut's avatar
      Fix DROP SUBSCRIPTION hang · 8edacab2
      Peter Eisentraut authored
      When ALTER SUBSCRIPTION DISABLE is run in the same transaction before
      DROP SUBSCRIPTION, the latter will hang because workers will still be
      running, not having seen the DISABLE committed, and DROP SUBSCRIPTION
      will wait until the workers have vacated the replication origin slots.
      
      Previously, DROP SUBSCRIPTION killed the logical replication workers
      immediately only if it was going to drop the replication slot, otherwise
      it scheduled the worker killing for the end of the transaction, as a
      result of 7e174fa7.  This, however,
      causes the present problem.  To fix, kill the workers immediately in all
      cases.  This covers all cases: A subscription that doesn't have a
      replication slot must be disabled.  It was either disabled in the same
      transaction, or it was already disabled before the current transaction,
      but then there shouldn't be any workers left and this won't make a
      difference.
      Reported-by: default avatarArseny Sher <a.sher@postgrespro.ru>
      Discussion: https://www.postgresql.org/message-id/flat/87mv6av84w.fsf%40ars-thinkpad
      8edacab2
  39. 01 Sep, 2017 1 commit