77 Commits

Author SHA1 Message Date
FIRST man
7487a775d5 skip transactions and locks in other databases when checking pg_locks' entries
problem: in case there are open transactions on other databases then the
         one pg_repack is working on and pg_locks doesn't contain any
         information about the affected database oid of the locked relation
         (e.g. there is no locked relation, only an open transaction),
         pg_repack will wait for that connection to release the lock
         (even if the relation that gets reorganized is held in an
         different database).

solution: join pg_database (via pg_stat_activity's datid) and check
          if the connection (of the conflicted transaction) is established
          on a different database than the relation treated by pg_repack
          and skip them.
          furthermore don't exclude transactions from other databases when
          shared objects are locked.
2013-08-02 15:22:16 +02:00
Josh Kupershmidt
27ea0fabe4 Several documentation updates for the pending 1.2 release:
* More mentions of new --only-indexes feature
 * Note we now support up to Postgres 9.3, and get rid of outdated list
   of supported operating systems. (As far as we know, pg_repack should
   build on any platforms supported by PostgreSQL itself, although no one
   has tested the Windows build in a long time.)
 * Remove most of the warnings about data corruption possible with concurrent
   DDL: this should no longer be a concern now that we hold an ACCESS SHARE
   lock during full-table repacks. Keep a short warning about old versions
   being susceptible to this problem, just to make clear that it's fixed now
   and as an enticement to upgrade.
 * A few grammar, phrasing, and typo fixes
2013-07-05 21:02:28 -04:00
Josh Kupershmidt
3f7a05162f Improved error message distinction for repack_table_indexes().
Previously, any error creating the temp index was blamed on a previous
temporary index existing. However, other errors could occur, e.g. if
--tablespace=pg_global was specified. Perform an explicit check for
whether an existing index_xxxxx already exists first, so that we
can give that error message only in the appropriate case.
2013-07-03 04:44:59 -04:00
Josh Kupershmidt
cd0b4ebf9d Improved error handling for repack_table_indexes()
If we do not successfully build any indexes on the target table, bail out
early instead of acquiring an ACCESS EXCLUSIVE lock on the table.
2013-07-01 21:11:37 -04:00
Josh Kupershmidt
fa9af9ddc0 A few more tweaks/fixes to repack_table_indexes()
* Avoid using create_idx from a PGresult that's already been PQclear'ed
 * Now that we're properly tracking which indexes have been repacked,
   don't bother with IF EXISTS in DROP INDEX. Better to make any errors
   here stand out.
2013-06-30 21:18:15 -04:00
Josh Kupershmidt
1c82aaefd9 Documentation updates for indexes-only mode.
Beena Emerson, with some additional cleanup from me.
2013-06-29 10:13:05 -04:00
Josh Kupershmidt
1e8ac21336 Several more fixes for indexes-only mode:
* Fix error handling in repack_table_indexes() to keep track of which
   indexes were actually rebuilt successfully by pg_repack, so that only
   those indexes will be dropped. Previously, we would issue an error
   message telling the user to use DROP INDEX but then just drop the
   index anyway.
 * DROP INDEX command needs to quote the schema name in case it is
   not simple.
 * missing CLEARPGRES() in repack_all_indexes()
2013-06-29 09:41:27 -04:00
Josh Kupershmidt
f0f36688f0 A few fixes to the indexes-only building.
Improve locking behavior in indexes-only mode so we only need one
ACCESS EXCLUSIVE lock per table instead of one per index. Support
multiple --index options. Fix for schema-name parsing.

Patch from Beena Emerson.
2013-06-29 09:32:18 -04:00
Josh Kupershmidt
df53964529 Rename --only-index to --only-indexes.
Hopefully makes more clear that all indexes of a table will be repacked.
2013-06-26 21:47:53 -04:00
Josh Kupershmidt
8337204ae6 Some error handling cleanup for index building.
Don't bother doing a 'goto cleanup;' after an ereport(ERROR, ...).
2013-06-22 16:45:57 -04:00
Josh Kupershmidt
61bf8acaf0 Use our own namespace for advisory locks.
Switch to using the two-input form of pg_advisory_lock(), so as
to avoid impacting other applications which might happen to lock
just the OID of the table. The REPACK_LOCK_PREFIX_STR is a decimal
version of the first three bytes of
  echo -n "pg_repack" | sha1sum
2013-06-22 09:56:44 -04:00
Josh Kupershmidt
bebe6ffb2b Factor out advisory locking code into advisory_lock()
Also, some further small fixes of error messages, comments,
marking dubious kludges (e.g. strchr() to determine schema name).
2013-06-22 09:35:19 -04:00
Josh Kupershmidt
673eac7b42 Change 'have_error' to 'ret' for simplicity. 2013-06-22 08:59:47 -04:00
Josh Kupershmidt
d79d342eea Add advisory locking to repack_one_table()
Avoids danger (or just pointlessness) of having someone run a
table-wide repack and an indexes-only repack of the same table
at the same time.
2013-06-22 08:41:41 -04:00
Josh Kupershmidt
62b5e4fb11 A few cosmetic fixes to pg_repack.c:
* fix old reference to --indexes-only
 * trailing whitespace and indentation cleanup to match rest of code
 * XXX note about improving advisory locking
2013-06-22 06:51:41 -04:00
Josh Kupershmidt
ee23ec8ffd Initial import of indexes-only building patch.
Patch from Beena Emerson.
2013-06-21 18:41:09 -04:00
Josh Kupershmidt
5b6a162996 Shuffle sanity checks into preliminary_checks().
This refactoring helps pave the way for online indexes-only
repacking. Patch by Beena Emerson.
2013-06-20 21:11:25 -04:00
Josh Kupershmidt
a942042215 Fix up the --help output for --jobs. 2013-06-18 19:45:05 -04:00
Josh Kupershmidt
29023206b5 Fix lock_exclusive()'s behavior during swap step.
Since we are not starting a new transaction in conn2 during the
swap step, we need to make sure that if our LOCK query is canceled
due to statement_timeout that conn2's transaction is not left in
a useless error state. Use SAVEPOINT and ROLLBACK TO SAVEPOINT to
avoid this problem.
2013-06-16 20:17:24 -04:00
Daniele Varrazzo
f886e0dba6 Fixed --order-by broken by namespaces refactoring
Also added a regression test for it.

Bug and patch from Beena Emerson, thany you.
2013-04-22 11:19:56 +01:00
Daniele Varrazzo
fb07fad34a Make sure to close the transactions after repack_one_table
If we exit early (e.g. checking the triggers) repack_cleanup() is not called
but we must close the transactions anyway.
2013-04-18 02:29:51 +01:00
Daniele Varrazzo
db40e71abc Fixed query for PG 8.4
Posgtres cannot find a cast rule.
2013-04-17 22:08:24 +01:00
Daniele Varrazzo
3d0b02c654 Try to repack all tables with pkey, not only the ones with ckey
This is consistent with --no-order not been required anymore.
2013-04-17 18:56:50 +01:00
Daniele Varrazzo
08a8c943e5 Logging the table we are working on at info level 2013-04-17 18:35:54 +01:00
Daniele Varrazzo
5773c75b58 Using elog instead of printf to report what database we are on
I know the ... is pretty but it messes up with warnings etc. By the way there
was a \n so the skipped part wasn't even going on the same line.
2013-04-17 18:35:49 +01:00
Daniele Varrazzo
4a3f42ab70 Dropped unneeded error check
if pgut_execute fails it bails out.
2013-04-17 18:11:34 +01:00
Daniele Varrazzo
2335a4da82 Dropped redundant check for missing schema
If the schema is missing we have already stopped trying to check
the version numbers above.
2013-04-17 18:11:34 +01:00
Daniele Varrazzo
700a1a6c48 More explicit error message if the version functions are not found 2013-04-17 18:11:33 +01:00
Daniele Varrazzo
0e74882429 Had to shorten the tablespace metavar
In the rst docs two spaces are required between option and doc.
2013-04-17 09:17:35 +01:00
Daniele Varrazzo
42c65d16f8 Merge branch 'change-tablespace'
Conflicts:
	bin/pg_repack.c
	doc/pg_repack.rst
2013-04-17 09:07:09 +01:00
Daniele Varrazzo
7617e07f10 Options sorted in a slightly more rational order
--no-order now is almost useless, but list it next to --order-by.
--jobs only specifies how to do something, not what to do. On the
same basis probably --no-analyze should be pushed further up.
2013-04-17 01:44:50 +01:00
Daniele Varrazzo
8efbd9e1c6 Imply --no-order for non-clustered tables
--no-order can still be specified to VACUUM FULL a clustered tables
(not so useful I guess...)

Fixes issue #6.
2013-04-17 01:42:22 +01:00
Daniele Varrazzo
1d62d8d0c5 More helpful error messages in case of conflicting triggers
Closes issue #5.
2013-04-17 00:57:01 +01:00
Daniele Varrazzo
83fdb2a9e0 Added implementation for --moveidx
Note: if original namespace is "foo bar", repack_indexdef gives a bad
result. This is weird as apparently skip_ident can deal with spaces in
a quoted identifier. Committing as I'm going home, will deal with that
later.
2013-04-16 22:42:23 +01:00
Daniele Varrazzo
43dfe229c9 Added check for target tablespace existence 2013-04-16 22:42:23 +01:00
Daniele Varrazzo
6488ecabd2 Added --moveidx command line option
The option is only parsed, not implemented yet.
2013-04-16 18:32:46 +01:00
Daniele Varrazzo
6710e514db Added --namespace option to set the namespace of repacked tables
Bumped version number to enforce extension re-creation as the SQL has
been modified.

Current limitations:

- Check for namespace existence: on error temp objects are left around
- What happens to the indexes?
- Tests needed.
- Should the default be the GUC default_tablespace instead of pg_default?
  This is actually an original pg_repack shortcoming, not a regression.
2013-02-21 17:20:54 +00:00
Daniele Varrazzo
89031f9cc5 Dropped unused indexes info 2013-02-21 17:20:28 +00:00
Daniele Varrazzo
f9dc02191d Dropped bogus check and unused parameters allocation 2013-02-21 15:06:39 +00:00
Josh Kupershmidt
7a31f4fbf6 comment typofix. 2013-02-20 20:26:48 -07:00
Josh Kupershmidt
f551b56f1a Merge branch 'master' into concurrent_indexes.
Conflicts:
	bin/pg_repack.c
2012-12-14 22:17:36 -07:00
Josh Kupershmidt
7213e2fe7b Use CLEARPGRES() macro to call PQclear() and set res to NULL.
This simplifies some of the error handling blocks, as now
we can unconditionally use this macro without worrying about multiple
PQclear() calls causing a double-free().

Per discussion with Daniele.
2012-12-14 20:13:23 -07:00
Josh Kupershmidt
2e4ac733c1 Fix up buggy initialization code for poll() and select().
Also some logging and variable name cleanup.
2012-12-14 18:49:00 -07:00
Josh Kupershmidt
d43ff3cd24 Add description of --jobs to the docs. Also, add missing newline in --help output. 2012-12-14 18:49:00 -07:00
Josh Kupershmidt
4f25c26284 restore the warning message about invalid indexes, to match old behavior and pass installcheck. 2012-12-14 18:49:00 -07:00
Josh Kupershmidt
a1821e3dcb Several fixes for concurrent index builds:
* Use poll() if it is available, or select() otherwise, to
   efficiently wait on index builds in worker queries to finish.
 * fix off-by-one error when initially assigning workers
 * move PQsetnonblocking() calls to setup_workers()
2012-12-14 18:49:00 -07:00
Josh Kupershmidt
8ab54cc803 Small fixes related to the concurrent_indexes changes.
Move PQsetnonblocking() call to setup_workers(), and make
sure we're not forgetting any workers.
2012-12-14 18:49:00 -07:00
Josh Kupershmidt
509e568c52 First pass at implementing concurrent index builds using multiple connections.
Adds a new --jobs command-line argument to specify how many worker
connections you want. These worker connections should stick around
while processing table(s) in a single database. For each table,
parcel out the indexes to be built among these worker conns,
submitting each CREATE INDEX ... request using PQsendQuery() i.e.
in non-blocking fashion.

Most of this is still rather crude, in particular the
while (num_active_workers) ... loop in rebuild_indexes(), but
it seems to be working, so I'm committing here.
2012-12-14 18:49:00 -07:00
Josh Kupershmidt
b4d8a90437 Don't perform repack_cleanup() if we haven't actually set up z_repack_trigger etc.
Fixes a regression introduced in master (by the multiple --tables
changes, I think).
2012-12-13 18:55:19 -07:00
Josh Kupershmidt
0bdb4bb96f Missing PQclear(). 2012-12-11 19:12:57 -07:00