]> granicus.if.org Git - postgresql/log
postgresql
10 years agoCorrect copy/pasto in comment for REPLICA IDENTITY
Simon Riggs [Sun, 9 Mar 2014 09:05:16 +0000 (09:05 +0000)]
Correct copy/pasto in comment for REPLICA IDENTITY

10 years agodoc: remove extra whitespace in SGML markup
Bruce Momjian [Sat, 8 Mar 2014 22:08:01 +0000 (17:08 -0500)]
doc: remove extra whitespace in SGML markup

10 years agoC comments: improve description of relfilenode uniqueness
Bruce Momjian [Sat, 8 Mar 2014 17:20:30 +0000 (12:20 -0500)]
C comments: improve description of relfilenode uniqueness

Report by Antonin Houska

10 years agopg_ctl: improve handling of invalid data directory
Bruce Momjian [Sat, 8 Mar 2014 17:15:25 +0000 (12:15 -0500)]
pg_ctl:  improve handling of invalid data directory

Return '4' and report a meaningful error message when a non-existent or
invalid data directory is passed.  Previously, pg_ctl would just report
the server was not running.

Patch by me and Amit Kapila
Report from Peter Eisentraut

10 years agodocs: small adjustements to recent SELECT and pg_upgrade improvements
Bruce Momjian [Sat, 8 Mar 2014 16:26:47 +0000 (11:26 -0500)]
docs:  small adjustements to recent SELECT and pg_upgrade improvements

10 years agopg_upgrade: document delete problems with tablespaces inside the cluster directory
Bruce Momjian [Sat, 8 Mar 2014 03:46:38 +0000 (22:46 -0500)]
pg_upgrade: document delete problems with tablespaces inside the cluster directory

Per report by Marc Mamin

10 years agodoc: improve server's keepalive description
Bruce Momjian [Sat, 8 Mar 2014 03:02:38 +0000 (22:02 -0500)]
doc: improve server's keepalive description

Use superior libpq keepalive description for the server-level
parameters.

Per report by Tatsuo Ishii and Marko Tiikkaja

10 years agodocs: improve TABLE command by showing supported clauses
Bruce Momjian [Sat, 8 Mar 2014 01:56:00 +0000 (20:56 -0500)]
docs:  improve TABLE command by showing supported clauses

Initial patch by Colin 't Hart

10 years agoRemove unportable use of anonymous unions from reorderbuffer.h.
Tom Lane [Fri, 7 Mar 2014 22:02:48 +0000 (17:02 -0500)]
Remove unportable use of anonymous unions from reorderbuffer.h.

In b89e151054a I had assumed it was ok to use anonymous unions as
struct members, but while a longstanding extension in many compilers,
it's only been standardized in C11.

To fix, remove one of the anonymous unions which tried to hide some
implementation specific enum values and give the other a name. The
latter unfortunately requires changes in output plugins, but since the
feature has only been added a few days ago...

Andres Freund

10 years agoFix contrib/postgres_fdw to handle multiple join conditions properly.
Tom Lane [Fri, 7 Mar 2014 21:35:58 +0000 (16:35 -0500)]
Fix contrib/postgres_fdw to handle multiple join conditions properly.

The previous coding supposed that it could consider just a single join
condition in any one parameterized path for the foreign table.  But in
reality, the parameterized-path machinery forces all join clauses that are
"movable to" the foreign table to be evaluated at that node; including
clauses that we might not consider safe to send across.  Such cases would
result in an Assert failure in an assert-enabled build, and otherwise in
sending an unsafe clause to the foreign server, which might result in
errors or silently-wrong answers.  A lesser problem was that the
cost/rowcount estimates generated for the parameterized path failed to
account for any additional join quals that get assigned to the scan.

To fix, rewrite postgresGetForeignPaths so that it correctly collects all
the movable quals for any one outer relation when generating parameterized
paths; we'll now generate just one path per outer relation not one per join
qual.  Also fix bogus assumptions in postgresGetForeignPlan and
estimate_path_cost_size that only safe-to-send join quals will be
presented.

Based on complaint from Etsuro Fujita that the path costs were being
miscalculated, though this is significantly different from his proposed
patch.

10 years agorelease notes: add item missed in 9.2.5 release
Bruce Momjian [Fri, 7 Mar 2014 18:45:38 +0000 (13:45 -0500)]
release notes:  add item missed in 9.2.5 release

Item is "Prevent errors in WAL replay due to references to uninitialized
empty pages".

Report and text by Andres Freund

Backpatch through 9.2.

10 years agofix ReplicationSlotsCountDBSlots for dropping unrelated databases
Bruce Momjian [Fri, 7 Mar 2014 16:42:18 +0000 (11:42 -0500)]
fix ReplicationSlotsCountDBSlots for dropping unrelated databases

YAMAMOTO Takashi

10 years agoFix dangling smgr_owner pointer when a fake relcache entry is freed.
Heikki Linnakangas [Fri, 7 Mar 2014 11:25:11 +0000 (13:25 +0200)]
Fix dangling smgr_owner pointer when a fake relcache entry is freed.

A fake relcache entry can "own" a SmgrRelation object, like a regular
relcache entry. But when it was free'd, the owner field in SmgrRelation
was not cleared, so it was left pointing to free'd memory.

Amazingly this apparently hasn't caused crashes in practice, or we would've
heard about it earlier. Andres found this with Valgrind.

Report and fix by Andres Freund, with minor modifications by me. Backpatch
to all supported versions.

10 years agoAvoid memcpy() with same source and destination address.
Heikki Linnakangas [Fri, 7 Mar 2014 11:13:33 +0000 (13:13 +0200)]
Avoid memcpy() with same source and destination address.

The behavior of that is undefined, although unlikely to lead to problems in
practice.

Found by running regression tests with Valgrind.

10 years agoFix name of syslog_ident GUC in docs.
Heikki Linnakangas [Fri, 7 Mar 2014 08:35:37 +0000 (10:35 +0200)]
Fix name of syslog_ident GUC in docs.

Michael Paquier

10 years agoAvoid getting more than AccessShareLock when deparsing a query.
Tom Lane [Fri, 7 Mar 2014 00:31:05 +0000 (19:31 -0500)]
Avoid getting more than AccessShareLock when deparsing a query.

In make_ruledef and get_query_def, we have long used AcquireRewriteLocks
to ensure that the querytree we are about to deparse is up-to-date and
the schemas of the underlying relations aren't changing.  Howwever, that
function thinks the query is about to be executed, so it acquires locks
that are stronger than necessary for the purpose of deparsing.  Thus for
example, if pg_dump asks to deparse a rule that includes "INSERT INTO t",
we'd acquire RowExclusiveLock on t.  That results in interference with
concurrent transactions that might for example ask for ShareLock on t.
Since pg_dump is documented as being purely read-only, this is unexpected.
(Worse, it used to actually be read-only; this behavior dates back only
to 8.1, cf commit ba4200246.)

Fix this by adding a parameter to AcquireRewriteLocks to tell it whether
we want the "real" execution locks or only AccessShareLock.

Report, diagnosis, and patch by Dean Rasheed.  Back-patch to all supported
branches.

10 years agoisdigit() needs an unsigned char argument.
Heikki Linnakangas [Thu, 6 Mar 2014 19:19:00 +0000 (21:19 +0200)]
isdigit() needs an unsigned char argument.

Per the C standard, the routine should be passed an int, with a value that's
representable as an unsigned char or EOF. Passing a signed char is wrong,
because a negative value is not representable as an unsigned char.
Unfortunately no compiler warns about that.

10 years agoSend keepalives from walsender even when busy sending WAL.
Heikki Linnakangas [Thu, 6 Mar 2014 19:13:38 +0000 (21:13 +0200)]
Send keepalives from walsender even when busy sending WAL.

If walsender doesn't hear from the client for the time specified by
wal_sender_timeout, it will conclude the connection or client is dead, and
disconnect. When half of wal_sender_timeout has elapsed, it sends a ping
to the client, leaving it the remainig half of wal_sender_timeout to
respond. However, it only checked if half of wal_sender_timeout had elapsed
when it was about to sleep, so if it was busy sending WAL to the client for
long enough, it would not send the ping request in time. Then the client
would not know it needs to send a reply, and the walsender will disconnect
even though the client is still alive. Fix that.

Andres Freund, reviewed by Robert Haas, and some further changes by me.
Backpatch to 9.3. Earlier versions relied on the client to send the
keepalives on its own, and hence didn't have this problem.

10 years agoDon't reject ROW_MARK_REFERENCE rowmarks for materialized views.
Tom Lane [Thu, 6 Mar 2014 16:37:02 +0000 (11:37 -0500)]
Don't reject ROW_MARK_REFERENCE rowmarks for materialized views.

We should allow this so that matviews can be referenced in UPDATE/DELETE
statements in READ COMMITTED isolation level.  The requirement for that
is that a re-fetch by TID will see the same row version the query saw
earlier, which is true of matviews, so there's no reason for the
restriction.  Per bug #9398.

Michael Paquier, after a suggestion by me

10 years agoC comment update: relfilenode is only unique with a tablespace
Bruce Momjian [Thu, 6 Mar 2014 01:52:34 +0000 (20:52 -0500)]
C comment update: relfilenode is only unique with a tablespace

Report from Antonin Houska

10 years agodocs: to_timestamp and to_date do minimal range checking
Bruce Momjian [Thu, 6 Mar 2014 01:45:27 +0000 (20:45 -0500)]
docs:  to_timestamp and to_date do minimal range checking

Initial patch from Steve Crawford

10 years agopg_dump: make argument combination error exit code consistent
Bruce Momjian [Wed, 5 Mar 2014 23:15:19 +0000 (18:15 -0500)]
pg_dump:  make argument combination error exit code consistent

Per report from Pavel Golub

10 years agoFix portability issues in recently added make_timestamp/make_interval code.
Tom Lane [Wed, 5 Mar 2014 21:42:18 +0000 (16:42 -0500)]
Fix portability issues in recently added make_timestamp/make_interval code.

Explicitly reject infinity/NaN inputs, rather than just assuming that
something else will do it for us.  Per buildfarm.

While at it, make some over-parenthesized and under-legible code
more readable.

10 years agoAdd comment that ec_relids excludes "child" EquivalenceClass members.
Tom Lane [Wed, 5 Mar 2014 21:00:22 +0000 (16:00 -0500)]
Add comment that ec_relids excludes "child" EquivalenceClass members.

This was already documented a few lines further down, but the comment
just beside the field declaration could be misleading.  Per gripe
from Kyotaro Horiguchi.

10 years agoFix some typos introduced by the logical decoding patch.
Robert Haas [Wed, 5 Mar 2014 18:00:22 +0000 (13:00 -0500)]
Fix some typos introduced by the logical decoding patch.

Erik Rijkers

10 years agoFix test_decoding regression test outputs.
Robert Haas [Wed, 5 Mar 2014 17:55:43 +0000 (12:55 -0500)]
Fix test_decoding regression test outputs.

Commit 6f37c08057685ee3c6c63222dba0dac012760dde removed whitespace
from the SQL file but not the expected-output file, and commit
7e8db2dc420099df3fa73987cf2d2d6d1a609d86 changed the error message
without updating the expected outputs.

10 years agoRemove unused field "evttype".
Tom Lane [Wed, 5 Mar 2014 16:57:53 +0000 (11:57 -0500)]
Remove unused field "evttype".

Apparent oversight in commit 3855968f.

10 years agoRemove the correct pgstat file on DROP DATABASE
Alvaro Herrera [Wed, 5 Mar 2014 16:03:29 +0000 (13:03 -0300)]
Remove the correct pgstat file on DROP DATABASE

We were unlinking the permanent file, not the non-permanent one.  But
since the stat collector already unlinks all permanent files on startup,
there was nothing for it to unlink.  The non-permanent file remained in
place, and was copied to the permanent directory on shutdown, so in
effect no file was ever dropped.

Backpatch to 9.3, where the issue was introduced by commit 187492b6c2e8.
Before that, there were no per-database files and thus no file to drop
on DROP DATABASE.

Per report from Thom Brown.

Author: Tomáš Vondra

10 years agopg_upgrade: improve C comment about what old/new oids match
Bruce Momjian [Wed, 5 Mar 2014 15:43:45 +0000 (10:43 -0500)]
pg_upgrade:  improve C comment about what old/new oids match

10 years agoAllocate fresh memory for post_opts/exec_path
Stephen Frost [Wed, 5 Mar 2014 13:50:12 +0000 (08:50 -0500)]
Allocate fresh memory for post_opts/exec_path

Instead of having read_post_opts() depend on the memory allocated for
the config file (which is now getting free'd), pg_strdup() for
post_opts and exec_path (similar to how it's being done elsewhere).

Noted by Thom Brown.

10 years agoDo wal_level and hot standby checks when doing crash-then-archive recovery.
Heikki Linnakangas [Wed, 5 Mar 2014 12:41:55 +0000 (14:41 +0200)]
Do wal_level and hot standby checks when doing crash-then-archive recovery.

CheckRequiredParameterValues() should perform the checks if archive recovery
was requested, even if we are going to perform crash recovery first.

Reported by Kyotaro HORIGUCHI. Backpatch to 9.2, like the crash-then-archive
recovery mode.

10 years agoFix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.
Heikki Linnakangas [Wed, 5 Mar 2014 11:27:18 +0000 (13:27 +0200)]
Fix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.

When entering crash recovery followed by archive recovery, and the latest
checkpoint is a shutdown checkpoint, and there are no more WAL records to
replay before transitioning from crash to archive recovery, we would not
immediately allow read-only connections in hot standby mode even if we
could. That's because when starting from a shutdown checkpoint, we set
lastReplayedEndRecPtr incorrectly to the record before the checkpoint
record, instead of the checkpoint record itself. We don't run the redo
routine of the shutdown checkpoint record, but starting recovery from it
goes through the same motions, so it should be considered as replayed.

Reported by Kyotaro HORIGUCHI. All versions with hot standby are affected,
so backpatch to 9.0.

10 years agoFix issues with pg_ctl
Stephen Frost [Wed, 5 Mar 2014 06:30:03 +0000 (01:30 -0500)]
Fix issues with pg_ctl

The new, small, free_readfile managed to have bug in it which could
cause it to try and free something it shouldn't, and fix the case
where it was being called with an invalid pointer leading to a
segfault.

Noted by Bruce, issues introduced and fixed by me.

10 years agoFix whitespace
Peter Eisentraut [Wed, 5 Mar 2014 02:53:25 +0000 (21:53 -0500)]
Fix whitespace

10 years agoProvide a FORCE NULL option to COPY in CSV mode.
Andrew Dunstan [Tue, 4 Mar 2014 22:31:59 +0000 (17:31 -0500)]
Provide a FORCE NULL option to COPY in CSV mode.

This forces an input field containing the quoted null string to be
returned as a NULL. Without this option, only unquoted null strings
behave this way. This helps where some CSV producers insist on quoting
every field, whether or not it is needed. The option takes a list of
fields, and only applies to those columns. There is an equivalent
column-level option added to file_fdw.

Ian Barwick, with some tweaking by Andrew Dunstan, reviewed by Payal
Singh.

10 years agoauto_explain: Add logging of trigger execution
Alvaro Herrera [Tue, 4 Mar 2014 18:31:18 +0000 (15:31 -0300)]
auto_explain: Add logging of trigger execution

Author: Kyotaro HORIGUCHI
Reviewed-by: Jaime Casanova
10 years agoConstructors for interval, timestamp, timestamptz
Alvaro Herrera [Tue, 4 Mar 2014 18:09:43 +0000 (15:09 -0300)]
Constructors for interval, timestamp, timestamptz

Author: Pavel Stěhule, editorialized somewhat by Álvaro Herrera
Reviewed-by: Tomáš Vondra, Marko Tiikkaja
With input from Fabrízio de Royes Mello, Jim Nasby

10 years agoAllow VACUUM FULL/CLUSTER to bump freeze horizons even for pg_class.
Robert Haas [Tue, 4 Mar 2014 16:08:18 +0000 (11:08 -0500)]
Allow VACUUM FULL/CLUSTER to bump freeze horizons even for pg_class.

pg_class is a special case for CLUSTER and VACUUM FULL, so although
commit 3cff1879f8d03cb729368722ca823a4bf74c0cac caused these
operations to advance relfrozenxid and relminmxid for all other
tables, it did not provide the same benefit for pg_class.  This
plugs that gap.

Andres Freund

10 years agoMinor corrections to logical decoding patch.
Robert Haas [Tue, 4 Mar 2014 16:07:54 +0000 (11:07 -0500)]
Minor corrections to logical decoding patch.

10 years agoError out on send failure in walsender loop.
Heikki Linnakangas [Tue, 4 Mar 2014 13:30:52 +0000 (15:30 +0200)]
Error out on send failure in walsender loop.

I changed the loop in 9.3 to use "goto send_failure" instead of "break" on
errors, but I missed this one case. It was a relatively harmless bug: if
the flush fails once it will most likely fail again as soon as we try to
flush the output again. But it's a bug nevertheless.

Report and fix by Andres Freund.

10 years agoIntroduce logical decoding.
Robert Haas [Mon, 3 Mar 2014 21:32:18 +0000 (16:32 -0500)]
Introduce logical decoding.

This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables.  The output format is controlled by a
so-called "output plugin"; an example is included.  To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.

Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.

Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.

10 years agoFix whitespace
Peter Eisentraut [Mon, 3 Mar 2014 19:05:33 +0000 (14:05 -0500)]
Fix whitespace

10 years agoRename huge_tlb_pages to huge_pages, and improve docs.
Heikki Linnakangas [Mon, 3 Mar 2014 18:52:48 +0000 (20:52 +0200)]
Rename huge_tlb_pages to huge_pages, and improve docs.

Christian Kruse

10 years agopg_dump et al: Add --if-exists option
Alvaro Herrera [Mon, 3 Mar 2014 18:02:18 +0000 (15:02 -0300)]
pg_dump et al: Add --if-exists option

This option makes pg_dump, pg_dumpall and pg_restore inject an IF EXISTS
clause to each DROP command they emit.  (In pg_dumpall, the clause is
not added to individual objects drops, but rather to the CREATE DATABASE
commands, as well as CREATE ROLE and CREATE TABLESPACE.)

This allows for a better user dump experience when using --clean in case
some objects do not already exist.  Per bug #7873 by Dave Rolsky.

Author: Pavel Stěhule
Reviewed-by: Jeevan Chalke, Álvaro Herrera, Josh Kupershmidt
10 years agoUse a longer buffer in libpqrcv_startstreaming.
Robert Haas [Mon, 3 Mar 2014 12:24:52 +0000 (07:24 -0500)]
Use a longer buffer in libpqrcv_startstreaming.

Because of the new SLOT clause in the START_REPLICATION command, it's
possible for the command to end up too long for the old maximum buffer
length.

Andres Freund

10 years agoBump catversion.
Robert Haas [Mon, 3 Mar 2014 12:22:20 +0000 (07:22 -0500)]
Bump catversion.

The previous patch should have entailed a catversion bump, but I
forgot.

10 years agoCorrections to replication slots code and documentation.
Robert Haas [Mon, 3 Mar 2014 12:16:54 +0000 (07:16 -0500)]
Corrections to replication slots code and documentation.

Andres Freund, per a report from Vik Faering

10 years agopageinspect: Use new pg_lsn datatype.
Robert Haas [Mon, 3 Mar 2014 12:14:31 +0000 (07:14 -0500)]
pageinspect: Use new pg_lsn datatype.

Michael Paquier, with slight comment changes by me

10 years agoDefine LSNOID in pg_type.h.
Robert Haas [Mon, 3 Mar 2014 12:03:41 +0000 (07:03 -0500)]
Define LSNOID in pg_type.h.

Most other built-in types have a similarly-named constant, so this
type should probably have one, too.

Michael Paquier

10 years agoAnother round of Coverity fixes
Stephen Frost [Mon, 3 Mar 2014 08:18:51 +0000 (03:18 -0500)]
Another round of Coverity fixes

Additional non-security issues/improvements spotted by Coverity.

In backend/libpq, no sense trying to protect against port->hba being
NULL after we've already dereferenced it in the switch() statement.

Prevent against possible overflow due to 32bit arithmitic in
basebackup throttling (not yet released, so no security concern).

Remove nonsensical check of array pointer against NULL in procarray.c,
looks to be a holdover from 9.1 and earlier when there were pointers
being used but now it's just an array.

Remove pointer check-against-NULL in tsearch/spell.c as we had already
dereferenced it above (in the strcmp()).

Remove dead code from adt/orderedsetaggs.c, isnull is checked
immediately after each tuplesort_getdatum() call and if true we return,
so no point checking it again down at the bottom.

Remove recently added minor error-condition memory leak in pg_regress.

10 years agoVarious Coverity-spotted fixes
Stephen Frost [Sun, 2 Mar 2014 03:14:14 +0000 (22:14 -0500)]
Various Coverity-spotted fixes

A number of issues were identified by the Coverity scanner and are
addressed in this patch.  None of these appear to be security issues
and many are mostly cosmetic changes.

Short comments for each of the changes follows.

Correct the semi-colon placement in be-secure.c regarding SSL retries.
Remove a useless comparison-to-NULL in proc.c (value is dereferenced
  prior to this check and therefore can't be NULL).
Add checking of chmod() return values to initdb.
Fix a couple minor memory leaks in initdb.
Fix memory leak in pg_ctl- involves free'ing the config file contents.
Use an int to capture fgetc() return instead of an enum in pg_dump.
Fix minor memory leaks in pg_dump.
  (note minor change to convertOperatorReference()'s API)
Check fclose()/remove() return codes in psql.
Check fstat(), find_my_exec() return codes in psql.
Various ECPG memory leak fixes.
Check find_my_exec() return in ECPG.
Explicitly ignore pqFlush return in libpq error-path.
Change PQfnumber() to avoid doing an strdup() when no changes required.
Remove a few useless check-against-NULL's (value deref'd beforehand).
Check rmtree(), malloc() results in pg_regress.
Also check get_alternative_expectfile() return in pg_regress.

10 years agoAllow regex operations to be terminated early by query cancel requests.
Tom Lane [Sat, 1 Mar 2014 20:20:56 +0000 (15:20 -0500)]
Allow regex operations to be terminated early by query cancel requests.

The regex code didn't have any provision for query cancel; which is
unsurprising given its non-Postgres origin, but still problematic since
some operations can take a long time.  Introduce a callback function to
check for a pending query cancel or session termination request, and
call it in a couple of strategic spots where we can make the regex code
exit with an error indicator.

If we ever actually split out the regex code as a standalone library,
some additional work will be needed to let the cancel callback function
be specified externally to the library.  But that's straightforward
(certainly so by comparison to putting the locale-dependent character
classification logic on a similar arms-length basis), and there seems
no need to do it right now.

A bigger issue is that there may be more places than these two where
we need to check for cancels.  We can always add more checks later,
now that the infrastructure is in place.

Since there are known examples of not-terribly-long regexes that can
lock up a backend for a long time, back-patch to all supported branches.
I have hopes of fixing the known performance problems later, but adding
query cancel ability seems like a good idea even if they were all fixed.

10 years agoRemove bogus while-loop.
Heikki Linnakangas [Fri, 28 Feb 2014 11:22:25 +0000 (13:22 +0200)]
Remove bogus while-loop.

Commit abf5c5c9a4f142b3343614746bb9e99a794f8e7b added a bogus while-
statement after the for(;;)-loop. It went unnoticed in testing, because
it was dead code.

Report by KONDO Mitsumasa. Backpatch to 9.3. The commit that introduced
this was also applied to 9.2, but not the bogus while-loop part, because
the code in 9.2 looks quite different.

10 years agopgbench: Fix help message
Peter Eisentraut [Fri, 28 Feb 2014 02:52:21 +0000 (21:52 -0500)]
pgbench: Fix help message

Add NUM placeholder to -t option in help message.  It got lost in
79cddb18419778be3202c971b3f21cdd90f7b719.

Author: Fabien COELHO <coelho@cri.ensmp.fr>

10 years agoAllow BASE_BACKUP to be throttled
Alvaro Herrera [Thu, 27 Feb 2014 21:55:57 +0000 (18:55 -0300)]
Allow BASE_BACKUP to be throttled

A new MAX_RATE option allows imposing a limit to the network transfer
rate from the server side.  This is useful to limit the stress that
taking a base backup has on the server.

pg_basebackup is now able to specify a value to the server, too.

Author: Antonin Houska

Patch reviewed by Stefan Radomski, Andres Freund, Zoltán Böszörményi,
Fujii Masao, and Álvaro Herrera.

10 years agoRemove dependency on database encoding in citext regression test.
Tom Lane [Thu, 27 Feb 2014 19:58:47 +0000 (14:58 -0500)]
Remove dependency on database encoding in citext regression test.

Testing convert_to(..., 'ISO-8859-1') fails if there isn't a conversion
function available from the database encoding to ISO-8859-1.  This has
been broken since day one, but the breakage was hidden by
pg_do_encoding_conversion's failure to complain, up till commit
49c817eab78c6f0ce8c3bf46766b73d6cf3190b7.

Since the data being converted in this test is plain ASCII, no actual
conversion need happen (and if it did, it would prove little about citext
anyway).  So that we still have some code coverage of the convert() family
of functions, let's switch to using convert_from, with SQL_ASCII as the
specified source encoding.  Per buildfarm.

10 years agodoc: bgw_main takes a Datum argument, not void *.
Alvaro Herrera [Thu, 27 Feb 2014 14:41:43 +0000 (11:41 -0300)]
doc: bgw_main takes a Datum argument, not void *.

Per report from James Harper.

10 years agoFix WAL replay of locking an updated tuple
Alvaro Herrera [Thu, 27 Feb 2014 14:13:39 +0000 (11:13 -0300)]
Fix WAL replay of locking an updated tuple

We were resetting the tuple's HEAP_HOT_UPDATED flag as well as t_ctid on
WAL replay of a tuple-lock operation, which is incorrect when the tuple
is already updated.

Back-patch to 9.3.  The clearing of both header elements was there
previously, but since no update could be present on a tuple that was
being locked, it was harmless.

Bug reported by Peter Geoghegan and Greg Stark in
CAM3SWZTMQiCi5PV5OWHb+bYkUcnCk=O67w0cSswPvV7XfUcU5g@mail.gmail.com and
CAM-w4HPTOeMT4KP0OJK+mGgzgcTOtLRTvFZyvD0O4aH-7dxo3Q@mail.gmail.com
respectively; diagnosis by Andres Freund.

10 years agobtbuild no longer calls _bt_doinsert(), update comment.
Heikki Linnakangas [Wed, 26 Feb 2014 16:48:21 +0000 (18:48 +0200)]
btbuild no longer calls _bt_doinsert(), update comment.

Peter Geoghegan

10 years agoFix crash in json_to_record().
Jeff Davis [Wed, 26 Feb 2014 15:47:09 +0000 (07:47 -0800)]
Fix crash in json_to_record().

json_to_record() depends on get_call_result_type() for the tuple
descriptor of the record that should be returned, but in some cases
that cannot be determined. Add a guard to check if the tuple
descriptor has been properly resolved, similar to other callers of
get_call_result_type().

Also add guard for two other callers of get_call_result_type() in
jsonfuncs.c. Although json_to_record() is the only actual bug, it's a
good idea to follow convention.

10 years agoUse SnapshotDirty rather than an active snapshot to probe index endpoints.
Tom Lane [Tue, 25 Feb 2014 21:04:06 +0000 (16:04 -0500)]
Use SnapshotDirty rather than an active snapshot to probe index endpoints.

If there are lots of uncommitted tuples at the end of the index range,
get_actual_variable_range() ends up fetching each one and doing an MVCC
visibility check on it, until it finally hits a visible tuple.  This is
bad enough in isolation, considering that we don't need an exact answer
only an approximate one.  But because the tuples are not yet committed,
each visibility check does a TransactionIdIsInProgress() test, which
involves scanning the ProcArray.  When multiple sessions do this
concurrently, the ensuing contention results in horrid performance loss.
20X overall throughput loss on not-too-complicated queries is easy to
demonstrate in the back branches (though someone's made it noticeably
less bad in HEAD).

We can dodge the problem fairly effectively by using SnapshotDirty rather
than a normal MVCC snapshot.  This will cause the index probe to take
uncommitted tuples as good, so that we incur only one tuple fetch and test
even if there are many such tuples.  The extent to which this degrades the
estimate is debatable: it's possible the result is actually a more accurate
prediction than before, if the endmost tuple has become committed by the
time we actually execute the query being planned.  In any case, it's not
very likely that it makes the estimate a lot worse.

SnapshotDirty will still reject tuples that are known committed dead, so
we won't give bogus answers if an invalid outlier has been deleted but not
yet vacuumed from the index.  (Because btrees know how to mark such tuples
dead in the index, we shouldn't have a big performance problem in the case
that there are many of them at the end of the range.)  This consideration
motivates not using SnapshotAny, which was also considered as a fix.

Note: the back branches were using SnapshotNow instead of an MVCC snapshot,
but the problem and solution are the same.

Per performance complaints from Bartlomiej Romanski, Josh Berkus, and
others.  Back-patch to 9.0, where the issue was introduced (by commit
40608e7f949fb7e4025c0ddd5be01939adc79eec).

10 years agoUpdate a few comments to mention materialized views.
Robert Haas [Tue, 25 Feb 2014 18:40:12 +0000 (13:40 -0500)]
Update a few comments to mention materialized views.

Etsuro Fujita

10 years agoShow xid and xmin in pg_stat_activity and pg_stat_replication.
Robert Haas [Tue, 25 Feb 2014 17:34:04 +0000 (12:34 -0500)]
Show xid and xmin in pg_stat_activity and pg_stat_replication.

Christian Kruse, reviewed by Andres Freund and myself, with further
minor adjustments by me.

10 years agopg_basebackup: Skip only the *contents* of pg_replslot.
Robert Haas [Tue, 25 Feb 2014 16:23:45 +0000 (11:23 -0500)]
pg_basebackup: Skip only the *contents* of pg_replslot.

Include the directory itself.

Fujii Masao

10 years agoUpdate and clarify ssl_ciphers default
Peter Eisentraut [Tue, 25 Feb 2014 01:30:28 +0000 (20:30 -0500)]
Update and clarify ssl_ciphers default

- Write HIGH:MEDIUM instead of DEFAULT:!LOW:!EXP for clarity.
- Order 3DES last to work around inappropriate OpenSSL default.
- Remove !MD5 and @STRENGTH, because they are irrelevant.
- Add clarifying documentation.

Effectively, the new default is almost the same as the old one, but it
is arguably easier to understand and modify.

Author: Marko Kreen <markokr@gmail.com>

10 years agoIncrease work_mem and maintenance_work_mem defaults by 4x
Bruce Momjian [Mon, 24 Feb 2014 18:04:51 +0000 (13:04 -0500)]
Increase work_mem and maintenance_work_mem defaults by 4x

New defaults are 4MB and 64MB.

10 years agodocs: remove unnecessary references to old PG versions
Bruce Momjian [Mon, 24 Feb 2014 17:56:37 +0000 (12:56 -0500)]
docs:  remove unnecessary references to old PG versions

10 years agopsql: add separate \d display for disabled system triggers
Bruce Momjian [Mon, 24 Feb 2014 17:44:55 +0000 (12:44 -0500)]
psql:  add separate \d display for disabled system triggers

Previously if you disabled all triggers, only user triggers would
show as disabled

Per report from Andres Freund

10 years agopg_dump: fix subtle memory leak in func and arg signature processing
Bruce Momjian [Mon, 24 Feb 2014 17:32:41 +0000 (12:32 -0500)]
pg_dump:  fix subtle memory leak in func and arg signature processing

10 years agoFix markup for CHAR() doc patch
Bruce Momjian [Mon, 24 Feb 2014 17:26:04 +0000 (12:26 -0500)]
Fix markup for CHAR() doc patch

10 years agoAllow single-point polygons to be converted to circles
Bruce Momjian [Mon, 24 Feb 2014 17:24:00 +0000 (12:24 -0500)]
Allow single-point polygons to be converted to circles

This allows finding the center of a single-point polygon and converting
it to a point.

Per report from Josef Grahn

10 years agodocs: document behavior of CHAR() comparisons with chars < space
Bruce Momjian [Mon, 24 Feb 2014 17:09:23 +0000 (12:09 -0500)]
docs: document behavior of CHAR() comparisons with chars < space

Space trimming rather than space-padding causes unusual behavior, which
might not be standards-compliant.

Also remove recently-added now-redundant C comment.

10 years agoUse pg_lsn data type in pg_stat_replication, too.
Robert Haas [Mon, 24 Feb 2014 15:38:45 +0000 (10:38 -0500)]
Use pg_lsn data type in pg_stat_replication, too.

Michael Paquier, per a suggestion from Andres Freund

10 years agoRemove a couple of comments from the pg_lsn regression test.
Robert Haas [Mon, 24 Feb 2014 14:32:21 +0000 (09:32 -0500)]
Remove a couple of comments from the pg_lsn regression test.

Previously, one of these was a negative test case, but that got
changed along the way and the comments didn't get the memo.

Michael Paquier

10 years agodoc: Improve DocBook XML validity
Peter Eisentraut [Mon, 24 Feb 2014 02:25:35 +0000 (21:25 -0500)]
doc: Improve DocBook XML validity

DocBook XML is superficially compatible with DocBook SGML but has a
slightly stricter DTD that we have been violating in a few cases.
Although XSLT doesn't care whether the document is valid, the style
sheets don't necessarily process invalid documents correctly, so we need
to work toward fixing this.

This first commit moves the indexterms in refentry elements to an
allowed position.  It has no impact on the output.

10 years agoPrefer pg_any_to_server/pg_server_to_any over pg_do_encoding_conversion.
Tom Lane [Sun, 23 Feb 2014 21:59:05 +0000 (16:59 -0500)]
Prefer pg_any_to_server/pg_server_to_any over pg_do_encoding_conversion.

A large majority of the callers of pg_do_encoding_conversion were
specifying the database encoding as either source or target of the
conversion, meaning that we can use the less general functions
pg_any_to_server/pg_server_to_any instead.

The main advantage of using the latter functions is that they can make use
of a cached conversion-function lookup in the common case that the other
encoding is the current client_encoding.  It's notationally cleaner too in
most cases, not least because of the historical artifact that the latter
functions use "char *" rather than "unsigned char *" in their APIs.

Note that pg_any_to_server will apply an encoding verification step in
some cases where pg_do_encoding_conversion would have just done nothing.
This seems to me to be a good idea at most of these call sites, though
it partially negates the performance benefit.

Per discussion of bug #9210.

10 years agoPlug some more holes in encoding conversion.
Tom Lane [Sun, 23 Feb 2014 20:22:50 +0000 (15:22 -0500)]
Plug some more holes in encoding conversion.

Various places assume that pg_do_encoding_conversion() and
pg_server_to_any() will ensure encoding validity of their results;
but they failed to do so in the case that the source encoding is SQL_ASCII
while the destination is not.  We cannot perform any actual "conversion"
in that scenario, but we should still validate the string according to the
destination encoding.  Per bug #9210 from Digoal Zhou.

Arguably this is a back-patchable bug fix, but on the other hand adding
more enforcing of encoding checks might break existing applications that
were being sloppy.  On balance there doesn't seem to be much enthusiasm
for a back-patch, so fix in HEAD only.

While at it, remove some apparently-no-longer-needed provisions for
letting pg_do_encoding_conversion() "work" outside a transaction ---
if you consider it "working" to silently fail to do the requested
conversion.

Also, make a few cosmetic improvements in mbutils.c, notably removing
some Asserts that are certainly dead code since the variables they
assert aren't null are never null, even at process start.  (I think
this wasn't true at one time, but it is now.)

10 years agoconfigure.in: Use dnl in place of # where appropriate
Peter Eisentraut [Sun, 23 Feb 2014 01:42:39 +0000 (20:42 -0500)]
configure.in: Use dnl in place of # where appropriate

The comment added by ed011d9754fd4b76eac0eaa8c057fcfc0c302a6a used #,
which means it gets copied into configure, but it doesn't make sense
there.  So use dnl, which gets dropped when creating configure.

10 years agopg_basebackup: Add support for relocating tablespaces
Peter Eisentraut [Sat, 22 Feb 2014 18:38:06 +0000 (13:38 -0500)]
pg_basebackup: Add support for relocating tablespaces

Tablespaces can be relocated in plain backup mode by specifying one or
more -T olddir=newdir options.

Author: Steeve Lennmark <steevel@handeldsbanken.se>
Reviewed-by: Peter Eisentraut <peter_e@gmx.net>
10 years agoDo ScalarArrayOp estimation correctly when array is a stable expression.
Tom Lane [Fri, 21 Feb 2014 22:10:46 +0000 (17:10 -0500)]
Do ScalarArrayOp estimation correctly when array is a stable expression.

Most estimation functions apply estimate_expression_value to see if they
can reduce an expression to a constant; the key difference is that it
allows evaluation of stable as well as immutable functions in hopes of
ending up with a simple Const node.  scalararraysel didn't get the memo
though, and neither did gincost_opexpr/gincost_scalararrayopexpr.  Fix
that, and remove a now-unnecessary estimate_expression_value step in the
subsidiary function scalararraysel_containment.

Per complaint from Alexey Klyukin.  Back-patch to 9.3.  The problem
goes back further, but I'm hesitant to change estimation behavior in
long-stable release branches.

10 years agoAvoid integer overflow in hstore_to_json().
Heikki Linnakangas [Fri, 21 Feb 2014 13:43:31 +0000 (15:43 +0200)]
Avoid integer overflow in hstore_to_json().

The length of the output buffer was calculated based on the size of the
argument hstore. On a sizeof(int) == 4 platform and a huge argument, it
could overflow, causing a too small buffer to be allocated.

Refactor the function to use a StringInfo instead of pre-allocating the
buffer. Makes it shorter and more readable, too.

10 years agodoc: Clarify documentation page header customization code
Peter Eisentraut [Fri, 21 Feb 2014 02:41:24 +0000 (21:41 -0500)]
doc: Clarify documentation page header customization code

The customization overrode the fast-forward code with its custom Up
link.  So this is no longer really the fast-forward feature, so we might
as well turn that off and override the non-ff template instead, thus
removing one mental indirection.

Fix the wrong column span declaration.

Clarify and update the documentation.

10 years agoImprove comment on setting data_checksum GUC.
Heikki Linnakangas [Thu, 20 Feb 2014 08:43:36 +0000 (10:43 +0200)]
Improve comment on setting data_checksum GUC.

There was an extra space there, and "fixed" wasn't very descriptive.

10 years agoRemove inappropriate EXPORTS line.
Tom Lane [Thu, 20 Feb 2014 02:08:50 +0000 (21:08 -0500)]
Remove inappropriate EXPORTS line.

Looks like this gets added later ...

10 years agoAvoid using dllwrap to build pgevent in Mingw builds.
Tom Lane [Thu, 20 Feb 2014 00:34:50 +0000 (19:34 -0500)]
Avoid using dllwrap to build pgevent in Mingw builds.

If this works, we can get rid of configure's support for locating dllwrap
... but let's see what the buildfarm says, first.

Hiroshi Inoue

10 years agoFix some missing .gitignore and "make clean" items in ecpg.
Tom Lane [Wed, 19 Feb 2014 23:50:48 +0000 (18:50 -0500)]
Fix some missing .gitignore and "make clean" items in ecpg.

Some of the files we optionally link in from elsewhere weren't ignored
and/or weren't cleaned up at "make clean".  Noted while testing on a
machine that needs our version of snprintf.c.

10 years agoDocument pg_replslot in storage.sgml.
Robert Haas [Wed, 19 Feb 2014 16:57:31 +0000 (11:57 -0500)]
Document pg_replslot in storage.sgml.

Per an observation from Amit Kapila.

10 years agoSwitch various builtin functions to use pg_lsn instead of text.
Robert Haas [Wed, 19 Feb 2014 16:13:44 +0000 (11:13 -0500)]
Switch various builtin functions to use pg_lsn instead of text.

The functions in slotfuncs.c don't exist in any released version,
but the changes to xlogfuncs.c represent backward-incompatibilities.
Per discussion, we're hoping that the queries using these functions
are few enough and simple enough that this won't cause too much
breakage for users.

Michael Paquier, reviewed by Andres Freund and further modified
by me.

10 years agoFurther code review for pg_lsn data type.
Robert Haas [Wed, 19 Feb 2014 15:06:59 +0000 (10:06 -0500)]
Further code review for pg_lsn data type.

Change input function error messages to be more consistent with what is
done elsewhere.  Remove a bunch of redundant type casts, so that the
compiler will warn us if we screw up.  Don't pass LSNs by value on
platforms where a Datum is only 32 bytes, per buildfarm.  Move macros
for packing and unpacking LSNs to pg_lsn.h so that we can include
access/xlogdefs.h, to avoid an unsatisfied dependency on XLogRecPtr.

10 years agopg_lsn macro naming and type behavior revisions.
Robert Haas [Wed, 19 Feb 2014 14:34:15 +0000 (09:34 -0500)]
pg_lsn macro naming and type behavior revisions.

Change pg_lsn_mi so that it can return negative values when subtracting
LSNs, and clean up some perhaps ill-considered macro names.

10 years agoAdd a pg_lsn data type, to represent an LSN.
Robert Haas [Wed, 19 Feb 2014 13:35:23 +0000 (08:35 -0500)]
Add a pg_lsn data type, to represent an LSN.

Robert Haas and Michael Paquier

10 years agoRemove broken code that tried to handle OVERLAPS with a single argument.
Tom Lane [Tue, 18 Feb 2014 17:44:20 +0000 (12:44 -0500)]
Remove broken code that tried to handle OVERLAPS with a single argument.

The SQL standard says that OVERLAPS should have a two-element row
constructor on each side.  The original coding of OVERLAPS support in
our grammar attempted to extend that by allowing a single-element row
constructor, which it internally duplicated ... or tried to, anyway.
But that code has certainly not worked since our List infrastructure was
rewritten in 2004, and I'm none too sure it worked before that.  As it
stands, it ends up building a List that includes itself, leading to
assorted undesirable behaviors later in the parser.

Even if it worked as intended, it'd be a bit evil because of the
possibility of duplicate evaluation of a volatile function that the user
had written only once.  Given the lack of documentation, test cases, or
complaints, let's just get rid of the idea and only support the standard
syntax.

While we're at it, improve the error cursor positioning for the
wrong-number-of-arguments errors, and inline the makeOverlaps() function
since it's only called in one place anyway.

Per bug #9227 from Joshua Yanovski.  Initial patch by Joshua Yanovski,
extended a bit by me.

10 years agoDisable RandomizedBaseAddress on MSVC builds
Magnus Hagander [Tue, 18 Feb 2014 13:45:58 +0000 (14:45 +0100)]
Disable RandomizedBaseAddress on MSVC builds

The ASLR in Windows 8/Windows 2012 can break PostgreSQL's shared memory. It
doesn't fail every time (which is explained by the Random part in ASLR), but
can fail with errors abut failing to reserve shared memory region.

MauMau, reviewed by Craig Ringer

10 years agoFix comment; checkpointer, not bgwriter, performs checkpoints since 9.2.
Heikki Linnakangas [Tue, 18 Feb 2014 07:48:18 +0000 (09:48 +0200)]
Fix comment; checkpointer, not bgwriter, performs checkpoints since 9.2.

Amit Langote

10 years agoLast-minute updates for release notes.
Tom Lane [Mon, 17 Feb 2014 19:25:34 +0000 (14:25 -0500)]
Last-minute updates for release notes.

Add entries for security issues.

Security: CVE-2014-0060 through CVE-2014-0067

10 years agoFix capitalization in README.
Robert Haas [Mon, 17 Feb 2014 19:02:10 +0000 (14:02 -0500)]
Fix capitalization in README.

Vik Fearing

10 years agoImprove documentation about multixact IDs.
Tom Lane [Mon, 17 Feb 2014 17:20:57 +0000 (12:20 -0500)]
Improve documentation about multixact IDs.

Per gripe from Josh Berkus.

10 years agoDocument risks of "make check" in the regression testing instructions.
Tom Lane [Mon, 17 Feb 2014 16:24:32 +0000 (11:24 -0500)]
Document risks of "make check" in the regression testing instructions.

Since the temporary server started by "make check" uses "trust"
authentication, another user on the same machine could connect to it
as database superuser, and then potentially exploit the privileges of
the operating-system user who started the tests.  We should change
the testing procedures to prevent this risk; but discussion is required
about the best way to do that, as well as more testing than is practical
for an undisclosed security problem.  Besides, the same issue probably
affects some user-written test harnesses.  So for the moment, we'll just
warn people against using "make check" when there are untrusted users on
the same machine.

In passing, remove some ancient advice that suggested making the
regression testing subtree world-writable if you'd built as root.
That looks dangerously insecure in modern contexts, and anyway we
should not be encouraging people to build Postgres as root.

Security: CVE-2014-0067

10 years agoPrevent potential overruns of fixed-size buffers.
Tom Lane [Mon, 17 Feb 2014 16:20:21 +0000 (11:20 -0500)]
Prevent potential overruns of fixed-size buffers.

Coverity identified a number of places in which it couldn't prove that a
string being copied into a fixed-size buffer would fit.  We believe that
most, perhaps all of these are in fact safe, or are copying data that is
coming from a trusted source so that any overrun is not really a security
issue.  Nonetheless it seems prudent to forestall any risk by using
strlcpy() and similar functions.

Fixes by Peter Eisentraut and Jozef Mlich based on Coverity reports.

In addition, fix a potential null-pointer-dereference crash in
contrib/chkpass.  The crypt(3) function is defined to return NULL on
failure, but chkpass.c didn't check for that before using the result.
The main practical case in which this could be an issue is if libc is
configured to refuse to execute unapproved hashing algorithms (e.g.,
"FIPS mode").  This ideally should've been a separate commit, but
since it touches code adjacent to one of the buffer overrun changes,
I included it in this commit to avoid last-minute merge issues.
This issue was reported by Honza Horak.

Security: CVE-2014-0065 for buffer overruns, CVE-2014-0066 for crypt()

10 years agoPredict integer overflow to avoid buffer overruns.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Predict integer overflow to avoid buffer overruns.

Several functions, mostly type input functions, calculated an allocation
size such that the calculation wrapped to a small positive value when
arguments implied a sufficiently-large requirement.  Writes past the end
of the inadvertent small allocation followed shortly thereafter.
Coverity identified the path_in() vulnerability; code inspection led to
the rest.  In passing, add check_stack_depth() to prevent stack overflow
in related functions.

Back-patch to 8.4 (all supported versions).  The non-comment hstore
changes touch code that did not exist in 8.4, so that part stops at 9.0.

Noah Misch and Heikki Linnakangas, reviewed by Tom Lane.

Security: CVE-2014-0064