]> granicus.if.org Git - postgresql/log
postgresql
9 years agoAdd GUC and storage parameter to set the maximum size of GIN pending list.
Fujii Masao [Tue, 11 Nov 2014 12:08:21 +0000 (21:08 +0900)]
Add GUC and storage parameter to set the maximum size of GIN pending list.

Previously the maximum size of GIN pending list was controlled only by
work_mem. But the reasonable value of work_mem and the reasonable size
of the list are basically not the same, so it was not appropriate to
control both of them by only one GUC, i.e., work_mem. This commit
separates new GUC, pending_list_cleanup_size, from work_mem to allow
users to control only the size of the list.

Also this commit adds pending_list_cleanup_size as new storage parameter
to allow users to specify the size of the list per index. This is useful,
for example, when users want to increase the size of the list only for
the GIN index which can be updated heavily, and decrease it otherwise.

Reviewed by Etsuro Fujita.

9 years agoReally fix compilation failure on MIPS.
Heikki Linnakangas [Tue, 11 Nov 2014 08:25:22 +0000 (10:25 +0200)]
Really fix compilation failure on MIPS.

I missed an additional colon in previous patch. Oops. to make that mistake
less likely in the future, add comments as placeholders for unused inputs
and outputs in inline assembly.

9 years agoFix compilation failure on MIPS.
Heikki Linnakangas [Mon, 10 Nov 2014 23:04:57 +0000 (01:04 +0200)]
Fix compilation failure on MIPS.

Rémi Zara

9 years agoBRIN: fix bug in xlog backup block counting
Alvaro Herrera [Mon, 10 Nov 2014 21:13:49 +0000 (18:13 -0300)]
BRIN: fix bug in xlog backup block counting

The code that generates the BRIN_XLOG_UPDATE removes the buffer
reference when the page that's target for the updated tuple is freshly
initialized.  This is a pretty usual optimization, but was breaking the
case where the revmap buffer, which is referenced in the same WAL
record, is getting a backup block: the replay code was using backup
block index 1, which is not valid when the update target buffer gets
pruned; the revmap buffer gets assigned 0 instead.  Make sure to use the
correct backup block index for revmap when replaying.

Bug reported by Fujii Masao.

9 years agoFix potential NULL-pointer dereference.
Robert Haas [Mon, 10 Nov 2014 20:19:56 +0000 (15:19 -0500)]
Fix potential NULL-pointer dereference.

Commit 2781b4bea7db357be59f9a5fd73ca1eb12ff5a79 arranged to defer
the setup of after-trigger-related data structures, but
AfterTriggerPendingOnRel didn't get the memo.

9 years agoEnsure that RowExprs and whole-row Vars produce the expected column names.
Tom Lane [Mon, 10 Nov 2014 20:21:09 +0000 (15:21 -0500)]
Ensure that RowExprs and whole-row Vars produce the expected column names.

At one time it wasn't terribly important what column names were associated
with the fields of a composite Datum, but since the introduction of
operations like row_to_json(), it's important that looking up the rowtype
ID embedded in the Datum returns the column names that users would expect.
That did not work terribly well before this patch: you could get the column
names of the underlying table, or column aliases from any level of the
query, depending on minor details of the plan tree.  You could even get
totally empty field names, which is disastrous for cases like row_to_json().

To fix this for whole-row Vars, look to the RTE referenced by the Var, and
make sure its column aliases are applied to the rowtype associated with
the result Datums.  This is a tad scary because we might have to return
a transient RECORD type even though the Var is declared as having some
named rowtype.  In principle it should be all right because the record
type will still be physically compatible with the named rowtype; but
I had to weaken one Assert in ExecEvalConvertRowtype, and there might be
third-party code containing similar assumptions.

Similarly, RowExprs have to be willing to override the column names coming
from a named composite result type and produce a RECORD when the column
aliases visible at the site of the RowExpr differ from the underlying
table's column names.

In passing, revert the decision made in commit 398f70ec070fe601 to add
an alias-list argument to ExecTypeFromExprList: better to provide that
functionality in a separate function.  This also reverts most of the code
changes in d68581483564ec0f, which we don't need because we're no longer
depending on the tupdesc found in the child plan node's result slot to be
blessed.

Back-patch to 9.4, but not earlier, since this solution changes the results
in some cases that users might not have realized were buggy.  We'll apply a
more restricted form of this patch in older branches.

9 years agoFurther code and wording tweaks in BRIN
Alvaro Herrera [Mon, 10 Nov 2014 18:56:08 +0000 (15:56 -0300)]
Further code and wording tweaks in BRIN

Besides a couple of typo fixes, per David Rowley, Thom Brown, and Amit
Langote, and mentions of BRIN in the general CREATE INDEX page again per
David, this includes silencing MSVC compiler warnings (thanks Microsoft)
and an additional variable initialization per Coverity scanner.

9 years agoFix compiler warning for non-assert builds.
Kevin Grittner [Mon, 10 Nov 2014 15:42:46 +0000 (09:42 -0600)]
Fix compiler warning for non-assert builds.

Reported by Peter Geoghegan
David Rowley

9 years agoTab complete second argument to \c with role names.
Robert Haas [Mon, 10 Nov 2014 13:15:17 +0000 (08:15 -0500)]
Tab complete second argument to \c with role names.

Ian Barwick

9 years agoC comment: mention 1500-02-29 as an invalid date
Bruce Momjian [Mon, 10 Nov 2014 01:50:15 +0000 (20:50 -0500)]
C comment:  mention 1500-02-29 as an invalid date

It is invalid because the Gregorian calendar is used for all years.

9 years agoFix some coding issues in BRIN
Alvaro Herrera [Sat, 8 Nov 2014 03:31:03 +0000 (00:31 -0300)]
Fix some coding issues in BRIN

Reported by David Rowley: variadic macros are a problem.  Get rid of
them using a trick suggested by Tom Lane: add extra parentheses where
needed.  In the future we might decide we don't need the calls at all
and remove them, but it seems appropriate to keep them while this code
is still new.

Also from David Rowley: brininsert() was trying to use a variable before
initializing it.  Fix by moving the brin_form_tuple call (which
initializes the variable) to within the locked section.

Reported by Peter Eisentraut: can't use "new" as a struct member name,
because C++ compilers will choke on it, as reported by cpluspluscheck.

9 years agopg_basebackup: Adjust tests for long file name issues
Peter Eisentraut [Sat, 8 Nov 2014 01:47:38 +0000 (20:47 -0500)]
pg_basebackup: Adjust tests for long file name issues

Work around accidental test failures because the working directory path
is too long by creating a temporary directory in the (hopefully shorter)
system location, symlinking that to the working directory, and creating
the tablespaces using the shorter path.

9 years agodoc: Update pg_receivexlog note
Peter Eisentraut [Sat, 8 Nov 2014 01:15:22 +0000 (20:15 -0500)]
doc: Update pg_receivexlog note

The old note about how to use pg_receivexlog as an alternative to
archive_command was obsoleted by replication slots.

9 years agoIntroduce custom path and scan providers.
Robert Haas [Fri, 7 Nov 2014 22:26:02 +0000 (17:26 -0500)]
Introduce custom path and scan providers.

This allows extension modules to define their own methods for
scanning a relation, and get the core code to use them.  It's
unclear as yet how much use this capability will find, but we
won't find out if we never commit it.

KaiGai Kohei, reviewed at various times and in various levels
of detail by Shigeru Hanada, Tom Lane, Andres Freund, Álvaro
Herrera, and myself.

9 years agoFix building with WAL_DEBUG.
Heikki Linnakangas [Fri, 7 Nov 2014 21:04:53 +0000 (23:04 +0200)]
Fix building with WAL_DEBUG.

Now that the backup blocks are appended to the WAL record in xloginsert.c,
XLogInsert doesn't see them anymore and cannot remove them from the version
reconstructed for xlog_outdesc. This makes running with wal_debug=on more
expensive, as we now make (unnecessary) temporary copies of the backup
blocks, but it doesn't seem worth convoluting the code to keep that
optimization.

Reported by Alvaro Herrera.

9 years agoUse the sortsupport infrastructure in more cases.
Robert Haas [Fri, 7 Nov 2014 20:50:09 +0000 (15:50 -0500)]
Use the sortsupport infrastructure in more cases.

This removes some fmgr overhead from cases such as btree index builds.

Peter Geoghegan, reviewed by Andreas Karlsson and me.

9 years agoUpdate pg_xlogdump's .gitignore for brindesc.c.
Robert Haas [Fri, 7 Nov 2014 20:41:52 +0000 (15:41 -0500)]
Update pg_xlogdump's .gitignore for brindesc.c.

9 years agoFix serial schedule
Alvaro Herrera [Fri, 7 Nov 2014 20:05:26 +0000 (17:05 -0300)]
Fix serial schedule

Test misc depends on brin, but it was earlier in the serial schedule
file.  I didn't notice this because I only run the parallel schedule,
but the buildfarm exposed my folly ...

9 years agoBRIN: Block Range Indexes
Alvaro Herrera [Fri, 7 Nov 2014 19:38:14 +0000 (16:38 -0300)]
BRIN: Block Range Indexes

BRIN is a new index access method intended to accelerate scans of very
large tables, without the maintenance overhead of btrees or other
traditional indexes.  They work by maintaining "summary" data about
block ranges.  Bitmap index scans work by reading each summary tuple and
comparing them with the query quals; all pages in the range are returned
in a lossy TID bitmap if the quals are consistent with the values in the
summary tuple, otherwise not.  Normal index scans are not supported
because these indexes do not store TIDs.

As new tuples are added into the index, the summary information is
updated (if the block range in which the tuple is added is already
summarized) or not; in the latter case, a subsequent pass of VACUUM or
the brin_summarize_new_values() function will create the summary
information.

For data types with natural 1-D sort orders, the summary info consists
of the maximum and the minimum values of each indexed column within each
page range.  This type of operator class we call "Minmax", and we
supply a bunch of them for most data types with B-tree opclasses.
Since the BRIN code is generalized, other approaches are possible for
things such as arrays, geometric types, ranges, etc; even for things
such as enum types we could do something different than minmax with
better results.  In this commit I only include minmax.

Catalog version bumped due to new builtin catalog entries.

There's more that could be done here, but this is a good step forwards.

Loosely based on ideas from Simon Riggs; code mostly by Álvaro Herrera,
with contribution by Heikki Linnakangas.

Patch reviewed by: Amit Kapila, Heikki Linnakangas, Robert Haas.
Testing help from Jeff Janes, Erik Rijkers, Emanuel Calvo.

PS:
  The research leading to these results has received funding from the
  European Union's Seventh Framework Programme (FP7/2007-2013) under
  grant agreement n° 318633.

9 years agoFix generation of SP-GiST vacuum WAL records.
Heikki Linnakangas [Fri, 7 Nov 2014 19:14:35 +0000 (21:14 +0200)]
Fix generation of SP-GiST vacuum WAL records.

I broke these in 8776faa81cb651322b8993422bdd4633f1f6a487. Backpatch to
9.4, where that was done.

9 years agoRemove obsolete cases from GiST update redo code.
Heikki Linnakangas [Fri, 7 Nov 2014 13:03:46 +0000 (15:03 +0200)]
Remove obsolete cases from GiST update redo code.

The code that generated a record to clear the F_TUPLES_DELETED flag hasn't
existed since we got rid of old-style VACUUM FULL. I kept the code that sets
the flag, although it's not used for anything anymore, because it might
still be interesting information for debugging purposes that some tuples
have been deleted from a page.

Likewise, the code to turn the root page from non-leaf to leaf page was
removed when we got rid of old-style VACUUM FULL. Remove the code to replay
that action, too.

9 years agoCope with more than 64K phrases in a thesaurus dictionary.
Tom Lane [Fri, 7 Nov 2014 01:52:40 +0000 (20:52 -0500)]
Cope with more than 64K phrases in a thesaurus dictionary.

dict_thesaurus stored phrase IDs in uint16 fields, so it would get confused
and even crash if there were more than 64K entries in the configuration
file.  It turns out to be basically free to widen the phrase IDs to uint32,
so let's just do so.

This was complained of some time ago by David Boutin (in bug #7793);
he later submitted an informal patch but it was never acted on.
We now have another complaint (bug #11901 from Luc Ouellette) so it's
time to make something happen.

This is basically Boutin's patch, but for future-proofing I also added a
defense against too many words per phrase.  Note that we don't need any
explicit defense against overflow of the uint32 counters, since before that
happens we'd hit array allocation sizes that repalloc rejects.

Back-patch to all supported branches because of the crash risk.

9 years agoFix normalization of numeric values in JSONB GIN indexes.
Tom Lane [Thu, 6 Nov 2014 16:41:06 +0000 (11:41 -0500)]
Fix normalization of numeric values in JSONB GIN indexes.

The default JSONB GIN opclass (jsonb_ops) converts numeric data values
to strings for storage in the index.  It must ensure that numeric values
that would compare equal (such as 12 and 12.00) produce identical strings,
else index searches would have behavior different from regular JSONB
comparisons.  Unfortunately the function charged with doing this was
completely wrong: it could reduce distinct numeric values to the same
string, or reduce equivalent numeric values to different strings.  The
former type of error would only lead to search inefficiency, but the
latter type of error would cause index entries that should be found by
a search to not be found.

Repairing this bug therefore means that it will be necessary for 9.4 beta
testers to reindex GIN jsonb_ops indexes, if they care about getting
correct results from index searches involving numeric data values within
the comparison JSONB object.

Per report from Thomas Fanghaenel.

9 years agoPrevent the unnecessary creation of .ready file for the timeline history file.
Fujii Masao [Thu, 6 Nov 2014 12:24:40 +0000 (21:24 +0900)]
Prevent the unnecessary creation of .ready file for the timeline history file.

Previously .ready file was created for the timeline history file at the end
of an archive recovery even when WAL archiving was not enabled.
This creation is unnecessary and causes .ready file to remain infinitely.

This commit changes an archive recovery so that it creates .ready file for
the timeline history file only when WAL archiving is enabled.

Backpatch to all supported versions.

9 years agoMove the backup-block logic from XLogInsert to a new file, xloginsert.c.
Heikki Linnakangas [Thu, 6 Nov 2014 11:52:08 +0000 (13:52 +0200)]
Move the backup-block logic from XLogInsert to a new file, xloginsert.c.

xlog.c is huge, this makes it a little bit smaller, which is nice. Functions
related to putting together the WAL record are in xloginsert.c, and the
lower level stuff for managing WAL buffers and such are in xlog.c.

Also move the definition of XLogRecord to a separate header file. This
causes churn in the #includes of all the files that write WAL records, and
redo routines, but it avoids pulling in xlog.h into most places.

Reviewed by Michael Paquier, Alvaro Herrera, Andres Freund and Amit Kapila.

9 years agoFix typo in comment.
Fujii Masao [Thu, 6 Nov 2014 11:04:11 +0000 (20:04 +0900)]
Fix typo in comment.

Etsuro Fujita

9 years agoImplement IF NOT EXIST for CREATE INDEX.
Fujii Masao [Thu, 6 Nov 2014 09:48:33 +0000 (18:48 +0900)]
Implement IF NOT EXIST for CREATE INDEX.

Fabrízio de Royes Mello, reviewed by Marti Raudsepp, Adam Brightwell and me.

9 years agoC comment: mention why the Gregorian calendar is used pre-1582
Bruce Momjian [Thu, 6 Nov 2014 07:33:05 +0000 (02:33 -0500)]
C comment:  mention why the Gregorian calendar is used pre-1582

9 years agoRemove the last vestige of server-side autocommit.
Tom Lane [Thu, 6 Nov 2014 00:35:23 +0000 (19:35 -0500)]
Remove the last vestige of server-side autocommit.

Long ago we briefly had an "autocommit" GUC that turned server-side
autocommit on and off.  That behavior was removed in 7.4 after concluding
that it broke far too much client-side logic, and making clients cope with
both behaviors was impractical.  But the GUC variable was left behind, so
as not to break any client code that might be trying to read its value.
Enough time has now passed that we should remove the GUC completely.
Whatever vestigial backwards-compatibility benefit it had is outweighed by
the risk of confusion for newbies who assume it ought to do something,
as per a recent complaint from Wolfgang Wilhelm.

In passing, adjust what seemed to me a rather confusing documentation
reference to libpq's autocommit behavior.  libpq as such knows nothing
about autocommit, so psql is probably what was meant.

9 years agoFix thinko in commit 2bd9e412f92bc6a68f3e8bcb18e04955cc35001d.
Robert Haas [Wed, 5 Nov 2014 22:12:23 +0000 (17:12 -0500)]
Fix thinko in commit 2bd9e412f92bc6a68f3e8bcb18e04955cc35001d.

Obviously, every translation unit should not be declaring this
separately.  It needs to be PGDLLIMPORT as well, to avoid breaking
third-party code that uses any of the functions that the commit
mentioned above changed to macros.

9 years agoMake CREATE TYPE print warnings if a datatype's I/O functions are volatile.
Tom Lane [Wed, 5 Nov 2014 16:44:06 +0000 (11:44 -0500)]
Make CREATE TYPE print warnings if a datatype's I/O functions are volatile.

This is a followup to commit 43ac12c6e6e397fd9142ed908447eba32d3785b2,
which added regression tests checking that I/O functions of built-in
types are not marked volatile.  Complaining in CREATE TYPE should push
developers of add-on types to fix any misdeclared functions in their
types.  It's just a warning not an error, to avoid creating upgrade
problems for what might be just cosmetic mis-markings.

Aside from adding the warning code, fix a number of types that were
sloppily created in the regression tests.

9 years agoFix volatility markings of some contrib I/O functions.
Tom Lane [Wed, 5 Nov 2014 16:34:11 +0000 (11:34 -0500)]
Fix volatility markings of some contrib I/O functions.

In general, datatype I/O functions are supposed to be immutable or at
worst stable.  Some contrib I/O functions were, through oversight, not
marked with any volatility property at all, which made them VOLATILE.
Since (most of) these functions actually behave immutably, the erroneous
marking isn't terribly harmful; but it can be user-visible in certain
circumstances, as per a recent bug report from Joe Van Dyk in which a
cast to text was disallowed in an expression index definition.

To fix, just adjust the declarations in the extension SQL scripts.  If we
were being very fussy about this, we'd bump the extension version numbers,
but that seems like more trouble (for both developers and users) than the
problem is worth.

A fly in the ointment is that chkpass_in actually is volatile, because
of its use of random() to generate a fresh salt when presented with a
not-yet-encrypted password.  This is bad because of the general assumption
that I/O functions aren't volatile: the consequence is that records or
arrays containing chkpass elements may have input behavior a bit different
from a bare chkpass column.  But there seems no way to fix this without
breaking existing usage patterns for chkpass, and the consequences of the
inconsistency don't seem bad enough to justify that.  So for the moment,
just document it in a comment.

Since we're not bumping version numbers, there seems no harm in
back-patching these fixes; at least future installations will get the
functions marked correctly.

9 years agodoc: Move misplaced paragraph
Peter Eisentraut [Tue, 4 Nov 2014 21:10:58 +0000 (16:10 -0500)]
doc: Move misplaced paragraph

9 years agoDrop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE.
Tom Lane [Tue, 4 Nov 2014 18:24:06 +0000 (13:24 -0500)]
Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE.

The previous coding assumed that we could just let buffers for the
database's old tablespace age out of the buffer arena naturally.
The folly of that is exposed by bug #11867 from Marc Munro: the user could
later move the database back to its original tablespace, after which any
still-surviving buffers would match lookups again and appear to contain
valid data.  But they'd be missing any changes applied while the database
was in the new tablespace.

This has been broken since ALTER SET TABLESPACE was introduced, so
back-patch to all supported branches.

9 years agoSwitch to CRC-32C in WAL and other places.
Heikki Linnakangas [Tue, 4 Nov 2014 09:35:15 +0000 (11:35 +0200)]
Switch to CRC-32C in WAL and other places.

The old algorithm was found to not be the usual CRC-32 algorithm, used by
Ethernet et al. We were using a non-reflected lookup table with code meant
for a reflected lookup table. That's a strange combination that AFAICS does
not correspond to any bit-wise CRC calculation, which makes it difficult to
reason about its properties. Although it has worked well in practice, seems
safer to use a well-known algorithm.

Since we're changing the algorithm anyway, we might as well choose a
different polynomial. The Castagnoli polynomial has better error-correcting
properties than the traditional CRC-32 polynomial, even if we had
implemented it correctly. Another reason for picking that is that some new
CPUs have hardware support for calculating CRC-32C, but not CRC-32, let
alone our strange variant of it. This patch doesn't add any support for such
hardware, but a future patch could now do that.

The old algorithm is kept around for tsquery and pg_trgm, which use the
values in indexes that need to remain compatible so that pg_upgrade works.
While we're at it, share the old lookup table for CRC-32 calculation
between hstore, ltree and core. They all use the same table, so might as
well.

9 years agoRemove support for 64-bit CRC.
Heikki Linnakangas [Tue, 4 Nov 2014 09:33:08 +0000 (11:33 +0200)]
Remove support for 64-bit CRC.

It hasn't been used for anything for a long time.

9 years agopqmq.h needs to include something that defines StringInfo.
Robert Haas [Mon, 3 Nov 2014 17:23:08 +0000 (12:23 -0500)]
pqmq.h needs to include something that defines StringInfo.

Reported by Peter Eisentraut.

9 years agoDocs: fix incorrect spelling of contrib/pgcrypto option.
Tom Lane [Mon, 3 Nov 2014 16:11:34 +0000 (11:11 -0500)]
Docs: fix incorrect spelling of contrib/pgcrypto option.

pgp_sym_encrypt's option is spelled "sess-key", not "enable-session-key".
Spotted by Jeff Janes.

In passing, improve a comment in pgp-pgsql.c to make it clearer that
the debugging options are intentionally undocumented.

9 years agoRemove dead-since-introduction pgcrypto code.
Noah Misch [Mon, 3 Nov 2014 02:43:39 +0000 (21:43 -0500)]
Remove dead-since-introduction pgcrypto code.

Marko Tiikkaja

9 years agoClarify .def file comments.
Noah Misch [Mon, 3 Nov 2014 02:43:33 +0000 (21:43 -0500)]
Clarify .def file comments.

9 years agoRe-remove dependency on the DLL of pythonxx.def file.
Noah Misch [Mon, 3 Nov 2014 02:43:30 +0000 (21:43 -0500)]
Re-remove dependency on the DLL of pythonxx.def file.

The reasons behind commit 0d147e43adcf5d2bff9caa073608f381a27439bf still
stand, so this reverts the non-cosmetic portion of commit
a7983e989d9cafc9cef49becfee054e34b1ed9b4.  Back-patch to 9.4, where the
latter commit first appeared.

9 years agoMake ECPG test programs depend on "ecpg$(X)", not "ecpg".
Noah Misch [Mon, 3 Nov 2014 02:43:25 +0000 (21:43 -0500)]
Make ECPG test programs depend on "ecpg$(X)", not "ecpg".

Cygwin builds require this of dependencies pertaining to pattern rules.
On Cygwin, stat("foo") in the absence of a file with that exact name can
locate foo.exe.  While GNU make uses stat() for dependencies of ordinary
rules, it uses readdir() to assess dependencies of pattern rules.
Therefore, a pattern rule dependency should match any underlying file
name exactly.  Back-patch to 9.4, where the dependency was introduced.

9 years agoFix win32setlocale.c const-related warnings.
Noah Misch [Mon, 3 Nov 2014 02:43:20 +0000 (21:43 -0500)]
Fix win32setlocale.c const-related warnings.

Back-patch to 9.2, like commit db29620d4d16e08241f965ccd70d0f65883ff0de.

9 years agoFix generation of INSTALL file by removing link
Peter Eisentraut [Mon, 3 Nov 2014 01:17:32 +0000 (20:17 -0500)]
Fix generation of INSTALL file by removing link

9 years agoAdd configure --enable-tap-tests option
Peter Eisentraut [Sun, 2 Nov 2014 14:14:36 +0000 (09:14 -0500)]
Add configure --enable-tap-tests option

Don't skip the TAP tests anymore when IPC::Run is not found.  This will
fail normally now.

9 years agoPL/Python: Fix example
Peter Eisentraut [Sat, 1 Nov 2014 15:31:35 +0000 (11:31 -0400)]
PL/Python: Fix example

Revert "6f6b46c9c0ca3d96acbebc5499c32ee6369e1eec", which was broken.

Reported-by: Jonathan Rogers <jrogers@socialserve.com>
9 years agoSupport frontend-backend protocol communication using a shm_mq.
Robert Haas [Fri, 31 Oct 2014 16:02:40 +0000 (12:02 -0400)]
Support frontend-backend protocol communication using a shm_mq.

A background worker can use pq_redirect_to_shm_mq() to direct protocol
that would normally be sent to the frontend to a shm_mq so that another
process may read them.

The receiving process may use pq_parse_errornotice() to parse an
ErrorResponse or NoticeResponse from the background worker and, if
it wishes, ThrowErrorData() to propagate the error (with or without
further modification).

Patch by me.  Review by Andres Freund.

9 years agodoc: Fix typos
Peter Eisentraut [Fri, 31 Oct 2014 12:11:06 +0000 (08:11 -0400)]
doc: Fix typos

per Andres Freund

9 years agodoc: Wording and formatting improvements in new logical decoding docs
Peter Eisentraut [Fri, 31 Oct 2014 02:52:21 +0000 (22:52 -0400)]
doc: Wording and formatting improvements in new logical decoding docs

9 years agodoc: Improve CREATE VIEW / WITH documentation
Peter Eisentraut [Fri, 31 Oct 2014 02:50:02 +0000 (22:50 -0400)]
doc: Improve CREATE VIEW / WITH documentation

Similar to 590eb0c14eebe834f716721a9659b77899cf3084, remove the options
list from the synopsis and elaborate in the main description.

9 years agoExtend dsm API with a new function dsm_unpin_mapping.
Robert Haas [Thu, 30 Oct 2014 18:55:23 +0000 (14:55 -0400)]
Extend dsm API with a new function dsm_unpin_mapping.

This reassociates a dynamic shared memory handle previous passed to
dsm_pin_mapping with the current resource owner, so that it will be
cleaned up at the end of the current query.

Patch by me.  Review of the function name by Andres Freund, Amit
Kapila, Jim Nasby, Petr Jelinek, and Álvaro Herrera.

9 years agoTest IsInTransactionChain, not IsTransactionBlock, in vac_update_relstats.
Tom Lane [Thu, 30 Oct 2014 17:03:22 +0000 (13:03 -0400)]
Test IsInTransactionChain, not IsTransactionBlock, in vac_update_relstats.

As noted by Noah Misch, my initial cut at fixing bug #11638 didn't cover
all cases where ANALYZE might be invoked in an unsafe context.  We need to
test the result of IsInTransactionChain not IsTransactionBlock; which is
notationally a pain because IsInTransactionChain requires an isTopLevel
flag, which would have to be passed down through several levels of callers.
I chose to pass in_outer_xact (ie, the result of IsInTransactionChain)
rather than isTopLevel per se, as that seemed marginally more apropos
for the intermediate functions to know about.

9 years ago"Pin", rather than "keep", dynamic shared memory mappings and segments.
Robert Haas [Thu, 30 Oct 2014 15:35:55 +0000 (11:35 -0400)]
"Pin", rather than "keep", dynamic shared memory mappings and segments.

Nobody seemed concerned about this naming when it originally went in,
but there's a pending patch that implements the opposite of
dsm_keep_mapping, and the term "unkeep" was judged unpalatable.
"unpin" has existing precedent in the PostgreSQL code base, and the
English language, so use this terminology instead.

Per discussion, back-patch to 9.4.

9 years agoRemove use of TAP subtests
Peter Eisentraut [Wed, 29 Oct 2014 23:41:19 +0000 (19:41 -0400)]
Remove use of TAP subtests

They turned out to be too much of a portability headache, because they
need a fairly new version of Test::More to work properly.

9 years agoAvoid corrupting tables when ANALYZE inside a transaction is rolled back.
Tom Lane [Wed, 29 Oct 2014 22:12:02 +0000 (18:12 -0400)]
Avoid corrupting tables when ANALYZE inside a transaction is rolled back.

VACUUM and ANALYZE update the target table's pg_class row in-place, that is
nontransactionally.  This is OK, more or less, for the statistical columns,
which are mostly nontransactional anyhow.  It's not so OK for the DDL hint
flags (relhasindex etc), which might get changed in response to
transactional changes that could still be rolled back.  This isn't a
problem for VACUUM, since it can't be run inside a transaction block nor
in parallel with DDL on the table.  However, we allow ANALYZE inside a
transaction block, so if the transaction had earlier removed the last
index, rule, or trigger from the table, and then we roll back the
transaction after ANALYZE, the table would be left in a corrupted state
with the hint flags not set though they should be.

To fix, suppress the hint-flag updates if we are InTransactionBlock().
This is safe enough because it's always OK to postpone hint maintenance
some more; the worst-case consequence is a few extra searches of pg_index
et al.  There was discussion of instead using a transactional update,
but that would change the behavior in ways that are not all desirable:
in most scenarios we're better off keeping ANALYZE's statistical values
even if the ANALYZE itself rolls back.  In any case we probably don't want
to change this behavior in back branches.

Per bug #11638 from Casey Shobe.  This has been broken for a good long
time, so back-patch to all supported branches.

Tom Lane and Michael Paquier, initial diagnosis by Andres Freund

9 years agoAvoid setup work for invalidation messages at start-of-(sub)xact.
Robert Haas [Wed, 29 Oct 2014 16:35:19 +0000 (12:35 -0400)]
Avoid setup work for invalidation messages at start-of-(sub)xact.

Instead of initializing a new TransInvalidationInfo for every
transaction or subtransaction, we can just do it for those
transactions or subtransactions that actually need to queue
invalidation messages.  That also avoids needing to free those
entries at the end of a transaction or subtransaction that does
not generate any invalidation messages, which is by far the
common case.

Patch by me.  Review by Simon Riggs and Andres Freund.

9 years agoReset error message at PQreset()
Heikki Linnakangas [Wed, 29 Oct 2014 12:32:01 +0000 (14:32 +0200)]
Reset error message at PQreset()

If you call PQreset() repeatedly, and the connection cannot be
re-established, the error messages from the failed connection attempts
kept accumulating in the error string.

Fixes bug #11455 reported by Caleb Epstein. Backpatch to all supported
versions.

9 years agoRemove obsolete commentary.
Tom Lane [Tue, 28 Oct 2014 22:36:02 +0000 (18:36 -0400)]
Remove obsolete commentary.

Since we got rid of non-MVCC catalog scans, the fourth reason given for
using a non-transactional update in index_update_stats() is obsolete.
The other three are still good, so we're not going to change the code,
but fix the comment.

9 years agoRemove unnecessary assignment.
Heikki Linnakangas [Tue, 28 Oct 2014 18:26:20 +0000 (20:26 +0200)]
Remove unnecessary assignment.

Reported by MauMau.

9 years agoMinGW: Include .dll extension in .def file LIBRARY commands.
Noah Misch [Mon, 27 Oct 2014 23:59:39 +0000 (19:59 -0400)]
MinGW: Include .dll extension in .def file LIBRARY commands.

Newer toolchains append the extension implicitly if missing, but
buildfarm member narwhal (gcc 3.4.2, ld 2.15.91 20040904) does not.
This affects most core libraries having an exports.txt file, namely
libpq and the ECPG support libraries.  On Windows Server 2003, Windows
API functions that load and unload DLLs internally will mistakenly
unload a libpq whose DLL header reports "LIBPQ" instead of "LIBPQ.dll".
When, subsequently, control would return to libpq, the backend crashes.
Back-patch to 9.4, like commit 846e91e0223cf9f2821c3ad4dfffffbb929cb027.
Before that commit, we used a different linking technique that yielded
"libpq.dll" in the DLL header.

Commit 53566fc0940cf557416b13252df57350a4511ce4 worked around this by
eliminating a call to a function that loads and unloads DLLs internally.
That commit is no longer necessary for correctness, but its improving
consistency with the MSVC build remains valid.

9 years agoAdd missing equals signs to pg_recvlogical documentation.
Robert Haas [Mon, 27 Oct 2014 12:53:16 +0000 (08:53 -0400)]
Add missing equals signs to pg_recvlogical documentation.

Michael Paquier

9 years agoFix two bugs in tsquery @> operator.
Heikki Linnakangas [Mon, 27 Oct 2014 08:50:41 +0000 (10:50 +0200)]
Fix two bugs in tsquery @> operator.

1. The comparison for matching terms used only the CRC to decide if there's
a match. Two different terms with the same CRC gave a match.

2. It assumed that if the second operand has more terms than the first, it's
never a match. That assumption is bogus, because there can be duplicate
terms in either operand.

Rewrite the implementation in a way that doesn't have those bugs.

Backpatch to all supported versions.

9 years agoAdd variable names to two LWLock C prototypes
Bruce Momjian [Mon, 27 Oct 2014 08:45:57 +0000 (04:45 -0400)]
Add variable names to two LWLock C prototypes

Previously only the variable types appeared.

9 years agoAvoid unportable strftime() behavior in pg_dump/pg_dumpall.
Tom Lane [Mon, 27 Oct 2014 00:59:21 +0000 (20:59 -0400)]
Avoid unportable strftime() behavior in pg_dump/pg_dumpall.

Commit ad5d46a4494b0b480a3af246bb4227d9bdadca37 thought that we could
get around the known portability issues of strftime's %Z specifier by
using %z instead.  However, that idea seems to have been innocent of
any actual research, as it certainly missed the facts that
(1) %z is not portable to pre-C99 systems, and
(2) %z doesn't actually act differently from %Z on Windows anyway.

Per failures on buildfarm member hamerkop.

While at it, centralize the code defining what strftime format we
want to use in pg_dump; three copies of that string seems a bit much.

9 years agoFix undersized result buffer in pset_quoted_string().
Tom Lane [Sun, 26 Oct 2014 23:17:55 +0000 (19:17 -0400)]
Fix undersized result buffer in pset_quoted_string().

The malloc request was 1 byte too small for the worst-case output.
This seems relatively unlikely to cause any problems in practice,
as the worst case only occurs if the input string contains no
characters other than single-quote or newline, and even then
malloc alignment padding would probably save the day.  But it's
definitely a bug.

David Rowley

9 years agoImprove planning of btree index scans using ScalarArrayOpExpr quals.
Tom Lane [Sun, 26 Oct 2014 20:12:22 +0000 (16:12 -0400)]
Improve planning of btree index scans using ScalarArrayOpExpr quals.

Since we taught btree to handle ScalarArrayOpExpr quals natively (commit
9e8da0f75731aaa7605cf4656c21ea09e84d2eb1), the planner has always included
ScalarArrayOpExpr quals in index conditions if possible.  However, if the
qual is for a non-first index column, this could result in an inferior plan
because we can no longer take advantage of index ordering (cf. commit
807a40c551dd30c8dd5a0b3bd82f5bbb1e7fd285).  It can be better to omit the
ScalarArrayOpExpr qual from the index condition and let it be done as a
filter, so that the output doesn't need to get sorted.  Indeed, this is
true for the query introduced as a test case by the latter commit.

To fix, restructure get_index_paths and build_index_paths so that we
consider paths both with and without ScalarArrayOpExpr quals in non-first
index columns.  Redesign the API of build_index_paths so that it reports
what it found, saving useless second or third calls.

Report and patch by Andrew Gierth (though rather heavily modified by me).
Back-patch to 9.2 where this code was introduced, since the issue can
result in significant performance regressions compared to plans produced
by 9.1 and earlier.

9 years agoFix TAP tests with Perl 5.12
Peter Eisentraut [Sun, 26 Oct 2014 14:26:36 +0000 (10:26 -0400)]
Fix TAP tests with Perl 5.12

Perl 5.12 ships with a somewhat broken version of Test::Simple, so skip
the tests if that is found.

The relevant fix is

    0.98  Wed, 23 Feb 2011 14:38:02 +1100
        Bug Fixes
        * subtest() should not fail if $? is non-zero. (Aaron Crane)

9 years agoFix TAP tests with Perl 5.8
Peter Eisentraut [Sun, 26 Oct 2014 13:47:01 +0000 (09:47 -0400)]
Fix TAP tests with Perl 5.8

The prove program included in Perl 5.8 does not support the --ext
option, so don't use that and use wildcards on the command line instead.

Note that the tests will still all be skipped, because, for instance,
the version of Test::More is too old, but at least the regular
mechanisms for handling that will apply, instead of failing to call
prove altogether.

9 years agoAdd native compiler and memory barriers for solaris studio.
Andres Freund [Sat, 25 Oct 2014 08:27:41 +0000 (10:27 +0200)]
Add native compiler and memory barriers for solaris studio.

Discussion: 20140925133459.GB9633@alap3.anarazel.de
Author: Oskari Saarenmaa

9 years agoWork around Windows locale name with non-ASCII character.
Heikki Linnakangas [Fri, 24 Oct 2014 18:10:13 +0000 (21:10 +0300)]
Work around Windows locale name with non-ASCII character.

Windows has one a locale whose name contains a non-ASCII character:
"Norwegian (Bokmål)" (that's an 'a' with a ring on top). That causes
trouble; when passing it setlocale(), it's not clear what encoding the
argument should be in. Another problem is that the locale name is stored in
pg_database catalog table, and the encoding used there depends on what
server encoding happens to be in use when the database is created. For
example, if you issue the CREATE DATABASE when connected to a UTF-8
database, the locale name is stored in pg_database in UTF-8. As long as all
locale names are pure ASCII, that's not a problem.

To work around that, map the troublesome locale name to a pure-ASCII alias
of the same locale, "norwegian-bokmal".

Now, this doesn't change the existing values that are already in
pg_database and in postgresql.conf. Old clusters will need to be fixed
manually. Instructions for that need to be put in the release notes.

This fixes bug #11431 reported by Alon Siman-Tov. Backpatch to 9.2;
backpatching further would require more work than seems worth it.

9 years agoForgot #include "pg_getopt.h", now that pg_controldata uses getopt.
Heikki Linnakangas [Fri, 24 Oct 2014 17:39:56 +0000 (20:39 +0300)]
Forgot #include "pg_getopt.h", now that pg_controldata uses getopt.

Needed at least on Windows.

9 years agoComplain if too many options are passed to pg_controldata or pg_resetxlog.
Heikki Linnakangas [Fri, 24 Oct 2014 15:59:08 +0000 (18:59 +0300)]
Complain if too many options are passed to pg_controldata or pg_resetxlog.

9 years agoOops, the commit accept pg_controldata -D datadir missed code changes.
Heikki Linnakangas [Fri, 24 Oct 2014 15:55:33 +0000 (18:55 +0300)]
Oops, the commit accept pg_controldata -D datadir missed code changes.

I updated the docs and usage blurp, but forgot to commit the code changes
required.

Spotted by Michael Paquier.

9 years agoFix off-by-one error in 2781b4bea7db357be59f9a5fd73ca1eb12ff5a79.
Robert Haas [Fri, 24 Oct 2014 12:17:00 +0000 (08:17 -0400)]
Fix off-by-one error in 2781b4bea7db357be59f9a5fd73ca1eb12ff5a79.

Spotted by Tom Lane.

9 years agopsql: complain if pg_dump custom-format is detected
Alvaro Herrera [Fri, 24 Oct 2014 10:14:09 +0000 (07:14 -0300)]
psql: complain if pg_dump custom-format is detected

Apparently, this is a very common mistake for users to make; it is
better to have it fail reasonably rather than throw potentially a large
number of errors.  Since we have a magic string at the start of the
file, we can detect the case easily and there's no other possible useful
behavior anyway.

Author: Craig Ringer

9 years agoUpdate README.tuplock
Alvaro Herrera [Thu, 23 Oct 2014 23:51:58 +0000 (20:51 -0300)]
Update README.tuplock

This file was documenting an older version of patch 0ac5ad5134; update
it to match what was really committed

Author: Florian Pflug

9 years agoIn type_sanity, check I/O functions of built-in types are not volatile.
Tom Lane [Thu, 23 Oct 2014 19:59:40 +0000 (15:59 -0400)]
In type_sanity, check I/O functions of built-in types are not volatile.

We have a project policy that I/O functions must not be volatile, as per
commit aab353a60b95aadc00f81da0c6d99bde696c4b75, but we weren't doing
anything to enforce that.  In most usage the marking of the function
doesn't matter as long as its behavior is sane --- but I/O casts can
expose the marking as user-visible behavior, as per today's complaint
from Joe Van Dyk about contrib/ltree.

This test as such will only protect us against future errors in built-in
data types.  To catch the same error in contrib or third-party types,
perhaps we should make CREATE TYPE complain?  But that's a separate
issue from enforcing the policy for built-in types.

9 years agoImprove ispell dictionary's defenses against bad affix files.
Tom Lane [Thu, 23 Oct 2014 17:11:28 +0000 (13:11 -0400)]
Improve ispell dictionary's defenses against bad affix files.

Don't crash if an ispell dictionary definition contains flags but not
any compound affixes.  (This isn't a security issue since only superusers
can install affix files, but still it's a bad thing.)

Also, be more careful about detecting whether an affix-file FLAG command
is old-format (ispell) or new-format (myspell/hunspell).  And change the
error message about mixed old-format and new-format commands into something
intelligible.

Per bug #11770 from Emre Hasegeli.  Back-patch to all supported branches.

9 years agoPerform less setup work for AFTER triggers at transaction start.
Robert Haas [Thu, 23 Oct 2014 16:33:02 +0000 (12:33 -0400)]
Perform less setup work for AFTER triggers at transaction start.

Testing reveals that the memory allocation we do at transaction start
has small but measurable overhead on simple transactions.  To cut
down on that overhead, defer some of that work to the point when
AFTER triggers are first used, thus avoiding it altogether if they
never are.

Patch by me.  Review by Andres Freund.

9 years agoRemove the unused argument of PSQLexec().
Fujii Masao [Thu, 23 Oct 2014 13:33:56 +0000 (22:33 +0900)]
Remove the unused argument of PSQLexec().

This commit simply removes the second argument of PSQLexec that was
set to the same value everywhere. Comments and code blocks related
to this parameter are removed.

Noticed by Heikki Linnakangas, reviewed by Michael Paquier

9 years agoAdd a function to get the authenticated user ID.
Robert Haas [Thu, 23 Oct 2014 12:18:45 +0000 (08:18 -0400)]
Add a function to get the authenticated user ID.

Previously, this was not exposed outside of miscinit.c.  It is needed
for the pending pg_background patch, and will also be needed for
parallelism.  Without it, there's no way for a background worker to
re-create the exact authentication environment that was present in the
process that started it, which could lead to security exposures.

9 years agoPrevent the already-archived WAL file from being archived again.
Fujii Masao [Thu, 23 Oct 2014 07:21:27 +0000 (16:21 +0900)]
Prevent the already-archived WAL file from being archived again.

Previously the archive recovery always created .ready file for
the last WAL file of the old timeline at the end of recovery even when
it's restored from the archive and has .done file. That is, there was
the case where the WAL file had both .ready and .done files.
This caused the already-archived WAL file to be archived again.

This commit prevents the archive recovery from creating .ready file
for the last WAL file if it has .done file, in order to prevent it from
being archived again.

This bug was added when cascading replication feature was introduced,
i.e., the commit 5286105800c7d5902f98f32e11b209c471c0c69c.
So, back-patch to 9.2, where cascading replication was added.

Reviewed by Michael Paquier

9 years agoMinimize calls of pg_class_aclcheck to minimum necessary
Peter Eisentraut [Thu, 23 Oct 2014 01:41:43 +0000 (21:41 -0400)]
Minimize calls of pg_class_aclcheck to minimum necessary

In a couple of code paths, pg_class_aclcheck is called in succession
with multiple different modes set.  This patch combines those modes to
have a single call of this function and reduce a bit process overhead
for permission checking.

Author: Michael Paquier <michael@otacoo.com>
Reviewed-by: Fabrízio de Royes Mello <fabriziomello@gmail.com>
9 years agoAdd tests for sequence privileges
Peter Eisentraut [Thu, 23 Oct 2014 01:39:07 +0000 (21:39 -0400)]
Add tests for sequence privileges

9 years agoEnsure libpq reports a suitable error message on unexpected socket EOF.
Tom Lane [Wed, 22 Oct 2014 22:41:44 +0000 (18:41 -0400)]
Ensure libpq reports a suitable error message on unexpected socket EOF.

The EOF-detection logic in pqReadData was a bit confused about who should
set up the error message in case the kernel gives us read-ready-but-no-data
rather than ECONNRESET or some other explicit error condition.  Since the
whole point of this situation is that the lower-level functions don't know
there's anything wrong, pqReadData itself must set up the message.  But
keep the assumption that if an errno was reported, a message was set up at
lower levels.

Per bug #11712 from Marko Tiikkaja.  It's been like this for a very long
time, so back-patch to all supported branches.

9 years agoSmall code cleanup.
Michael Meskes [Wed, 22 Oct 2014 08:35:36 +0000 (10:35 +0200)]
Small code cleanup.

Declare static variable as static and external as extern.

9 years agoUpdate comment.
Heikki Linnakangas [Wed, 22 Oct 2014 12:39:28 +0000 (15:39 +0300)]
Update comment.

The _bt_tuplecompare() function mentioned in comment hasn't existed for a
long time.

Peter Geoghegan

9 years agoMinGW: Use -static-libgcc when linking a DLL.
Noah Misch [Wed, 22 Oct 2014 02:55:47 +0000 (22:55 -0400)]
MinGW: Use -static-libgcc when linking a DLL.

When commit 846e91e0223cf9f2821c3ad4dfffffbb929cb027 switched the linker
driver from dlltool/dllwrap to gcc, it became possible for linking to
choose shared libgcc.  Backends having loaded a module dynamically
linked to libgcc can exit abnormally, which the postmaster treats like a
crash.  Resume use of static libgcc exclusively, like 9.3 and earlier.
Back-patch to 9.4.

9 years agoMinGW: Link with shell32.dll instead of shfolder.dll.
Noah Misch [Wed, 22 Oct 2014 02:55:43 +0000 (22:55 -0400)]
MinGW: Link with shell32.dll instead of shfolder.dll.

This improves consistency with the MSVC build.  On buildfarm member
narwhal, since commit 846e91e0223cf9f2821c3ad4dfffffbb929cb027,
shfolder.dll:SHGetFolderPath() crashes when dblink calls it by way of
pqGetHomeDirectory().  Back-patch to 9.4, where that commit first
appeared.  How it caused this regression remains a mystery.  This is a
partial revert of commit 889f03812916b146ae504c0fad5afdc7bf2e8a2a, which
adopted shfolder.dll for Windows NT 4.0 compatibility.  PostgreSQL 8.2
dropped support for that operating system.

9 years agoUpdate expected/sequence_1.out.
Tom Lane [Tue, 21 Oct 2014 22:25:58 +0000 (18:25 -0400)]
Update expected/sequence_1.out.

The last three updates to the sequence regression test have all forgotten
to touch the alternate expected-output file.  Sigh.

Michael Paquier

9 years agoAllow input format xxxx-xxxx-xxxx for macaddr type
Peter Eisentraut [Tue, 21 Oct 2014 20:16:39 +0000 (16:16 -0400)]
Allow input format xxxx-xxxx-xxxx for macaddr type

Author: Herwin Weststrate <herwin@quarantainenet.nl>
Reviewed-by: Ali Akbar <the.apaan@gmail.com>
9 years agodoc: Check DocBook XML validity during the build
Peter Eisentraut [Tue, 21 Oct 2014 18:46:38 +0000 (14:46 -0400)]
doc: Check DocBook XML validity during the build

Building the documentation with XSLT does not check the DTD, like a
DSSSL build would.  One can often get away with having invalid XML, but
the stylesheets might then create incorrect output, as they are not
designed to handle that.  Therefore, check the validity of the XML
against the DTD, using xmllint, during the build.

Add xmllint detection to configure, and add some documentation.

xmllint comes with libxml2, which is already in use, but it might be in
a separate package, such as libxml2-utils on Debian.

Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr>
9 years agodoc: Update Red Hat documentation tools information
Peter Eisentraut [Tue, 21 Oct 2014 14:43:09 +0000 (10:43 -0400)]
doc: Update Red Hat documentation tools information

The old text was written in ancient times when RPM packages could be
shared more or less freely across a plethora of RPM-based Linux
distributions.  This isn't really the case anymore, so just make this
information more concrete for the Red Hat family.

9 years agodoc: Update FreeBSD documentation tools information
Peter Eisentraut [Tue, 21 Oct 2014 14:32:28 +0000 (10:32 -0400)]
doc: Update FreeBSD documentation tools information

based on patch from Dag-Erling Smørgrav <des@des.no>

9 years agoDon't duplicate log_checkpoint messages for both of restart and checkpoints.
Andres Freund [Mon, 20 Oct 2014 23:01:56 +0000 (01:01 +0200)]
Don't duplicate log_checkpoint messages for both of restart and checkpoints.

The duplication originated in cdd46c765, where restartpoints were
introduced.

In LogCheckpointStart's case the duplication actually lead to the
compiler's format string checking not to be effective because the
format string wasn't constant.

Arguably these messages shouldn't be elog(), but ereport() style
messages. That'd even allow to translate the messages... But as
there's more mistakes of that kind in surrounding code, it seems
better to change that separately.

9 years agoRenumber CHECKPOINT_* flags.
Andres Freund [Mon, 20 Oct 2014 22:20:08 +0000 (00:20 +0200)]
Renumber CHECKPOINT_* flags.

Commit 7dbb6069382 added a new CHECKPOINT_FLUSH_ALL flag. As that
commit needed to be backpatched I didn't change the numeric values of
the existing flags as that could lead to nastly problems if any
external code issued checkpoints. That's not a concern on master, so
renumber them there.

Also add a comment about CHECKPOINT_FLUSH_ALL above
CreateCheckPoint().

9 years agoFlush unlogged table's buffers when copying or moving databases.
Andres Freund [Mon, 20 Oct 2014 21:43:46 +0000 (23:43 +0200)]
Flush unlogged table's buffers when copying or moving databases.

CREATE DATABASE and ALTER DATABASE .. SET TABLESPACE copy the source
database directory on the filesystem level. To ensure the on disk
state is consistent they block out users of the affected database and
force a checkpoint to flush out all data to disk. Unfortunately, up to
now, that checkpoint didn't flush out dirty buffers from unlogged
relations.

That bug means there could be leftover dirty buffers in either the
template database, or the database in its old location. Leading to
problems when accessing relations in an inconsistent state; and to
possible problems during shutdown in the SET TABLESPACE case because
buffers belonging files that don't exist anymore are flushed.

This was reported in bug #10675 by Maxim Boguk.

Fix by Pavan Deolasee, modified somewhat by me. Reviewed by MauMau and
Fujii Masao.

Backpatch to 9.1 where unlogged tables were introduced.

9 years agopg_test_fsync: Update output format
Peter Eisentraut [Mon, 20 Oct 2014 19:34:59 +0000 (15:34 -0400)]
pg_test_fsync: Update output format

Apparently, computers are now a bit faster than when this was first
added, so we need to make room for a digit or two in the ops/sec format.

While we're at it, adjust some of the other output for a more consistent
line length.

9 years agoCorrect volatility markings of a few json functions.
Andrew Dunstan [Mon, 20 Oct 2014 18:55:35 +0000 (14:55 -0400)]
Correct volatility markings of a few json functions.

json_agg and json_object_agg and their associated transition functions
should have been marked as stable rather than immutable, as they call IO
functions indirectly. Changing this probably isn't going to make much
difference, as you can't use an aggregate function in an index
expression, but we should be correct nevertheless.

json_object, on the other hand, should be marked immutable rather than
stable, as it does not call IO functions.

As discussed on -hackers, this change is being made without bumping the
catalog version, as we don't want to do that at this stage of the  cycle,
and  the changes are very unlikely to affect anyone.

9 years agoFix mishandling of FieldSelect-on-whole-row-Var in nested lateral queries.
Tom Lane [Mon, 20 Oct 2014 16:23:42 +0000 (12:23 -0400)]
Fix mishandling of FieldSelect-on-whole-row-Var in nested lateral queries.

If an inline-able SQL function taking a composite argument is used in a
LATERAL subselect, and the composite argument is a lateral reference,
the planner could fail with "variable not found in subplan target list",
as seen in bug #11703 from Karl Bartel.  (The outer function call used in
the bug report and in the committed regression test is not really necessary
to provoke the bug --- you can get it if you manually expand the outer
function into "LATERAL (SELECT inner_function(outer_relation))", too.)

The cause of this is that we generate the reltargetlist for the referenced
relation before doing eval_const_expressions() on the lateral sub-select's
expressions (cf find_lateral_references()), so what's scheduled to be
emitted by the referenced relation is a whole-row Var, not the simplified
single-column Var produced by optimizing the function's FieldSelect on the
whole-row Var.  Then setrefs.c fails to match up that lateral reference to
what's available from the outer scan.

Preserving the FieldSelect optimization in such cases would require either
major planner restructuring (to recursively do expression simplification
on sub-selects much earlier) or some amazingly ugly kluge to change the
reltargetlist of a possibly-already-planned relation.  It seems better
just to skip the optimization when the Var is from an upper query level;
the case is not so common that it's likely anyone will notice a few
wasted cycles.

AFAICT this problem only occurs for uplevel LATERAL references, so
back-patch to 9.3 where LATERAL was added.