Merge remote-tracking branch 'origin/master' into pg10

This commit is contained in:
Daniele Varrazzo 2017-09-25 02:45:49 +01:00
commit 7413a65985
9 changed files with 165 additions and 26 deletions

View File

@ -2,11 +2,12 @@
"name": "pg_repack", "name": "pg_repack",
"abstract": "PostgreSQL module for data reorganization", "abstract": "PostgreSQL module for data reorganization",
"description": "Reorganize tables in PostgreSQL databases with minimal locks", "description": "Reorganize tables in PostgreSQL databases with minimal locks",
"version": "1.4", "version": "1.4.1",
"maintainer": [ "maintainer": [
"Beena Emerson <memissemerson@gmail.com>",
"Josh Kupershmidt <schmiddy@gmail.com>", "Josh Kupershmidt <schmiddy@gmail.com>",
"Daniele Varrazzo <daniele.varrazzo@gmail.com>", "Masahiko Sawada <sawada.mshk@gmail.com>",
"Beena Emerson <memissemerson@gmail.com>" "Daniele Varrazzo <daniele.varrazzo@gmail.com>"
], ],
"tags": [ "bloat", "maintenance", "vacuum", "cluster" ], "tags": [ "bloat", "maintenance", "vacuum", "cluster" ],
"release_status": "stable", "release_status": "stable",
@ -14,14 +15,14 @@
"provides": { "provides": {
"pg_repack": { "pg_repack": {
"file": "lib/pg_repack.sql", "file": "lib/pg_repack.sql",
"version": "1.4", "version": "1.4.1",
"abstract": "Reorganize tables in PostgreSQL databases with minimal locks" "abstract": "Reorganize tables in PostgreSQL databases with minimal locks"
} }
}, },
"prereqs": { "prereqs": {
"runtime": { "runtime": {
"requires": { "requires": {
"PostgreSQL": "8.3.0" "PostgreSQL": "9.1.0"
} }
} }
}, },

View File

@ -24,6 +24,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\}
EXTVERSION = $(shell grep '"version":' META.json | head -1 \ EXTVERSION = $(shell grep '"version":' META.json | head -1 \
| sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/') | sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/')
# NOTE: keep consistent with META.json
ifeq ($(shell echo $$(($(INTVERSION) < 901))),1) ifeq ($(shell echo $$(($(INTVERSION) < 901))),1)
$(error $(EXTENSION) requires PostgreSQL 9.1 or later. This is $(VERSION)) $(error $(EXTENSION) requires PostgreSQL 9.1 or later. This is $(VERSION))
endif endif

View File

@ -772,6 +772,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
repack_table table; repack_table table;
StringInfoData copy_sql;
const char *create_table_1; const char *create_table_1;
const char *create_table_2; const char *create_table_2;
const char *tablespace; const char *tablespace;
@ -814,17 +815,27 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
table.sql_pop = getstr(res, i, c++); table.sql_pop = getstr(res, i, c++);
tablespace = getstr(res, i, c++); tablespace = getstr(res, i, c++);
/* Craft CREATE TABLE SQL */
resetStringInfo(&sql); resetStringInfo(&sql);
appendStringInfoString(&sql, create_table_1); appendStringInfoString(&sql, create_table_1);
appendStringInfoString(&sql, tablespace); appendStringInfoString(&sql, tablespace);
appendStringInfoString(&sql, create_table_2); appendStringInfoString(&sql, create_table_2);
/* Always append WITH NO DATA to CREATE TABLE SQL*/
appendStringInfoString(&sql, " WITH NO DATA");
table.create_table = sql.data;
/* Craft Copy SQL */
initStringInfo(&copy_sql);
appendStringInfoString(&copy_sql, table.copy_data);
if (!orderby) if (!orderby)
{ {
if (ckey != NULL) if (ckey != NULL)
{ {
/* CLUSTER mode */ /* CLUSTER mode */
appendStringInfoString(&sql, " ORDER BY "); appendStringInfoString(&copy_sql, " ORDER BY ");
appendStringInfoString(&sql, ckey); appendStringInfoString(&copy_sql, ckey);
} }
/* else, VACUUM FULL mode (non-clustered tables) */ /* else, VACUUM FULL mode (non-clustered tables) */
@ -836,13 +847,10 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
else else
{ {
/* User specified ORDER BY */ /* User specified ORDER BY */
appendStringInfoString(&sql, " ORDER BY "); appendStringInfoString(&copy_sql, " ORDER BY ");
appendStringInfoString(&sql, orderby); appendStringInfoString(&copy_sql, orderby);
} }
table.copy_data = copy_sql.data;
/* Always append WITH NOT DATA */
appendStringInfoString(&sql, " WITH NO DATA");
table.create_table = sql.data;
repack_one_table(&table, orderby); repack_one_table(&table, orderby);
} }
@ -852,6 +860,7 @@ cleanup:
CLEARPGRES(res); CLEARPGRES(res);
disconnect(); disconnect();
termStringInfo(&sql); termStringInfo(&sql);
free(params);
return ret; return ret;
} }
@ -1771,6 +1780,12 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
{ {
elog(WARNING, "timed out, do not cancel conflicting backends"); elog(WARNING, "timed out, do not cancel conflicting backends");
ret = false; ret = false;
/* Before exit the loop reset the transaction */
if (start_xact)
pgut_rollback(conn);
else
pgut_command(conn, "ROLLBACK TO SAVEPOINT repack_sp1", 0, NULL);
break; break;
} }
else else

View File

@ -466,6 +466,10 @@ Creating indexes concurrently comes with a few caveats, please see `the document
Releases Releases
-------- --------
* pg_repack 1.4.1
* fixed broken ``--order-by`` option (issue #138)
* pg_repack 1.4 * pg_repack 1.4
* added support for PostgreSQL 9.6, dropped support for versions before 9.1 * added support for PostgreSQL 9.6, dropped support for versions before 9.1

View File

@ -289,6 +289,7 @@ OPTIONには以下のものが指定できます。
.. ``-I TABLE``, ``--parent-table=TABLE`` .. ``-I TABLE``, ``--parent-table=TABLE``
Reorganize both the specified table(s) and its inheritors. Multiple Reorganize both the specified table(s) and its inheritors. Multiple
table hierarchies may be reorganized by writing multiple ``-I`` switches. table hierarchies may be reorganized by writing multiple ``-I`` switches.
``-I TABLE``, ``--parent-table=TABLE`` ``-I TABLE``, ``--parent-table=TABLE``
指定したテーブルとその子テーブルのみを再編成します。 ``-I`` オプションを複数同時に使用することで、複数の親テーブルを指定することができます。 指定したテーブルとその子テーブルのみを再編成します。 ``-I`` オプションを複数同時に使用することで、複数の親テーブルを指定することができます。
@ -863,6 +864,12 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A
リリースノート リリースノート
--------------- ---------------
.. * pg_repack 1.4.1
.. * fixed broken ``--order-by`` option (issue #138)
* pg_repack 1.4.1
* 壊れていた ``--order-by`` オプションを修正しました (issue #138)
.. * pg_repack 1.4 .. * pg_repack 1.4
.. * added support for PostgreSQL 9.6 .. * added support for PostgreSQL 9.6
.. * use ``AFTER`` trigger to solve concurrency problems with ``INSERT .. * use ``AFTER`` trigger to solve concurrency problems with ``INSERT

View File

@ -14,9 +14,6 @@ with the right privileges: contact Daniele Varrazzo to obtain them.
places). places).
- Set the right release_status in ``META.json``: ``testing`` or ``stable``. - Set the right release_status in ``META.json``: ``testing`` or ``stable``.
- Commit the above metadata changes. - Commit the above metadata changes.
- Create a tag, signed if possible::
git tag -a -s ver_$VER
- Create a package running ``make package``. The package will be called - Create a package running ``make package``. The package will be called
``dist/pg_repack-$VER.zip``. ``dist/pg_repack-$VER.zip``.
@ -32,25 +29,31 @@ with the right privileges: contact Daniele Varrazzo to obtain them.
.. __: http://pgxnclient.projects.pgfoundry.org/ .. __: http://pgxnclient.projects.pgfoundry.org/
- Push the code changes and tags on github:: - Push the code changes on github::
git push git push
git push --tags
- Upload the package on http://manager.pgxn.org/. - Upload the package on http://manager.pgxn.org/.
- Check the uploaded package works as expected:: - Check the uploaded package works as expected; if not fix and push more::
pgxn install --sudo -- pg_repack pgxn install --sudo -- pg_repack
pgxn check pg_repack pgxn check pg_repack
- Create a tag, signed if possible::
git tag -a -s ver_$VER
- Push the new tag on github::
git push --tags
- Upload the docs by pushing in the repos at - Upload the docs by pushing in the repos at
http://reorg.github.io/pg_repack/. The operations are roughly:: http://reorg.github.io/pg_repack/. The operations are roughly::
git clone git@github.com:reorg/reorg.github.com.git git clone --recursive git@github.com:reorg/reorg.github.com.git
cd reorg.github.com.git cd reorg.github.com.git
git submodule init make sm
git submodule update
make make
git commit -a -m "Docs upload for release $VER" git commit -a -m "Docs upload for release $VER"
git push git push

View File

@ -84,6 +84,7 @@ CREATE TABLE tbl_with_mod_column_storage (
c text c text
); );
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
CREATE TABLE tbl_order (c int primary key);
-- --
-- insert data -- insert data
-- --
@ -118,6 +119,10 @@ SET client_min_messages = fatal;
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
SET client_min_messages = warning; SET client_min_messages = warning;
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
-- Insert no-ordered data
INSERT INTO tbl_order SELECT generate_series(100, 51, -1);
CLUSTER tbl_order USING tbl_order_pkey;
INSERT INTO tbl_order SELECT generate_series(50, 1, -1);
-- --
-- before -- before
-- --
@ -161,6 +166,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin
INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_idxopts"
INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_toast"
INFO: repacking table "tbl_with_mod_column_storage" INFO: repacking table "tbl_with_mod_column_storage"
INFO: repacking table "tbl_order"
-- --
-- after -- after
-- --
@ -272,8 +278,8 @@ SET enable_indexscan = off;
SELECT * FROM tbl_with_dropped_column ; SELECT * FROM tbl_with_dropped_column ;
c1 | id | c2 | c3 c1 | id | c2 | c3
----+----+----+---- ----+----+----+----
c1 | 2 | c2 |
c1 | 1 | c2 | c1 | 1 | c2 |
c1 | 2 | c2 |
(2 rows) (2 rows)
SELECT * FROM view_for_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column ORDER BY 1, 2;
@ -302,8 +308,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2;
SELECT * FROM view_for_dropped_column; SELECT * FROM view_for_dropped_column;
c1 | id | c2 | c3 c1 | id | c2 | c3
----+----+----+---- ----+----+----+----
c1 | 2 | c2 |
c1 | 1 | c2 | c1 | 1 | c2 |
c1 | 2 | c2 |
(2 rows) (2 rows)
SELECT * FROM tbl_with_dropped_toast; SELECT * FROM tbl_with_dropped_toast;
@ -417,6 +423,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY);
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
\! pg_repack --dbname=contrib_regression --table=trg3 \! pg_repack --dbname=contrib_regression --table=trg3
INFO: repacking table "trg3" INFO: repacking table "trg3"
--
-- Table re-organization using specific column
--
-- reorganize table using cluster key. Sort in ascending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order
INFO: repacking table "tbl_order"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
ctid | c
--------+----
(0,1) | 1
(0,2) | 2
(0,3) | 3
(0,4) | 4
(0,5) | 5
(0,6) | 6
(0,7) | 7
(0,8) | 8
(0,9) | 9
(0,10) | 10
(10 rows)
-- reorganize table using specific column order. Sort in descending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC"
INFO: repacking table "tbl_order"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
ctid | c
--------+-----
(0,1) | 100
(0,2) | 99
(0,3) | 98
(0,4) | 97
(0,5) | 96
(0,6) | 95
(0,7) | 94
(0,8) | 93
(0,9) | 92
(0,10) | 91
(10 rows)
-- --
-- Dry run -- Dry run
-- --

View File

@ -84,6 +84,7 @@ CREATE TABLE tbl_with_mod_column_storage (
c text c text
); );
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
CREATE TABLE tbl_order (c int primary key);
-- --
-- insert data -- insert data
-- --
@ -118,6 +119,10 @@ SET client_min_messages = fatal;
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
SET client_min_messages = warning; SET client_min_messages = warning;
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
-- Insert no-ordered data
INSERT INTO tbl_order SELECT generate_series(100, 51, -1);
CLUSTER tbl_order USING tbl_order_pkey;
INSERT INTO tbl_order SELECT generate_series(50, 1, -1);
-- --
-- before -- before
-- --
@ -161,6 +166,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin
INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_idxopts"
INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_toast"
INFO: repacking table "tbl_with_mod_column_storage" INFO: repacking table "tbl_with_mod_column_storage"
INFO: repacking table "tbl_order"
-- --
-- after -- after
-- --
@ -272,8 +278,8 @@ SET enable_indexscan = off;
SELECT * FROM tbl_with_dropped_column ; SELECT * FROM tbl_with_dropped_column ;
c1 | id | c2 | c3 c1 | id | c2 | c3
----+----+----+---- ----+----+----+----
c1 | 2 | c2 |
c1 | 1 | c2 | c1 | 1 | c2 |
c1 | 2 | c2 |
(2 rows) (2 rows)
SELECT * FROM view_for_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column ORDER BY 1, 2;
@ -302,8 +308,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2;
SELECT * FROM view_for_dropped_column; SELECT * FROM view_for_dropped_column;
c1 | id | c2 | c3 c1 | id | c2 | c3
----+----+----+---- ----+----+----+----
c1 | 2 | c2 |
c1 | 1 | c2 | c1 | 1 | c2 |
c1 | 2 | c2 |
(2 rows) (2 rows)
SELECT * FROM tbl_with_dropped_toast; SELECT * FROM tbl_with_dropped_toast;
@ -417,6 +423,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY);
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
\! pg_repack --dbname=contrib_regression --table=trg3 \! pg_repack --dbname=contrib_regression --table=trg3
INFO: repacking table "trg3" INFO: repacking table "trg3"
--
-- Table re-organization using specific column
--
-- reorganize table using cluster key. Sort in ascending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order
INFO: repacking table "tbl_order"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
ctid | c
--------+----
(0,1) | 1
(0,2) | 2
(0,3) | 3
(0,4) | 4
(0,5) | 5
(0,6) | 6
(0,7) | 7
(0,8) | 8
(0,9) | 9
(0,10) | 10
(10 rows)
-- reorganize table using specific column order. Sort in descending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC"
INFO: repacking table "tbl_order"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
ctid | c
--------+-----
(0,1) | 100
(0,2) | 99
(0,3) | 98
(0,4) | 97
(0,5) | 96
(0,6) | 95
(0,7) | 94
(0,8) | 93
(0,9) | 92
(0,10) | 91
(10 rows)
-- --
-- Dry run -- Dry run
-- --

View File

@ -92,6 +92,7 @@ CREATE TABLE tbl_with_mod_column_storage (
); );
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
CREATE TABLE tbl_order (c int primary key);
-- --
-- insert data -- insert data
-- --
@ -137,6 +138,10 @@ SET client_min_messages = warning;
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
-- Insert no-ordered data
INSERT INTO tbl_order SELECT generate_series(100, 51, -1);
CLUSTER tbl_order USING tbl_order_pkey;
INSERT INTO tbl_order SELECT generate_series(50, 1, -1);
-- --
-- before -- before
-- --
@ -252,6 +257,19 @@ CREATE TABLE trg3 (id integer PRIMARY KEY);
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
\! pg_repack --dbname=contrib_regression --table=trg3 \! pg_repack --dbname=contrib_regression --table=trg3
--
-- Table re-organization using specific column
--
-- reorganize table using cluster key. Sort in ascending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
-- reorganize table using specific column order. Sort in descending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
-- --
-- Dry run -- Dry run
-- --