1. 17 3月, 2016 1 次提交
    • R
      Fix problems in commit c16dc1ac. · bc55cc0b
      Robert Haas 提交于
      Vinayak Pokale provided a patch for a copy-and-paste error in a
      comment.  I noticed that I'd use the word "automatically" nearby where
      I meant to talk about things being "atomic".  Rahila Syed spotted a
      misplaced counter update.  Fix all that stuff.
      bc55cc0b
  2. 16 3月, 2016 1 次提交
    • R
      Add simple VACUUM progress reporting. · c16dc1ac
      Robert Haas 提交于
      There's a lot more that could be done here yet - in particular, this
      reports only very coarse-grained information about the index vacuuming
      phase - but even as it stands, the new pg_stat_progress_vacuum can
      tell you quite a bit about what a long-running vacuum is actually
      doing.
      
      Amit Langote and Robert Haas, based on earlier work by Vinayak Pokale
      and Rahila Syed.
      c16dc1ac
  3. 11 3月, 2016 1 次提交
    • R
      Provide much better wait information in pg_stat_activity. · 53be0b1a
      Robert Haas 提交于
      When a process is waiting for a heavyweight lock, we will now indicate
      the type of heavyweight lock for which it is waiting.  Also, you can
      now see when a process is waiting for a lightweight lock - in which
      case we will indicate the individual lock name or the tranche, as
      appropriate - or for a buffer pin.
      
      Amit Kapila, Ildus Kurbangaliev, reviewed by me.  Lots of helpful
      discussion and suggestions by many others, including Alexander
      Korotkov, Vladimir Borodin, and many others.
      53be0b1a
  4. 10 3月, 2016 2 次提交
    • R
      Code review for b6fb6471. · 090b287f
      Robert Haas 提交于
      Reports by Tomas Vondra, Vinayak Pokale, and Aleksander Alekseev.
      Patch by Amit Langote.
      090b287f
    • R
      Add a generic command progress reporting facility. · b6fb6471
      Robert Haas 提交于
      Using this facility, any utility command can report the target relation
      upon which it is operating, if there is one, and up to 10 64-bit
      counters; the intent of this is that users should be able to figure out
      what a utility command is doing without having to resort to ugly hacks
      like attaching strace to a backend.
      
      As a demonstration, this adds very crude reporting to lazy vacuum; we
      just report the target relation and nothing else.  A forthcoming patch
      will make VACUUM report a bunch of additional data that will make this
      much more interesting.  But this gets the basic framework in place.
      
      Vinayak Pokale, Rahila Syed, Amit Langote, Robert Haas, reviewed by
      Kyotaro Horiguchi, Jim Nasby, Thom Brown, Masahiko Sawada, Fujii Masao,
      and Masanori Oyama.
      b6fb6471
  5. 03 1月, 2016 1 次提交
  6. 28 7月, 2015 2 次提交
    • T
      Further code review for pg_stat_ssl patch. · 4c8f8ffa
      Tom Lane 提交于
      Fix additional bogosity in commit 9029f4b3.  Include the
      BackendSslStatusBuffer in the BackendStatusShmemSize calculation,
      avoid ugly and error-prone casts to char* and back, put related
      code stanzas into a consistent order (and fix a couple of previous
      instances of that sin).  All cosmetic except for the size oversight.
      4c8f8ffa
    • T
      Fix pointer-arithmetic thinko in pg_stat_ssl patch. · 7d791ed4
      Tom Lane 提交于
      Nasty memory-stomp bug in commit 9029f4b3.  It's not apparent how
      this survived even cursory testing :-(.  Per report from Peter Holzer.
      7d791ed4
  7. 24 5月, 2015 1 次提交
  8. 13 4月, 2015 1 次提交
    • M
      Add system view pg_stat_ssl · 9029f4b3
      Magnus Hagander 提交于
      This view shows information about all connections, such as if the
      connection is using SSL, which cipher is used, and which client
      certificate (if any) is used.
      
      Reviews by Alex Shulgin, Heikki Linnakangas, Andres Freund & Michael Paquier
      9029f4b3
  9. 27 3月, 2015 1 次提交
    • T
      Tweak __attribute__-wrapping macros for better pgindent results. · 785941cd
      Tom Lane 提交于
      This improves on commit bbfd7eda by
      making two simple changes:
      
      * pg_attribute_noreturn now takes parentheses, ie pg_attribute_noreturn().
      Likewise pg_attribute_unused(), pg_attribute_packed().  This reduces
      pgindent's tendency to misformat declarations involving them.
      
      * attributes are now always attached to function declarations, not
      definitions.  Previously some places were taking creative shortcuts,
      which were not merely candidates for bad misformatting by pgindent
      but often were outright wrong anyway.  (It does little good to put a
      noreturn annotation where callers can't see it.)  In any case, if
      we would like to believe that these macros can be used with non-gcc
      compilers, we should avoid gratuitous variance in usage patterns.
      
      I also went through and manually improved the formatting of a lot of
      declarations, and got rid of excessively repetitive (and now obsolete
      anyway) comments informing the reader what pg_attribute_printf is for.
      785941cd
  10. 11 3月, 2015 1 次提交
    • A
      Add macros wrapping all usage of gcc's __attribute__. · bbfd7eda
      Andres Freund 提交于
      Until now __attribute__() was defined to be empty for all compilers but
      gcc. That's problematic because it prevents using it in other compilers;
      which is necessary e.g. for atomics portability.  It's also just
      generally dubious to do so in a header as widely included as c.h.
      
      Instead add pg_attribute_format_arg, pg_attribute_printf,
      pg_attribute_noreturn macros which are implemented in the compilers that
      understand them. Also add pg_attribute_noreturn and pg_attribute_packed,
      but don't provide fallbacks, since they can affect functionality.
      
      This means that external code that, possibly unwittingly, relied on
      __attribute__ defined to be empty on !gcc compilers may now run into
      warnings or errors on those compilers. But there shouldn't be many
      occurances of that and it's hard to work around...
      
      Discussion: 54B58BA3.8040302@ohmu.fi
      Author: Oskari Saarenmaa, with some minor changes by me.
      bbfd7eda
  11. 20 2月, 2015 1 次提交
    • A
      Have TRUNCATE update pgstat tuple counters · d42358ef
      Alvaro Herrera 提交于
      This works by keeping a per-subtransaction record of the ins/upd/del
      counters before the truncate, and then resetting them; this record is
      useful to return to the previous state in case the truncate is rolled
      back, either in a subtransaction or whole transaction.  The state is
      propagated upwards as subtransactions commit.
      
      When the per-table data is sent to the stats collector, a flag indicates
      to reset the live/dead counters to zero as well.
      
      Catalog version bumped due to the change in pgstat format.
      
      Author: Alexander Shulgin
      Discussion: 1007.1207238291@sss.pgh.pa.us
      Discussion: 548F7D38.2000401@BlueTreble.com
      Reviewed-by: Álvaro Herrera, Jim Nasby
      d42358ef
  12. 25 1月, 2015 1 次提交
    • T
      Replace a bunch more uses of strncpy() with safer coding. · 586dd5d6
      Tom Lane 提交于
      strncpy() has a well-deserved reputation for being unsafe, so make an
      effort to get rid of nearly all occurrences in HEAD.
      
      A large fraction of the remaining uses were passing length less than or
      equal to the known strlen() of the source, in which case no null-padding
      can occur and the behavior is equivalent to memcpy(), though doubtless
      slower and certainly harder to reason about.  So just use memcpy() in
      these cases.
      
      In other cases, use either StrNCpy() or strlcpy() as appropriate (depending
      on whether padding to the full length of the destination buffer seems
      useful).
      
      I left a few strncpy() calls alone in the src/timezone/ code, to keep it
      in sync with upstream (the IANA tzcode distribution).  There are also a
      few such calls in ecpg that could possibly do with more analysis.
      
      AFAICT, none of these changes are more than cosmetic, except for the four
      occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength
      source leads to a non-null-terminated destination buffer and ensuing
      misbehavior.  These don't seem like security issues, first because no stack
      clobber is possible and second because if your values of sslcert etc are
      coming from untrusted sources then you've got problems way worse than this.
      Still, it's undesirable to have unpredictable behavior for overlength
      inputs, so back-patch those four changes to all active branches.
      586dd5d6
  13. 20 1月, 2015 1 次提交
    • T
      Adjust "pgstat wait timeout" message to be a translatable LOG message. · 75b48e1f
      Tom Lane 提交于
      Per discussion, change the log level of this message to be LOG not WARNING.
      The main point of this change is to avoid causing buildfarm run failures
      when the stats collector is exceptionally slow to respond, which it not
      infrequently is on some of the smaller/slower buildfarm members.
      
      This change does lose notice to an interactive user when his stats query
      is looking at out-of-date stats, but the majority opinion (not necessarily
      that of yours truly) is that WARNING messages would probably not get
      noticed anyway on heavily loaded production systems.  A LOG message at
      least ensures that the problem is recorded somewhere where bulk auditing
      for the issue is possible.
      
      Also, instead of an untranslated "pgstat wait timeout" message, provide
      a translatable and hopefully more understandable message "using stale
      statistics instead of current ones because stats collector is not
      responding".  The original text was written hastily under the assumption
      that it would never really happen in practice, which we now know to be
      unduly optimistic.
      
      Back-patch to all active branches, since we've seen the buildfarm issue
      in all branches.
      75b48e1f
  14. 15 1月, 2015 1 次提交
    • A
      Add a default local latch for use in signal handlers. · 59f71a0d
      Andres Freund 提交于
      To do so, move InitializeLatchSupport() into the new common process
      initialization functions, and add a new global variable MyLatch.
      
      MyLatch is usable as soon InitPostmasterChild() has been called
      (i.e. very early during startup). Initially it points to a process
      local latch that exists in all processes. InitProcess/InitAuxiliaryProcess
      then replaces that local latch with PGPROC->procLatch. During shutdown
      the reverse happens.
      
      This is primarily advantageous for two reasons: For one it simplifies
      dealing with the shared process latch, especially in signal handlers,
      because instead of having to check for MyProc, MyLatch can be used
      unconditionally. For another, a later patch that makes FEs/BE
      communication use latches, now can rely on the existence of a latch,
      even before having gone through InitProcess.
      
      Discussion: 20140927191243.GD5423@alap3.anarazel.de
      59f71a0d
  15. 14 1月, 2015 1 次提交
    • A
      Commonalize process startup code. · 31c45316
      Andres Freund 提交于
      Move common code, that was duplicated in every postmaster child/every
      standalone process, into two functions in miscinit.c.  Not only does
      that already result in a fair amount of net code reduction but it also
      makes it much easier to remove more duplication in the future. The
      prime motivation wasn't code deduplication though, but easier addition
      of new common code.
      31c45316
  16. 07 1月, 2015 1 次提交
  17. 19 12月, 2014 1 次提交
    • T
      Improve hash_create's API for selecting simple-binary-key hash functions. · 4a14f13a
      Tom Lane 提交于
      Previously, if you wanted anything besides C-string hash keys, you had to
      specify a custom hashing function to hash_create().  Nearly all such
      callers were specifying tag_hash or oid_hash; which is tedious, and rather
      error-prone, since a caller could easily miss the opportunity to optimize
      by using hash_uint32 when appropriate.  Replace this with a design whereby
      callers using simple binary-data keys just specify HASH_BLOBS and don't
      need to mess with specific support functions.  hash_create() itself will
      take care of optimizing when the key size is four bytes.
      
      This nets out saving a few hundred bytes of code space, and offers
      a measurable performance improvement in tidbitmap.c (which was not
      exploiting the opportunity to use hash_uint32 for its 4-byte keys).
      There might be some wins elsewhere too, I didn't analyze closely.
      
      In future we could look into offering a similar optimized hashing function
      for 8-byte keys.  Under this design that could be done in a centralized
      and machine-independent fashion, whereas getting it right for keys of
      platform-dependent sizes would've been notationally painful before.
      
      For the moment, the old way still works fine, so as not to break source
      code compatibility for loadable modules.  Eventually we might want to
      remove tag_hash and friends from the exported API altogether, since there's
      no real need for them to be explicitly referenced from outside dynahash.c.
      
      Teodor Sigaev and Tom Lane
      4a14f13a
  18. 18 12月, 2014 1 次提交
    • F
      Add memory barriers for PgBackendStatus.st_changecount protocol. · 38628db8
      Fujii Masao 提交于
      st_changecount protocol needs the memory barriers to ensure that
      the apparent order of execution is as it desires. Otherwise,
      for example, the CPU might rearrange the code so that st_changecount
      is incremented twice before the modification on a machine with
      weak memory ordering. This surprising result can lead to bugs.
      
      This commit introduces the macros to load and store st_changecount
      with the memory barriers. These are called before and after
      PgBackendStatus entries are modified or copied into private memory,
      in order to prevent CPU from reordering PgBackendStatus access.
      
      Per discussion on pgsql-hackers, we decided not to back-patch this
      to 9.4 or before until we get an actual bug report about this.
      
      Patch by me. Review by Robert Haas.
      38628db8
  19. 12 12月, 2014 1 次提交
    • T
      Fix assorted confusion between Oid and int32. · 06d5803f
      Tom Lane 提交于
      In passing, also make some debugging elog's in pgstat.c a bit more
      consistently worded.
      
      Back-patch as far as applicable (9.3 or 9.4; none of these mistakes are
      really old).
      
      Mark Dilger identified and patched the type violations; the message
      rewordings are mine.
      06d5803f
  20. 03 7月, 2014 1 次提交
    • K
      Smooth reporting of commit/rollback statistics. · ac46de56
      Kevin Grittner 提交于
      If a connection committed or rolled back any transactions within a
      PGSTAT_STAT_INTERVAL pacing interval without accessing any tables,
      the reporting of those statistics would be held up until the
      connection closed or until it ended a PGSTAT_STAT_INTERVAL interval
      in which it had accessed a table.  This could result in under-
      reporting of transactions for an extended period, followed by a
      spike in reported transactions.
      
      While this is arguably a bug, the impact is minimal, primarily
      affecting, and being affected by, monitoring software.  It might
      cause more confusion than benefit to change the existing behavior
      in released stable branches, so apply only to master and the 9.4
      beta.
      
      Gurjeet Singh, with review and editing by Kevin Grittner,
      incorporating suggested changes from Abhijit Menon-Sen and Tom
      Lane.
      ac46de56
  21. 04 6月, 2014 1 次提交
    • F
      Save pg_stat_statements statistics file into $PGDATA/pg_stat directory at shutdown. · 654e8e44
      Fujii Masao 提交于
      187492b6 changed pgstat.c so that
      the stats files were saved into $PGDATA/pg_stat directory when the server
      was shutdowned. But it accidentally forgot to change the location of
      pg_stat_statements permanent stats file. This commit fixes pg_stat_statements
      so that its stats file is also saved into $PGDATA/pg_stat at shutdown.
      
      Since this fix changes the file layout, we don't back-patch it to 9.3
      where this oversight was introduced.
      654e8e44
  22. 07 5月, 2014 1 次提交
    • B
      pgindent run for 9.4 · 0a783200
      Bruce Momjian 提交于
      This includes removing tabs after periods in C comments, which was
      applied to back branches, so this change should not effect backpatching.
      0a783200
  23. 17 4月, 2014 1 次提交
    • T
      Use AF_UNSPEC not PF_UNSPEC in getaddrinfo calls. · cad4fe64
      Tom Lane 提交于
      According to the Single Unix Spec and assorted man pages, you're supposed
      to use the constants named AF_xxx when setting ai_family for a getaddrinfo
      call.  In a few places we were using PF_xxx instead.  Use of PF_xxx
      appears to be an ancient BSD convention that was not adopted by later
      standardization.  On BSD and most later Unixen, it doesn't matter much
      because those constants have equivalent values anyway; but nonetheless
      this code is not per spec.
      
      In the same vein, replace PF_INET by AF_INET in one socket() call, which
      wasn't even consistent with the other socket() call in the same function
      let alone the remainder of our code.
      
      Per investigation of a Cygwin trouble report from Marco Atzeri.  It's
      probably a long shot that this will fix his issue, but it's wrong in
      any case.
      cad4fe64
  24. 02 4月, 2014 1 次提交
    • T
      Fix bugs in manipulation of PgBackendStatus.st_clienthostname. · 682c5bbe
      Tom Lane 提交于
      Initialization of this field was not being done according to the
      st_changecount protocol (it has to be done within the changecount increment
      range, not outside).  And the test to see if the value should be reported
      as null was wrong.  Noted while perusing uses of Port.remote_hostname.
      
      This was wrong from the introduction of this code (commit 4a25bc14),
      so back-patch to 9.1.
      682c5bbe
  25. 18 3月, 2014 1 次提交
    • R
      Make it easy to detach completely from shared memory. · 79a4d24f
      Robert Haas 提交于
      The new function dsm_detach_all() can be used either by postmaster
      children that don't wish to take any risk of accidentally corrupting
      shared memory; or by forked children of regular backends with
      the same need.  This patch also updates the postmaster children that
      already do PGSharedMemoryDetach() to do dsm_detach_all() as well.
      
      Per discussion with Tom Lane.
      79a4d24f
  26. 06 3月, 2014 1 次提交
    • A
      Remove the correct pgstat file on DROP DATABASE · 2b4f2ab3
      Alvaro Herrera 提交于
      We were unlinking the permanent file, not the non-permanent one.  But
      since the stat collector already unlinks all permanent files on startup,
      there was nothing for it to unlink.  The non-permanent file remained in
      place, and was copied to the permanent directory on shutdown, so in
      effect no file was ever dropped.
      
      Backpatch to 9.3, where the issue was introduced by commit 187492b6.
      Before that, there were no per-database files and thus no file to drop
      on DROP DATABASE.
      
      Per report from Thom Brown.
      
      Author: Tomáš Vondra
      2b4f2ab3
  27. 26 2月, 2014 1 次提交
  28. 29 1月, 2014 1 次提交
    • F
      Add pg_stat_archiver statistics view. · 9132b189
      Fujii Masao 提交于
      This view shows the statistics about the WAL archiver process's activity.
      
      Gabriele Bartolini, reviewed by Michael Paquier, refactored a bit by me.
      9132b189
  29. 19 1月, 2014 1 次提交
    • T
      Fix VACUUM's reporting of dead-tuple counts to the stats collector. · 115f4141
      Tom Lane 提交于
      Historically, VACUUM has just reported its new_rel_tuples estimate
      (the same thing it puts into pg_class.reltuples) to the stats collector.
      That number counts both live and dead-but-not-yet-reclaimable tuples.
      This behavior may once have been right, but modern versions of the
      pgstats code track live and dead tuple counts separately, so putting
      the total into n_live_tuples and zero into n_dead_tuples is surely
      pretty bogus.  Fix it to report live and dead tuple counts separately.
      
      This doesn't really do much for situations where updating transactions
      commit concurrently with a VACUUM scan (possibly causing double-counting or
      omission of the tuples they add or delete); but it's clearly an improvement
      over what we were doing before.
      
      Hari Babu, reviewed by Amit Kapila
      115f4141
  30. 08 1月, 2014 1 次提交
  31. 03 1月, 2014 2 次提交
    • T
      Ooops, should use double not single quotes in StaticAssertStmt(). · a3b4aeec
      Tom Lane 提交于
      That's what I get for testing this on an older compiler.
      a3b4aeec
    • T
      Fix calculation of maximum statistics-message size. · a7ef273e
      Tom Lane 提交于
      The PGSTAT_NUM_TABENTRIES macro should have been updated when new fields
      were added to struct PgStat_MsgTabstat in commit 64482890, but it wasn't.
      Fix that.
      
      Also, add a static assertion that we didn't overrun the intended size limit
      on stats messages.  This will not necessarily catch every mistake in
      computing the maximum array size for stats messages, but it will catch ones
      that have practical consequences.  (The assertion in fact doesn't complain
      about the aforementioned error in PGSTAT_NUM_TABENTRIES, because that was
      not big enough to cause the array length to increase.)
      
      No back-patch, as there's no actual bug in existing releases; this is just
      in the nature of future-proofing.
      
      Mark Dilger and Tom Lane
      a7ef273e
  32. 20 8月, 2013 2 次提交
    • T
      Be more wary of unwanted whitespace in pgstat_reset_remove_files(). · 20fe8707
      Tom Lane 提交于
      sscanf isn't the easiest thing to use for exact pattern checks ...
      also, don't use strncmp where strcmp will do.
      20fe8707
    • A
      Fix removal of files in pgstats directories · f9b50b7c
      Alvaro Herrera 提交于
      Instead of deleting all files in stats_temp_directory and the permanent
      directory on a crash, only remove those files that match the pattern of
      files we actually write in them, to avoid possibly clobbering existing
      unrelated contents of the temporary directory.  Per complaint from Jeff
      Janes, and subsequent discussion, starting at message
      CAMkU=1z9+7RsDODnT4=cDFBRBp8wYQbd_qsLcMtKEf-oFwuOdQ@mail.gmail.com
      
      Also, fix a bug in the same routine to avoid removing files from the
      permanent directory twice (instead of once from that directory and then
      from the temporary directory), also per report from Jeff Janes, in
      message
      CAMkU=1wbk947=-pAosDMX5VC+sQw9W4ttq6RM9rXu=MjNeEQKA@mail.gmail.com
      f9b50b7c
  33. 25 7月, 2013 1 次提交
    • T
      Improve ilist.h's support for deletion of slist elements during iteration. · fa2fad3c
      Tom Lane 提交于
      Previously one had to use slist_delete(), implying an additional scan of
      the list, making this infrastructure considerably less efficient than
      traditional Lists when deletion of element(s) in a long list is needed.
      Modify the slist_foreach_modify() macro to support deleting the current
      element in O(1) time, by keeping a "prev" pointer in addition to "cur"
      and "next".  Although this makes iteration with this macro a bit slower,
      no real harm is done, since in any scenario where you're not going to
      delete the current list element you might as well just use slist_foreach
      instead.  Improve the comments about when to use each macro.
      
      Back-patch to 9.3 so that we'll have consistent semantics in all branches
      that provide ilist.h.  Note this is an ABI break for callers of
      slist_foreach_modify().
      
      Andres Freund and Tom Lane
      fa2fad3c
  34. 02 7月, 2013 1 次提交
    • R
      Use an MVCC snapshot, rather than SnapshotNow, for catalog scans. · 568d4138
      Robert Haas 提交于
      SnapshotNow scans have the undesirable property that, in the face of
      concurrent updates, the scan can fail to see either the old or the new
      versions of the row.  In many cases, we work around this by requiring
      DDL operations to hold AccessExclusiveLock on the object being
      modified; in some cases, the existing locking is inadequate and random
      failures occur as a result.  This commit doesn't change anything
      related to locking, but will hopefully pave the way to allowing lock
      strength reductions in the future.
      
      The major issue has held us back from making this change in the past
      is that taking an MVCC snapshot is significantly more expensive than
      using a static special snapshot such as SnapshotNow.  However, testing
      of various worst-case scenarios reveals that this problem is not
      severe except under fairly extreme workloads.  To mitigate those
      problems, we avoid retaking the MVCC snapshot for each new scan;
      instead, we take a new snapshot only when invalidation messages have
      been processed.  The catcache machinery already requires that
      invalidation messages be sent before releasing the related heavyweight
      lock; else other backends might rely on locally-cached data rather
      than scanning the catalog at all.  Thus, making snapshot reuse
      dependent on the same guarantees shouldn't break anything that wasn't
      already subtly broken.
      
      Patch by me.  Review by Michael Paquier and Andres Freund.
      568d4138
  35. 30 5月, 2013 1 次提交
  36. 04 4月, 2013 1 次提交