227 Commits

Author SHA1 Message Date
Josh Kupershmidt
6fc41e9c1a Fix 'installcheck', since the last commit broke the expected output when the table is missing a valid primary/unique key. 2012-12-06 21:26:12 -07:00
Josh Kupershmidt
66ae2f33a7 Downgrade ERROR to WARNING in the case where a table does not have a primary key or not-null unique key.
We want to be able to keep processing further tables if we
encounter this problem on one of many --tables.
2012-12-06 21:05:54 -07:00
Josh Kupershmidt
f6ca290fb2 Support for multiple --tables, as well as Concurrent DDL Guard.
Code merged in, with a few more changes, from the multiple_tables branch.

The multiple --table support and SimpleStringList code is largely
borrowed from pg_dump. (pg_reorg Issue #18).

The concurrent DDL guard is implemented using an auxiliary
database connection (pg_reorg Issue #8) which holds an ACCESS SHARE
lock on the target table while pg_repack conducts the rest of its work.
2012-12-06 20:58:33 -07:00
Josh Kupershmidt
a072cc9812 Ignore other pg_repack clients which may be running concurrently for the purposes of SQL_XID_SNAPSHOT.
Use application_name from pg_stat_activity, if available, to identify
other pg_repack clients. Fixes Issue #1.
2012-12-06 16:11:55 -07:00
Josh Kupershmidt
fbcd24b4e0 Have the client double-check that it is connected as a database superuser before plowing through initialization steps.
Addresses Issue #2.
2012-11-30 20:09:22 -07:00
Josh Kupershmidt
3b856623fd Add comment explaining how race condition between CREATE TABLE ... AS SELECT and recording of log entries is avoided. 2012-11-29 20:27:33 -07:00
Josh Kupershmidt
3c13a0d05e Don't forget to disconnect conn2 when disconnect() is called, otherwise
we leave a connection hanging open for every database processed
via pg_repack -a.
2012-11-18 14:36:09 -07:00
Daniele Varrazzo
d13f1b141d Merge branch 'version_check' 2012-11-16 21:32:45 +00:00
Daniele Varrazzo
deaae7dd72 Added version_sql() function and consistency check of sql version 2012-11-16 21:32:28 +00:00
Josh Kupershmidt
3c73a0204a More consistent error reporting
This patch is a port of Daniele's commit 0be414ad10c32d from his own fork,
"error_reporting" branch.

reorg_all_database can return an error message: in case of any error different
from "missing schema" return the error and keep processing the other databases
instead of printing and stopping the program.

The output of the program is now something like:

    $ pg_reorg --all
    pg_reorg: reorg database "contrib_regression"
    pg_reorg: reorg database "template1" ... skipped: pg_reorg is not installed in the database
2012-11-16 15:37:31 +00:00
Josh Kupershmidt
8ba92a1f49 Rename argument to simple_string_list_size() for consistency. 2012-11-16 15:27:53 +00:00
Josh Kupershmidt
decd822393 Move simple_string_list_size() into pgut.c, with the rest of these string functions.
Also, fix an error with this function not actually using its string_list argument.
2012-11-16 15:27:53 +00:00
Josh Kupershmidt
40626769d8 Since commit 742380f0429b6 included some of the same changes
already in 6a0af679e14d1d, go ahead and include a few more of
the error cleanup from 6a0af679e14d1d.
2012-11-16 15:27:53 +00:00
Josh Kupershmidt
34605aef27 Fix bogus use of table name parameters.
Mimic the original code, which used execute_elevel() with params to
pass in table names which are assumed to be quoted already by the user.
2012-11-16 15:27:53 +00:00
Josh Kupershmidt
00ddb1edf9 Improved error handling, particularly when processing multiple tables.
Previously, an error while processing any single table would cause
pg_reorg to cause exit() and bail out. Quick summary of fixes:
 * get rid of pgut_atexit_push() and pgut_atexit_pop() use, since
   we are no longer relying on calling exit() to handle mundane errors
 * remove lock_conn_pid variable; we can just use buffer instead
 * lock_exclusive() and lock_access_share() now return bool instead of
   bailing out on any error
 * ERROR-level ereport() or elog() calls now return WARNING instead,
   to avoid bailing out unnecessarily
 * signature of reorg_cleanup() changed; it no longer needs to take a
   void pointer
 * check return of strdup() for vxid
 * Use pgut_rollback() instead of sending ROLLBACK; command directly

There are still one or two FIXMEs left, including fixing table name
escaping, but I'm committing this much.
2012-11-16 15:25:41 +00:00
Josh Kupershmidt
ad75dcfbb1 Allow multiple --table options to be specified on the command-line.
Per Issue #18. SimpleStringList code borrowed from pg_dump and a
pending patch to add similar functionality to pg_restore,
clusterdb, vacuumdb, and reindexdb.

The error handling in reorg_one_table() could still be much improved,
so that an error processing a single table doesn't cause pg_reorg to
necessarily bail out and skip further tables, but I'll leave that for
another day.
2012-11-16 15:19:35 +00:00
Josh Kupershmidt
ad00eb181d Several fixes for concurrent-DDL guard.
* KILL_COMPETING_LOCKS was using pg_cancel_backend() instead of
   pg_terminate_backend()
 * create kill_ddl() function for canceling+terminating any pending
   unsafe concurrent DDL, i.e. anyone hanging out waiting for
   an ACCESS EXCLUSIVE lock on our table.
 * create lock_access_share() function for reliably obtaining an
   ACCESS SHARE lock on the target table, killing off any queued
   ACCESS EXCLUSIVE lockers in the process via kill_ddl()
 * Avoid deadlock possible before we run:
     CREATE TABLE reorg.table_xxx AS SELECT ... FROM ONLY ...
   by using lock_access_share()
 * Fix a few calls in lock_exclusive() which were forgetting to
   specify the passed-in connection.

These fixes are related to Issue #8. The main thing remaining AFAIK
is to review or fix some of the unlikely-error handling bits;
most of these should be marked with XXX now.
2012-11-16 15:18:25 +00:00
Josh Kupershmidt
cf25780575 Further improvements to concurrent-DDL guard.
Fix table locking so that race conditions don't exist between lock
release in primary conn, and lock acquisition in conn2. Also, have
conn2 be in charge of performing the table swap step, to avoid a
similar race.

Part of work for Issue #8.
2012-11-16 15:18:25 +00:00
Josh Kupershmidt
3606e0a957 Switch to using pgut_command() and pgut_execute() for conn2. 2012-11-16 15:14:12 +00:00
Josh Kupershmidt
78bae38718 Take an ACCESS SHARE LOCK on the target table, in an initial attempt to prevent concurrent DDL.
This is a first pass at Daniele's suggestion in Issue #8, although it is
definitely still buggy -- it is still possible for another transaction
to get in an AccessExclusive lock and perform DDL either before the
ACCESS SHARE lock is acquired or immediately after it is released.
2012-11-16 15:14:12 +00:00
Daniele Varrazzo
e02811689a Fixed non-portable use of sed to parse the version from META
Patch from Josh, with the help of RhodiumToad.
2012-11-16 10:36:16 +00:00
Daniele Varrazzo
1bcaf267b3 Stop database processing if library version doesn't match the binary
Actually this leaves out the case of the SQL schema not consistent with the
library/binary installed, and this is a relatively likely case:
the user has run "make install" but the repack schema was already loaded
from an older version.
2012-11-15 23:32:21 +00:00
Daniele Varrazzo
c43b6bdceb More consistent error reporting
repack_all_database can return an error message: in case of any error different
from "missing schema" return the error and keep processing the other databases
instead of printing and stopping the program.

The output of the program is now something like:

    $ pg_reorg --all
    pg_reorg: reorg database "contrib_regression"
    pg_reorg: reorg database "template1" ... skipped: pg_reorg is not installed in the database
2012-11-15 23:32:21 +00:00
Daniele Varrazzo
292e00835e Use correct homepage link in pg_repack --help
Also fixed punctuation in help.
2012-11-15 11:53:00 +00:00
Daniele Varrazzo
44bf1543be Don't choose a partial index as primary key
Fixes reorg/pg_reorg#22
2012-11-15 00:16:38 +00:00
Daniele Varrazzo
6f8a8bab6d support for ENABLE TRIGGER renamed to enable_trigger from alter_table 2012-11-12 11:51:20 +00:00
Daniele Varrazzo
a92fefab8a Silence error message during test
It is different across server versions.
2012-11-11 23:38:38 +00:00
Daniele Varrazzo
7b84eeb010 Get the program and library version from the META file 2012-11-11 18:30:27 +00:00
Daniele Varrazzo
71af7f20be Dropped support for building "in tree": always use PGXS 2012-11-11 17:17:41 +00:00
Daniele Varrazzo
1d60a946ff Added The Reorg Development Team copyright 2012-11-11 03:00:00 +00:00
Daniele Varrazzo
db1c554f60 Dropped executable flags 2012-11-11 02:48:46 +00:00
Daniele Varrazzo
107a8b1324 Uppercase help metavars 2012-11-10 23:45:56 +00:00
Daniele Varrazzo
1852775c48 email and meta updated to pg_repack
For the moment we are advertising the pg_reorg email.
2012-11-10 22:57:22 +00:00
Daniele Varrazzo
b7799c1782 Fork the pg_repack extension 2012-11-10 22:33:57 +00:00
Daniele Varrazzo
41f3c5c0f3 Ignore temporary test files 2012-11-10 19:52:50 +00:00
Daniele Varrazzo
16adb3359e Fixed cleanup of init test script 2012-11-10 19:52:43 +00:00
Masahiko Sakamoto
69cc976b39 Updated regression tests to use CREATE EXTENSION for PostgreSQL 9.1 or higher. 2012-11-10 19:51:40 +00:00
Josh Kupershmidt
d603c49b40 Get rid of unused getint16() function to quiet compiler.
Also, small whitespace fixup.
2012-11-06 20:30:49 -07:00
Daniele Varrazzo
841f656012 Skip bgwriter's lock on newly promoted standby servers
Fixes ticket #1.
2012-11-06 01:49:00 +00:00
Josh Kupershmidt
05111376c8 Remove TODO comment about ASC/DESC and NULLS FIRST/LAST index options.
As far as I can tell, the code already supports these index options, so
put in a small installcheck test exercising these index options and call
it good.
2012-10-21 16:54:33 -07:00
Josh Kupershmidt
0942141245 Fix compiler warnings about appendStringInfoVA and appendStringInfoVA_s.
gcc was correctly complaining that these functions should be
declared with the `printf` format attribute. Addresses Issue #14.
2012-10-18 20:32:18 -07:00
Daniele Varrazzo
9f5c4f55c7 Don't try to rebuild invalid indexes
Closes ticket #9
2012-10-16 23:29:36 +01:00
Josh Kupershmidt
df12c37edf Add in a call to:
ALTER TABLE [table_name] ENABLE ALWAYS TRIGGER z_reorg_trigger

so that pg_reorg and the z_reorg_trigger can properly work in "replica" mode,
as when using pg_reorg on a Slony slave.

Bug report and patch by Norman Yamada.
2012-10-14 10:50:05 -07:00
Josh Kupershmidt
370e572cfc Get rid of support for PG versions 8.2 and earlier. These have been unsupported for some time, and the #defines do clutter up the codebase. 2012-09-22 20:00:53 +01:00
Josh Kupershmidt
59db5d4630 Make ordering of 'Options' printed by pg_reorg --help alphabetical. 2012-09-22 19:33:40 +01:00
Josh Kupershmidt
612495ecd6 Print a status message while waiting on old transactions to finish, including a backend PID we are waiting on, so that the user knows pg_reorg is hung and can do something about it. 2012-09-22 19:33:40 +01:00
Josh Kupershmidt
2ba1a575ac Add missing PQclear(), and comment touchups.
Fixed by Daniele: PQclear already committed, only left the comments touchups.
2012-09-22 19:33:40 +01:00
Michael Paquier
805c3bb1f7 Add gitignore entries to ensure folder consistency 2012-09-22 12:43:26 +01:00
Masahiko Sakamoto
55ee42bebf Added missing PQclear().
reported by josh.
2012-09-20 07:17:26 +00:00
Takahiro Itagaki
aad43aa1ae version 1.1.7. Supports 9.2dev. 2011-08-07 04:20:23 +00:00