Commit Graph

2267 Commits

Author SHA1 Message Date
Bruce Momjian 6dd9584507 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.
2012-12-07 12:26:13 -05:00
Alvaro Herrera da07a1e856 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
2012-12-06 17:47:30 -03:00
Heikki Linnakangas 357cbaaeae Add pgstatginindex() function to get the size of the GIN pending list.
Fujii Masao, reviewed by Kyotaro Horiguchi.
2012-12-05 09:58:03 +02:00
Bruce Momjian c47d261c07 In pg_upgrade testing script, turn off command echo at the end so status
report is clearer.
2012-12-04 08:17:45 -05:00
Bruce Momjian 2f22765607 Restore set -x in pg_upgrade/test.sh, so the user can see what is being
executed.
2012-12-03 23:44:23 -05:00
Bruce Momjian 630cd14426 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. ]
2012-12-03 22:47:59 -05:00
Bruce Momjian 25d1ed04a2 Revert initdb --sync-only patch that had incorrect commit messages. 2012-12-03 22:46:51 -05:00
Bruce Momjian 4d88bc8f2b dummy commit 2012-12-03 22:45:02 -05:00
Bruce Momjian cd7569a546 dummy commit 2012-12-03 22:45:02 -05:00
Andrew Dunstan fc5c1bbbeb Revert "Add mode where contrib installcheck runs each module in a separately named database."
This reverts commit e2b3c21b05.
2012-12-03 15:00:51 -05:00
Andrew Dunstan e2b3c21b05 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.
2012-12-02 17:20:38 -05:00
Bruce Momjian 452739df82 In pg_upgrade, remove 'set -x' from test script. 2012-12-01 12:07:14 -05:00
Bruce Momjian 1c59e37665 Revert:
In pg_upgrade, remove pg_restore's --single-transaction option,
    as it throws errors in certain cases.
2012-12-01 10:21:45 -05:00
Bruce Momjian 209772350b Remove pg_restore's --single-transaction option, as it throws errors in
certain cases.
2012-12-01 09:58:00 -05:00
Bruce Momjian 5eeab9c85c In pg_upgrade, improve status wording now that we have per-database
status output for dump/restore.
2012-11-30 22:32:25 -05:00
Tom Lane d54a94b806 Take buffer lock while inspecting btree index pages in contrib/pageinspect.
It's not safe to examine a shared buffer without any lock.
2012-11-30 17:03:31 -05:00
Bruce Momjian 12ee6ec71f 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.
2012-11-30 16:30:13 -05:00
Bruce Momjian bd9c8e741b Move long_options structures to the top of main() functions, for
consistency.

Per suggestion from Tom.
2012-11-30 14:49:55 -05:00
Andrew Dunstan abece8af17 Clean environment for pg_upgrade test.
This removes exisiting PG settings from the environment for
pg_upgrade tests, just like pg_regress does.
2012-11-30 07:54:24 -05:00
Tom Lane 3c84046490 Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY.
Commit 8cb53654db, 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.
2012-11-28 21:26:01 -05:00
Bruce Momjian 6b711cf37c In pg_upgrade, simplify function copy_file() by using pg_malloc() and
centralizing error/shutdown code.
2012-11-24 22:39:03 -05:00
Bruce Momjian 16e1ae77f9 In pg_upgrade, fix a few place that used maloc/free rather than
pg_malloc/pg_free.
2012-11-24 22:12:39 -05:00
Bruce Momjian b55743a5df In pg_upgrade, report errno string if file existence check returns an
error and errno != ENOENT.
2012-11-19 16:41:58 -05:00
Tom Lane b6e3798f3a 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.
2012-11-18 17:15:06 -05:00
Bruce Momjian 546d65d55f In pg_upgrade, add third meaningless parameter to open(). 2012-11-14 19:01:29 -05:00
Bruce Momjian 29add0de49 In pg_upgrade, copy fsm, vm, and extent files by checking for file
existence via open(), rather than collecting a directory listing and
looking up matching relfilenode files with sequential scans of the
array.  This speeds up pg_upgrade by 2x for a large number of tables,
e.g. 16k.

Per observation by Ants Aasma.
2012-11-14 17:32:07 -05:00
Bruce Momjian dec10ba4c5 Mark pg_upgrade's free_db_and_rel_infos() as a static function. 2012-11-13 21:10:40 -05:00
Heikki Linnakangas d092d116ed Oops, have to rename local variables called 'errcontext' in contrib, too.
As pointed out by Alvaro.
2012-11-12 18:30:51 +02:00
Bruce Momjian ed5699dd1b In pg_upgrade, set synchronous_commit=off for the new cluster, to
improve performance when restoring the schema from the old cluster.

Backpatch to 9.2.
2012-11-06 14:28:57 -05:00
Alvaro Herrera f4c4335a4a Add context info to OAT_POST_CREATE security hook
... and have sepgsql use it to determine whether to check permissions
during certain operations.  Indexes that are being created as a result
of REINDEX, for instance, do not need to have their permissions checked;
they were already checked when the index was created.

Author: KaiGai Kohei, slightly revised by me
2012-10-23 18:24:24 -03:00
Tom Lane ca0b960eb5 Prevent overflow in pgbench's percent-done display.
Per Thom Brown.
2012-10-20 12:44:18 -04:00
Andrew Dunstan 2f2be7473b Use a more portable platform test. 2012-10-18 16:14:11 -04:00
Bruce Momjian 49ec613201 In our source code, make a copy of getopt's 'optarg' string arguments,
rather than just storing a pointer.
2012-10-12 13:35:43 -04:00
Tom Lane 427fd88552 Fix unportable format string.
Per compiler warning.
2012-10-12 13:22:11 -04:00
Peter Eisentraut 8521d13194 Refactor flex and bison make rules
Numerous flex and bison make rules have appeared in the source tree
over time, and they are all virtually identical, so we can replace
them by pattern rules with some variables for customization.

Users of pgxs will also be able to benefit from this.
2012-10-11 06:57:04 -04:00
Tom Lane c3bf3ea2b6 Remove configure-option-dependent test cases from dblink tests.
The HINTs generated for these error cases vary across builds.  We
could try to work around that, but the test cases aren't really useful
enough to justify taking any trouble.

Per buildfarm.
2012-10-10 20:14:26 -04:00
Tom Lane 8255566f9d Create an improved FDW option validator function for contrib/dblink.
dblink now has its own validator function dblink_fdw_validator(), which is
better than the core function postgresql_fdw_validator() because it gets
the list of legal options from libpq instead of having a hard-wired list.

Make the dblink extension module provide a standard foreign data wrapper
dblink_fdw that encapsulates use of this validator, and recommend use of
that wrapper instead of making up wrappers on the fly.

Unfortunately, because ad-hoc wrappers *were* recommended practice
previously, it's not clear when we can get rid of postgresql_fdw_validator
without causing upgrade problems.  But this is a step in the right
direction.

Shigeru Hanada, reviewed by KaiGai Kohei
2012-10-10 16:53:08 -04:00
Bruce Momjian a9701a1d7d In pg_upgrade, issue proper error message when we can't open PG_VERSION.
Backpatch to 9.2.
2012-10-10 13:53:03 -04:00
Simon Riggs 82e429794b Add microsecs/op display to pg_test_fsync utility
e.g. fsync  2103.613 ops/sec (   475 microsecs/op)

Peter Geoghegan
2012-10-09 08:15:23 +01:00
Heikki Linnakangas e1be1df51f Add --sampling-rate option to pgbench.
This allows logging only some fraction of transactions, greatly reducing
the amount of log generated.

Tomas Vondra, reviewed by Robert Haas and Jeff Janes.
2012-10-03 15:37:42 +03:00
Bruce Momjian ce75457949 In pg_upgrade, use full path name for analyze_new_cluster.sh script.
Backpatch to 9.2.
2012-10-02 21:18:43 -04:00
Tom Lane 09ac603c36 Work around unportable behavior of malloc(0) and realloc(NULL, 0).
On some platforms these functions return NULL, rather than the more common
practice of returning a pointer to a zero-sized block of memory.  Hack our
various wrapper functions to hide the difference by substituting a size
request of 1.  This is probably not so important for the callers, who
should never touch the block anyway if they asked for size 0 --- but it's
important for the wrapper functions themselves, which mistakenly treated
the NULL result as an out-of-memory failure.  This broke at least pg_dump
for the case of no user-defined aggregates, as per report from
Matthew Carrington.

Back-patch to 9.2 to fix the pg_dump issue.  Given the lack of previous
complaints, it seems likely that there is no live bug in previous releases,
even though some of these functions were in place before that.
2012-10-02 17:32:42 -04:00
Tom Lane a563d94180 Standardize naming of malloc/realloc/strdup wrapper functions.
We had a number of variants on the theme of "malloc or die", with the
majority named like "pg_malloc", but by no means all.  Standardize on the
names pg_malloc, pg_malloc0, pg_realloc, pg_strdup.  Get rid of pg_calloc
entirely in favor of using pg_malloc0.

This is an essentially cosmetic change, so no back-patch.  (I did find
a couple of places where psql and pg_dump were using plain malloc or
strdup instead of the pg_ versions, but they don't look significant
enough to bother back-patching.)
2012-10-02 15:35:48 -04:00
Bruce Momjian 8a7598091a In pg_upgrade, improve error reporting when the number of relation
objects does not match between the old and new clusters.

Backpatch to 9.2.
2012-10-02 11:53:45 -04:00
Bruce Momjian ac96b851ec Adjust pg_upgrade query so toast tables related to system catalog schema
entries are not dumped.   This fixes an error caused by
droping/recreating the information_schema, but other failures were also
possible.

Backpatch to 9.2.
2012-10-02 11:46:08 -04:00
Bruce Momjian b61837a49f In pg_upgrade, try to convert the locale names to canonical form before
comparison;  also report the old/new values if they don't match.

Backpatch to 9.2.
2012-10-02 11:42:34 -04:00
Tom Lane 0d0aa5d291 Provide some static-assertion functionality on all compilers.
On reflection (especially after noticing how many buildfarm critters have
__builtin_types_compatible_p but not _Static_assert), it seems like we
ought to try a bit harder to make these macros do something everywhere.
The initial cut at it would have been no help to code that is compiled only
on platforms without _Static_assert, for instance; and in any case not all
our contributors do their initial coding on the latest gcc version.

Some googling about static assertions turns up quite a bit of prior art
for making it work in compilers that lack _Static_assert.  The method
that seems closest to our needs involves defining a struct with a bit-field
that has negative width if the assertion condition fails.  There seems no
reliable way to get the error message string to be output, but throwing a
compile error with a confusing message is better than missing the problem
altogether.

In the same spirit, if we don't have __builtin_types_compatible_p we can at
least insist that the variable have the same width as the type.  This won't
catch errors such as "wrong pointer type", but it's far better than
nothing.

In addition to changing the macro definitions, adjust a
compile-time-constant Assert in contrib/hstore to use StaticAssertStmt,
so we can get some buildfarm coverage on whether that macro behaves sanely
or not.  There's surely more places that could be converted, but this is
the first one I came across.
2012-09-30 22:46:29 -04:00
Peter Eisentraut 10bfe81dee pg_upgrade test: Disable fsync in initdb and postgres calls
This mirrors the behavior of pg_regress and makes the test run much
faster.
2012-09-26 22:41:57 -04:00
Peter Eisentraut 5cfd5bb15b pg_upgrade: Remove check for pg_config
It is no longer used, but was still being checked for.

bug #7548 from Reinhard Max
2012-09-18 22:04:28 -04:00
Andrew Dunstan f8c81c5dde In pg_upgrade, try a few times to open a log file.
If we call pg_ctl stop, the server might continue and thus
hold a log file for a short time after it has deleted its pid file,
(which is when pg_ctl will exit), and so a subsequent attempt to
open the log file might fail.

We therefore try to open it a few times, sleeping one second between
tries, to give the server time to exit.

This corrects an error that was observed on the buildfarm.

Backpatched to 9.2,
2012-09-05 23:14:49 -04:00