]> granicus.if.org Git - postgresql/log
postgresql
12 years agoFix bogus code in contrib/ tsearch dictionary examples.
Tom Lane [Thu, 3 Nov 2011 23:17:48 +0000 (19:17 -0400)]
Fix bogus code in contrib/ tsearch dictionary examples.

Both dict_int and dict_xsyn were blithely assuming that whatever memory
palloc gives back will be pre-zeroed.  This would typically work for
just about long enough to run their regression tests, and no longer :-(.

The pre-9.0 code in dict_xsyn was even lamer than that, as it would
happily give back a pointer to the result of palloc(0), encouraging
its caller to access off the end of memory.  Again, this would just
barely fail to fail as long as memory contained nothing but zeroes.

Per a report from Rodrigo Hjort that code based on these examples
didn't work reliably.

12 years agoImprove comments for TSLexeme data structure.
Tom Lane [Thu, 3 Nov 2011 22:47:28 +0000 (18:47 -0400)]
Improve comments for TSLexeme data structure.

Mostly, clean up long-ago pgindent damage.

12 years agoFix inline_set_returning_function() to allow multiple OUT parameters.
Tom Lane [Thu, 3 Nov 2011 21:53:13 +0000 (17:53 -0400)]
Fix inline_set_returning_function() to allow multiple OUT parameters.

inline_set_returning_function failed to distinguish functions returning
generic RECORD (which require a column list in the RTE, as well as run-time
type checking) from those with multiple OUT parameters (which do not).
This prevented inlining from happening.  Per complaint from Jay Levitt.
Back-patch to 8.4 where this capability was introduced.

12 years agoRole membership of superusers is only by explicit membership for HBA.
Andrew Dunstan [Thu, 3 Nov 2011 20:29:41 +0000 (16:29 -0400)]
Role membership of superusers is only by explicit membership for HBA.

Document that this rule applies to 'samerole' as well as to named roles.

Per gripe from Tom Lane.

12 years agoAdjust pg_upgrade "new database skip" code, e.g. 'postgres', to more
Bruce Momjian [Thu, 3 Nov 2011 17:56:56 +0000 (13:56 -0400)]
Adjust pg_upgrade "new database skip" code, e.g. 'postgres', to more
cleanly handle old/new database mismatches.

12 years agoImplement a dry-run mode for isolationtester
Alvaro Herrera [Thu, 3 Nov 2011 17:06:08 +0000 (15:06 -0200)]
Implement a dry-run mode for isolationtester

This mode prints out the permutations that would be run by the given
spec file, in the same format used by the permutation lines in spec
files.  This helps in building new spec files.

Author: Alexander Shulgin, with some tweaks by me

12 years agoDo not treat a superuser as a member of every role for HBA purposes.
Andrew Dunstan [Thu, 3 Nov 2011 16:45:02 +0000 (12:45 -0400)]
Do not treat a superuser as a member of every role for HBA purposes.

This makes it possible to use reject lines with group roles.

Andrew Dunstan, reviewd by Robert Haas.

12 years agoProperly close replication connection in pg_receivexlog
Magnus Hagander [Thu, 3 Nov 2011 14:43:25 +0000 (15:43 +0100)]
Properly close replication connection in pg_receivexlog

12 years agoPre-pad WAL files when streaming transaction log
Magnus Hagander [Thu, 3 Nov 2011 14:37:08 +0000 (15:37 +0100)]
Pre-pad WAL files when streaming transaction log

Instead of filling files as they appear, pre-pad the
WAL files received when streaming xlog the same way
that the server does. Data is streamed into a .partial
file which is then renamed()d into palce when it's complete,
but it will always be 16MB.

This also means that the starting position for pg_receivexlog
is now simply right after the last complete segment, and we
never need to deal with partial segments there.

Patch by me, review by Fujii Masao

12 years agoSupport range data types.
Heikki Linnakangas [Thu, 3 Nov 2011 11:16:28 +0000 (13:16 +0200)]
Support range data types.

Selectivity estimation functions are missing for some range type operators,
which is a TODO.

Jeff Davis

12 years agoImprove docs for timing and skipping of checkpoints
Simon Riggs [Thu, 3 Nov 2011 08:52:20 +0000 (08:52 +0000)]
Improve docs for timing and skipping of checkpoints

Greg Smith

12 years agoFix handling of PlaceHolderVars in nestloop parameter management.
Tom Lane [Thu, 3 Nov 2011 04:50:58 +0000 (00:50 -0400)]
Fix handling of PlaceHolderVars in nestloop parameter management.

If we use a PlaceHolderVar from the outer relation in an inner indexscan,
we need to reference the PlaceHolderVar as such as the value to be passed
in from the outer relation.  The previous code effectively tried to
reconstruct the PHV from its component expression, which doesn't work since
(a) the Vars therein aren't necessarily bubbled up far enough, and (b) it
would be the wrong semantics anyway because of the possibility that the PHV
is supposed to have gone to null at some point before the current join.
Point (a) led to "variable not found in subplan target list" planner
errors, but point (b) would have led to silently wrong answers.
Per report from Roger Niederland.

12 years agoAvoid scanning nulls at the beginning of a btree index scan.
Tom Lane [Wed, 2 Nov 2011 23:35:48 +0000 (19:35 -0400)]
Avoid scanning nulls at the beginning of a btree index scan.

If we have an inequality key that constrains the other end of the index,
it doesn't directly help us in doing the initial positioning ... but it
does imply a NOT NULL constraint on the index column.  If the index stores
nulls at this end, we can use the implied NOT NULL condition for initial
positioning, just as if it had been stated explicitly.  This avoids wasting
time when there are a lot of nulls in the column.  This is the reverse of
the examples given in bugs #6278 and #6283, which were about failing to
stop early when we encounter nulls at the end of the indexscan.

12 years agoFix btree stop-at-nulls logic properly.
Tom Lane [Wed, 2 Nov 2011 21:53:49 +0000 (17:53 -0400)]
Fix btree stop-at-nulls logic properly.

As pointed out by Naoya Anzai, my previous try at this was a few bricks
shy of a load, because I had forgotten that the initial-positioning logic
might not try to skip over nulls at the end of the index the scan will
start from.  We ought to fix that, because it represents an unnecessary
inefficiency, but first let's get the scan-stop logic back to a safe
state.  With this patch, we preserve the performance benefit requested
in bug #6278 for the case of scanning forward into NULLs (in a NULLS
LAST index), but the reverse case of scanning backward across NULLs
when there's no suitable initial-positioning qual is still inefficient.

12 years agoUpdate more comments about checkpoints being done by bgwriter
Simon Riggs [Wed, 2 Nov 2011 17:15:35 +0000 (17:15 +0000)]
Update more comments about checkpoints being done by bgwriter

12 years agoReduce checkpoints and WAL traffic on low activity database server
Simon Riggs [Wed, 2 Nov 2011 15:26:33 +0000 (15:26 +0000)]
Reduce checkpoints and WAL traffic on low activity database server
Previously, we skipped a checkpoint if no WAL had been written since
last checkpoint, though this does not appear in user documentation.
As of now, we skip a checkpoint until we have written at least one
enough WAL to switch the next WAL file. This greatly reduces the
level of activity and number of WAL messages generated by a very
low activity server. This is safe because the purpose of a checkpoint
is to act as a starting place for a recovery, in case of crash.
This patch maintains minimal WAL volume for replay in case of crash,
thus maintaining very low crash recovery time.

12 years agoRefactor xlog.c to create src/backend/postmaster/startup.c
Simon Riggs [Wed, 2 Nov 2011 14:25:01 +0000 (14:25 +0000)]
Refactor xlog.c to create src/backend/postmaster/startup.c
Startup process now has its own dedicated file, just like all other
special/background processes. Reduces role and size of xlog.c

12 years agoDerive oldestActiveXid at correct time for Hot Standby.
Simon Riggs [Wed, 2 Nov 2011 08:54:56 +0000 (08:54 +0000)]
Derive oldestActiveXid at correct time for Hot Standby.
There was a timing window between when oldestActiveXid was derived
and when it should have been derived that only shows itself under
heavy load. Move code around to ensure correct timing of derivation.
No change to StartupSUBTRANS() code, which is where this failed.

Bug report by Chris Redekop

12 years agoStart Hot Standby faster when initial snapshot is incomplete.
Simon Riggs [Wed, 2 Nov 2011 08:47:43 +0000 (08:47 +0000)]
Start Hot Standby faster when initial snapshot is incomplete.
If the initial snapshot had overflowed then we can start whenever
the latest snapshot is empty, not overflowed or as we did already,
start when the xmin on primary was higher than xmax of our starting
snapshot, which proves we have full snapshot data.

Bug report by Chris Redekop

12 years agoRemove spurious entry from missed catch while patch juggling
Simon Riggs [Wed, 2 Nov 2011 08:37:52 +0000 (08:37 +0000)]
Remove spurious entry from missed catch while patch juggling

12 years agoFix timing of Startup CLOG and MultiXact during Hot Standby
Simon Riggs [Wed, 2 Nov 2011 08:07:44 +0000 (08:07 +0000)]
Fix timing of Startup CLOG and MultiXact during Hot Standby

Patch by me, bug report by Chris Redekop, analysis by Florian Pflug

12 years agoInitialize myProcLocks queues just once, at postmaster startup.
Robert Haas [Wed, 2 Nov 2011 02:44:54 +0000 (22:44 -0400)]
Initialize myProcLocks queues just once, at postmaster startup.

In assert-enabled builds, we assert during the shutdown sequence that
the queues have been properly emptied, and during process startup that
we are inheriting empty queues.  In non-assert enabled builds, we just
save a few cycles.

12 years agoPreserve Var location information during flatten_join_alias_vars.
Tom Lane [Wed, 2 Nov 2011 02:13:11 +0000 (22:13 -0400)]
Preserve Var location information during flatten_join_alias_vars.

This allows us to give correct syntax error pointers when complaining
about ungrouped variables in a join query with aggregates or GROUP BY.
It's pretty much irrelevant for the planner's use of the function, though
perhaps it might aid debugging sometimes.

12 years agoFix race condition with toast table access from a stale syscache entry.
Tom Lane [Tue, 1 Nov 2011 23:48:37 +0000 (19:48 -0400)]
Fix race condition with toast table access from a stale syscache entry.

If a tuple in a syscache contains an out-of-line toasted field, and we
try to fetch that field shortly after some other transaction has committed
an update or deletion of the tuple, there is a race condition: vacuum
could come along and remove the toast tuples before we can fetch them.
This leads to transient failures like "missing chunk number 0 for toast
value NNNNN in pg_toast_2619", as seen in recent reports from Andrew
Hammond and Tim Uckun.

The design idea of syscache is that access to stale syscache entries
should be prevented by relation-level locks, but that fails for at least
two cases where toasted fields are possible: ANALYZE updates pg_statistic
rows without locking out sessions that might want to plan queries on the
same table, and CREATE OR REPLACE FUNCTION updates pg_proc rows without
any meaningful lock at all.

The least risky fix seems to be an idea that Heikki suggested when we
were dealing with a related problem back in August: forcibly detoast any
out-of-line fields before putting a tuple into syscache in the first place.
This avoids the problem because at the time we fetch the parent tuple from
the catalog, we should be holding an MVCC snapshot that will prevent
removal of the toast tuples, even if the parent tuple is outdated
immediately after we fetch it.  (Note: I'm not convinced that this
statement holds true at every instant where we could be fetching a syscache
entry at all, but it does appear to hold true at the times where we could
fetch an entry that could have a toasted field.  We will need to be a bit
wary of adding toast tables to low-level catalogs that don't have them
already.)  An additional benefit is that subsequent uses of the syscache
entry should be faster, since they won't have to detoast the field.

Back-patch to all supported versions.  The problem is significantly harder
to reproduce in pre-9.0 releases, because of their willingness to flush
every entry in a syscache whenever the underlying catalog is vacuumed
(cf CatalogCacheFlushRelation); but there is still a window for trouble.

12 years agoClean up whitespace and indentation in parser and scanner files
Peter Eisentraut [Tue, 1 Nov 2011 19:50:00 +0000 (21:50 +0200)]
Clean up whitespace and indentation in parser and scanner files

These are not touched by pgindent, so clean them up a bit manually.

12 years agoComment changes to show bgwriter no longer performs checkpoints.
Simon Riggs [Tue, 1 Nov 2011 18:48:47 +0000 (18:48 +0000)]
Comment changes to show bgwriter no longer performs checkpoints.

12 years agoHave checkpointer send stats once each processing loop.
Simon Riggs [Tue, 1 Nov 2011 18:38:27 +0000 (18:38 +0000)]
Have checkpointer send stats once each processing loop.

Noted by Fujii Masao

12 years agoUpdate pg_upgrade comment on missing 'postgres' database.
Bruce Momjian [Tue, 1 Nov 2011 18:33:51 +0000 (14:33 -0400)]
Update pg_upgrade comment on missing 'postgres' database.

12 years agoAdd new file for checkpointer.c
Simon Riggs [Tue, 1 Nov 2011 18:07:29 +0000 (18:07 +0000)]
Add new file for checkpointer.c

12 years agoAllow pg_upgrade to upgrade an old cluster that doesn't have a
Bruce Momjian [Tue, 1 Nov 2011 17:49:03 +0000 (13:49 -0400)]
Allow pg_upgrade to upgrade an old cluster that doesn't have a
'postgres' database.

12 years agoSplit work of bgwriter between 2 processes: bgwriter and checkpointer.
Simon Riggs [Tue, 1 Nov 2011 17:14:47 +0000 (17:14 +0000)]
Split work of bgwriter between 2 processes: bgwriter and checkpointer.
bgwriter is now a much less important process, responsible for page
cleaning duties only. checkpointer is now responsible for checkpoints
and so has a key role in shutdown. Later patches will correct doc
references to the now old idea that bgwriter performs checkpoints.
Has beneficial effect on performance at high write rates, but mainly
refactoring to more easily allow changes for power reduction by
simplifying previously tortuous code around required to allow page
cleaning and checkpointing to time slice in the same process.

Patch by me, Review by Dickson Guedes

12 years agoDocument that multiple LDAP servers can be specified
Magnus Hagander [Tue, 1 Nov 2011 14:44:26 +0000 (15:44 +0100)]
Document that multiple LDAP servers can be specified

12 years agoStop btree indexscans upon reaching nulls in either direction.
Tom Lane [Mon, 31 Oct 2011 20:40:04 +0000 (16:40 -0400)]
Stop btree indexscans upon reaching nulls in either direction.

The existing scan-direction-sensitive tests were overly complex, and
failed to stop the scan in cases where it's perfectly legitimate to do so.
Per bug #6278 from Maksym Boguk.

Back-patch to 8.3, which is as far back as the patch applies easily.
Doesn't seem worth sweating over a relatively minor performance issue in
8.2 at this late date.  (But note that this was a performance regression
from 8.1 and before, so 8.2 is being left as an outlier.)

12 years agoSupport more locale-specific formatting options in cash_out().
Tom Lane [Sun, 30 Oct 2011 19:02:58 +0000 (15:02 -0400)]
Support more locale-specific formatting options in cash_out().

The POSIX spec defines locale fields for controlling the ordering of the
value, sign, and currency symbol in monetary output, but cash_out only
supported a small subset of these options.  Fully implement p/n_sign_posn,
p/n_cs_precedes, and p/n_sep_by_space per spec.  Fix up cash_in so that
it will accept all these format variants.

Also, make sure that thousands_sep is only inserted to the left of the
decimal point, as required by spec.

Per bug #6144 from Eduard Kracmar and discussion of bug #6277.  This patch
includes some ideas from Alexander Lakhin's proposed patch, though it is
very different in detail.

12 years agoFurther improvement of make_greater_string.
Tom Lane [Sun, 30 Oct 2011 16:21:28 +0000 (12:21 -0400)]
Further improvement of make_greater_string.

Make sure that it considers all the possibilities that the old code did,
instead of trying only one possibility per character position.  To keep the
runtime in bounds, instead tweak the character incrementers to not try
every possible multibyte character code.  Remove unnecessary logic to
restore the old character value on failure.  Additional comment and
formatting cleanup.

12 years agoUpdate visibilitymap.c header comments.
Robert Haas [Sat, 29 Oct 2011 18:45:39 +0000 (14:45 -0400)]
Update visibilitymap.c header comments.

Recent work on index-only scans left this somewhat out of date.

12 years agoFix assorted bogosities in cash_in() and cash_out().
Tom Lane [Sat, 29 Oct 2011 18:30:55 +0000 (14:30 -0400)]
Fix assorted bogosities in cash_in() and cash_out().

cash_out failed to handle multiple-byte thousands separators, as per bug
#6277 from Alexander Law.  In addition, cash_in didn't handle that either,
nor could it handle multiple-byte positive_sign.  Both routines failed to
support multiple-byte mon_decimal_point, which I did not think was worth
changing, but at least now they check for the possibility and fall back to
using '.' rather than emitting invalid output.  Also, make cash_in handle
trailing negative signs, which formerly it would reject.  Since cash_out
generates trailing negative signs whenever the locale tells it to, this
last omission represents a fail-to-reload-dumped-data bug.  IMO that
justifies patching this all the way back.

12 years agoImprove make_greater_string() with encoding-specific incrementers.
Robert Haas [Sat, 29 Oct 2011 18:22:20 +0000 (14:22 -0400)]
Improve make_greater_string() with encoding-specific incrementers.

This infrastructure doesn't in any way guarantee that the character
we produce will sort before the one we incremented; but it does at least
make it much more likely that we'll end up with something that is a valid
character, which improves our chances.

Kyotaro Horiguchi, with various adjustments by me.

12 years agoRemove pg_upgrade dependency on the 'postgres' database existing in the
Bruce Momjian [Sat, 29 Oct 2011 01:18:36 +0000 (21:18 -0400)]
Remove pg_upgrade dependency on the 'postgres' database existing in the
new cluster.   vacuumdb, used by pg_upgrade, still has this dependency.

12 years agoAllow hint bits to be set sooner for temporary and unlogged tables.
Robert Haas [Fri, 28 Oct 2011 21:08:09 +0000 (17:08 -0400)]
Allow hint bits to be set sooner for temporary and unlogged tables.

We need not wait until the commit record is durably on disk, because
in the event of a crash the page we're updating with hint bits will
be gone anyway.  Per off-list report from Heikki Linnakangas, this
can significantly degrade the performance of unlogged tables; I was
able to show a 2x speedup from this patch on a pgbench run with scale
factor 15.  In practice, this will mostly help small, heavily updated
tables, because on larger tables you're unlikely to run into the same
row again before the commit record makes it out to disk.

12 years agoDemote some sanity checks in BufferIsValid() to assertions.
Robert Haas [Fri, 28 Oct 2011 21:04:22 +0000 (17:04 -0400)]
Demote some sanity checks in BufferIsValid() to assertions.

Testing reveals that this macro is a hot-spot for index-only-scans.
Per discussion with Tom Lane.

12 years agoRemove hard-coded "\connect postgres" from pg_dumpall.
Robert Haas [Fri, 28 Oct 2011 19:45:28 +0000 (15:45 -0400)]
Remove hard-coded "\connect postgres" from pg_dumpall.

This doesn't appear to accompish anything useful, and does make the
restore fail if the postgres database happens to have been dropped.

12 years agoDe-parallelize ecpg build some more.
Tom Lane [Fri, 28 Oct 2011 19:16:40 +0000 (15:16 -0400)]
De-parallelize ecpg build some more.

Make sure ecpg/include/ is rebuilt before the other subdirectories,
so that ecpg_config.h is up to date.  This is not likely to matter
during production builds, only development, so no back-patch.

12 years agoClarify that ORDER BY/FOR UPDATE can't malfunction at higher iso levels.
Robert Haas [Fri, 28 Oct 2011 16:02:04 +0000 (12:02 -0400)]
Clarify that ORDER BY/FOR UPDATE can't malfunction at higher iso levels.

Kevin Grittner

12 years agoChange "and and" to "and".
Robert Haas [Fri, 28 Oct 2011 15:59:55 +0000 (11:59 -0400)]
Change "and and" to "and".

Report by Vik Reykja, patch by Kevin Grittner.

12 years agoClarify pg_upgrade error message that the 'postgres' database must exist
Bruce Momjian [Fri, 28 Oct 2011 12:07:30 +0000 (08:07 -0400)]
Clarify pg_upgrade error message that the 'postgres' database must exist
in the old cluster.

12 years agoUpdate docs to point to the timezone library's new home at IANA.
Tom Lane [Fri, 28 Oct 2011 03:09:05 +0000 (23:09 -0400)]
Update docs to point to the timezone library's new home at IANA.

The recent unpleasantness with copyrights has accelerated a move that
was already in planning.

12 years agoUpdate pg_upgrade testing instructions.
Bruce Momjian [Fri, 28 Oct 2011 01:29:03 +0000 (21:29 -0400)]
Update pg_upgrade testing instructions.

12 years agoFix the number of lwlocks needed by the "fast path" lock patch. It needs
Heikki Linnakangas [Thu, 27 Oct 2011 19:39:58 +0000 (22:39 +0300)]
Fix the number of lwlocks needed by the "fast path" lock patch. It needs
one lock per backend or auxiliary process - the need for a lock for each
aux processes was not accounted for in NumLWLocks(). No-one noticed,
because the three locks needed for the three aux processes fit into the
few extra lwlocks we allocate for 3rd party modules that don't call
RequestAddinLWLocks() (NUM_USER_DEFINED_LWLOCKS, 4 by default).

12 years agoAvoid recursion while processing ELSIF lists in plpgsql.
Tom Lane [Thu, 27 Oct 2011 19:21:51 +0000 (15:21 -0400)]
Avoid recursion while processing ELSIF lists in plpgsql.

The original implementation of ELSIF in plpgsql converted the construct
into nested simple IF statements.  This was prone to stack overflow with
long ELSIF lists, in two different ways.  First, it's difficult to generate
the parsetree without using right-recursion in the bison grammar, and
that's prone to parser stack overflow since nothing can be reduced until
the whole list has been read.  Second, we'd recurse during execution, thus
creating an unnecessary risk of execution-time stack overflow.  Rewrite
so that the ELSIF list is represented as a flat list, scanned via iteration
not recursion, and generated through left-recursion in the grammar.
Per a gripe from Håvard Kongsgård.

12 years agoAdd simple script to check for right recursion in Bison grammars.
Tom Lane [Thu, 27 Oct 2011 17:50:57 +0000 (13:50 -0400)]
Add simple script to check for right recursion in Bison grammars.

We should generally use left-recursion not right-recursion to parse lists.
Bison hasn't got any built-in way to check for this type of inefficiency,
and I didn't find anything on the net in a quick search, so I wrote a
little Perl script to do it.  Add to src/tools/ so we don't have to
re-invent this wheel next time we wonder if we're doing anything stupid.

Currently, the only place that seems to need fixing is plpgsql's stmt_else
production, so the problem doesn't appear to be common enough to warrant
trying to include such a test in our standard build process.  If we did
want to do that, we'd need a way to ignore some false positives, such as
a_expr := '-' a_expr

12 years agoTypo fixes.
Tom Lane [Wed, 26 Oct 2011 22:04:13 +0000 (18:04 -0400)]
Typo fixes.

expect -> except, noted by Andrew Dunstan.  Also, "cannot" seems more
readable here than "can not", per David Wheeler.

12 years agoImprove planner's ability to recognize cases where an IN's RHS is unique.
Tom Lane [Wed, 26 Oct 2011 21:52:02 +0000 (17:52 -0400)]
Improve planner's ability to recognize cases where an IN's RHS is unique.

If the right-hand side of a semijoin is unique, then we can treat it like a
normal join (or another way to say that is: we don't need to explicitly
unique-ify the data before doing it as a normal join).  We were recognizing
such cases when the RHS was a sub-query with appropriate DISTINCT or GROUP
BY decoration, but there's another way: if the RHS is a plain relation with
unique indexes, we can check if any of the indexes prove the output is
unique.  Most of the infrastructure for that was there already in the join
removal code, though I had to rearrange it a bit.  Per reflection about a
recent example in pgsql-performance.

12 years agoFix pg_bsd_indent bug where newlines were not being trimmed from typedef
Bruce Momjian [Wed, 26 Oct 2011 21:23:33 +0000 (17:23 -0400)]
Fix pg_bsd_indent bug where newlines were not being trimmed from typedef
lines.  Update pg_bsd_indent required version to 1.1 (and update ftp
site).

Problem reported by Magnus.

12 years agoImplement streaming xlog for backup tools
Magnus Hagander [Wed, 26 Oct 2011 18:13:33 +0000 (20:13 +0200)]
Implement streaming xlog for backup tools

Add option for parallel streaming of the transaction log while a
base backup is running, to get the logfiles before the server has
removed them.

Also add a tool called pg_receivexlog, which streams the transaction
log into files, creating a log archive without having to wait for
segments to complete, thus decreasing the window of data loss without
having to waste space using archive_timeout. This works best in
combination with archive_command - suggested usage docs etc coming later.

12 years agoMingW doesn't support wcstombs_s()...
Magnus Hagander [Wed, 26 Oct 2011 17:26:13 +0000 (19:26 +0200)]
MingW doesn't support wcstombs_s()...

12 years agoChange FK trigger naming convention to fix self-referential FKs.
Tom Lane [Wed, 26 Oct 2011 17:19:42 +0000 (13:19 -0400)]
Change FK trigger naming convention to fix self-referential FKs.

Use names like "RI_ConstraintTrigger_a_NNNN" for FK action triggers and
"RI_ConstraintTrigger_c_NNNN" for FK check triggers.  This ensures the
action trigger fires first in self-referential cases where the very same
row update fires both an action and a check trigger.  This change provides
a non-probabilistic solution for bug #6268, at the risk that it could break
client code that is making assumptions about the exact names assigned to
auto-generated FK triggers.  Hence, change this in HEAD only.  No need for
forced initdb since old triggers continue to work fine.

12 years agoChange FK trigger creation order to better support self-referential FKs.
Tom Lane [Wed, 26 Oct 2011 17:02:28 +0000 (13:02 -0400)]
Change FK trigger creation order to better support self-referential FKs.

When a foreign-key constraint references another column of the same table,
row updates will queue both the PK's ON UPDATE action and the FK's CHECK
action in the same event.  The ON UPDATE action must execute first, else
the CHECK will check a non-final state of the row and possibly throw an
inappropriate error, as seen in bug #6268 from Roman Lytovchenko.

Now, the firing order of multiple triggers for the same event is determined
by the sort order of their pg_trigger.tgnames, and the auto-generated names
we use for FK triggers are "RI_ConstraintTrigger_NNNN" where NNNN is the
trigger OID.  So most of the time the firing order is the same as creation
order, and so rearranging the creation order fixes it.

This patch will fail to fix the problem if the OID counter wraps around or
adds a decimal digit (eg, from 99999 to 100000) while we are creating the
triggers for an FK constraint.  Given the small odds of that, and the low
usage of self-referential FKs, we'll live with that solution in the back
branches.  A better fix is to change the auto-generated names for FK
triggers, but it seems unwise to do that in stable branches because there
may be client code that depends on the naming convention.  We'll fix it
that way in HEAD in a separate patch.

Back-patch to all supported branches, since this bug has existed for a long
time.

12 years agoFix typo
Magnus Hagander [Tue, 25 Oct 2011 20:46:14 +0000 (22:46 +0200)]
Fix typo

12 years agoMake event_source visible on all platforms
Magnus Hagander [Tue, 25 Oct 2011 20:40:58 +0000 (22:40 +0200)]
Make event_source visible on all platforms

On non-windows platform, we just ignore any value set there.

Noted by Jaime Casanova

12 years agoRemove argument decoration that appears unsupported on mingw
Magnus Hagander [Tue, 25 Oct 2011 19:30:53 +0000 (21:30 +0200)]
Remove argument decoration that appears unsupported on mingw

12 years agoSupport configurable eventlog application names on Windows
Magnus Hagander [Tue, 25 Oct 2011 18:02:55 +0000 (20:02 +0200)]
Support configurable eventlog application names on Windows

This allows different instances to use the eventlog with different
identifiers, by setting the event_source GUC, similar to how
syslog_ident works.

Original patch by MauMau, heavily modified by Magnus Hagander

12 years agoAdd debugging aid in isolationtester
Alvaro Herrera [Tue, 25 Oct 2011 01:11:10 +0000 (22:11 -0300)]
Add debugging aid in isolationtester

12 years agoMake TABLE tab complation in psql include all relations
Magnus Hagander [Mon, 24 Oct 2011 11:22:59 +0000 (13:22 +0200)]
Make TABLE tab complation in psql include all relations

Not just tables, since views also work fine with the
TABLE command.

12 years agoMake psql support tab completion of EXECUTE <prepared-statement-name>.
Tom Lane [Sun, 23 Oct 2011 23:25:34 +0000 (19:25 -0400)]
Make psql support tab completion of EXECUTE <prepared-statement-name>.

Andreas Karlsson, reviewed by Josh Kupershmidt

12 years agoImprove git_changelog's handling of inconsistent commit orderings.
Tom Lane [Sun, 23 Oct 2011 18:34:36 +0000 (14:34 -0400)]
Improve git_changelog's handling of inconsistent commit orderings.

Use the CommitDate not the AuthorDate, as the former is representative of
the order in which things went into the main repository, and the latter
isn't very; we now have instances where the AuthorDate is as much as a
month before the patch really went in.  Also, get rid of the "commit order
inversions" heuristic, which turns out not to do anything very desirable.
Instead we just print commits in strict timestamp order, interpreting the
"timestamp" of a merged commit as its timestamp on the newest branch it
appears in.  This fixes some cases where very ancient commits were being
printed relatively early in the report.

12 years agoDon't trust deferred-unique indexes for join removal.
Tom Lane [Sun, 23 Oct 2011 04:43:39 +0000 (00:43 -0400)]
Don't trust deferred-unique indexes for join removal.

The uniqueness condition might fail to hold intra-transaction, and assuming
it does can give incorrect query results.  Per report from Marti Raudsepp,
though this is not his proposed patch.

Back-patch to 9.0, where both these features were introduced.  In the
released branches, add the new IndexOptInfo field to the end of the struct,
to try to minimize ABI breakage for third-party code that may be examining
that struct.

12 years agoSupport synchronization of snapshots through an export/import procedure.
Tom Lane [Sat, 22 Oct 2011 22:22:45 +0000 (18:22 -0400)]
Support synchronization of snapshots through an export/import procedure.

A transaction can export a snapshot with pg_export_snapshot(), and then
others can import it with SET TRANSACTION SNAPSHOT.  The data does not
leave the server so there are not security issues.  A snapshot can only
be imported while the exporting transaction is still running, and there
are some other restrictions.

I'm not totally convinced that we've covered all the bases for SSI (true
serializable) mode, but it works fine for lesser isolation modes.

Joachim Wieland, reviewed by Marko Tiikkaja, and rather heavily modified
by Tom Lane

12 years agoFix overly-complicated usage of errcode_for_file_access().
Heikki Linnakangas [Sat, 22 Oct 2011 17:16:05 +0000 (20:16 +0300)]
Fix overly-complicated usage of errcode_for_file_access().

No need to do  "errcode(errcode_for_file_access())", just
"errcode_for_file_access()" is enough. The extra errcode() call is useless
but harmless, so there's no user-visible bug here. Nevertheless, backpatch
to 9.1 where this code were added.

12 years agoCode review for pgstat_get_crashed_backend_activity patch.
Tom Lane [Fri, 21 Oct 2011 20:36:04 +0000 (16:36 -0400)]
Code review for pgstat_get_crashed_backend_activity patch.

Avoid possibly dumping core when pgstat_track_activity_query_size has a
less-than-default value; avoid uselessly searching for the query string
of a successfully-exited backend; don't bother putting out an ERRDETAIL if
we don't have a query to show; some other minor stylistic improvements.

12 years agoMore cleanup after failed reduced-lock-levels-for-DDL feature.
Tom Lane [Fri, 21 Oct 2011 17:49:51 +0000 (13:49 -0400)]
More cleanup after failed reduced-lock-levels-for-DDL feature.

Turns out that use of ShareUpdateExclusiveLock or ShareRowExclusiveLock
to protect DDL changes had gotten copied into several places that were
not touched by either of Simon's original patches for the feature, and
thus neither he nor I thought to revert them.  (Indeed, it appears that
two of these uses were committed *after* the reversion, which just goes
to show that git merging is no panacea.)  Change these places to use
AccessExclusiveLock again.  If we ever manage to resurrect that feature,
we're going to have to think a bit harder about how to keep lock level
usage in sync for DDL operations that aren't within the AlterTable
infrastructure.

Two of these bugs are only in HEAD, but one is in the 9.1 branch too.
Alvaro found one of them, I found the other two.

12 years agoTry to log current the query string when a backend crashes.
Robert Haas [Fri, 21 Oct 2011 17:26:40 +0000 (13:26 -0400)]
Try to log current the query string when a backend crashes.

To avoid minimize risk inside the postmaster, we subject this feature
to a number of significant limitations.  We very much wish to avoid
doing any complex processing inside the postmaster, due to the
posssibility that the crashed backend has completely corrupted shared
memory.  To that end, no encoding conversion is done; instead, we just
replace anything that doesn't look like an ASCII character with a
question mark.  We limit the amount of data copied to 1024 characters,
and carefully sanity check the source of that data.  While these
restrictions would doubtless be unacceptable in a general-purpose
logging facility, even this limited facility seems like an improvement
over the status quo ante.

Marti Raudsepp, reviewed by PDXPUG and myself

12 years agoFix DROP OPERATOR FAMILY IF EXISTS.
Robert Haas [Fri, 21 Oct 2011 13:10:46 +0000 (09:10 -0400)]
Fix DROP OPERATOR FAMILY IF EXISTS.

Essentially, the "IF EXISTS" portion was being ignored, and an error
thrown anyway if the opfamily did not exist.

I broke this in commit fd1843ff8979c0461fb3f1a9eab61140c977e32d; so
backpatch to 9.1.X.

Report and diagnosis by KaiGai Kohei.

12 years agoSimplify and improve ProcessStandbyHSFeedbackMessage logic.
Tom Lane [Thu, 20 Oct 2011 23:43:31 +0000 (19:43 -0400)]
Simplify and improve ProcessStandbyHSFeedbackMessage logic.

There's no need to clamp the standby's xmin to be greater than
GetOldestXmin's result; if there were any such need this logic would be
hopelessly inadequate anyway, because it fails to account for
within-database versus cluster-wide values of GetOldestXmin.  So get rid of
that, and just rely on sanity-checking that the xmin is not wrapped around
relative to the nextXid counter.  Also, don't reset the walsender's xmin if
the current feedback xmin is indeed out of range; that just creates more
problems than we already had.  Lastly, don't bother to take the
ProcArrayLock; there's no need to do that to set xmin.

Also improve the comments about this in GetOldestXmin itself.

12 years agoRewrite tab completion's previous-word fetching for more sanity.
Tom Lane [Thu, 20 Oct 2011 19:38:57 +0000 (15:38 -0400)]
Rewrite tab completion's previous-word fetching for more sanity.

Make it return empty strings when there are no more words to the left of
the current position, instead of sometimes returning NULL and other times
returning copies of the leftmost word.  Also, fetch the words in one scan,
rather than the previous wasteful approach of starting from scratch for
each word.  Make the code a bit harder to break when someone decides we
need more words of context, too.  (There was actually a memory leak here,
because whoever added prev6_wd neglected to free it.)

12 years agoFix get_object_namespace() not to think extensions are "in" a schema.
Robert Haas [Thu, 20 Oct 2011 04:05:31 +0000 (00:05 -0400)]
Fix get_object_namespace() not to think extensions are "in" a schema.

extnamespace means something altogether different in this context.
Mostly by accident, this coding error (introduced in my commit
82a4a777d94bec965ab2f1d04b6e6a3f0447b377) broke the buildfarm instead
of just silently doing the wrong thing.

12 years agoAdd "skipping" to the NOTICE produced by DROP OPERATOR CLASS IF EXISTS.
Robert Haas [Thu, 20 Oct 2011 03:45:31 +0000 (23:45 -0400)]
Add "skipping" to the NOTICE produced by DROP OPERATOR CLASS IF EXISTS.

This makes this message consistent with all the other similar notices
produced by other DROP IF EXISTS commands.

Noted by KaiGai Kohei

12 years agoRemove a few of the new DROP-IF-EXISTS regression tests.
Robert Haas [Thu, 20 Oct 2011 03:38:06 +0000 (23:38 -0400)]
Remove a few of the new DROP-IF-EXISTS regression tests.

Commit 3301c83536e9da1e573e24ded2e610062dbf9cdc broke the build farm.
Let's try to fix that.

12 years agoConsolidate DROP handling for some object types.
Robert Haas [Thu, 20 Oct 2011 03:25:20 +0000 (23:25 -0400)]
Consolidate DROP handling for some object types.

This gets rid of a significant amount of duplicative code.

KaiGai Kohei, reviewed in earlier versions by Dimitri Fontaine, with
further review and cleanup by me.

12 years agoAdd some more regression tests for DROP IF EXISTS.
Robert Haas [Thu, 20 Oct 2011 00:55:56 +0000 (20:55 -0400)]
Add some more regression tests for DROP IF EXISTS.

KaiGai Kohei

12 years agoDocument that postmaster.opts is excluded from base backups
Robert Haas [Wed, 19 Oct 2011 04:19:43 +0000 (00:19 -0400)]
Document that postmaster.opts is excluded from base backups

Fujii Masao

12 years agoSuppress remaining -Waddress warnings from recent gcc versions.
Tom Lane [Wed, 19 Oct 2011 01:44:23 +0000 (21:44 -0400)]
Suppress remaining -Waddress warnings from recent gcc versions.

Still an exercise in satisfying pedants.

12 years agoSuppress -Wunused-result warnings about write() and fwrite().
Tom Lane [Wed, 19 Oct 2011 01:37:51 +0000 (21:37 -0400)]
Suppress -Wunused-result warnings about write() and fwrite().

This is merely an exercise in satisfying pedants, not a bug fix, because
in every case we were checking for failure later with ferror(), or else
there was nothing useful to be done about a failure anyway.  Document
the latter cases.

12 years agoMake the CHECKPOINT reference page more clear.
Robert Haas [Wed, 19 Oct 2011 00:13:27 +0000 (20:13 -0400)]
Make the CHECKPOINT reference page more clear.

Josh Kupershmidt, reviewed by Fujii Masao

12 years agoReject empty pg_hba.conf files.
Tom Lane [Wed, 19 Oct 2011 00:09:18 +0000 (20:09 -0400)]
Reject empty pg_hba.conf files.

An empty HBA file is surely an error, since it means there is no way to
connect to the server.  We've not heard identifiable reports of people
actually doing that, but this will also close off the case Thom Brown just
complained of, namely pointing hba_file at a directory.  (On at least some
platforms with some directories, it will read as an empty file.)

Perhaps this should be back-patched, but given the lack of previous
complaints, I won't add extra work for the translators.

12 years agoRemove unnecessary AssertMacro() to suppress gcc 4.6 compiler warning.
Tom Lane [Tue, 18 Oct 2011 21:39:14 +0000 (17:39 -0400)]
Remove unnecessary AssertMacro() to suppress gcc 4.6 compiler warning.

There's no particular value in doing AssertMacro((tup) != NULL) in front
of code that's certain to crash anyway if tup is NULL.  And if "tup" is
actually the address of a local variable, gcc 4.6 whinges about it.  That's
arguably pretty broken on gcc's part, but we might as well remove the
useless test to silence the warnings.  This gets rid of all the -Waddress
warnings in the backend; there are some in libpq and psql that are a bit
harder to avoid.

12 years agoFix pg_dump to dump casts between auto-generated types.
Tom Lane [Tue, 18 Oct 2011 21:10:56 +0000 (17:10 -0400)]
Fix pg_dump to dump casts between auto-generated types.

The heuristic for when to dump a cast failed for a cast between table
rowtypes, as reported by Frédéric Rejol.  Fix it by setting
the "dump" flag for such a type the same way as the flag is set for the
underlying table or base type.  This won't result in the auto-generated
type appearing in the output, since setting its objType to DO_DUMMY_TYPE
unconditionally suppresses that.  But it will result in dumpCast doing what
was intended.

Back-patch to 8.3.  The 8.2 code is rather different in this area, and it
doesn't seem worth any risk to fix a corner case that nobody has stumbled
on before.

12 years agoExclude postmaster.opts from base backups
Magnus Hagander [Sun, 16 Oct 2011 15:42:59 +0000 (17:42 +0200)]
Exclude postmaster.opts from base backups

Noted by Fujii Masao

12 years agoAvoid assuming that index-only scan data matches the index's rowtype.
Tom Lane [Sun, 16 Oct 2011 23:15:04 +0000 (19:15 -0400)]
Avoid assuming that index-only scan data matches the index's rowtype.

In general the data returned by an index-only scan should have the
datatypes originally computed by FormIndexDatum.  If the index opclasses
use "storage" datatypes different from their input datatypes, the scan
tuple will not have the same rowtype attributed to the index; but we had
a hard-wired assumption that that was true in nodeIndexonlyscan.c.  We'd
already hacked around the issue for the one case where the types are
different in btree indexes (btree name_ops), but this would definitely
come back to bite us if we ever implement index-only scans in GiST.

To fix, require the index AM to explicitly provide the tupdesc for the
tuple it is returning.  btree can just pass back the index's tupdesc, but
GiST will have to work harder when and if it supports index-only scans.

I had previously proposed fixing this by allowing the index AM to fill the
scan tuple slot directly; but on reflection that seemed like a module
layering violation, since TupleTableSlots are creatures of the executor.
At least in the btree case, it would also be less efficient, since the
tuple deconstruction work would occur even for rows later found to be
invisible to the scan's snapshot.

12 years agoFix collate.linux.utf8 expected output for recent error message change.
Tom Lane [Sun, 16 Oct 2011 20:07:40 +0000 (16:07 -0400)]
Fix collate.linux.utf8 expected output for recent error message change.

Noted by Jeff Davis.

12 years agoTeach btree to handle ScalarArrayOpExpr quals natively.
Tom Lane [Sun, 16 Oct 2011 19:39:24 +0000 (15:39 -0400)]
Teach btree to handle ScalarArrayOpExpr quals natively.

This allows "indexedcol op ANY(ARRAY[...])" conditions to be used in plain
indexscans, and particularly in index-only scans.

12 years agoMarginal improvements to documentation of plpgsql's OPEN cursor statement.
Tom Lane [Sat, 15 Oct 2011 17:02:37 +0000 (13:02 -0400)]
Marginal improvements to documentation of plpgsql's OPEN cursor statement.

Rearrange text to improve clarity, and add an example of implicit reference
to a plpgsql variable in a bound cursor's query.  Byproduct of some work
I'd done on the "named cursor parameters" patch before giving up on it.

12 years agoDocument that is the psql version number, not the server version number,
Bruce Momjian [Sat, 15 Oct 2011 15:43:19 +0000 (11:43 -0400)]
Document that is the psql version number, not the server version number,
that controls .psqlrc.

12 years agoImprove doc wording of drop table permission.
Bruce Momjian [Sat, 15 Oct 2011 14:08:02 +0000 (10:08 -0400)]
Improve doc wording of drop table permission.

12 years agoAllow a major PG version psql .psqlrc file to be used if a minor
Bruce Momjian [Sat, 15 Oct 2011 00:26:28 +0000 (20:26 -0400)]
Allow a major PG version psql .psqlrc file to be used if a minor
matching version file does not exist.  This avoids needing to rename
.psqlrc files after minor version upgrades.

12 years agoFix bugs in information_schema.referential_constraints view.
Tom Lane [Sat, 15 Oct 2011 00:24:17 +0000 (20:24 -0400)]
Fix bugs in information_schema.referential_constraints view.

This view was being insufficiently careful about matching the FK constraint
to the depended-on primary or unique key constraint.  That could result in
failure to show an FK constraint at all, or showing it multiple times, or
claiming that it depended on a different constraint than the one it really
does.  Fix by joining via pg_depend to ensure that we find only the correct
dependency.

Back-patch, but don't bump catversion because we can't force initdb in back
branches.  The next minor-version release notes should explain that if you
need to fix this in an existing installation, you can drop the
information_schema schema then re-create it by sourcing
$SHAREDIR/information_schema.sql in each database (as a superuser of
course).

12 years agoMeasure the number of all-visible pages for use in index-only scan costing.
Tom Lane [Fri, 14 Oct 2011 21:23:01 +0000 (17:23 -0400)]
Measure the number of all-visible pages for use in index-only scan costing.

Add a column pg_class.relallvisible to remember the number of pages that
were all-visible according to the visibility map as of the last VACUUM
(or ANALYZE, or some other operations that update pg_class.relpages).
Use relallvisible/relpages, instead of an arbitrary constant, to estimate
how many heap page fetches can be avoided during an index-only scan.

This is pretty primitive and will no doubt see refinements once we've
acquired more field experience with the index-only scan mechanism, but
it's way better than using a constant.

Note: I had to adjust an underspecified query in the window.sql regression
test, because it was changing answers when the plan changed to use an
index-only scan.  Some of the adjacent tests perhaps should be adjusted
as well, but I didn't do that here.

12 years agoDump all roles first, then all config settings on roles.
Robert Haas [Fri, 14 Oct 2011 18:16:02 +0000 (14:16 -0400)]
Dump all roles first, then all config settings on roles.

This way, if a role's config setting uses the name of another role,
the validity of the dump isn't dependent on the order in which those
two roles are dumped.

Code by Phil Sorber, comment by me.

12 years agoAvoid potential relcache leak in objectaddress.c.
Robert Haas [Fri, 14 Oct 2011 15:35:40 +0000 (11:35 -0400)]
Avoid potential relcache leak in objectaddress.c.

Nobody using the missing_ok flag yet, but let's speculate that this will
be a better interface for future callers.

KaiGai Kohei, with some adjustments by me.

12 years agoDocument actual string that has to be returned by the client for MD5
Bruce Momjian [Fri, 14 Oct 2011 00:48:50 +0000 (20:48 -0400)]
Document actual string that has to be returned by the client for MD5
authentication.

Report and pseudo code by Cyan Ogilvie