]> granicus.if.org Git - postgresql/log
postgresql
10 years agoFix dumping of a materialized view that depends on a table's primary key.
Tom Lane [Sat, 29 Mar 2014 21:34:00 +0000 (17:34 -0400)]
Fix dumping of a materialized view that depends on a table's primary key.

It is possible for a view or materialized view to depend on a table's
primary key, if the view query relies on functional dependency to
abbreviate a GROUP BY list.  This is problematic for pg_dump since we
ordinarily want to dump view definitions in the pre-data section but
indexes in post-data.  pg_dump knows how to deal with this situation for
regular views, by breaking the view's ON SELECT rule apart from the view
proper.  But it had not been taught what to do about materialized views,
and in fact mistakenly dumped them as regular views in such cases, as
seen in bug #9616 from Jesse Denardo.

If we had CREATE OR REPLACE MATERIALIZED VIEW, we could fix this in a
manner analogous to what's done for regular views; but we don't yet,
and we'd not back-patch such a thing into 9.3 anyway.  As a hopefully-
temporary workaround, break the circularity by postponing the matview
into post-data altogether when this case occurs.

10 years agoRevert "Secure Unix-domain sockets of "make check" temporary clusters."
Noah Misch [Sat, 29 Mar 2014 07:12:00 +0000 (03:12 -0400)]
Revert "Secure Unix-domain sockets of "make check" temporary clusters."

About half of the buildfarm members use too-long directory names,
strongly suggesting that this approach is a dead end.

10 years agoSecure Unix-domain sockets of "make check" temporary clusters.
Noah Misch [Sat, 29 Mar 2014 04:52:56 +0000 (00:52 -0400)]
Secure Unix-domain sockets of "make check" temporary clusters.

Any OS user able to access the socket can connect as the bootstrap
superuser and in turn execute arbitrary code as the OS user running the
test.  Protect against that by placing the socket in the temporary data
directory, which has mode 0700 thanks to initdb.  Back-patch to 8.4 (all
supported versions).  The hazard remains wherever the temporary cluster
accepts TCP connections, notably on Windows.

Attempts to run "make check" from a directory with a long name will now
fail.  An alternative not sharing that problem was to place the socket
in a subdirectory of /tmp, but that is only secure if /tmp is sticky.
The PG_REGRESS_SOCK_DIR environment variable is available as a
workaround when testing from long directory paths.

As a convenient side effect, this lets testing proceed smoothly in
builds that override DEFAULT_PGSOCKET_DIR.  Popular non-default values
like /var/run/postgresql are often unwritable to the build user.

Security: CVE-2014-0067

10 years agoDocument platform-specificity of unix_socket_permissions.
Noah Misch [Sat, 29 Mar 2014 04:52:31 +0000 (00:52 -0400)]
Document platform-specificity of unix_socket_permissions.

Back-patch to 8.4 (all supported versions).

10 years agoForce consistent row order in contrib/test_decoding regression test.
Noah Misch [Sat, 29 Mar 2014 04:31:44 +0000 (00:31 -0400)]
Force consistent row order in contrib/test_decoding regression test.

10 years agoImprove regression test for pg_filenode_relation().
Tom Lane [Fri, 28 Mar 2014 20:58:09 +0000 (16:58 -0400)]
Improve regression test for pg_filenode_relation().

Make it print the details in case there's a failure.

Andres Freund, slightly modified by me

10 years agoAdjust getpwuid() fix commit to display errno string on failure
Bruce Momjian [Fri, 28 Mar 2014 16:50:11 +0000 (12:50 -0400)]
Adjust getpwuid() fix commit to display errno string on failure

This adjusts patch 613c6d26bd42dd8c2dd0664315be9551475b8864.

10 years agoFix EquivalenceClass processing for nested append relations.
Tom Lane [Fri, 28 Mar 2014 15:50:01 +0000 (11:50 -0400)]
Fix EquivalenceClass processing for nested append relations.

The original coding of EquivalenceClasses didn't foresee that appendrel
child relations might themselves be appendrels; but this is possible for
example when a UNION ALL subquery scans a table with inheritance children.
The oversight led to failure to optimize ordering-related issues very well
for the grandchild tables.  After some false starts involving explicitly
flattening the appendrel representation, we found that this could be fixed
easily by removing a few implicit assumptions about appendrel parent rels
not being children themselves.

Kyotaro Horiguchi and Tom Lane, reviewed by Noah Misch

10 years agoUn-break peer authentication.
Tom Lane [Fri, 28 Mar 2014 14:30:37 +0000 (10:30 -0400)]
Un-break peer authentication.

Commit 613c6d26bd42dd8c2dd0664315be9551475b8864 sloppily replaced a
lookup of the UID obtained from getpeereid() with a lookup of the
server's own user name, thus totally destroying peer authentication.
Revert.  Per report from Christoph Berg.

In passing, make sure get_user_name() zeroes *errstr on success on
Windows as well as non-Windows.  I don't think any callers actually
depend on this ATM, but we should be consistent across platforms.

10 years agoImprove documentation note about Python 2.3 and cdecimal.
Tom Lane [Thu, 27 Mar 2014 21:15:45 +0000 (17:15 -0400)]
Improve documentation note about Python 2.3 and cdecimal.

Explain exactly what fails (ie, function arguments of type numeric)
if you don't have it.

10 years agocontrib/test_decoding: adjust expected output
Bruce Momjian [Thu, 27 Mar 2014 14:47:48 +0000 (10:47 -0400)]
contrib/test_decoding:  adjust expected output

Expected output has changed because of psql replica identity output
changes.

Reported by Christoph Berg

10 years agoSilence compiler warnings in new jsonb code.
Heikki Linnakangas [Thu, 27 Mar 2014 06:53:44 +0000 (08:53 +0200)]
Silence compiler warnings in new jsonb code.

Amit Kapila.

10 years agoDocument that Python 2.3 requires cdecimal module for full functionality.
Tom Lane [Thu, 27 Mar 2014 02:43:22 +0000 (22:43 -0400)]
Document that Python 2.3 requires cdecimal module for full functionality.

This has been true for some time, but we were leaving users to discover it
the hard way.

Back-patch to 9.2.  It might've been true before that, but we were claiming
Python 2.2 compatibility before that, so I won't guess at the exact
requirements back then.

10 years agoFix uninitialized variables in json's populate_record_worker().
Andrew Dunstan [Wed, 26 Mar 2014 22:20:56 +0000 (18:20 -0400)]
Fix uninitialized variables in json's populate_record_worker().

Peter Geoghegan.

10 years agoFix refcounting bug in PLy_modify_tuple().
Tom Lane [Wed, 26 Mar 2014 20:41:32 +0000 (16:41 -0400)]
Fix refcounting bug in PLy_modify_tuple().

We must increment the refcount on "plntup" as soon as we have the
reference, not sometime later.  Otherwise, if an error is thrown in
between, the Py_XDECREF(plntup) call in the PG_CATCH block removes a
refcount we didn't add, allowing the object to be freed even though
it's still part of the plpython function's parsetree.

This appears to be the cause of crashes seen on buildfarm member
prairiedog.  It's a bit surprising that we've not seen it fail repeatably
before, considering that the regression tests have been exercising the
faulty code path since 2009.

The real-world impact is probably minimal, since it's unlikely anyone would
be provoking the "TD["new"] is not a dictionary" error in production, and
that's the only case that is actually wrong.  Still, it's a bug affecting
the regression tests, so patch all supported branches.

In passing, remove dead variable "plstr", and demote "platt" to a local
variable inside the PG_TRY block, since we don't need to clean it up
in the PG_CATCH path.

10 years agoPass more than the first XLogRecData entry to rm_desc, with WAL_DEBUG.
Heikki Linnakangas [Wed, 26 Mar 2014 16:04:57 +0000 (18:04 +0200)]
Pass more than the first XLogRecData entry to rm_desc, with WAL_DEBUG.

If you compile with WAL_DEBUG and enable it with wal_debug=on, we used to
only pass the first XLogRecData entry to the rm_desc routine. I think the
original assumprion was that the first XLogRecData entry contains all the
necessary information for the rm_desc routine, but that's a pretty shaky
assumption. At least standby_redo didn't get the memo.

To fix, piece together all the data in a temporary buffer, and pass that to
the rm_desc routine.

It's been like this forever, but the patch didn't apply cleanly to
back-branches. Probably wouldn't be hard to fix the conflicts, but it's
not worth the trouble.

10 years agopsql: update "replica identity" display for \d+
Bruce Momjian [Wed, 26 Mar 2014 15:13:17 +0000 (11:13 -0400)]
psql:  update "replica identity" display for \d+

Display "replica identity" only for \d plus mode, exclude system schema
objects, and display all possible values, not just non-default,
non-index ones.

10 years agopg_upgrade: use pg_usleep(); remove Windows workaround
Bruce Momjian [Wed, 26 Mar 2014 14:22:16 +0000 (10:22 -0400)]
pg_upgrade: use pg_usleep();  remove Windows workaround

10 years agoCleanup around json_to_record/json_to_recordset
Andrew Dunstan [Wed, 26 Mar 2014 14:18:24 +0000 (10:18 -0400)]
Cleanup around json_to_record/json_to_recordset

Set function parameter names and defaults. Add jsonb versions (which the
code already provided for so the actual new code is trivial). Add jsonb
regression tests and docs.

Bump catalog version (which I apparently forgot to do when jsonb was
committed).

10 years agoUse pg_usleep() instead of plain sleep(), to fix Windows build
Heikki Linnakangas [Wed, 26 Mar 2014 13:25:39 +0000 (15:25 +0200)]
Use pg_usleep() instead of plain sleep(), to fix Windows build

Per buildfarm.

10 years agoAdd -f/--follow option to pg_xlogdump.
Heikki Linnakangas [Wed, 26 Mar 2014 11:48:20 +0000 (13:48 +0200)]
Add -f/--follow option to pg_xlogdump.

This is useful for seeing what WAL records are inserted in real-time, by
pointing pg_xlogdump to a live server.

10 years agoFix 'recheck' flag in tsquery's GIN tri-consistent function.
Heikki Linnakangas [Wed, 26 Mar 2014 08:13:44 +0000 (10:13 +0200)]
Fix 'recheck' flag in tsquery's GIN tri-consistent function.

It needs to be initialized, like in the boolean gin_tsquery_consistent
version.

Peter Geoghegan.

10 years agoTidy up the populate/to_record{set} code for json a bit.
Andrew Dunstan [Wed, 26 Mar 2014 01:20:54 +0000 (21:20 -0400)]
Tidy up the populate/to_record{set} code for json a bit.

In the process fix a small bug.

10 years agoDon't forget to flush XLOG_PARAMETER_CHANGE record.
Fujii Masao [Tue, 25 Mar 2014 17:12:39 +0000 (02:12 +0900)]
Don't forget to flush XLOG_PARAMETER_CHANGE record.

Backpatch to 9.0 where XLOG_PARAMETER_CHANGE record was instroduced.

10 years agoFix typos in pg_basebackup documentation
Magnus Hagander [Tue, 25 Mar 2014 10:16:57 +0000 (11:16 +0100)]
Fix typos in pg_basebackup documentation

Joshua Tolley

10 years agodoc: list unlogged tables as a non-durable option
Bruce Momjian [Tue, 25 Mar 2014 02:04:44 +0000 (22:04 -0400)]
doc:  list unlogged tables as a non-durable option

10 years agoRemove wchar.c Asserts that were stricter than the main code
Bruce Momjian [Mon, 24 Mar 2014 19:59:38 +0000 (15:59 -0400)]
Remove wchar.c Asserts that were stricter than the main code

Assert errors were thrown for functions being passed invalid encodings,
while the main code handled it just fine.

Also document that libpq's PQclientEncoding() returns -1 for an encoding
lookup failure.

Per report from Peter Geoghegan

10 years agodocs: Add short "cover density" description
Bruce Momjian [Mon, 24 Mar 2014 19:46:59 +0000 (15:46 -0400)]
docs:  Add short "cover density" description

Also, previous commit 1420f3a9827a39e5c6c998f6fa35a6fc97903145 to fix
ts_rank_cd() for stripped lexemes was from a patch created by Alex Hill.

10 years agoFix ts_rank_cd() to ignore stripped lexemes
Bruce Momjian [Mon, 24 Mar 2014 18:36:36 +0000 (14:36 -0400)]
Fix ts_rank_cd() to ignore stripped lexemes

Previously, stripped lexemes got a default location and could be
considered if mixed with non-stripped lexemes.

BACKWARD INCOMPATIBILITY CHANGE

10 years agoChange ginMergeItemPointers to return a palloc'd array.
Heikki Linnakangas [Mon, 24 Mar 2014 16:40:26 +0000 (18:40 +0200)]
Change ginMergeItemPointers to return a palloc'd array.

That seems nicer than making it the caller's responsibility to pass a
suitable-sized array. All the callers were just palloc'ing an array anyway.

10 years agoFix START_REPLICATION syntax in document.
Fujii Masao [Mon, 24 Mar 2014 10:23:32 +0000 (19:23 +0900)]
Fix START_REPLICATION syntax in document.

Enclose "TIMELINE tli" part with brackets because it's optional.

Backport to 9.3 where TIMELINE option was introduced.

Noted by Marko Tiikkaja

10 years agoRemove dead code and add comments.
Heikki Linnakangas [Mon, 24 Mar 2014 09:02:23 +0000 (11:02 +0200)]
Remove dead code and add comments.

'cbuffer' variable was left over from an earlier version of the patch to
rewrite the incomplete split handling.

10 years agoFix "the the" typos.
Heikki Linnakangas [Mon, 24 Mar 2014 06:42:13 +0000 (08:42 +0200)]
Fix "the the" typos.

Erik Rijkers

10 years agoDo jsonb regression test input in the conventional way.
Andrew Dunstan [Mon, 24 Mar 2014 00:18:06 +0000 (20:18 -0400)]
Do jsonb regression test input in the conventional way.

This should make the buildfarm happier.

10 years agoFix mis-spelling in jsonb docs.
Andrew Dunstan [Sun, 23 Mar 2014 22:25:16 +0000 (18:25 -0400)]
Fix mis-spelling in jsonb docs.

Per Thom Brown.

10 years agoIntroduce jsonb, a structured format for storing json.
Andrew Dunstan [Sun, 23 Mar 2014 20:40:19 +0000 (16:40 -0400)]
Introduce jsonb, a structured format for storing json.

The new format accepts exactly the same data as the json type. However, it is
stored in a format that does not require reparsing the orgiginal text in order
to process it, making it much more suitable for indexing and other operations.
Insignificant whitespace is discarded, and the order of object keys is not
preserved. Neither are duplicate object keys kept - the later value for a given
key is the only one stored.

The new type has all the functions and operators that the json type has,
with the exception of the json generation functions (to_json, json_agg etc.)
and with identical semantics. In addition, there are operator classes for
hash and btree indexing, and two classes for GIN indexing, that have no
equivalent in the json type.

This feature grew out of previous work by Oleg Bartunov and Teodor Sigaev, which
was intended to provide similar facilities to a nested hstore type, but which
in the end proved to have some significant compatibility issues.

Authors: Oleg Bartunov,  Teodor Sigaev, Peter Geoghegan and Andrew Dunstan.
Review: Andres Freund

10 years agoDon't test xmin/xmax columns of a postgres_fdw foreign table.
Noah Misch [Sun, 23 Mar 2014 07:48:17 +0000 (03:48 -0400)]
Don't test xmin/xmax columns of a postgres_fdw foreign table.

Their values are unspecified and system-dependent.

Per buildfarm member kouprey.

10 years agoOffer triggers on foreign tables.
Noah Misch [Sun, 23 Mar 2014 06:16:34 +0000 (02:16 -0400)]
Offer triggers on foreign tables.

This covers all the SQL-standard trigger types supported for regular
tables; it does not cover constraint triggers.  The approach for
acquiring the old row mirrors that for view INSTEAD OF triggers.  For
AFTER ROW triggers, we spool the foreign tuples to a tuplestore.

This changes the FDW API contract; when deciding which columns to
populate in the slot returned from data modification callbacks, writable
FDWs will need to check for AFTER ROW triggers in addition to checking
for a RETURNING clause.

In support of the feature addition, refactor the TriggerFlags bits and
the assembly of old tuples in ModifyTable.

Ronan Dunklau, reviewed by KaiGai Kohei; some additional hacking by me.

10 years agoImprove comments about AfterTriggerBeginQuery() query level usage.
Noah Misch [Sun, 23 Mar 2014 06:15:52 +0000 (02:15 -0400)]
Improve comments about AfterTriggerBeginQuery() query level usage.

10 years agoAddress ccvalid/ccnoinherit in TupleDesc support functions.
Noah Misch [Sun, 23 Mar 2014 06:13:43 +0000 (02:13 -0400)]
Address ccvalid/ccnoinherit in TupleDesc support functions.

equalTupleDescs() neglected both of these ConstrCheck fields, and
CreateTupleDescCopyConstr() neglected ccnoinherit.  At this time, the
only known behavior defect resulting from these omissions is constraint
exclusion disregarding a CHECK constraint validated by an ALTER TABLE
VALIDATE CONSTRAINT statement issued earlier in the same transaction.
Back-patch to 9.2, where these fields were introduced.

10 years agoFix thinkos in GinLogicValue enum.
Heikki Linnakangas [Fri, 21 Mar 2014 22:41:37 +0000 (23:41 +0100)]
Fix thinkos in GinLogicValue enum.

It was incorrectly declared as global variable, not an enum type, and
the comments for GIN_FALSE and GIN_TRUE were backwards.

10 years agoFix build with LWLOCK_STATS or dtrace.
Heikki Linnakangas [Fri, 21 Mar 2014 22:11:24 +0000 (23:11 +0100)]
Fix build with LWLOCK_STATS or dtrace.

Also fix the name of the dtrace probe for LWLockAcquireOrWait(). The
function was renamed from LWLockWaitUntilFree to LWLockAqcuireOrWait, but
the dtrace probe was neglected.

Pointed out by Andres Freund and the buildfarm.

10 years agoRemove MinGW readdir/errno bug workaround fixed on 2003-10-10
Bruce Momjian [Fri, 21 Mar 2014 17:47:37 +0000 (13:47 -0400)]
Remove MinGW readdir/errno bug workaround fixed on 2003-10-10

10 years agoProperly check for readdir/closedir() failures
Bruce Momjian [Fri, 21 Mar 2014 17:45:11 +0000 (13:45 -0400)]
Properly check for readdir/closedir() failures

Clear errno before calling readdir() and handle old MinGW errno bug
while adding full test coverage for readdir/closedir failures.

Backpatch through 8.4.

10 years agoReplace the XLogInsert slots with regular LWLocks.
Heikki Linnakangas [Fri, 21 Mar 2014 14:06:08 +0000 (15:06 +0100)]
Replace the XLogInsert slots with regular LWLocks.

The special feature the XLogInsert slots had over regular LWLocks is the
insertingAt value that was updated atomically with releasing backends
waiting on it. Add new functions to the LWLock API to do that, and replace
the slots with LWLocks. This reduces the amount of duplicated code.
(There's still some duplication, but at least it's all in lwlock.c now.)

Reviewed by Andres Freund.

10 years agoAgain fix initialization of auto-tuned effective_cache_size.
Tom Lane [Thu, 20 Mar 2014 16:58:13 +0000 (12:58 -0400)]
Again fix initialization of auto-tuned effective_cache_size.

The previous method was overly complex and underly correct; in particular,
by assigning the default value with PGC_S_OVERRIDE, it prevented later
attempts to change the setting in postgresql.conf, as noted by Jeff Janes.
We should just assign the default value with source PGC_S_DYNAMIC_DEFAULT,
which will have the desired priority relative to the boot_val as well as
user-set values.

There is still a gap in this method: if there's an explicit assignment of
effective_cache_size = -1 in the postgresql.conf file, and that assignment
appears before shared_buffers is assigned, the code will substitute 4 times
the bootstrap default for shared_buffers, and that value will then persist
(since it will have source PGC_S_FILE).  I don't see any very nice way
to avoid that though, and it's not a case to be expected in practice.
The existing comments in guc-file.l look forward to a redesign of the
DYNAMIC_DEFAULT mechanism; if that ever happens, we should consider this
case as one of the things we'd like to improve.

10 years agolibpq: pass a memory allocation failure error up to PQconndefaults()
Bruce Momjian [Thu, 20 Mar 2014 15:48:31 +0000 (11:48 -0400)]
libpq:  pass a memory allocation failure error up to PQconndefaults()

Previously user name memory allocation failures were ignored and the
default user name set to NULL.

10 years agotest_shm_mq: Improve regression tests.
Robert Haas [Thu, 20 Mar 2014 12:42:53 +0000 (08:42 -0400)]
test_shm_mq: Improve regression tests.

Per discussion with Tom Lane.

10 years agoSetup error context callback for transaction lock waits
Alvaro Herrera [Wed, 19 Mar 2014 18:10:36 +0000 (15:10 -0300)]
Setup error context callback for transaction lock waits

With this in place, a session blocking behind another one because of
tuple locks will get a context line mentioning the relation name, tuple
TID, and operation being done on tuple.  For example:

LOG:  process 11367 still waiting for ShareLock on transaction 717 after 1000.108 ms
DETAIL:  Process holding the lock: 11366. Wait queue: 11367.
CONTEXT:  while updating tuple (0,2) in relation "foo"
STATEMENT:  UPDATE foo SET value = 3;

Most usefully, the new line is displayed by log entries due to
log_lock_waits, although of course it will be printed by any other log
message as well.

Author: Christian Kruse, some tweaks by Álvaro Herrera
Reviewed-by: Amit Kapila, Andres Freund, Tom Lane, Robert Haas
10 years agoFix memory leak during regular expression execution.
Tom Lane [Wed, 19 Mar 2014 15:09:24 +0000 (11:09 -0400)]
Fix memory leak during regular expression execution.

For a regex containing backrefs, pg_regexec() might fail to free all the
sub-DFAs that were created during execution, resulting in a permanent
(session lifespan) memory leak.  Problem was introduced by me in commit
587359479acbbdc95c8e37da40707e37097423f5.  Per report from Sandro Santilli;
diagnosis by Greg Stark.

10 years agoSome minor improvements to logical decoding document.
Fujii Masao [Wed, 19 Mar 2014 13:13:05 +0000 (22:13 +0900)]
Some minor improvements to logical decoding document.

Also improve help message in pg_recvlogical.

10 years agoFix compilation of pg_xlogdump, now that rm_safe_restartpoint is no more.
Heikki Linnakangas [Tue, 18 Mar 2014 20:23:00 +0000 (22:23 +0200)]
Fix compilation of pg_xlogdump, now that rm_safe_restartpoint is no more.

Oops. Pointed out by Andres Freund.

10 years agoRemove rm_safe_restartpoint machinery.
Heikki Linnakangas [Tue, 18 Mar 2014 20:06:59 +0000 (22:06 +0200)]
Remove rm_safe_restartpoint machinery.

It is no longer used, none of the resource managers have multi-record
actions that would make it unsafe to perform a restartpoint.

Also don't allow rm_cleanup to write WAL records, it's also no longer
required. Move the call to rm_cleanup routines to make it more symmetric
with rm_startup.

10 years agoFix misc typos in comments.
Heikki Linnakangas [Tue, 18 Mar 2014 19:03:17 +0000 (21:03 +0200)]
Fix misc typos in comments.

10 years agoLogical decoding documentation corrections.
Robert Haas [Tue, 18 Mar 2014 18:57:49 +0000 (14:57 -0400)]
Logical decoding documentation corrections.

Thom Brown

10 years agoFix uninitialized variable.
Robert Haas [Tue, 18 Mar 2014 18:54:00 +0000 (14:54 -0400)]
Fix uninitialized variable.

Report from Andres Freund, but not his fix.

10 years agoMake the handling of interrupted B-tree page splits more robust.
Heikki Linnakangas [Tue, 18 Mar 2014 18:12:58 +0000 (20:12 +0200)]
Make the handling of interrupted B-tree page splits more robust.

Splitting a page consists of two separate steps: splitting the child page,
and inserting the downlink for the new right page to the parent. Previously,
we handled the case that you crash in between those steps with a cleanup
routine after the WAL recovery had finished, which finished the incomplete
split. However, that doesn't help if the page split is interrupted but the
database doesn't crash, so that you don't perform WAL recovery. That could
happen for example if you run out of disk space.

Remove the end-of-recovery cleanup step. Instead, when a page is split, the
left page is marked with a new INCOMPLETE_SPLIT flag, and when the downlink
is inserted to the parent, the flag is cleared again. If an insertion sees
a page with the flag set, it knows that the split was interrupted for some
reason, and inserts the missing downlink before proceeding.

I used the same approach to fix GIN and GiST split algorithms earlier. This
was the last WAL cleanup routine, so we could get rid of that whole
machinery now, but I'll leave that for a separate patch.

Reviewed by Peter Geoghegan.

10 years agoFix some remaining int64 vestiges in contrib/test_shm_mq.
Tom Lane [Tue, 18 Mar 2014 18:26:44 +0000 (14:26 -0400)]
Fix some remaining int64 vestiges in contrib/test_shm_mq.

Andres Freund and Tom Lane

10 years agotest_shm_mq: Use Size rather than uint64.
Robert Haas [Tue, 18 Mar 2014 17:30:19 +0000 (13:30 -0400)]
test_shm_mq: Use Size rather than uint64.

Commit 3bd261ca18c67eafe18088e58fab511e3b965418 updated the API but
neglected to make the corresponding edits here.

Per Tom Lane and the buildfarm.

10 years agoDocumentation for logical decoding.
Robert Haas [Tue, 18 Mar 2014 17:20:01 +0000 (13:20 -0400)]
Documentation for logical decoding.

Craig Ringer, Andres Freund, Christian Kruse, with edits by me.

10 years agoAdd pg_recvlogical, a tool to receive data logical decoding data.
Robert Haas [Tue, 18 Mar 2014 16:19:57 +0000 (12:19 -0400)]
Add pg_recvlogical, a tool to receive data logical decoding data.

This is fairly basic at the moment, but it's at least useful for
testing and debugging, and possibly more.

Andres Freund

10 years agoRewrite comment for shm_mq_receive_bytes.
Robert Haas [Tue, 18 Mar 2014 15:51:51 +0000 (11:51 -0400)]
Rewrite comment for shm_mq_receive_bytes.

The comment and the code diverged at some point before the initial
commit of this feature, and I failed to notice.

Noted by Tom Lane.

10 years agoFix relcache reference leak in refresh_by_match_merge().
Tom Lane [Tue, 18 Mar 2014 15:36:45 +0000 (11:36 -0400)]
Fix relcache reference leak in refresh_by_match_merge().

One path through the loop over indexes forgot to do index_close().  Rather
than adding a fourth call, restructure slightly so that there's only one.

In passing, get rid of an unnecessary syscache lookup: the pg_index struct
for the index is already available from its relcache entry.

Per report from YAMAMOTO Takashi, though this is a bit different from his
suggested patch.  This is new code in HEAD, so no need for back-patch.

10 years agoImprove shm_mq portability around MAXIMUM_ALIGNOF and sizeof(Size).
Robert Haas [Tue, 18 Mar 2014 15:19:13 +0000 (11:19 -0400)]
Improve shm_mq portability around MAXIMUM_ALIGNOF and sizeof(Size).

Revise the original decision to expose a uint64-based interface and
use Size everywhere possible.  Avoid assuming that MAXIMUM_ALIGNOF is
8, or making any assumption about the relationship between that value
and sizeof(Size).  If MAXIMUM_ALIGNOF is bigger, we'll now insert
padding after the length word; if it's smaller, we are now prepared
to read and write the length word in chunks.

Per discussion with Tom Lane.

10 years agoFix pg_dumpall option parsing: -i doesn't take an argument.
Tom Lane [Tue, 18 Mar 2014 14:38:25 +0000 (10:38 -0400)]
Fix pg_dumpall option parsing: -i doesn't take an argument.

This used to work properly, but got fat-fingered in commit
3dee636e0404885d07885d41c0d70e50c784f324.  Per bug #9620 from
Nicolas Payart.

10 years agoFix help message and document in pg_receivexlog.
Fujii Masao [Tue, 18 Mar 2014 12:15:45 +0000 (21:15 +0900)]
Fix help message and document in pg_receivexlog.

Add SLOTNAME placeholder to --slot option in help message and
document.

10 years agoMake it easy to detach completely from shared memory.
Robert Haas [Tue, 18 Mar 2014 11:58:53 +0000 (07:58 -0400)]
Make it easy to detach completely from shared memory.

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.

10 years agoRelease notes for 9.3.4, 9.2.8, 9.1.13, 9.0.17, 8.4.21.
Tom Lane [Mon, 17 Mar 2014 19:28:22 +0000 (15:28 -0400)]
Release notes for 9.3.4, 9.2.8, 9.1.13, 9.0.17, 8.4.21.

10 years agoDuring index build, check and elog (not just Assert) for broken HOT chain.
Tom Lane [Mon, 17 Mar 2014 16:36:11 +0000 (12:36 -0400)]
During index build, check and elog (not just Assert) for broken HOT chain.

The recently-fixed bug in WAL replay could result in not finding a parent
tuple for a heap-only tuple.  The existing code would either Assert or
generate an invalid index entry, neither of which is desirable.  Throw a
regular error instead.

10 years agoFix thinko: have trueTriConsistentFn return GIN_TRUE.
Heikki Linnakangas [Mon, 17 Mar 2014 15:18:40 +0000 (17:18 +0200)]
Fix thinko: have trueTriConsistentFn return GIN_TRUE.

While we're at it, also improve comments in ginlogic.c.

10 years agoFix typos in comments.
Fujii Masao [Mon, 17 Mar 2014 11:47:28 +0000 (20:47 +0900)]
Fix typos in comments.

Thom Brown

10 years agoFix bug in clean shutdown of walsender that pg_receiving is connecting to.
Fujii Masao [Mon, 17 Mar 2014 11:37:50 +0000 (20:37 +0900)]
Fix bug in clean shutdown of walsender that pg_receiving is connecting to.

On clean shutdown, walsender waits for all WAL to be replicated to a standby,
and exits. It determined whether that replication had been completed by
checking whether its sent location had been equal to a standby's flush
location. Unfortunately this condition never becomes true when the standby
such as pg_receivexlog which always returns an invalid flush location is
connecting to walsender, and then walsender waits forever.

This commit changes walsender so that it just checks a standby's write
location if a flush location is invalid.

Back-patch to 9.1 where enough infrastructure for this exists.

10 years agoFix small typo in comment
Magnus Hagander [Mon, 17 Mar 2014 08:09:21 +0000 (09:09 +0100)]
Fix small typo in comment

Michael Paquier

10 years agoplperl: Fix memory leak in hek2cstr
Alvaro Herrera [Mon, 17 Mar 2014 02:22:21 +0000 (23:22 -0300)]
plperl: Fix memory leak in hek2cstr

Backpatch all the way back to 9.1, where it was introduced by commit
50d89d42.

Reported by Sergey Burladyan in #9223
Author: Alex Hunsaker

10 years agoFix unportable shell-script syntax in pg_upgrade's test.sh.
Tom Lane [Mon, 17 Mar 2014 01:55:02 +0000 (21:55 -0400)]
Fix unportable shell-script syntax in pg_upgrade's test.sh.

I discovered the hard way that on some old shells, the locution
    FOO=""   unset FOO
does not behave the same as
    FOO="";  unset FOO
and in fact leaves FOO set to an empty string.  test.sh was inconsistently
spelling it different ways on adjacent lines.

This got broken relatively recently, in commit c737a2e56, so the lack of
field reports to date doesn't represent a lot of evidence that the problem
is rare.

10 years agoMake punctuation consistent
Peter Eisentraut [Mon, 17 Mar 2014 01:44:58 +0000 (21:44 -0400)]
Make punctuation consistent

10 years agoFix whitespace
Peter Eisentraut [Mon, 17 Mar 2014 01:43:59 +0000 (21:43 -0400)]
Fix whitespace

10 years agoFix advertised dispsize for libpq's sslmode connection parameter.
Tom Lane [Mon, 17 Mar 2014 01:43:40 +0000 (21:43 -0400)]
Fix advertised dispsize for libpq's sslmode connection parameter.

"8" was correct back when "disable" was the longest allowed value, but
since "verify-full" was added, it should be "12".  Given the lack of
complaints, I wouldn't be surprised if nobody is actually using these
values ... but still, if they're in the API, they should be right.

Noticed while pursuing a different problem.  It's been wrong for quite
a long time, so back-patch to all supported branches.

10 years agoCleanups from the remove-native-krb5 patch
Magnus Hagander [Sun, 16 Mar 2014 14:18:52 +0000 (15:18 +0100)]
Cleanups from the remove-native-krb5 patch

krb_srvname is actually not available anymore as a parameter server-side, since
with gssapi we accept all principals in our keytab. It's still used in libpq for
client side specification.

In passing remove declaration of krb_server_hostname, where all the functionality
was already removed.

Noted by Stephen Frost, though a different solution than his suggestion

10 years agoFirst-draft release notes for 9.3.4.
Tom Lane [Sat, 15 Mar 2014 19:58:59 +0000 (15:58 -0400)]
First-draft release notes for 9.3.4.

As usual, the release notes for older branches will be made by cutting
these down, but put them up for community review first.

10 years agoUpdate time zone data files to tzdata release 2014a.
Tom Lane [Sat, 15 Mar 2014 17:36:07 +0000 (13:36 -0400)]
Update time zone data files to tzdata release 2014a.

DST law changes in Fiji, Turkey; historical changes in Israel, Ukraine.

10 years agoFix race condition in B-tree page deletion.
Heikki Linnakangas [Fri, 14 Mar 2014 13:43:58 +0000 (15:43 +0200)]
Fix race condition in B-tree page deletion.

In short, we don't allow a page to be deleted if it's the rightmost child
of its parent, but that situation can change after we check for it.

Problem
-------

We check that the page to be deleted is not the rightmost child of its
parent, and then lock its left sibling, the page itself, its right sibling,
and the parent, in that order. However, if the parent page is split after
the check but before acquiring the locks, the target page might become the
rightmost child, if the split happens at the right place. That leads to an
error in vacuum (I reproduced this by setting a breakpoint in debugger):

ERROR:  failed to delete rightmost child 41 of block 3 in index "foo_pkey"

We currently re-check that the page is still the rightmost child, and throw
the above error if it's not. We could easily just give up rather than throw
an error, but that approach doesn't scale to half-dead pages. To recap,
although we don't normally allow deleting the rightmost child, if the page
is the *only* child of its parent, we delete the child page and mark the
parent page as half-dead in one atomic operation. But before we do that, we
check that the parent can later be deleted, by checking that it in turn is
not the rightmost child of the grandparent (potentially recursing all the
way up to the root). But the same situation can arise there - the
grandparent can be split while we're not holding the locks. We end up with
a half-dead page that we cannot delete.

To make things worse, the keyspace of the deleted page has already been
transferred to its right sibling. As the README points out, the keyspace at
the grandparent level is "out-of-whack" until the half-dead page is deleted,
and if enough tuples with keys in the transferred keyspace are inserted, the
page might get split and a downlink might be inserted into the grandparent
that is out-of-order. That might not cause any serious problem if it's
transient (as the README ponders), but is surely bad if it stays that way.

Solution
--------

This patch changes the page deletion algorithm to avoid that problem. After
checking that the topmost page in the chain of to-be-deleted pages is not
the rightmost child of its parent, and then deleting the pages from bottom
up, unlink the pages from top to bottom. This way, the intermediate stages
are similar to the intermediate stages in page splitting, and there is no
transient stage where the keyspace is "out-of-whack". The topmost page in
the to-be-deleted chain doesn't have a downlink pointing to it, like a page
split before the downlink has been inserted.

This also allows us to get rid of the cleanup step after WAL recovery, if we
crash during page deletion. The deletion will be continued at next VACUUM,
but the tree is consistent for searches and insertions at every step.

This bug is old, all supported versions are affected, but this patch is too
big to back-patch (and changes the WAL record formats of related records).
We have not heard any reports of the bug from users, so clearly it's not
easy to bump into. Maybe backpatch later, after this has had some field
testing.

Reviewed by Kevin Grittner and Peter Geoghegan.

10 years agoPrevent interrupts while reporting non-ERROR elog messages.
Tom Lane [Fri, 14 Mar 2014 00:59:42 +0000 (20:59 -0400)]
Prevent interrupts while reporting non-ERROR elog messages.

This should eliminate the risk of recursive entry to syslog(3), which
appears to be the cause of the hang reported in bug #9551 from James
Morton.

Arguably, the real problem here is auth.c's willingness to turn on
ImmediateInterruptOK while executing fairly wide swaths of backend code.
We may well need to work at narrowing the code ranges in which the
authentication_timeout interrupt is enabled.  For the moment, though,
this is a cheap and reasonably noninvasive fix for a field-reported
failure; the other approach would be complex and not necessarily
bug-free itself.

Back-patch to all supported branches.

10 years agoAllow psql to print COPY command status in more cases.
Tom Lane [Thu, 13 Mar 2014 17:49:03 +0000 (13:49 -0400)]
Allow psql to print COPY command status in more cases.

Previously, psql would print the "COPY nnn" command status only for COPY
commands executed server-side.  Now it will print that for frontend copies
too (including \copy).  However, we continue to suppress the command status
for COPY TO STDOUT, since in that case the copy data has been routed to the
same place that the command status would go, and there is a risk of the
status line being mistaken for another line of COPY data.  Doing that would
break existing scripts, and it doesn't seem worth the benefit --- this case
seems fairly analogous to SELECT, for which we also suppress the command
status.

Kumar Rajeev Rastogi, with substantial review by Amit Khandekar

10 years agoAvoid transaction-commit race condition while receiving a NOTIFY message.
Tom Lane [Thu, 13 Mar 2014 16:02:54 +0000 (12:02 -0400)]
Avoid transaction-commit race condition while receiving a NOTIFY message.

Use TransactionIdIsInProgress, then TransactionIdDidCommit, to distinguish
whether a NOTIFY message's originating transaction is in progress,
committed, or aborted.  The previous coding could accept a message from a
transaction that was still in-progress according to the PGPROC array;
if the client were fast enough at starting a new transaction, it might fail
to see table rows added/updated by the message-sending transaction.  Which
of course would usually be the point of receiving the message.  We noted
this type of race condition long ago in tqual.c, but async.c overlooked it.

The race condition probably cannot occur unless there are multiple NOTIFY
senders in action, since an individual backend doesn't send NOTIFY signals
until well after it's done committing.  But if two senders commit in close
succession, it's certainly possible that we could see the second sender's
message within the race condition window while responding to the signal
from the first one.

Per bug #9557 from Marko Tiikkaja.  This patch is slightly more invasive
than what he proposed, since it removes the now-redundant
TransactionIdDidAbort call.

Back-patch to 9.0, where the current NOTIFY implementation was introduced.

10 years agoFix a couple of typos in docs.
Heikki Linnakangas [Thu, 13 Mar 2014 13:01:45 +0000 (15:01 +0200)]
Fix a couple of typos in docs.

Thom Brown

10 years agoC comments: remove odd blank lines after #ifdef WIN32 lines
Bruce Momjian [Thu, 13 Mar 2014 05:42:24 +0000 (01:42 -0400)]
C comments:  remove odd blank lines after #ifdef WIN32 lines

A few more

10 years agoC comments: remove odd blank lines after #ifdef WIN32 lines
Bruce Momjian [Thu, 13 Mar 2014 05:34:42 +0000 (01:34 -0400)]
C comments:  remove odd blank lines after #ifdef WIN32 lines

10 years agoOnly WAL-log the modified portion in an UPDATE, if possible.
Heikki Linnakangas [Wed, 12 Mar 2014 20:46:04 +0000 (22:46 +0200)]
Only WAL-log the modified portion in an UPDATE, if possible.

When a row is updated, and the new tuple version is put on the same page as
the old one, only WAL-log the part of the new tuple that's not identical to
the old. This saves significantly on the amount of WAL that needs to be
written, in the common case that most fields are not modified.

Amit Kapila, with a lot of back and forth with me, Robert Haas, and others.

10 years agoItems on GIN data pages are no longer always 6 bytes; update gincostestimate.
Heikki Linnakangas [Wed, 12 Mar 2014 18:43:07 +0000 (20:43 +0200)]
Items on GIN data pages are no longer always 6 bytes; update gincostestimate.

Also improve the comments a bit.

10 years agoShow PIDs of lock holders and waiters in log_lock_waits log message.
Fujii Masao [Wed, 12 Mar 2014 18:26:47 +0000 (03:26 +0900)]
Show PIDs of lock holders and waiters in log_lock_waits log message.

Christian Kruse, reviewed by Kumar Rajeev Rastogi.

10 years agotest_decoding: Documentation fix.
Robert Haas [Wed, 12 Mar 2014 18:11:06 +0000 (14:11 -0400)]
test_decoding: Documentation fix.

Andres Freund

10 years agoFix incorrect assertion about historical snapshots.
Robert Haas [Wed, 12 Mar 2014 18:07:41 +0000 (14:07 -0400)]
Fix incorrect assertion about historical snapshots.

Also fix some nearby comments.

Andres Freund

10 years agoComment fixes related to logical decoding.
Robert Haas [Wed, 12 Mar 2014 18:03:09 +0000 (14:03 -0400)]
Comment fixes related to logical decoding.

Andres Freund, per complaints by Peter Eisentraut.

10 years agoAllow opclasses to provide tri-valued GIN consistent functions.
Heikki Linnakangas [Wed, 12 Mar 2014 15:13:22 +0000 (17:13 +0200)]
Allow opclasses to provide tri-valued GIN consistent functions.

With the GIN "fast scan" feature, GIN can skip items without fetching all
the keys for them, if it can prove that they don't match regardless of
those keys. So far, it has done the proving by calling the boolean
consistent function with all combinations of TRUE/FALSE for the unfetched
keys, but since that's O(n^2), it becomes unfeasible with more than a few
keys. We can avoid calling consistent with all the combinations, if we can
tell the operator class implementation directly which keys are unknown.

This commit includes a triConsistent function for the built-in array and
tsvector opclasses.

Alexander Korotkov, with some changes by me.

10 years agoIn WAL replay, restore GIN metapage unconditionally to avoid torn page.
Heikki Linnakangas [Wed, 12 Mar 2014 07:59:49 +0000 (09:59 +0200)]
In WAL replay, restore GIN metapage unconditionally to avoid torn page.

We don't take a full-page image of the GIN metapage; instead, the WAL record
contains all the information required to reconstruct it from scratch. But
to avoid torn page hazards, we must re-initialize it from the WAL record
every time, even if it already has a greater LSN, similar to how normal full
page images are restored.

This was highly unlikely to cause any problems in practice, because the GIN
metapage is small. We rely on an update smaller than a 512 byte disk sector
to be atomic elsewhere, at least in pg_control. But better safe than sorry,
and this would be easy to overlook if more fields are added to the metapage
so that it's no longer small.

Reported by Noah Misch. Backpatch to all supported versions.

10 years agoFix tracking of psql script line numbers during \copy from another place.
Tom Lane [Mon, 10 Mar 2014 19:47:06 +0000 (15:47 -0400)]
Fix tracking of psql script line numbers during \copy from another place.

Commit 08146775acd8bfe0fcc509c71857abb928697171 changed do_copy() to
temporarily scribble on pset.cur_cmd_source.  That was a mighty ugly bit of
code in any case, but in particular it broke handleCopyIn's ability to tell
whether it was reading from the current script source file (in which case
pset.lineno should be incremented for each line of COPY data), or from
someplace else (in which case it shouldn't).  The former case still worked,
the latter not so much.  The visible effect was that line numbers reported
for errors in a script file would be wrong if there were an earlier \copy
that was reading anything other than inline-in-the-script-file data.

To fix, introduce another pset field that holds the file do_copy wants the
COPY code to use.  This is a little bit ugly, but less so than passing the
file down explicitly through several layers that aren't COPY-specific.

Extracted from a larger patch by Kumar Rajeev Rastogi; that patch also
changes printing of COPY command tags, which is not a bug fix and shouldn't
get back-patched.  This particular idea was from a suggestion by Amit
Khandekar, if I'm reading the thread correctly.

Back-patch to 9.2 where the faulty code was introduced.

10 years agoAllow dynamic shared memory segments to be kept until shutdown.
Robert Haas [Mon, 10 Mar 2014 18:04:47 +0000 (14:04 -0400)]
Allow dynamic shared memory segments to be kept until shutdown.

Amit Kapila, reviewed by Kyotaro Horiguchi, with some further
changes by me.

10 years agoAllow logical decoding via the walsender interface.
Robert Haas [Mon, 10 Mar 2014 17:50:28 +0000 (13:50 -0400)]
Allow logical decoding via the walsender interface.

In order for this to work, walsenders need the optional ability to
connect to a database, so the "replication" keyword now allows true
or false, for backward-compatibility, and the new value "database"
(which causes the "dbname" parameter to be respected).

walsender needs to loop not only when idle but also when sending
decoded data to the user and when waiting for more xlog data to decode.
This means that there are now three separate loops inside walsender.c;
although some refactoring has been done here, this is still a bit ugly.

Andres Freund, with contributions from Álvaro Herrera, and further
review by me.

10 years agoTeach on_exit_reset() to discard pending cleanups for dsm.
Robert Haas [Mon, 10 Mar 2014 14:17:19 +0000 (10:17 -0400)]
Teach on_exit_reset() to discard pending cleanups for dsm.

If a postmaster child invokes fork() and then calls on_exit_reset, that
should be sufficient to let it exit() without breaking anything, but
dynamic shared memory broke that by not updating on_exit_reset() to
discard callbacks registered with dynamic shared memory segments.

Per investigation of a complaint from Tom Lane.