Commit Graph

342 Commits

Author SHA1 Message Date
Bruce Momjian 203d8ae2db pg_upgrade: don't copy/link files for invalid indexes
Now that pg_dump no longer dumps invalid indexes, per commit
683abc73df, have pg_upgrade also skip
them.  Previously pg_upgrade threw an error if invalid indexes existed.

Backpatch to 9.2, 9.1, and 9.0 (where pg_upgrade was added to git)
2013-03-30 22:20:53 -04:00
Andrew Dunstan 67eb3e5075 Avoid moving data directory in upgrade testing.
Windows sometimes gets upset if we rename a large directory and then try
to use the old name quickly, as seen in occasional buildfarm failures.
So we avoid that by building the old version in the intended
destination in the first place instead of renaming it, similar to the
change made for the same reason in commit b7f8465c.
2013-03-30 12:44:29 -04:00
Simon Riggs 96ef3b8ff1 Allow I/O reliability checks using 16-bit checksums
Checksums are set immediately prior to flush out of shared buffers
and checked when pages are read in again. Hint bit setting will
require full page write when block is dirtied, which causes various
infrastructure changes. Extensive comments, docs and README.

WARNING message thrown if checksum fails on non-all zeroes page;
ERROR thrown but can be disabled with ignore_checksum_failure = on.

Feature enabled by an initdb option, since transition from option off
to option on is long and complex and has not yet been implemented.
Default is not to use checksums.

Checksum used is WAL CRC-32 truncated to 16-bits.

Simon Riggs, Jeff Davis, Greg Smith
Wide input and assistance from many community members. Thank you.
2013-03-22 13:54:07 +00:00
Kevin Grittner 3bf3ab8c56 Add a materialized view relations.
A materialized view has a rule just like a view and a heap and
other physical properties like a table.  The rule is only used to
populate the table, references in queries refer to the
materialized data.

This is a minimal implementation, but should still be useful in
many cases.  Currently data is only populated "on demand" by the
CREATE MATERIALIZED VIEW and REFRESH MATERIALIZED VIEW statements.
It is expected that future releases will add incremental updates
with various timings, and that a more refined concept of defining
what is "fresh" data will be developed.  At some point it may even
be possible to have queries use a materialized in place of
references to underlying tables, but that requires the other
above-mentioned features to be working first.

Much of the documentation work by Robert Haas.
Review by Noah Misch, Thom Brown, Robert Haas, Marko Tiikkaja
Security review by KaiGai Kohei, with a decision on how best to
implement sepgsql still pending.
2013-03-03 18:23:31 -06:00
Alvaro Herrera cd7d00ad65 Improve pg_upgrade commentary on multixact change
Per gripe from Andres Freund
2013-02-28 16:29:17 -03:00
Bruce Momjian 4765dd7921 pg_upgrade: conditionally create cluster delete script
If users create tablespaces inside the old cluster directory, it is
impossible for the delete script to delete _only_ the old cluster files,
so don't create a script in that case, and issue a message to the user.
2013-02-14 10:53:03 -05:00
Bruce Momjian 74205266d4 Fix pg_upgrade log file cleanup code
Recent pg_upgrade parallel improvements introduced a bug that prevented
cleanup of per-database log files.
2013-02-14 00:04:15 -05:00
Alvaro Herrera 8396447cdb Create libpgcommon, and move pg_malloc et al to it
libpgcommon is a new static library to allow sharing code among the
various frontend programs and backend; this lets us eliminate duplicate
implementations of common routines.  We avoid libpgport, because that's
intended as a place for porting issues; per discussion, it seems better
to keep them separate.

The first use case, and the only implemented by this patch, is pg_malloc
and friends, which many frontend programs were already using.

At the same time, we can use this to provide palloc emulation functions
for the frontend; this way, some palloc-using files in the backend can
also be used by the frontend cleanly.  To do this, we change palloc() in
the backend to be a function instead of a macro on top of
MemoryContextAlloc().  This was previously believed to cause loss of
performance, but this implementation has been tweaked by Tom and Andres
so that on modern compilers it provides a slight improvement over the
previous one.

This lets us clean up some places that were already with
localized hacks.

Most of the pg_malloc/palloc changes in this patch were authored by
Andres Freund. Zoltán Böszörményi also independently provided a form of
that.  libpgcommon infrastructure was authored by Álvaro.
2013-02-12 11:21:05 -03:00
Bruce Momjian a9ceaa53be pg_upgrade: detect stale postmaster.pid lock files
If the postmaster.pid lock file exists, try starting/stopping the
cluster to check if the lock file is valid.

Per request from Tom.
2013-01-24 15:20:40 -05:00
Alvaro Herrera 34da700405 Use the catversion to distinguish old/new clusters
This makes 9.3 -> 9.3 upgrades work when they cross the commit that
added persistent multixacts; early 9.3 pg_controldata did not have the
required oldestMultiXact line, and so would fail to upgrade.

per Bruce Momjian
2013-01-24 12:36:18 -03:00
Alvaro Herrera 2494a9af4c Don't require oldestMultixact if server doesn't have it 2013-01-24 11:55:10 -03:00
Bruce Momjian bd6aca8a77 pg_upgrade: report failed cluster name
When pg_upgrade can't find required pg_controldata information, report
_which_ cluster is failing, with this message:

	The %s cluster lacks some required control information:
2013-01-24 08:35:57 -05:00
Alvaro Herrera 0ac5ad5134 Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE".  These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE".  UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.

Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.

The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid.  Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates.  This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed.  pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.

Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header.  This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.

Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)

With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.

As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.

Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane.  There's probably room for several more tests.

There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it.  Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.

This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
	AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
	1290721684-sup-3951@alvh.no-ip.org
	1294953201-sup-2099@alvh.no-ip.org
	1320343602-sup-2290@alvh.no-ip.org
	1339690386-sup-8927@alvh.no-ip.org
	4FE5FF020200002500048A3D@gw.wicourts.gov
	4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 12:04:59 -03:00
Bruce Momjian 861ad67bd9 pg_upgrade: remove --single-transaction usage
With AtEOXact applied, --single-transaction makes pg_restore slower, and
has the potential to require lock table configuration, so remove the
argument.

Per suggestion from Tom.
2013-01-22 22:27:16 -05:00
Bruce Momjian 600250d0ed Improve pg_upgrade error report
If the cluster alignments don't match, output this suggestion:

	Likely one cluster is a 32-bit install, the other 64-bit
2013-01-18 09:26:55 -05:00
Andrew Dunstan 4ae5ee6c9b Extend and improve use of EXTRA_REGRESS_OPTS.
This is now used by ecpg tests, and not clobbered by pg_upgrade
tests. This change won't affect anything that doesn't set this
environment variable, but will enable the buildfarm to control
exactly what port regression test installs will be running on,
and thus to detect possible rogue postmasters more easily.

Backpatch to release 9.2 where EXTRA_REGRESS_OPTS was first used.
2013-01-12 08:28:58 -05:00
Bruce Momjian a89c46f9bc Allow parallel copy/link in pg_upgrade
This patch implements parallel copying/linking of files by tablespace
using the --jobs option in pg_upgrade.
2013-01-09 08:57:47 -05:00
Tom Lane 78a5e738e9 Prevent creation of postmaster's TCP socket during pg_upgrade testing.
On non-Windows machines, we use the Unix socket for connections to test
postmasters, so there is no need to create a TCP socket.  Furthermore,
doing so causes failures due to port conflicts if two builds are carried
out concurrently on one machine.  (If the builds are done in different
chroots, which is standard practice at least in Red Hat distros, there
is no risk of conflict on the Unix socket.)  Suppressing the TCP socket
by setting listen_addresses to empty has long been standard practice
for pg_regress, and pg_upgrade knows about this too ... but pg_upgrade's
test.sh didn't get the memo.

Back-patch to 9.2, and also sync the 9.2 version of the script with HEAD
as much as practical.
2013-01-03 18:34:51 -05:00
Bruce Momjian bcbe99244f Adjust a few pg_upgrade functions to return void.
Adjust pg_upgrade page conversion functions (which are not used) to
return void so transfer_all_new_dbs can return void.
2013-01-02 21:20:20 -05:00
Bruce Momjian bd61a623ac Update copyrights for 2013
Fully update git head, and update back branches in ./COPYRIGHT and
legal.sgml files.
2013-01-01 17:15:01 -05:00
Bruce Momjian 6f1b9e4efd Add pg_upgrade --jobs parameter
Add pg_upgrade --jobs, which allows parallel dump/restore of databases,
which improves performance.
2012-12-26 19:26:30 -05:00
Bruce Momjian dc9896a245 Avoid using NAMEDATALEN in pg_upgrade
Because the client encoding might not match the server encoding,
pg_upgrade can't allocate NAMEDATALEN bytes for storage of database,
relation, and namespace identifiers.  Instead pg_strdup() the memory and
free it.

Also add C comment in initdb.c about safe NAMEDATALEN usage.
2012-12-20 13:56:31 -05:00
Bruce Momjian 345fb82f16 Add pg_upgrade comment about mismatch error
Add comment stating that constraint and index names must match.
2012-12-20 07:37:27 -05:00
Bruce Momjian e95c4bd113 Fix pg_upgrade for invalid indexes
All versions of pg_upgrade upgraded invalid indexes caused by CREATE
INDEX CONCURRENTLY failures and marked them as valid.  The patch adds a
check to all pg_upgrade versions and throws an error during upgrade or
--check.

Backpatch to 9.2, 9.1, 9.0.  Patch slightly adjusted.
2012-12-11 15:09:22 -05:00
Bruce Momjian acdb8c2259 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.
2012-12-10 23:03:25 -05:00
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
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
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
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
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
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
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
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
Andrew Dunstan 2f2be7473b Use a more portable platform test. 2012-10-18 16:14:11 -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
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
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