From 910d5fd86a996e2a3cc855fefc13ebf97cdabfc9 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 16:11:27 +0100 Subject: [PATCH 01/13] Fixed version number 1.4 would have been good for me too... But semver requires 1.4.0 --- META.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/META.json b/META.json index b67b0be..5d31e50 100644 --- a/META.json +++ b/META.json @@ -2,11 +2,12 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.4", + "version": "1.4.0", "maintainer": [ + "Beena Emerson ", "Josh Kupershmidt ", - "Daniele Varrazzo ", - "Beena Emerson " + "Masahiko Sawada ", + "Daniele Varrazzo " ], "tags": [ "bloat", "maintenance", "vacuum", "cluster" ], "release_status": "stable", @@ -14,7 +15,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.4", + "version": "1.4.0", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, From 2d11efea18e4cc8672a4e5890eb5a1dcdbc220de Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 16:13:53 +0100 Subject: [PATCH 02/13] Fixed reST error in Japanese docs --- doc/pg_repack_jp.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index 7d5ee14..b958400 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -289,6 +289,7 @@ OPTIONには以下のものが指定できます。 .. ``-I TABLE``, ``--parent-table=TABLE`` Reorganize both the specified table(s) and its inheritors. Multiple table hierarchies may be reorganized by writing multiple ``-I`` switches. + ``-I TABLE``, ``--parent-table=TABLE`` 指定したテーブルとその子テーブルのみを再編成します。 ``-I`` オプションを複数同時に使用することで、複数の親テーブルを指定することができます。 From 5b1001d62008515eec21f69aeaea3e7f1f332e99 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 16:28:56 +0100 Subject: [PATCH 03/13] Fixed info to refresh website, suggest to tag after deployment --- doc/release.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/doc/release.rst b/doc/release.rst index 2a2c277..8e9719c 100644 --- a/doc/release.rst +++ b/doc/release.rst @@ -14,9 +14,6 @@ with the right privileges: contact Daniele Varrazzo to obtain them. places). - Set the right release_status in ``META.json``: ``testing`` or ``stable``. - 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 ``dist/pg_repack-$VER.zip``. @@ -32,25 +29,31 @@ with the right privileges: contact Daniele Varrazzo to obtain them. .. __: http://pgxnclient.projects.pgfoundry.org/ -- Push the code changes and tags on github:: +- Push the code changes on github:: git push - git push --tags - 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 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 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 - git submodule init - git submodule update + make sm make git commit -a -m "Docs upload for release $VER" git push From cbb3b7f916732b7248bcfd90fce4af2816a1aa08 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 26 Apr 2017 11:30:02 +0100 Subject: [PATCH 04/13] Minimum postgres version supported fixed in META.json --- META.json | 2 +- Makefile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/META.json b/META.json index 5d31e50..afb0a4b 100644 --- a/META.json +++ b/META.json @@ -22,7 +22,7 @@ "prereqs": { "runtime": { "requires": { - "PostgreSQL": "8.3.0" + "PostgreSQL": "9.1.0" } } }, diff --git a/Makefile b/Makefile index 445575a..e132d9f 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\) EXTVERSION = $(shell grep '"version":' META.json | head -1 \ | sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/') +# NOTE: keep consistent with META.json ifeq ($(shell echo $$(($(INTVERSION) < 901))),1) $(error $(EXTENSION) requires PostgreSQL 9.1 or later. This is $(VERSION)) endif From c2ed98a85b0070d5ffc0a4a3a882f008bce6adf5 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Wed, 12 Jul 2017 17:04:33 -0700 Subject: [PATCH 05/13] Fix a small memory leak in repack_one_database function. Noticed by coverity scan. --- bin/pg_repack.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index f8988e0..46bdeb0 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -852,6 +852,7 @@ cleanup: CLEARPGRES(res); disconnect(); termStringInfo(&sql); + free(params); return ret; } From 33f4c30563197511d1a3fcefc3426df13751331a Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 02:31:47 +0900 Subject: [PATCH 06/13] Fix reorganize table without sorting. Commit 5adff6ff0b88d6f162719eff7176069730537c2a separated the data copy from creating table. This is a cause of bug that pg_repack doesn't actually sort table during reorganization. This commit fixes this issue by adding ORDER BY clause to Copy SQL rather than CREATE TABLE SQL. Reported by acmzero on issue #138. --- bin/pg_repack.c | 24 +++++++++++------ regress/expected/repack.out | 49 +++++++++++++++++++++++++++++++-- regress/expected/repack_1.out | 51 +++++++++++++++++++++++++++++++++-- regress/sql/repack.sql | 18 +++++++++++++ 4 files changed, 130 insertions(+), 12 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 46bdeb0..43e3f23 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -772,6 +772,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) for (i = 0; i < num; i++) { repack_table table; + StringInfoData copy_sql; const char *create_table_1; const char *create_table_2; 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++); tablespace = getstr(res, i, c++); + /* Craft CREATE TABLE SQL */ resetStringInfo(&sql); appendStringInfoString(&sql, create_table_1); appendStringInfoString(&sql, tablespace); appendStringInfoString(&sql, create_table_2); + + /* Always append WITH NOT DATA to CREATE TABLE SQL*/ + appendStringInfoString(&sql, " WITH NO DATA"); + table.create_table = sql.data; + + /* Craft Copy SQL */ + initStringInfo(©_sql); + appendStringInfoString(©_sql, table.copy_data); if (!orderby) + { if (ckey != NULL) { /* CLUSTER mode */ - appendStringInfoString(&sql, " ORDER BY "); - appendStringInfoString(&sql, ckey); + appendStringInfoString(©_sql, " ORDER BY "); + appendStringInfoString(©_sql, ckey); } /* else, VACUUM FULL mode (non-clustered tables) */ @@ -836,13 +847,10 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) else { /* User specified ORDER BY */ - appendStringInfoString(&sql, " ORDER BY "); - appendStringInfoString(&sql, orderby); + appendStringInfoString(©_sql, " ORDER BY "); + appendStringInfoString(©_sql, orderby); } - - /* Always append WITH NOT DATA */ - appendStringInfoString(&sql, " WITH NO DATA"); - table.create_table = sql.data; + table.copy_data = copy_sql.data; repack_one_table(&table, orderby); } diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 5934f65..7417f48 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -69,6 +69,7 @@ CREATE TABLE tbl_with_mod_column_storage ( c text ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -103,6 +104,10 @@ SET client_min_messages = fatal; CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); SET client_min_messages = warning; 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 -- @@ -146,6 +151,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" -- -- after -- @@ -257,8 +263,8 @@ SET enable_indexscan = off; SELECT * FROM tbl_with_dropped_column ; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM view_for_dropped_column ORDER BY 1, 2; @@ -287,8 +293,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM tbl_with_dropped_toast; @@ -402,6 +408,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! pg_repack --dbname=contrib_regression --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 -- diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 98360ee..7417f48 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -69,6 +69,7 @@ CREATE TABLE tbl_with_mod_column_storage ( c text ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -103,6 +104,10 @@ SET client_min_messages = fatal; CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); SET client_min_messages = warning; 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 -- @@ -146,6 +151,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" -- -- after -- @@ -257,8 +263,8 @@ SET enable_indexscan = off; SELECT * FROM tbl_with_dropped_column ; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM view_for_dropped_column ORDER BY 1, 2; @@ -287,8 +293,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM tbl_with_dropped_toast; @@ -402,6 +408,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! pg_repack --dbname=contrib_regression --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 -- @@ -451,6 +496,8 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack +LINE 1: select repack.version(), repack.version_sql() + ^ DROP ROLE IF EXISTS nosuper; -- -- exclude extension check diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 9f58c09..ce7c386 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -81,6 +81,7 @@ CREATE TABLE tbl_with_mod_column_storage ( ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -126,6 +127,10 @@ SET client_min_messages = warning; 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 -- @@ -241,6 +246,19 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! 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 -- From f8ba09fd3107f40e8d3e63c21e6365a575102f05 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 02:49:56 +0900 Subject: [PATCH 07/13] Get rid of unnecessary lines in expected file. --- regress/expected/repack_1.out | 2 -- 1 file changed, 2 deletions(-) diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 7417f48..62fc8dd 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -496,8 +496,6 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack -LINE 1: select repack.version(), repack.version_sql() - ^ DROP ROLE IF EXISTS nosuper; -- -- exclude extension check From 34e71adbbd82191a3f179b89007f26e14e81766c Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 20:16:31 +0900 Subject: [PATCH 08/13] Fix a typo in pg_repack.c file. --- bin/pg_repack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 43e3f23..2be03cd 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -821,7 +821,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) appendStringInfoString(&sql, tablespace); appendStringInfoString(&sql, create_table_2); - /* Always append WITH NOT DATA to CREATE TABLE SQL*/ + /* Always append WITH NO DATA to CREATE TABLE SQL*/ appendStringInfoString(&sql, " WITH NO DATA"); table.create_table = sql.data; From b2be4741c933abfae1ccde453d9cc432e2549eb5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 12 Aug 2017 11:39:04 +0100 Subject: [PATCH 09/13] Preparing release 1.4.1 --- META.json | 4 ++-- doc/pg_repack.rst | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/META.json b/META.json index afb0a4b..9ab89fd 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.4.0", + "version": "1.4.1", "maintainer": [ "Beena Emerson ", "Josh Kupershmidt ", @@ -15,7 +15,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.4.0", + "version": "1.4.1", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index 0969676..c8b1492 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -466,6 +466,10 @@ Creating indexes concurrently comes with a few caveats, please see `the document Releases -------- +* pg_repack 1.4.1 + + * fixed broken ``--ordery-by`` option (issue #138) + * pg_repack 1.4 * added support for PostgreSQL 9.6, dropped support for versions before 9.1 From ea27a94578be7853f589ba81c603f5c4355cd145 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 12 Aug 2017 13:15:14 +0100 Subject: [PATCH 10/13] Typo fixed (after releasing, of course...) --- doc/pg_repack.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index c8b1492..d32a48d 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -468,7 +468,7 @@ Releases * pg_repack 1.4.1 - * fixed broken ``--ordery-by`` option (issue #138) + * fixed broken ``--order-by`` option (issue #138) * pg_repack 1.4 From 20f5bf4878317143963f6cbeadbe520b4ef4b195 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sun, 13 Aug 2017 00:32:13 +0900 Subject: [PATCH 11/13] Update pg_repack_jp.rst for release 1.4.1. --- doc/pg_repack_jp.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index b958400..5ed4469 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -864,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 .. * added support for PostgreSQL 9.6 .. * use ``AFTER`` trigger to solve concurrency problems with ``INSERT From 1b651bd3d9e4216a8b30ee9faabbcba61302481f Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 3 Jun 2017 23:53:03 -0400 Subject: [PATCH 12/13] Avoid return from lock_exclusive() while in transaction .. ..causing "ERROR: DROP INDEX CONCURRENTLY cannot run inside a transaction block" github#129 --- bin/pg_repack.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 2be03cd..0316d98 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -1780,6 +1780,7 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta { elog(WARNING, "timed out, do not cancel conflicting backends"); ret = false; + pgut_rollback(conn); break; } else From 900bb8369bd3e28d14e67f017325e1109a12418c Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 18 Aug 2017 15:13:20 +0900 Subject: [PATCH 13/13] Reset the transcation state before exiting from lock_exclusive. Previously we exited from lock_exclusive() while opening the transaction that started at beggning if --no-kill-backend option is specified. This caused that DROP INDEX CONCURRENTLY fails because it cannot be executed within a user transaction block. Fixed issue #129. --- bin/pg_repack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 0316d98..9a62a47 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -1780,7 +1780,12 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta { elog(WARNING, "timed out, do not cancel conflicting backends"); ret = false; - pgut_rollback(conn); + + /* 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; } else