]> granicus.if.org Git - postgresql/log
postgresql
11 years agoAdd mode where contrib installcheck runs each module in a separately named database.
Andrew Dunstan [Tue, 11 Dec 2012 16:52:45 +0000 (11:52 -0500)]
Add mode where contrib installcheck runs each module in a separately named database.

Normally each module is tested in a database named contrib_regression,
which is dropped and recreated at the beginhning of each pg_regress run.
This new mode, enabled by adding USE_MODULE_DB=1 to the make command
line, runs most modules in a database with the module name embedded in
it.

This will make testing pg_upgrade on clusters with the contrib modules
a lot easier.

Second attempt at this, this time accomodating make versions older
than 3.82.

Still to be done: adapt to the MSVC build system.

Backpatch to 9.0, which is the earliest version it is reasonably
possible to test upgrading from.

11 years agoFix pg_upgrade -O/-o options
Bruce Momjian [Tue, 11 Dec 2012 04:03:17 +0000 (23:03 -0500)]
Fix pg_upgrade -O/-o options

Fix previous commit that added synchronous_commit=off, but broke -O/-o
due to missing space in argument passing.

Backpatch to 9.2.

11 years agodoc: Remove blastwave.org link
Peter Eisentraut [Tue, 11 Dec 2012 03:37:19 +0000 (22:37 -0500)]
doc: Remove blastwave.org link

Apparently, this service has been dead since 2008.

11 years agoUpdate minimum recovery point on truncation.
Heikki Linnakangas [Mon, 10 Dec 2012 13:54:42 +0000 (15:54 +0200)]
Update minimum recovery point on truncation.

If a file is truncated, we must update minRecoveryPoint. Once a file is
truncated, there's no going back; it would not be safe to stop recovery
at a point earlier than that anymore.

Per report from Kyotaro HORIGUCHI. Backpatch to 8.4. Before that,
minRecoveryPoint was not updated during recovery at all.

11 years agoFix the tracking of min recovery point timeline.
Heikki Linnakangas [Fri, 7 Dec 2012 14:29:39 +0000 (16:29 +0200)]
Fix the tracking of min recovery point timeline.

Forgot to update it at the right place. Also, consider checkpoint record
that switches to new timelne to be on the new timeline.

This fixes erroneous "requested timeline 2 does not contain minimum recovery
point" errors, pointed out by Amit Kapila while testing another patch.

11 years agoFix assorted bugs in privileges-for-types patch.
Tom Lane [Sun, 9 Dec 2012 05:08:23 +0000 (00:08 -0500)]
Fix assorted bugs in privileges-for-types patch.

Commit 729205571e81b4767efc42ad7beb53663e08d1ff added privileges on data
types, but there were a number of oversights.  The implementation of
default privileges for types missed a few places, and pg_dump was
utterly innocent of the whole concept.  Per bug #7741 from Nathan Alden,
and subsequent wider investigation.

11 years agoSupport automatically-updatable views.
Tom Lane [Sat, 8 Dec 2012 23:25:48 +0000 (18:25 -0500)]
Support automatically-updatable views.

This patch makes "simple" views automatically updatable, without the need
to create either INSTEAD OF triggers or INSTEAD rules.  "Simple" views
are those classified as updatable according to SQL-92 rules.  The rewriter
transforms INSERT/UPDATE/DELETE commands on such views directly into an
equivalent command on the underlying table, which will generally have
noticeably better performance than is possible with either triggers or
user-written rules.  A view that has INSTEAD OF triggers or INSTEAD rules
continues to operate the same as before.

For the moment, security_barrier views are not considered simple.
Also, we do not support WITH CHECK OPTION.  These features may be
added in future.

Dean Rasheed, reviewed by Amit Kapila

11 years agoUpdate iso.org page link
Peter Eisentraut [Sat, 8 Dec 2012 12:36:25 +0000 (07:36 -0500)]
Update iso.org page link

The old one is responding with 404.

11 years agoImprove pg_upgrade's status display
Bruce Momjian [Fri, 7 Dec 2012 17:26:13 +0000 (12:26 -0500)]
Improve pg_upgrade's status display

Pg_upgrade displays file names during copy and database names during
dump/restore.  Andrew Dunstan identified three bugs:

*  long file names were being truncated to 60 _leading_ characters, which
   often do not change for long file names

*  file names were truncated to 60 characters in log files

*  carriage returns were being output to log files

This commit fixes these --- it prints 60 _trailing_ characters to the
status display, and full path names without carriage returns to log
files.  It also suppresses status output to the log file unless verbose
mode is used.

11 years agoCorrect xmax test for COPY FREEZE
Simon Riggs [Fri, 7 Dec 2012 14:18:47 +0000 (14:18 +0000)]
Correct xmax test for COPY FREEZE

11 years agoOptimize COPY FREEZE with CREATE TABLE also.
Simon Riggs [Fri, 7 Dec 2012 13:26:52 +0000 (13:26 +0000)]
Optimize COPY FREEZE with CREATE TABLE also.

Jeff Davis, additional test by me

11 years agoClarify that COPY FREEZE is not a hard rule.
Simon Riggs [Fri, 7 Dec 2012 12:59:05 +0000 (12:59 +0000)]
Clarify that COPY FREEZE is not a hard rule.
Remove message when FREEZE not honoured,
clarify reasons in comments and docs.

11 years agoImprove pl/pgsql to support composite-type expressions in RETURN.
Tom Lane [Fri, 7 Dec 2012 04:09:52 +0000 (23:09 -0500)]
Improve pl/pgsql to support composite-type expressions in RETURN.

For some reason lost in the mists of prehistory, RETURN was only coded to
allow a simple reference to a composite variable when the function's return
type is composite.  Allow an expression instead, while preserving the
efficiency of the original code path in the case where the expression is
indeed just a composite variable's name.  Likewise for RETURN NEXT.

As is true in various other places, the supplied expression must yield
exactly the number and data types of the required columns.  There was some
discussion of relaxing that for pl/pgsql, but no consensus yet, so this
patch doesn't address that.

Asif Rehman, reviewed by Pavel Stehule

11 years agoBackground worker processes
Alvaro Herrera [Thu, 6 Dec 2012 17:57:52 +0000 (14:57 -0300)]
Background worker processes

Background workers are postmaster subprocesses that run arbitrary
user-specified code.  They can request shared memory access as well as
backend database connections; or they can just use plain libpq frontend
database connections.

Modules listed in shared_preload_libraries can register background
workers in their _PG_init() function; this is early enough that it's not
necessary to provide an extra GUC option, because the necessary extra
resources can be allocated early on.  Modules can install more than one
bgworker, if necessary.

Care is taken that these extra processes do not interfere with other
postmaster tasks: only one such process is started on each ServerLoop
iteration.  This means a large number of them could be waiting to be
started up and postmaster is still able to quickly service external
connection requests.  Also, shutdown sequence should not be impacted by
a worker process that's reasonably well behaved (i.e. promptly responds
to termination signals.)

The current implementation lets worker processes specify their start
time, i.e. at what point in the server startup process they are to be
started: right after postmaster start (in which case they mustn't ask
for shared memory access), when consistent state has been reached
(useful during recovery in a HOT standby server), or when recovery has
terminated (i.e. when normal backends are allowed).

In case of a bgworker crash, actions to take depend on registration
data: if shared memory was requested, then all other connections are
taken down (as well as other bgworkers), just like it were a regular
backend crashing.  The bgworker itself is restarted, too, within a
configurable timeframe (which can be configured to be never).

More features to add to this framework can be imagined without much
effort, and have been discussed, but this seems good enough as a useful
unit already.

An elementary sample module is supplied.

Author: Álvaro Herrera

This patch is loosely based on prior patches submitted by KaiGai Kohei,
and unsubmitted code by Simon Riggs.

Reviewed by: KaiGai Kohei, Markus Wanner, Andres Freund,
Heikki Linnakangas, Simon Riggs, Amit Kapila

11 years agoFix intermittent crash in DROP INDEX CONCURRENTLY.
Tom Lane [Thu, 6 Dec 2012 04:42:51 +0000 (23:42 -0500)]
Fix intermittent crash in DROP INDEX CONCURRENTLY.

When deleteOneObject closes and reopens the pg_depend relation,
we must see to it that the relcache pointer held by the calling function
(typically performMultipleDeletions) is updated.  Usually the relcache
entry is retained so that the pointer value doesn't change, which is why
the problem had escaped notice ... but after a cache flush event there's
no guarantee that the same memory will be reassigned.  To fix, change
the recursive functions' APIs so that we pass around a "Relation *"
not just "Relation".

Per investigation of occasional buildfarm failures.  This is trivial
to reproduce with -DCLOBBER_CACHE_ALWAYS, which points up the sad
lack of any buildfarm member running that way on a regular basis.

11 years agoUpdate comment at top of index_create
Alvaro Herrera [Thu, 6 Dec 2012 02:09:46 +0000 (23:09 -0300)]
Update comment at top of index_create

I neglected to update it in commit f4c4335.

Michael Paquier

11 years agoEnsure recovery pause feature doesn't pause unless users can connect.
Tom Lane [Wed, 5 Dec 2012 23:27:50 +0000 (18:27 -0500)]
Ensure recovery pause feature doesn't pause unless users can connect.

If we're not in hot standby mode, then there's no way for users to connect
to reset the recoveryPause flag, so we shouldn't pause.  The code was aware
of this but the test to see if pausing was safe was seriously inadequate:
it wasn't paying attention to reachedConsistency, and besides what it was
testing was that we could legally enter hot standby, not that we have
done so.  Get rid of that in favor of checking LocalHotStandbyActive,
which because of the coding in CheckRecoveryConsistency is tantamount to
checking that we have told the postmaster to enter hot standby.

Also, move the recoveryPausesHere() call that reacts to asynchronous
recoveryPause requests so that it's not in the middle of application of a
WAL record.  I put it next to the recoveryStopsHere() call --- in future
those are going to need to interact significantly, so this seems like a
good waystation.

Also, don't bother trying to read another WAL record if we've already
decided not to continue recovery.  This was no big deal when the code was
written originally, but now that reading a record might entail actions like
fetching an archive file, it seems a bit silly to do it like that.

Per report from Jeff Janes and subsequent discussion.  The pause feature
needs quite a lot more work, but this gets rid of some indisputable bugs,
and seems safe enough to back-patch.

11 years agoOops, meant to change the comment in writeTimeLineHistory.
Heikki Linnakangas [Wed, 5 Dec 2012 19:00:59 +0000 (21:00 +0200)]
Oops, meant to change the comment in writeTimeLineHistory.

11 years agoMust not reach consistency before XLOG_BACKUP_RECORD
Simon Riggs [Wed, 5 Dec 2012 13:28:03 +0000 (13:28 +0000)]
Must not reach consistency before XLOG_BACKUP_RECORD
When waiting for an XLOG_BACKUP_RECORD the minRecoveryPoint
will be incorrect, so we must not declare recovery as consistent
before we have seen the record. Major bug allowing recovery to end
too early in some cases, allowing people to see inconsistent db.
This patch to HEAD and 9.2, other fix required for 9.1 and 9.0

Simon Riggs and Andres Freund, bug report by Jeff Janes

11 years agoAdd pgstatginindex() function to get the size of the GIN pending list.
Heikki Linnakangas [Wed, 5 Dec 2012 07:58:03 +0000 (09:58 +0200)]
Add pgstatginindex() function to get the size of the GIN pending list.

Fujii Masao, reviewed by Kyotaro Horiguchi.

11 years agoAttempt to un-break Windows builds with USE_LDAP.
Tom Lane [Tue, 4 Dec 2012 22:25:51 +0000 (17:25 -0500)]
Attempt to un-break Windows builds with USE_LDAP.

The buildfarm shows this case is entirely broken, and I'm betting the
reason is lack of any include file.

11 years agoInclude isinf.o in libecpg if isinf() is not available on the system.
Michael Meskes [Tue, 4 Dec 2012 15:35:18 +0000 (16:35 +0100)]
Include isinf.o in libecpg if isinf() is not available on the system.

Patch done by Jiang Guiqing <jianggq@cn.fujitsu.com>.

11 years agoDowngrade a status message from LOG to DEBUG2.
Heikki Linnakangas [Tue, 4 Dec 2012 15:29:44 +0000 (17:29 +0200)]
Downgrade a status message from LOG to DEBUG2.

I never intended this to be anything other than a debugging aid, but forgot
to change the level before committing.

11 years agoWrite exact xlog position of timeline switch in the timeline history file.
Heikki Linnakangas [Tue, 4 Dec 2012 13:28:58 +0000 (15:28 +0200)]
Write exact xlog position of timeline switch in the timeline history file.

This allows us to do some more rigorous sanity checking for various
incorrect point-in-time recovery scenarios, and provides more information
for debugging purposes. It will also come handy in the upcoming patch to
allow timeline switches to be replicated by streaming replication.

11 years agoIn initdb.c, move auth warning code into main() from secondary function.
Bruce Momjian [Tue, 4 Dec 2012 14:52:00 +0000 (09:52 -0500)]
In initdb.c, move auth warning code into main() from secondary function.

11 years agoIn pg_upgrade testing script, turn off command echo at the end so status
Bruce Momjian [Tue, 4 Dec 2012 13:17:45 +0000 (08:17 -0500)]
In pg_upgrade testing script, turn off command echo at the end so status
report is clearer.

11 years agoFix build of LDAP URL feature
Peter Eisentraut [Tue, 4 Dec 2012 11:41:21 +0000 (06:41 -0500)]
Fix build of LDAP URL feature

Some code was not ifdef'ed out for non-LDAP builds.

patch from Bruce Momjian

11 years agoTrack the timeline associated with minRecoveryPoint, for more sanity checks.
Heikki Linnakangas [Tue, 4 Dec 2012 09:24:28 +0000 (11:24 +0200)]
Track the timeline associated with minRecoveryPoint, for more sanity checks.

This allows recovery to notice certain incorrect recovery scenarios.
If a server has recovered to point X on timeline 5, and you restart
recovery, it better be on timeline 5 when it reaches point X again, not on
some timeline with a higher ID. This can happen e.g if you a standby server
is shut down, a new timeline appears in the WAL archive, and the standby
server is restarted. It will try to follow the new timeline, which is wrong
because some WAL on the old timeline was already replayed before shutdown.

Requires an initdb (or at least pg_resetxlog), because this adds a field to
the control file.

11 years agoRestore set -x in pg_upgrade/test.sh, so the user can see what is being
Bruce Momjian [Tue, 4 Dec 2012 04:44:18 +0000 (23:44 -0500)]
Restore set -x in pg_upgrade/test.sh, so the user can see what is being
executed.

11 years agoAdd support for LDAP URLs
Peter Eisentraut [Tue, 4 Dec 2012 04:29:56 +0000 (23:29 -0500)]
Add support for LDAP URLs

Allow specifying LDAP authentication parameters as RFC 4516 LDAP URLs.

11 years agoIn initdb.c, rename some newly created functions, and move the directory
Bruce Momjian [Tue, 4 Dec 2012 04:22:56 +0000 (23:22 -0500)]
In initdb.c, rename some newly created functions, and move the directory
creation and xlog symlink creation to separate functions.

Per suggestions from Andrew Dunstan.

11 years agoAdd initdb --sync-only option to sync the data directory to durable
Bruce Momjian [Tue, 4 Dec 2012 03:47:59 +0000 (22:47 -0500)]
Add initdb --sync-only option to sync the data directory to durable
storage.

Have pg_upgrade use it, and enable server options fsync=off and
full_page_writes=off.

Document that users turning fsync from off to on should run initdb
--sync-only.

[ Previous commit was incorrectly applied as a git merge. ]

11 years agoRevert initdb --sync-only patch that had incorrect commit messages.
Bruce Momjian [Tue, 4 Dec 2012 03:46:51 +0000 (22:46 -0500)]
Revert initdb --sync-only patch that had incorrect commit messages.

11 years agodummy commit
Bruce Momjian [Sat, 1 Dec 2012 14:18:21 +0000 (09:18 -0500)]
dummy commit

11 years agodummy commit
Bruce Momjian [Sat, 1 Dec 2012 03:18:00 +0000 (22:18 -0500)]
dummy commit

11 years agodummy commit
Bruce Momjian [Sat, 1 Dec 2012 03:14:17 +0000 (22:14 -0500)]
dummy commit

11 years agodummy commit
Bruce Momjian [Fri, 30 Nov 2012 22:51:53 +0000 (17:51 -0500)]
dummy commit

11 years agoIn pg_upgrade, fix bug where no users were dumped in pg_dumpall
Bruce Momjian [Tue, 4 Dec 2012 00:43:02 +0000 (19:43 -0500)]
In pg_upgrade, fix bug where no users were dumped in pg_dumpall
binary-upgrade mode;  instead only skip dumping the current user.

This bug was introduced in during the removal of split_old_dump().  Bug
discovered during local testing.

11 years agoUpdate release notes for 9.2.2, 9.1.7, 9.0.11, 8.4.15, 8.3.22.
Tom Lane [Mon, 3 Dec 2012 20:09:59 +0000 (15:09 -0500)]
Update release notes for 9.2.2, 9.1.7, 9.0.11, 8.4.15, 8.3.22.

11 years agoRevert "Add mode where contrib installcheck runs each module in a separately named...
Andrew Dunstan [Mon, 3 Dec 2012 20:00:51 +0000 (15:00 -0500)]
Revert "Add mode where contrib installcheck runs each module in a separately named database."

This reverts commit e2b3c21b05c78c3a726b189242e41d4aa4422bf1.

11 years agoAvoid holding vmbuffer pin after VACUUM.
Simon Riggs [Mon, 3 Dec 2012 18:53:31 +0000 (18:53 +0000)]
Avoid holding vmbuffer pin after VACUUM.
During VACUUM if we pause to perform a cycle
of index cleanup we drop the vmbuffer pin,
so we should do the same thing when heap
scan completes. This avoids holding vmbuffer
pin across the main index cleanup in VACUUM,
which could be minutes or hours longer than
necessary for correctness.

Bug report and suggested fix from Pavan Deolasee

11 years agoFix documentation of path(polygon) function.
Tom Lane [Mon, 3 Dec 2012 16:08:50 +0000 (11:08 -0500)]
Fix documentation of path(polygon) function.

Obviously, this returns type "path", but somebody made a copy-and-pasteo
long ago.

Dagfinn Ilmari Mannsåker

11 years agoAttempt to unbreak MSVC builds broken by f21bb9cfb5646e1793dcc9c0ea697bab99afa523.
Andrew Dunstan [Mon, 3 Dec 2012 15:23:22 +0000 (10:23 -0500)]
Attempt to unbreak MSVC builds broken by f21bb9cfb5646e1793dcc9c0ea697bab99afa523.

We can't use type uint, so use uint32.

11 years agoRefactor inCommit flag into generic delayChkpt flag.
Simon Riggs [Mon, 3 Dec 2012 13:13:53 +0000 (13:13 +0000)]
Refactor inCommit flag into generic delayChkpt flag.
Rename PGXACT->inCommit flag into delayChkpt flag,
and generalise comments to allow use in other situations,
such as the forthcoming potential use in checksum patch.
Replace wait loop to look for VXIDs with delayChkpt set.
No user visible changes, not behaviour changes at present.

Simon Riggs, reviewed and rebased by Jeff Davis

11 years agoClarify locking for PageGetLSN() in XLogCheckBuffer()
Simon Riggs [Mon, 3 Dec 2012 12:20:31 +0000 (12:20 +0000)]
Clarify locking for PageGetLSN() in XLogCheckBuffer()

11 years agoClarify when to use PageSetLSN/PageGetLSN().
Simon Riggs [Mon, 3 Dec 2012 11:59:25 +0000 (11:59 +0000)]
Clarify when to use PageSetLSN/PageGetLSN().
Update README to explain prerequisites for
correct access to LSN fields of a page.
Independent chunk removed from checksums
patch to reduce size of patch.

11 years agoRefactor the code implementing standby-mode logic.
Heikki Linnakangas [Mon, 3 Dec 2012 10:32:44 +0000 (12:32 +0200)]
Refactor the code implementing standby-mode logic.

It is now easier to see that it's a state machine, making the code easier
to understand overall.

11 years agoAdd mode where contrib installcheck runs each module in a separately named database.
Andrew Dunstan [Sun, 2 Dec 2012 22:20:38 +0000 (17:20 -0500)]
Add mode where contrib installcheck runs each module in a separately named database.

Normally each module is tested in aq database named contrib_regression,
which is dropped and recreated at the beginhning of each pg_regress run.
This mode, enabled by adding USE_MODULE_DB=1 to the make command line,
runs most modules in a database with the module name embedded in it.

This will make testing pg_upgrade on clusters with the contrib modules
a lot easier.

Still to be done: adapt to the MSVC build system.

Backpatch to 9.0, which is the earliest version it is reasonably possible
to test upgrading from.

11 years agoUpdate time zone data files to tzdata release 2012j.
Tom Lane [Sun, 2 Dec 2012 21:35:23 +0000 (16:35 -0500)]
Update time zone data files to tzdata release 2012j.

DST law changes in Cuba, Israel, Jordan, Libya, Palestine, Western Samoa,
and portions of Brazil.

11 years agoRecommend triggers, not rules, in the CREATE VIEW reference page.
Tom Lane [Sun, 2 Dec 2012 21:17:53 +0000 (16:17 -0500)]
Recommend triggers, not rules, in the CREATE VIEW reference page.

We've generally recommended use of INSTEAD triggers over rules since that
feature was added; but this old text in the CREATE VIEW reference page
didn't get the memo.  Noted by Thomas Kellerer.

11 years agoReduce scope of changes for COPY FREEZE.
Simon Riggs [Sun, 2 Dec 2012 20:52:52 +0000 (20:52 +0000)]
Reduce scope of changes for COPY FREEZE.
Allow support only for freezing tuples by explicit
command. Previous coding mistakenly extended
slightly beyond what was agreed as correct on -hackers.
So essentially a partial revoke of earlier work,
leaving just the COPY FREEZE command.

11 years agoDon't advance checkPoint.nextXid near the end of a checkpoint sequence.
Tom Lane [Sun, 2 Dec 2012 20:19:57 +0000 (15:19 -0500)]
Don't advance checkPoint.nextXid near the end of a checkpoint sequence.

This reverts commit c11130690d6dca64267201a169cfb38c1adec5ef in favor of
actually fixing the problem: namely, that we should never have been
modifying the checkpoint record's nextXid at this point to begin with.
The nextXid should match the state as of the checkpoint's logical WAL
position (ie the redo point), not the state as of its physical position.
It's especially bogus to advance it in some wal_levels and not others.
In any case there is no need for the checkpoint record to carry the
same nextXid shown in the XLOG_RUNNING_XACTS record just emitted by
LogStandbySnapshot, as any replay operation will already have adopted
that value as current.

This fixes bug #7710 from Tarvi Pillessaar, and probably also explains bug
#6291 from Daniel Farina, in that if a checkpoint were in progress at the
instant of XID wraparound, the epoch bump would be lost as reported.
(And, of course, these days there's at least a 50-50 chance of a checkpoint
being in progress at any given instant.)

Diagnosed by me and independently by Andres Freund.  Back-patch to all
branches supporting hot standby.

11 years agoRearrange storage of data in xl_running_xacts.
Simon Riggs [Sun, 2 Dec 2012 19:39:37 +0000 (19:39 +0000)]
Rearrange storage of data in xl_running_xacts.
Previously we stored all xids mixed together.
Now we store top-level xids first, followed
by all subxids. Also skip logging any subxids
if the snapshot is suboverflowed, since there
are potentially large numbers of them and they
are not useful in that case anyway. Has value
in the envisaged design for decoding of WAL.
No planned effect on Hot Standby.

Andres Freund, reviewed by me

11 years agoXidEpoch++ if wraparound during checkpoint.
Simon Riggs [Sun, 2 Dec 2012 14:57:44 +0000 (14:57 +0000)]
XidEpoch++ if wraparound during checkpoint.
If wal_level = hot_standby we update the checkpoint nextxid,
though in the case where a wraparound occurred half-way through
a checkpoint we would neglect updating the epoch also. Updating
the nextxid is arguably the wrong thing to do, but changing that
may introduce subtle bugs into hot standby startup, while updating
the value doesn't cause any known bugs yet. Minimal fix now to
HEAD and backbranches, wider fix later in HEAD.

Bug reported in #6291 by Daniel Farina and slightly differently in

Cause analysis and recommended fixes from Tom Lane and Andres Freund.

Applied patch is minimal version of Andres Freund's work.

11 years agoClarify operation of online checkpoints.
Simon Riggs [Sun, 2 Dec 2012 13:09:55 +0000 (13:09 +0000)]
Clarify operation of online checkpoints.
Previous comments left, but were too obscure
for such an important aspect of the system.

11 years agoFix psql crash while parsing SQL file whose encoding is different from
Tatsuo Ishii [Sun, 2 Dec 2012 12:11:15 +0000 (21:11 +0900)]
Fix psql crash while parsing SQL file whose encoding is different from
client encoding and the client encoding is not *safe* one. Such an
example is, file encoding is UTF-8 and client encoding SJIS. Patch
contributed by Jiang Guiqing.

11 years agoPrevent passing gmake's environment variables down through pg_regress.
Tom Lane [Sat, 1 Dec 2012 22:23:49 +0000 (17:23 -0500)]
Prevent passing gmake's environment variables down through pg_regress.

When we do "make install" to create a temp installation, we don't want
that instance of make to try to communicate with any instance of make
that might be calling us.  This is known to cause problems if the
upper make has a -jN flag, and in principle could cause problems even
without that.  Unset the relevant environment variables to prevent such
issues.

Andres Freund

11 years agoMake sure sharedir/extension/ directory is created when needed.
Tom Lane [Sat, 1 Dec 2012 21:04:39 +0000 (16:04 -0500)]
Make sure sharedir/extension/ directory is created when needed.

The previous coding worked as long as MODULEDIR wasn't set explicitly,
because we create sharedir/$(datamoduledir) and the default value of
that is "extension".  But if some other value is specified for MODULEDIR
then the installation directory needed for the control file wasn't made.

Cédric Villemain

11 years agoAllow adding values to an enum type created in the current transaction.
Tom Lane [Sat, 1 Dec 2012 19:27:30 +0000 (14:27 -0500)]
Allow adding values to an enum type created in the current transaction.

Normally it is unsafe to allow ALTER TYPE ADD VALUE in a transaction block,
because instances of the value could be added to indexes later in the same
transaction, and then they would still be accessible even if the
transaction rolls back.  However, we can allow this if the enum type itself
was created in the current transaction, because then any such indexes would
have to go away entirely on rollback.

The reason for allowing this is to support pg_upgrade's new usage of
pg_restore --single-transaction: in --binary-upgrade mode, pg_dump emits
enum types as a succession of ALTER TYPE ADD VALUE commands so that it can
preserve the values' OIDs.  The support is a bit limited, so we'll leave
it undocumented.

Andres Freund

11 years agoIn pg_upgrade, remove 'set -x' from test script.
Bruce Momjian [Sat, 1 Dec 2012 17:07:14 +0000 (12:07 -0500)]
In pg_upgrade, remove 'set -x' from test script.

11 years agoRevert:
Bruce Momjian [Sat, 1 Dec 2012 15:21:45 +0000 (10:21 -0500)]
Revert:

    In pg_upgrade, remove pg_restore's --single-transaction option,
    as it throws errors in certain cases.

11 years agoRemove pg_restore's --single-transaction option, as it throws errors in
Bruce Momjian [Sat, 1 Dec 2012 14:57:55 +0000 (09:57 -0500)]
Remove pg_restore's --single-transaction option, as it throws errors in
certain cases.

11 years agoSecond tweak of COPY FREEZE
Simon Riggs [Sat, 1 Dec 2012 14:55:35 +0000 (14:55 +0000)]
Second tweak of COPY FREEZE

11 years agoTweak tests in COPY FREEZE
Simon Riggs [Sat, 1 Dec 2012 13:46:41 +0000 (13:46 +0000)]
Tweak tests in COPY FREEZE

11 years agoCOPY FREEZE and mark committed on fresh tables.
Simon Riggs [Sat, 1 Dec 2012 12:54:20 +0000 (12:54 +0000)]
COPY FREEZE and mark committed on fresh tables.
When a relfilenode is created in this subtransaction or
a committed child transaction and it cannot otherwise
be seen by our own process, mark tuples committed ahead
of transaction commit for all COPY commands in same
transaction. If FREEZE specified on COPY
and pre-conditions met then rows will also be frozen.
Both options designed to avoid revisiting rows after commit,
increasing performance of subsequent commands after
data load and upgrade. pg_restore changes later.

Simon Riggs, review comments from Heikki Linnakangas, Noah Misch and design
input from Tom Lane, Robert Haas and Kevin Grittner

11 years agodoc: Fix broken links to DocBook wiki
Peter Eisentraut [Sat, 1 Dec 2012 06:52:23 +0000 (01:52 -0500)]
doc: Fix broken links to DocBook wiki

11 years agoIn pg_upgrade, improve status wording now that we have per-database
Bruce Momjian [Sat, 1 Dec 2012 03:32:19 +0000 (22:32 -0500)]
In pg_upgrade, improve status wording now that we have per-database
status output for dump/restore.

11 years agoChange test ExceptionalCondition to return void
Alvaro Herrera [Fri, 30 Nov 2012 22:20:15 +0000 (19:20 -0300)]
Change test ExceptionalCondition to return void

Commit 81107282a changed it in assert.c, but overlooked this other file.

11 years agoTake buffer lock while inspecting btree index pages in contrib/pageinspect.
Tom Lane [Fri, 30 Nov 2012 22:02:29 +0000 (17:02 -0500)]
Take buffer lock while inspecting btree index pages in contrib/pageinspect.

It's not safe to examine a shared buffer without any lock.

11 years agoSplit initdb.c main() code into multiple functions, for easier
Bruce Momjian [Fri, 30 Nov 2012 21:45:08 +0000 (16:45 -0500)]
Split initdb.c main() code into multiple functions, for easier
maintenance.

11 years agoIn pg_upgrade, dump each database separately and use
Bruce Momjian [Fri, 30 Nov 2012 21:30:13 +0000 (16:30 -0500)]
In pg_upgrade, dump each database separately and use
--single-transaction to restore each database schema.  This yields
performance improvements for databases with many tables.  Also, remove
split_old_dump() as it is no longer needed.

11 years agoMove long_options structures to the top of main() functions, for
Bruce Momjian [Fri, 30 Nov 2012 19:49:55 +0000 (14:49 -0500)]
Move long_options structures to the top of main() functions, for
consistency.

Per suggestion from Tom.

11 years agoAdd missing buffer lock acquisition in GetTupleForTrigger().
Tom Lane [Fri, 30 Nov 2012 18:55:55 +0000 (13:55 -0500)]
Add missing buffer lock acquisition in GetTupleForTrigger().

If we had not been holding buffer pin continuously since the tuple was
initially fetched by the UPDATE or DELETE query, it would be possible for
VACUUM or a page-prune operation to move the tuple while we're trying to
copy it.  This would result in a garbage "old" tuple value being passed to
an AFTER ROW UPDATE or AFTER ROW DELETE trigger.  The preconditions for
this are somewhat improbable, and the timing constraints are very tight;
so it's not so surprising that this hasn't been reported from the field,
even though the bug has been there a long time.

Problem found by Andres Freund.  Back-patch to all active branches.

11 years agoClean environment for pg_upgrade test.
Andrew Dunstan [Fri, 30 Nov 2012 12:54:24 +0000 (07:54 -0500)]
Clean environment for pg_upgrade test.

This removes exisiting PG settings from the environment for
pg_upgrade tests, just like pg_regress does.

11 years agoAdd libpq function PQconninfo()
Magnus Hagander [Fri, 30 Nov 2012 06:09:18 +0000 (15:09 +0900)]
Add libpq function PQconninfo()

This allows a caller to get back the exact conninfo array that was
used to create a connection, including parameters read from the
environment.

In doing this, restructure how options are copied from the conninfo
to the actual connection.

Zoltan Boszormenyi and Magnus Hagander

11 years agoProduce a more useful error message for over-length Unix socket paths.
Tom Lane [Fri, 30 Nov 2012 00:57:01 +0000 (19:57 -0500)]
Produce a more useful error message for over-length Unix socket paths.

The length of a socket path name is constrained by the size of struct
sockaddr_un, and there's not a lot we can do about it since that is a
kernel API.  However, it would be a good thing if we produced an
intelligible error message when the user specifies a socket path that's too
long --- and getaddrinfo's standard API is too impoverished to do this in
the natural way.  So insert explicit tests at the places where we construct
a socket path name.  Now you'll get an error that makes sense and even
tells you what the limit is, rather than something generic like
"Non-recoverable failure in name resolution".

Per trouble report from Jeremy Drake and a fix idea from Andrew Dunstan.

11 years agoCorrectly init fast path fields on PGPROC
Simon Riggs [Thu, 29 Nov 2012 22:15:52 +0000 (22:15 +0000)]
Correctly init fast path fields on PGPROC

11 years agoCleanup VirtualXact at end of Hot Standby.
Simon Riggs [Thu, 29 Nov 2012 21:59:11 +0000 (21:59 +0000)]
Cleanup VirtualXact at end of Hot Standby.

11 years agoBasic binary heap implementation.
Robert Haas [Thu, 29 Nov 2012 16:13:08 +0000 (11:13 -0500)]
Basic binary heap implementation.

There are probably other places where this can be used, but for now,
this just makes MergeAppend use it, so that this code will have test
coverage.  There is other work in the queue that will use this, as
well.

Abhijit Menon-Sen, reviewed by Andres Freund, Robert Haas, Álvaro
Herrera, Tom Lane, and others.

11 years agoWhen processing nested structure pointer variables ecpg always expected an
Michael Meskes [Thu, 29 Nov 2012 16:12:00 +0000 (17:12 +0100)]
When processing nested structure pointer variables ecpg always expected an
array datatype which of course is wrong.

Applied patch by Muhammad Usama <m.usama@gmail.com> to fix this.

11 years agoSuppress parallel build in interfaces/ecpg/preproc/.
Tom Lane [Thu, 29 Nov 2012 03:19:46 +0000 (22:19 -0500)]
Suppress parallel build in interfaces/ecpg/preproc/.

This is to see if it will stop intermittent build failures on buildfarm
member okapi.  We know that gmake 3.82 has some problems with sometimes
not honoring dependencies in parallel builds, and it seems likely that
this is more of the same.  Since the vast bulk of the work in the preproc
directory is associated with creating preproc.c and then preproc.o,
parallelism buys us hardly anything here anyway.

Also, make both this .NOTPARALLEL and the one previously added in
interfaces/ecpg/Makefile be conditional on "ifeq ($(MAKE_VERSION),3.82)".
The known bug in gmake is fixed upstream and should not be present in
3.83 and up, and there's no reason to think it affects older releases.

11 years agoFix assorted bugs in CREATE/DROP INDEX CONCURRENTLY.
Tom Lane [Thu, 29 Nov 2012 02:25:27 +0000 (21:25 -0500)]
Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY.

Commit 8cb53654dbdb4c386369eb988062d0bbb6de725e, which introduced DROP
INDEX CONCURRENTLY, managed to break CREATE INDEX CONCURRENTLY via a poor
choice of catalog state representation.  The pg_index state for an index
that's reached the final pre-drop stage was the same as the state for an
index just created by CREATE INDEX CONCURRENTLY.  This meant that the
(necessary) change to make RelationGetIndexList ignore about-to-die indexes
also made it ignore freshly-created indexes; which is catastrophic because
the latter do need to be considered in HOT-safety decisions.  Failure to
do so leads to incorrect index entries and subsequently wrong results from
queries depending on the concurrently-created index.

To fix, add an additional boolean column "indislive" to pg_index, so that
the freshly-created and about-to-die states can be distinguished.  (This
change obviously is only possible in HEAD.  This patch will need to be
back-patched, but in 9.2 we'll use a kluge consisting of overloading the
formerly-impossible state of indisvalid = true and indisready = false.)

In addition, change CREATE/DROP INDEX CONCURRENTLY so that the pg_index
flag changes they make without exclusive lock on the index are made via
heap_inplace_update() rather than a normal transactional update.  The
latter is not very safe because moving the pg_index tuple could result in
concurrent SnapshotNow scans finding it twice or not at all, thus possibly
resulting in index corruption.  This is a pre-existing bug in CREATE INDEX
CONCURRENTLY, which was copied into the DROP code.

In addition, fix various places in the code that ought to check to make
sure that the indexes they are manipulating are valid and/or ready as
appropriate.  These represent bugs that have existed since 8.2, since
a failed CREATE INDEX CONCURRENTLY could leave a corrupt or invalid
index behind, and we ought not try to do anything that might fail with
such an index.

Also fix RelationReloadIndexInfo to ensure it copies all the pg_index
columns that are allowed to change after initial creation.  Previously we
could have been left with stale values of some fields in an index relcache
entry.  It's not clear whether this actually had any user-visible
consequences, but it's at least a bug waiting to happen.

In addition, do some code and docs review for DROP INDEX CONCURRENTLY;
some cosmetic code cleanup but mostly addition and revision of comments.

This will need to be back-patched, but in a noticeably different form,
so I'm committing it to HEAD before working on the back-patch.

Problem reported by Amit Kapila, diagnosis by Pavan Deolassee,
fix by Tom Lane and Andres Freund.

11 years agoSplit out rmgr rm_desc functions into their own files
Alvaro Herrera [Wed, 28 Nov 2012 15:35:01 +0000 (12:35 -0300)]
Split out rmgr rm_desc functions into their own files

This is necessary (but not sufficient) to have them compilable outside
of a backend environment.

11 years agoIf we don't have a backup-end-location, don't claim we've reached it.
Heikki Linnakangas [Wed, 28 Nov 2012 09:45:30 +0000 (11:45 +0200)]
If we don't have a backup-end-location, don't claim we've reached it.

This was apparently a typo, which caused recovery to think that it
immediately reached the end of backup, and allowed the database to start
up too early.

Reported by Jeff Janes. Backpatch to 9.2, where this code was introduced.

11 years agoAdd explicit casts in ilist.h's inline functions.
Tom Lane [Tue, 27 Nov 2012 15:58:37 +0000 (10:58 -0500)]
Add explicit casts in ilist.h's inline functions.

Needed to silence C++ errors, per report from Peter Eisentraut.

Andres Freund

11 years agoAdd OpenTransientFile, with automatic cleanup at end-of-xact.
Heikki Linnakangas [Tue, 27 Nov 2012 08:25:50 +0000 (10:25 +0200)]
Add OpenTransientFile, with automatic cleanup at end-of-xact.

Files opened with BasicOpenFile or PathNameOpenFile are not automatically
cleaned up on error. That puts unnecessary burden on callers that only want
to keep the file open for a short time. There is AllocateFile, but that
returns a buffered FILE * stream, which in many cases is not the nicest API
to work with. So add function called OpenTransientFile, which returns a
unbuffered fd that's cleaned up like the FILE* returned by AllocateFile().

This plugs a few rare fd leaks in error cases:

1. copy_file() - fixed by by using OpenTransientFile instead of BasicOpenFile
2. XLogFileInit() - fixed by adding close() calls to the error cases. Can't
   use OpenTransientFile here because the fd is supposed to persist over
   transaction boundaries.
3. lo_import/lo_export - fixed by using OpenTransientFile instead of
   PathNameOpenFile.

In addition to plugging those leaks, this replaces many BasicOpenFile() calls
with OpenTransientFile() that were not leaking, because the code meticulously
closed the file on error. That wasn't strictly necessary, but IMHO it's good
for robustness.

The same leaks exist in older versions, but given the rarity of the issues,
I'm not backpatching this. Not yet, anyway - it might be good to backpatch
later, after this mechanism has had some more testing in master branch.

11 years agoRevert patch for taking fewer snapshots.
Tom Lane [Mon, 26 Nov 2012 20:55:43 +0000 (15:55 -0500)]
Revert patch for taking fewer snapshots.

This reverts commit d573e239f03506920938bf0be56c868d9c3416da, "Take fewer
snapshots".  While that seemed like a good idea at the time, it caused
execution to use a snapshot that had been acquired before locking any of
the tables mentioned in the query.  This created user-visible anomalies
that were not present in any prior release of Postgres, as reported by
Tomas Vondra.  While this whole area could do with a redesign (since there
are related cases that have anomalies anyway), it doesn't seem likely that
any future patch would be reasonably back-patchable; and we don't want 9.2
to exhibit a behavior that's subtly unlike either past or future releases.
Hence, revert to prior code while we rethink the problem.

11 years agoFix SELECT DISTINCT with index-optimized MIN/MAX on inheritance trees.
Tom Lane [Mon, 26 Nov 2012 17:57:17 +0000 (12:57 -0500)]
Fix SELECT DISTINCT with index-optimized MIN/MAX on inheritance trees.

In a query such as "SELECT DISTINCT min(x) FROM tab", the DISTINCT is
pretty useless (there being only one output row), but nonetheless it
shouldn't fail.  But it could fail if "tab" is an inheritance parent,
because planagg.c's code for fixing up equivalence classes after making the
index-optimized MIN/MAX transformation wasn't prepared to find child-table
versions of the aggregate expression.  The least ugly fix seems to be
to add an option to mutate_eclass_expressions() to skip child-table
equivalence class members, which aren't used anymore at this stage of
planning so it's not really necessary to fix them.  Since child members
are ignored in many cases already, it seems plausible for
mutate_eclass_expressions() to have an option to ignore them too.

Per bug #7703 from Maxim Boguk.

Back-patch to 9.1.  Although the same code exists before that, it cannot
encounter child-table aggregates AFAICS, because the index optimization
transformation cannot succeed on inheritance trees before 9.1 (for lack
of MergeAppend).

11 years agoIn pg_upgrade, simplify function copy_file() by using pg_malloc() and
Bruce Momjian [Sun, 25 Nov 2012 03:39:03 +0000 (22:39 -0500)]
In pg_upgrade, simplify function copy_file() by using pg_malloc() and
centralizing error/shutdown code.

11 years agoIn pg_upgrade, fix a few place that used maloc/free rather than
Bruce Momjian [Sun, 25 Nov 2012 03:12:39 +0000 (22:12 -0500)]
In pg_upgrade, fix a few place that used maloc/free rather than
pg_malloc/pg_free.

11 years agoRemove -Wlogical-op from standard compiler flags
Peter Eisentraut [Fri, 23 Nov 2012 21:24:24 +0000 (16:24 -0500)]
Remove -Wlogical-op from standard compiler flags

It creates too many warnings with GCC 4.3 and 4.4.

11 years agoApplied patch by Chen Huajun <chenhj@cn.fujitsu.com> to make ecpg able to cope
Michael Meskes [Fri, 23 Nov 2012 13:39:27 +0000 (14:39 +0100)]
Applied patch by Chen Huajun <chenhj@cn.fujitsu.com> to make ecpg able to cope
with very long structs.

11 years agoFix pg_resetxlog to use correct path to postmaster.pid.
Tom Lane [Thu, 22 Nov 2012 16:23:24 +0000 (11:23 -0500)]
Fix pg_resetxlog to use correct path to postmaster.pid.

Since we've already chdir'd into the data directory, the file should
be referenced as just "postmaster.pid", without prefixing the directory
path.  This is harmless in the normal case where an absolute PGDATA path
is used, but quite dangerous if a relative path is specified, since the
program might then fail to notice an active postmaster.

Reported by Hari Babu.  This got broken in my commit
eb5949d190e80360386113fde0f05854f0c9824d, so patch all active versions.

11 years agoAvoid bogus "out-of-sequence timeline ID" errors in standby-mode.
Heikki Linnakangas [Thu, 22 Nov 2012 09:23:46 +0000 (11:23 +0200)]
Avoid bogus "out-of-sequence timeline ID" errors in standby-mode.

When startup process opens a WAL segment after replaying part of it, it
validates the first page on the WAL segment, even though the page it's
really interested in later in the file. As part of the validation, it checks
that the TLI on the page header is >= the TLI it saw on the last page it
read. If the segment contains a timeline switch, and we have already
replayed it, and then re-open the WAL segment (because of streaming
replication got disconnected and reconnected, for example), the TLI check
will fail when the first page is validated. Fix that by relaxing the TLI
check when re-opening a WAL segment.

Backpatch to 9.0. Earlier versions had the same code, but before standby
mode was introduced in 9.0, recovery never tried to re-read a segment after
partially replaying it.

Reported by Amit Kapila, while testing a new feature.

11 years agoDon't launch new child processes after we've been told to shut down.
Tom Lane [Wed, 21 Nov 2012 20:18:38 +0000 (15:18 -0500)]
Don't launch new child processes after we've been told to shut down.

Once we've received a shutdown signal (SIGINT or SIGTERM), we should not
launch any more child processes, even if we get signals requesting such.
The normal code path for spawning backends has always understood that,
but the postmaster's infrastructure for hot standby and autovacuum didn't
get the memo.  As reported by Hari Babu in bug #7643, this could lead to
failure to shut down at all in some cases, such as when SIGINT is received
just before the startup process sends PMSIGNAL_RECOVERY_STARTED: we'd
launch a bgwriter and checkpointer, and then those processes would have no
idea that they ought to quit.  Similarly, launching a new autovacuum worker
would result in waiting till it finished before shutting down.

Also, switch the order of the code blocks in reaper() that detect startup
process crash versus shutdown termination.  Once we've sent it a signal,
we should not consider that exit(1) is surprising.  This is just a cosmetic
fix since shutdown occurs correctly anyway, but better not to log a phony
complaint about startup process crash.

Back-patch to 9.0.  Some parts of this might be applicable before that,
but given the lack of prior complaints I'm not going to worry too much
about older branches.

11 years agoSpeed up operations on numeric, mostly by avoiding palloc() overhead.
Heikki Linnakangas [Wed, 21 Nov 2012 13:53:35 +0000 (15:53 +0200)]
Speed up operations on numeric, mostly by avoiding palloc() overhead.

In many functions, a NumericVar was initialized from an input Numeric, to be
passed as input to a calculation function. When the NumericVar is not
modified, the digits array of the NumericVar can point directly to the digits
array in the original Numeric, and we can avoid a palloc() and memcpy(). Add
init_var_from_num() function to initialize a var like that.

Remove dscale argument from get_str_from_var(), as all the callers just
passed the dscale of the variable. That means that the rounding it used to
do was not actually necessary, and get_str_from_var() no longer scribbles on
its input. That makes it safer in general, and allows us to use the new
init_var_from_num() function in e.g numeric_out().

Also modified numericvar_to_int8() to no scribble on its input either. It
creates a temporary copy to avoid that. To compensate, the callers no longer
need to create a temporary copy, so the net # of pallocs is the same, but this
is nicer.

In the passing, use a constant for the number 10 in get_str_from_var_sci(),
when calculating 10^exponent. Saves a palloc() and some cycles to convert
integer 10 to numeric.

Original patch by Kyotaro HORIGUCHI, with further changes by me. Reviewed
by Pavel Stehule.

11 years agoIn pg_upgrade, report errno string if file existence check returns an
Bruce Momjian [Mon, 19 Nov 2012 21:41:58 +0000 (16:41 -0500)]
In pg_upgrade, report errno string if file existence check returns an
error and errno != ENOENT.

11 years agoImprove handling of INT_MIN / -1 and related cases.
Tom Lane [Mon, 19 Nov 2012 17:24:25 +0000 (12:24 -0500)]
Improve handling of INT_MIN / -1 and related cases.

Some platforms throw an exception for this division, rather than returning
a necessarily-overflowed result.  Since we were testing for overflow after
the fact, an exception isn't nice.  We can avoid the problem by treating
division by -1 as negation.

Add some regression tests so that we'll find out if any compilers try to
optimize away the overflow check conditions.

This ought to be back-patched, but I'm going to see what the buildfarm
reports about the regression tests first.

Per discussion with Xi Wang, though this is different from the patch he
submitted.

11 years agoFix archive_cleanup_command.
Heikki Linnakangas [Mon, 19 Nov 2012 08:02:25 +0000 (10:02 +0200)]
Fix archive_cleanup_command.

When I moved ExecuteRecoveryCommand() from xlog.c to xlogarchive.c, I didn't
realize that it's called from the checkpoint process, not the startup
process. I tried to use InRedo variable to decide whether or not to attempt
cleaning up the archive (must not do so before we have read the initial
checkpoint record), but that variable is only valid within the startup
process.

Instead, let ExecuteRecoveryCommand() always clean up the archive, and add
an explicit argument to RestoreArchivedFile() to say whether that's allowed
or not. The caller knows better.

Reported by Erik Rijkers, diagnosis by Fujii Masao. Only 9.3devel is
affected.

11 years agoLimit values of archive_timeout, post_auth_delay, auth_delay.milliseconds.
Tom Lane [Sun, 18 Nov 2012 22:15:06 +0000 (17:15 -0500)]
Limit values of archive_timeout, post_auth_delay, auth_delay.milliseconds.

The previous definitions of these GUC variables allowed them to range
up to INT_MAX, but in point of fact the underlying code would suffer
overflows or other errors with large values.  Reduce the maximum values
to something that won't misbehave.  There's no apparent value in working
harder than this, since very large delays aren't sensible for any of
these.  (Note: the risk with archive_timeout is that if we're late
checking the state, the timestamp difference it's being compared to
might overflow.  So we need some amount of slop; the choice of INT_MAX/2
is arbitrary.)

Per followup investigation of bug #7670.  Although this isn't a very
significant fix, might as well back-patch.