Commit Graph

36999 Commits

Author SHA1 Message Date
Tom Lane 6aa61580e0 Clarify type resolution behavior for domain types.
The user documentation was vague and not entirely accurate about how
we treat domain inputs for ambiguous operators/functions.  Clarify
that, and add an example and some commentary.  Per a recent question
from Adam Mackler.

It's acted like this ever since we added domains, so back-patch
to all supported branches.
2014-08-10 16:13:13 -04:00
Tom Lane 92f57c9ae9 Clean up handling of unknown-type inputs in json_build_object and friends.
There's actually no need for any special case for unknown-type literals,
since we only need to push the value through its output function and
unknownout() works fine.  The code that was here was completely bizarre
anyway, and would fail outright in cases that should work, not to mention
suffering from some copy-and-paste bugs.
2014-08-09 17:31:13 -04:00
Tom Lane 495cadda5e Further cleanup of JSON-specific error messages.
Fix an obvious typo in json_build_object()'s complaint about invalid
number of arguments, and make the errhint a bit more sensible too.

Per discussion about how to word the improved hint, change the few places
in the documentation that refer to JSON object field names as "names" to
say "keys" instead, since that's what we've said in the vast majority of
places in the docs.  Arguably "name" is more correct, since that's the
terminology used in RFC 7159; but we're stuck with "key" in view of the
naming of json_object_keys() so let's at least be self-consistent.

I adjusted a few code comments to match this as well, and failed to
resist the temptation to clean up some odd whitespace choices in the
same area, as well as a useless duplicate PG_ARGISNULL() check.  There's
still quite a bit of code that uses the phrase "field name" in non-user-
visible ways, so I left those usages alone.
2014-08-09 16:35:29 -04:00
Tom Lane 9da8675373 Reject duplicate column names in foreign key referenced-columns lists.
Such cases are disallowed by the SQL spec, and even if we wanted to allow
them, the semantics seem ambiguous: how should the FK columns be matched up
with the columns of a unique index?  (The matching could be significant in
the presence of opclasses with different notions of equality, so this issue
isn't just academic.)  However, our code did not previously reject such
cases, but instead would either fail to match to any unique index, or
generate a bizarre opclass-lookup error because of sloppy thinking in the
index-matching code.

David Rowley
2014-08-09 13:46:34 -04:00
Peter Eisentraut f25e0bf5e0 Small message fixes 2014-08-09 00:07:00 -04:00
Fujii Masao 3dad73e71f Add -F option to pg_receivexlog, for specifying fsync interval.
This allows us to specify the maximum time to issue fsync to ensure
the received WAL file is safely flushed to disk. Without this,
pg_receivexlog always flushes WAL file only when it's closed and
which can cause WAL data to be lost at the event of a crash.

Furuya Osamu, heavily modified by me.
2014-08-08 16:50:54 +09:00
Tom Lane 1add956ac7 Fix typo in docs.
s/XIDs XIDs/XIDs/ in one place in maintenance.sgml.

Guillaume Lelarge
2014-08-07 20:46:41 -04:00
Bruce Momjian 4c6780fd17 pg_upgrade: prevent oid conflicts with new-cluster TOAST tables
Previously, TOAST tables only required in the new cluster could cause
oid conflicts if they were auto-numbered and a later conflicting oid had
to be assigned.

Backpatch through 9.3
2014-08-07 14:56:13 -04:00
Heikki Linnakangas ec903d20e3 Improve comment.
Based on the old comment, it took me a while to figure out what the
problem was. The importnat detail is that SSL_read() can return WANT_READ
even though some raw data was received from the socket.
2014-08-07 12:40:13 +03:00
Robert Haas 73cfa37afe Add PG_RETURN_UINT16 macro.
Manuel Kniep
2014-08-06 16:11:43 -04:00
Robert Haas 1d41739e5a Don't require sort support functions to provide a comparator.
This could be useful for datatypes like text, where we might want
to optimize for some collations but not others.  However, this patch
doesn't introduce any new sortsupport functions that work this way;
it merely revises the code so that future patches may do so.

Patch by me.  Review by Peter Geoghegan.
2014-08-06 16:06:06 -04:00
Robert Haas 873de34b71 Fix alternate regression test output file.
Commit 0ef99bdce3 broke this.

Jeff Janes
2014-08-06 11:30:32 -04:00
Fujii Masao 6805e02c66 Refactor pg_receivexlog main loop code, for readability, take 2.
Previously the source codes for processing the received data and handling
the end of stream were included in pg_receivexlog main loop. This commit
splits out them as separate functions. This is useful for improving the
readability of main loop code and making the future pg_receivexlog-related
patch simpler.
2014-08-06 20:58:13 +09:00
Fujii Masao e3da0d4d1a Change ParseConfigFp() so that it doesn't process unused entry of each parameter.
When more than one setting entries of same parameter exist in the
configuration file, PostgreSQL uses only entry appearing last in
configuration file scan. Since the other entries are not used,
ParseConfigFp() doesn't need to process them, but previously it did
that. This problematic behavior caused the configuration file scan
to detect invalid settings of unused entries (e.g., existence of
multiple entries of PGC_POSTMASTER parameter) and log the messages
complaining about them.

This commit changes the configuration file scan so that it processes
only last entry of each parameter.

Note that when multiple entries of same parameter exist both in
postgresql.conf and postgresql.auto.conf, unused entries in
postgresql.conf are still processed only at postmaster startup.

The problem has existed since old version, but a user is more likely
to encounter it since 9.4 where ALTER SYSTEM command was introduced.
So back-patch to 9.4.

Amit Kapila, slightly modified by me. Per report from Christoph Berg.
2014-08-06 14:49:43 +09:00
Kevin Grittner 49d1e03d64 Fix typo in C comment. 2014-08-05 14:17:21 -05:00
Robert Haas 0ef99bdce3 Improve some JSON error messages.
These messages are new in 9.4, which hasn't been released yet, so
back-patch to REL9_4_STABLE.

Daniele Varrazzo
2014-08-05 12:28:57 -04:00
Bruce Momjian ee646df59a pg_upgrade: assume user is install user
The user specified to the upgrade was effectively the install user, but
that was not clearly stated in the comments, documentation, or error
messages.
2014-08-04 11:56:16 -04:00
Bruce Momjian b4bd6f6b05 pg_upgrade: remove reference to autovacuum_multixact_freeze_max_age
autovacuum_multixact_freeze_max_age was added as a pg_ctl start
parameter in 9.3.X to prevent autovacuum from running.  However, only
some 9.3.X releases have autovacuum_multixact_freeze_max_age as it was
added in a minor PG 9.3 release.  It also isn't needed because -b turns
off autovacuum in 9.1+.

Without this fix, trying to upgrade from an early 9.3 release to 9.4
would fail.

Report by EDB

Backpatch through 9.3
2014-08-04 11:46:05 -04:00
Heikki Linnakangas cd74a151b5 Windows doesn't have M_PI; define it ourselves when needed.
This should fix the Windows build, broken by commit ed802e7d.
2014-08-04 18:06:34 +03:00
Fujii Masao b819dd7cb5 Add missing PQclear() calls into pg_receivexlog.
Back-patch to 9.3.
2014-08-02 15:18:09 +09:00
Fujii Masao 694fd33e23 Fix bug in pg_receivexlog --verbose.
In 9.2, pg_receivexlog with verbose option has emitted the messages
at the end of each WAL file. But the commit 0b63291 suppressed such
messages by mistake. This commit fixes the bug so that pg_receivexlog
--verbose outputs such messages again.

Back-patch to 9.3 where the bug was added.
2014-08-02 14:57:21 +09:00
Heikki Linnakangas 822ff44c82 Fix typo in user manual 2014-08-01 21:13:17 +03:00
Heikki Linnakangas 54685338e3 Move log_newpage and log_newpage_buffer to xlog.c.
log_newpage is used by many indexams, in addition to heap, but for
historical reasons it's always been part of the heapam rmgr. Starting with
9.3, we have another WAL record type for logging an image of a page,
XLOG_FPI. Simplify things by moving log_newpage and log_newpage_buffer to
xlog.c, and switch to using the XLOG_FPI record type.

Bump the WAL version number because the code to replay the old HEAP_NEWPAGE
records is removed.
2014-07-31 16:48:55 +03:00
Tom Lane f51ead09df Avoid wholesale autovacuuming when autovacuum is nominally off.
When autovacuum is nominally off, we will still launch autovac workers
to vacuum tables that are at risk of XID wraparound.  But after we'd done
that, an autovac worker would proceed to autovacuum every table in the
targeted database, if they meet the usual thresholds for autovacuuming.
This is at best pretty unexpected; at worst it delays response to the
wraparound threat.  Fix it so that if autovacuum is nominally off, we
*only* do forced vacuums and not any other work.

Per gripe from Andrey Zhidenkov.  This has been like this all along,
so back-patch to all supported branches.
2014-07-30 14:41:35 -04:00
Robert Haas ed802e7dc3 pgbench: Allow \setrandom to generate Gaussian/exponential distributions.
Mitsumasa KONDO and Fabien COELHO, with further wordsmithing by me.
2014-07-30 13:22:08 -04:00
Robert Haas e280c630a8 Fix mishandling of background worker PGPROCs in EXEC_BACKEND builds.
InitProcess() relies on IsBackgroundWorker to decide whether the PGPROC
for a new backend should be taken from ProcGlobal's freeProcs or from
bgworkerFreeProcs.  In EXEC_BACKEND builds, InitProcess() is called
sooner than in non-EXEC_BACKEND builds, and IsBackgroundWorker wasn't
getting initialized soon enough.

Report by Noah Misch.  Diagnosis and fix by me.
2014-07-30 11:34:06 -04:00
Peter Eisentraut 232f1475dc doc: Clean up some recently added PL/pgSQL documentation
- Capitalize titles consistently.
- Fix some grammar.
- Group "Obtaining Information About an Error" under "Trapping Errors",
  but make "Obtaining the Call Stack Context Information" its own
  section, since it's not about errors.
2014-07-29 23:47:16 -04:00
Bruce Momjian d826d8ecce pg_upgrade: improve C comment wording 2014-07-29 22:09:03 -04:00
Alvaro Herrera 0531549801 Avoid uselessly looking up old LOCK_ONLY multixacts
Commit 0ac5ad5134 removed an optimization in multixact.c that skipped
fetching members of MultiXactId that were older than our
OldestVisibleMXactId value.  The reason this was removed is that it is
possible for multixacts that contain updates to be older than that
value.  However, if the caller is certain that the multi does not
contain an update (because the infomask bits say so), it can pass this
info down to GetMultiXactIdMembers, enabling it to use the old
optimization.

Pointed out by Andres Freund in 20131121200517.GM7240@alap2.anarazel.de
2014-07-29 15:41:06 -04:00
Alvaro Herrera c2581794f3 Simplify multixact freezing a bit
Testing for abortedness of a multixact member that's being frozen is
unnecessary: we only need to know whether the transaction is still in
progress or committed to determine whether it must be kept or not.  This
let us simplify the code a bit and avoid a useless TransactionIdDidAbort
test.

Suggested by Andres Freund awhile back.
2014-07-29 15:40:55 -04:00
Heikki Linnakangas 60d931827b Oops, fix recoveryStopsBefore functions for regular commits.
Pointed out by Tom Lane. Backpatch to 9.4, the code was structured
differently in earlier branches and didn't have this mistake.
2014-07-29 17:19:43 +03:00
Heikki Linnakangas e74e0906fa Treat 2PC commit/abort the same as regular xacts in recovery.
There were several oversights in recovery code where COMMIT/ABORT PREPARED
records were ignored:

* pg_last_xact_replay_timestamp() (wasn't updated for 2PC commits)
* recovery_min_apply_delay (2PC commits were applied immediately)
* recovery_target_xid (recovery would not stop if the XID used 2PC)

The first of those was reported by Sergiy Zuban in bug #11032, analyzed by
Tom Lane and Andres Freund. The bug was always there, but was masked before
commit d19bd29f07, because COMMIT PREPARED
always created an extra regular transaction that was WAL-logged.

Backpatch to all supported versions (older versions didn't have all the
features and therefore didn't have all of the above bugs).
2014-07-29 11:59:22 +03:00
Fujii Masao 61e48efba5 Reword the sentence for pg_logical_slot_peek_changes function.
Previously the duplicated paragraphs were used next to each other
in the document to demonstrate that the changes in the stream
were not consumed by pg_logical_slot_peek_changes function.
But some users misunderstood that the duplication of the same
paragraph was just typo. So this commit rewords the sentence in
the latter paragraph for less confusing.

Christoph Moench-Tegeder
2014-07-29 12:07:54 +09:00
Tom Lane 248fc1f107 Fix obsolete statement in smgr/README.
Since commit 2d00190495, fork numbers are
defined in relpath.h not relfilenode.h.

Fabrízio de Royes Mello
2014-07-28 16:30:14 -04:00
Peter Eisentraut b0d3636c17 doc: Fix up ALTER TABLESPACE reference page
The documentation of ALTER TABLESPACE ... MOVE was added without any
markup, not even paragraph breaks.  Fix that, and clarify the text in a
few places.
2014-07-26 23:19:02 -04:00
Tom Lane c8e2e0e712 Fix a performance problem in pg_dump's dump order selection logic.
findDependencyLoops() was not bright about cases where there are multiple
dependency paths between the same two dumpable objects.  In most scenarios
this did not hurt us too badly; but since the introduction of section
boundary pseudo-objects in commit a1ef01fe16,
it was possible for this code to take unreasonable amounts of time (tens
of seconds on a database with a couple thousand objects), as reported in
bug #11033 from Joe Van Dyk.  Joe's particular problem scenario involved
"pg_dump -a" mode with long chains of foreign key constraints, but I think
that similar problems could arise with other situations as long as there
were enough objects.  To fix, add a flag array that lets us notice when we
arrive at the same object again while searching from a given start object.
This simple change seems to be enough to eliminate the performance problem.

Back-patch to 9.1, like the patch that introduced section boundary objects.
2014-07-25 19:48:42 -04:00
Noah Misch de35a97710 Handle WAIT_IO_COMPLETION return from WaitForMultipleObjectsEx().
This return code is possible wherever we pass bAlertable = TRUE; it
arises when Windows caused the current thread to run an "I/O completion
routine" or an "asynchronous procedure call".  PostgreSQL does not
provoke either of those Windows facilities, hence this bug remaining
largely unnoticed, but other local code might do so.  Due to a shortage
of complaints, no back-patch for now.

Per report from Shiv Shivaraju Gowda, this bug can cause
PGSemaphoreLock() to PANIC.  The bug can also cause select() to report
timeout expiration too early, which might confuse pgstat_init() and
CheckRADIUSAuth().
2014-07-25 18:51:48 -04:00
Noah Misch e565ff7553 Move PGAC_LDAP_SAFE to config/programs.m4.
This restores the style of keeping configure.in free of AC_DEFUN.  Per
gripe from Tom Lane.
2014-07-25 18:51:35 -04:00
Robert Haas 1144ea3421 Prevent shm_mq_send from reading uninitialized memory.
shm_mq_send_bytes didn't invariably initialize *bytes_written before
returning, which would cause shm_mq_send to read from uninitialized
memory and add the value it found there to mqh->mqh_partial_bytes.
This could cause the next attempt to send a message via the queue to
fail an assertion (if the queue was detached) or copy data from a
garbage pointer value into the queue (if non-blocking mode was in use).
2014-07-24 09:23:22 -04:00
Robert Haas 250c26ba9c Fix checkpointer crash in EXEC_BACKEND builds.
Nothing in the checkpointer calls InitXLOGAccess(), so WALInsertLocks
never got initialized there.  Without EXEC_BACKEND, it works anyway
because the correct value is inherited from the postmaster, but
with EXEC_BACKEND we've got a problem.  The problem appears to have
been introduced by commit 68a2e52bba.

To fix, move the relevant initialization steps from InitXLOGAccess()
to XLOGShmemInit(), making this more parallel to what we do
elsewhere.

Amit Kapila
2014-07-24 09:12:38 -04:00
Andres Freund 93a028f569 Properly remove ephemeral replication slots after a crash restart.
Ephemeral slots - slots that shouldn't survive database restarts -
weren't properly cleaned up after a immediate/crash restart. They were
ignored in the sense that they weren't restored into memory and thus
didn't cause unwanted resource retention; but they prevented a new
slot with the same name from being created.

Now ephemeral slots are fully removed during startup.

Backpatch to 9.4 where replication slots where added.
2014-07-24 14:44:45 +02:00
Robert Haas 32d78894c2 Avoid access to already-released lock in LockRefindAndRelease.
Spotted by Tom Lane.
2014-07-24 08:19:19 -04:00
Robert Haas 967a4e7f31 docs: Improve documentation of \pset without arguments.
The syntax summary previously failed to clarify that the first
argument is also optional.  The textual description did mention it,
but all the way at the bottom.  It fits better with the command
overview, so move it there, and fix the summary also.

Dilip Kumar, reviewed by Fabien Coelho
2014-07-24 08:06:54 -04:00
Fujii Masao 78493b7168 Fix bug where pg_receivexlog goes into busy loop if -s option is set to 0.
The problem is that pg_receivexlog calls select(2) with timeout=0 and
goes into busy loop when --status-interval option is set to 0. This bug
was introduced by the commit,
74cbe966fe.

Per report from Sawada Masahiko
2014-07-24 15:25:26 +09:00
Peter Eisentraut 455044d55a Fix TAP installcheck tests when current directory name contains spaces
This fixes the installcheck part.  The check part has additional
problems that will be addressed in a separate commit.
2014-07-23 22:06:56 -04:00
Tom Lane 4fd9e6ffdd Rearrange documentation paragraph describing pg_relation_size().
Break the list of available options into an <itemizedlist> instead of
inline sentences.  This is mostly motivated by wanting to ensure that the
cross-references to the FSM and VM docs don't cross page boundaries in PDF
format; but it seems to me to read more easily this way anyway.  I took the
liberty of editorializing a bit further while at it.

Per complaint from Magnus about 9.0.18 docs not building in A4 format.
Patch all active branches so we don't get blind-sided by this particular
issue again in future.
2014-07-23 15:20:31 -04:00
Noah Misch 0ea1f2a3a8 Report success when Windows kill() emulation signals an exiting process.
This is consistent with the POSIX verdict that kill() shall not report
ESRCH for a zombie process.  Back-patch to 9.0 (all supported versions).
Test code from commit d7cdf6ee36 depends
on it, and log messages about kill() reporting "Invalid argument" will
cease to appear for this not-unexpected condition.
2014-07-23 00:35:13 -04:00
Noah Misch 31f9bbf059 MSVC: Substitute $(top_builddir) in REGRESS_OPTS.
Commit d7cdf6ee36 introduced a usage
thereof.  Back-patch to 9.0, like that commit.
2014-07-23 00:35:07 -04:00
Tom Lane 27048980f5 Re-enable error for "SELECT ... OFFSET -1".
The executor has thrown errors for negative OFFSET values since 8.4 (see
commit bfce56eea4), but in a moment of brain
fade I taught the planner that OFFSET with a constant negative value was a
no-op (commit 1a1832eb08).  Reinstate the
former behavior by only discarding OFFSET with a value of exactly 0.  In
passing, adjust a planner comment that referenced the ancient behavior.

Back-patch to 9.3 where the mistake was introduced.
2014-07-22 13:30:01 -04:00
Tom Lane 27cef0a561 Check block number against the correct fork in get_raw_page().
get_raw_page tried to validate the supplied block number against
RelationGetNumberOfBlocks(), which of course is only right when
accessing the main fork.  In most cases, the main fork is longer
than the others, so that the check was too weak (allowing a
lower-level error to be reported, but no real harm to be done).
However, very small tables could have an FSM larger than their heap,
in which case the mistake prevented access to some FSM pages.
Per report from Torsten Foertsch.

In passing, make the bad-block-number error into an ereport not elog
(since it's certainly not an internal error); and fix sloppily
maintained comment for RelationGetNumberOfBlocksInFork.

This has been wrong since we invented relation forks, so back-patch
to all supported branches.
2014-07-22 11:46:29 -04:00