From 0cb08e5512206eb73dfd768ae258e528cc183054 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 11:37:04 +0000 Subject: [PATCH 1/5] Variable psql table output moved in separate file This made: - repack.out == repack_2.out - repack_3.out == repack_4.out - repack_1.out == repack_6.out --- regress/Makefile | 2 +- regress/expected/after-schema.out | 75 +++++++++++++++++++++++++++++ regress/expected/after-schema_1.out | 75 +++++++++++++++++++++++++++++ regress/expected/repack.out | 75 ----------------------------- regress/expected/repack_1.out | 75 ----------------------------- regress/expected/repack_2.out | 75 ----------------------------- regress/expected/repack_3.out | 75 ----------------------------- regress/expected/repack_4.out | 75 ----------------------------- regress/expected/repack_5.out | 75 ----------------------------- regress/expected/repack_6.out | 75 ----------------------------- regress/sql/after-schema.sql | 11 +++++ regress/sql/repack.sql | 13 +---- 12 files changed, 163 insertions(+), 538 deletions(-) create mode 100644 regress/expected/after-schema.out create mode 100644 regress/expected/after-schema_1.out create mode 100644 regress/sql/after-schema.sql diff --git a/regress/Makefile b/regress/Makefile index 006c332..28b4663 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -17,7 +17,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\} # Test suite # -REGRESS := init-extension repack tablespace issue3 +REGRESS := init-extension repack after-schema tablespace issue3 USE_PGXS = 1 # use pgxs if not in contrib directory PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/regress/expected/after-schema.out b/regress/expected/after-schema.out new file mode 100644 index 0000000..571f014 --- /dev/null +++ b/regress/expected/after-schema.out @@ -0,0 +1,75 @@ +-- +-- tables schema after running repack +-- +\d tbl_cluster + Table "public.tbl_cluster" + Column | Type | Modifiers +--------+-----------------------------+----------- + col1 | integer | not null + time | timestamp without time zone | + ,") | text | not null +Indexes: + "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') + ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER + +\d tbl_gistkey + Table "public.tbl_gistkey" + Column | Type | Modifiers +--------+---------+----------- + id | integer | not null + c | circle | +Indexes: + "tbl_gistkey_pkey" PRIMARY KEY, btree (id) + "cidx_circle" gist (c) CLUSTER + +\d tbl_only_ckey + Table "public.tbl_only_ckey" + Column | Type | Modifiers +--------+-----------------------------+----------- + col1 | integer | + col2 | timestamp without time zone | + ,") | text | +Indexes: + "cidx_only_ckey" btree (col2, ","")") CLUSTER + +\d tbl_only_pkey + Table "public.tbl_only_pkey" + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | not null + ,") | text | +Indexes: + "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) + +\d tbl_with_dropped_column +Table "public.tbl_with_dropped_column" + Column | Type | Modifiers +--------+---------+----------- + c1 | text | + id | integer | not null + c2 | text | + c3 | text | +Indexes: + "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER + "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') + "idx_c2c1" btree (c2, c1) + +\d tbl_with_dropped_toast +Table "public.tbl_with_dropped_toast" + Column | Type | Modifiers +--------+---------+----------- + i | integer | not null + j | integer | not null +Indexes: + "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER + +\d tbl_idxopts + Table "public.tbl_idxopts" + Column | Type | Modifiers +--------+---------+----------- + i | integer | not null + t | text | +Indexes: + "tbl_idxopts_pkey" PRIMARY KEY, btree (i) + "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text + diff --git a/regress/expected/after-schema_1.out b/regress/expected/after-schema_1.out new file mode 100644 index 0000000..2bd4d74 --- /dev/null +++ b/regress/expected/after-schema_1.out @@ -0,0 +1,75 @@ +-- +-- tables schema after running repack +-- +\d tbl_cluster + Table "public.tbl_cluster" + Column | Type | Collation | Nullable | Default +--------+-----------------------------+-----------+----------+--------- + col1 | integer | | not null | + time | timestamp without time zone | | | + ,") | text | | not null | +Indexes: + "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') + ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER + +\d tbl_gistkey + Table "public.tbl_gistkey" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + id | integer | | not null | + c | circle | | | +Indexes: + "tbl_gistkey_pkey" PRIMARY KEY, btree (id) + "cidx_circle" gist (c) CLUSTER + +\d tbl_only_ckey + Table "public.tbl_only_ckey" + Column | Type | Collation | Nullable | Default +--------+-----------------------------+-----------+----------+--------- + col1 | integer | | | + col2 | timestamp without time zone | | | + ,") | text | | | +Indexes: + "cidx_only_ckey" btree (col2, ","")") CLUSTER + +\d tbl_only_pkey + Table "public.tbl_only_pkey" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + col1 | integer | | not null | + ,") | text | | | +Indexes: + "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) + +\d tbl_with_dropped_column + Table "public.tbl_with_dropped_column" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + c1 | text | | | + id | integer | | not null | + c2 | text | | | + c3 | text | | | +Indexes: + "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER + "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') + "idx_c2c1" btree (c2, c1) + +\d tbl_with_dropped_toast + Table "public.tbl_with_dropped_toast" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + i | integer | | not null | + j | integer | | not null | +Indexes: + "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER + +\d tbl_idxopts + Table "public.tbl_idxopts" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + i | integer | | not null | + t | text | | | +Indexes: + "tbl_idxopts_pkey" PRIMARY KEY, btree (i) + "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text + diff --git a/regress/expected/repack.out b/regress/expected/repack.out index a18c744..07fc022 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | not null - time | timestamp without time zone | - ,") | text | not null -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Modifiers ---------+---------+----------- - id | integer | not null - c | circle | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | - col2 | timestamp without time zone | - ,") | text | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Modifiers ---------+---------+----------- - col1 | integer | not null - ,") | text | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column -Table "public.tbl_with_dropped_column" - Column | Type | Modifiers ---------+---------+----------- - c1 | text | - id | integer | not null - c2 | text | - c3 | text | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast -Table "public.tbl_with_dropped_toast" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - j | integer | not null -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - t | text | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 87cc038..e2047f7 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | not null - time | timestamp without time zone | - ,") | text | not null -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Modifiers ---------+---------+----------- - id | integer | not null - c | circle | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | - col2 | timestamp without time zone | - ,") | text | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Modifiers ---------+---------+----------- - col1 | integer | not null - ,") | text | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column -Table "public.tbl_with_dropped_column" - Column | Type | Modifiers ---------+---------+----------- - c1 | text | - id | integer | not null - c2 | text | - c3 | text | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast -Table "public.tbl_with_dropped_toast" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - j | integer | not null -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - t | text | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 3ceff4d..796b37e 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Collation | Nullable | Default ---------+-----------------------------+-----------+----------+--------- - col1 | integer | | not null | - time | timestamp without time zone | | | - ,") | text | | not null | -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - id | integer | | not null | - c | circle | | | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Collation | Nullable | Default ---------+-----------------------------+-----------+----------+--------- - col1 | integer | | | - col2 | timestamp without time zone | | | - ,") | text | | | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - col1 | integer | | not null | - ,") | text | | | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column - Table "public.tbl_with_dropped_column" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - c1 | text | | | - id | integer | | not null | - c2 | text | | | - c3 | text | | | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast - Table "public.tbl_with_dropped_toast" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - i | integer | | not null | - j | integer | | not null | -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - i | integer | | not null | - t | text | | | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index a7efdf8..fbe6b91 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Collation | Nullable | Default ---------+-----------------------------+-----------+----------+--------- - col1 | integer | | not null | - time | timestamp without time zone | | | - ,") | text | | not null | -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - id | integer | | not null | - c | circle | | | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Collation | Nullable | Default ---------+-----------------------------+-----------+----------+--------- - col1 | integer | | | - col2 | timestamp without time zone | | | - ,") | text | | | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - col1 | integer | | not null | - ,") | text | | | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column - Table "public.tbl_with_dropped_column" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - c1 | text | | | - id | integer | | not null | - c2 | text | | | - c3 | text | | | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast - Table "public.tbl_with_dropped_toast" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - i | integer | | not null | - j | integer | | not null | -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- - i | integer | | not null | - t | text | | | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_4.out b/regress/expected/repack_4.out index 6e868fa..6aa7cc2 100644 --- a/regress/expected/repack_4.out +++ b/regress/expected/repack_4.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | not null - time | timestamp without time zone | - ,") | text | not null -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Modifiers ---------+---------+----------- - id | integer | not null - c | circle | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | - col2 | timestamp without time zone | - ,") | text | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Modifiers ---------+---------+----------- - col1 | integer | not null - ,") | text | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column -Table "public.tbl_with_dropped_column" - Column | Type | Modifiers ---------+---------+----------- - c1 | text | - id | integer | not null - c2 | text | - c3 | text | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast -Table "public.tbl_with_dropped_toast" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - j | integer | not null -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - t | text | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out index 26d02e6..b561e20 100644 --- a/regress/expected/repack_5.out +++ b/regress/expected/repack_5.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | not null - time | timestamp without time zone | - ,") | text | not null -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75') - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Modifiers ---------+---------+----------- - id | integer | not null - c | circle | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | - col2 | timestamp without time zone | - ,") | text | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Modifiers ---------+---------+----------- - col1 | integer | not null - ,") | text | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column -Table "public.tbl_with_dropped_column" - Column | Type | Modifiers ---------+---------+----------- - c1 | text | - id | integer | not null - c2 | text | - c3 | text | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor='75') - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast -Table "public.tbl_with_dropped_toast" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - j | integer | not null -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - t | text | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack_6.out b/regress/expected/repack_6.out index 0da86a9..7d6c159 100644 --- a/regress/expected/repack_6.out +++ b/regress/expected/repack_6.out @@ -177,81 +177,6 @@ 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 --- -\d tbl_cluster - Table "public.tbl_cluster" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | not null - time | timestamp without time zone | - ,") | text | not null -Indexes: - "tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor=75) - ",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor=75) CLUSTER - -\d tbl_gistkey - Table "public.tbl_gistkey" - Column | Type | Modifiers ---------+---------+----------- - id | integer | not null - c | circle | -Indexes: - "tbl_gistkey_pkey" PRIMARY KEY, btree (id) - "cidx_circle" gist (c) CLUSTER - -\d tbl_only_ckey - Table "public.tbl_only_ckey" - Column | Type | Modifiers ---------+-----------------------------+----------- - col1 | integer | - col2 | timestamp without time zone | - ,") | text | -Indexes: - "cidx_only_ckey" btree (col2, ","")") CLUSTER - -\d tbl_only_pkey - Table "public.tbl_only_pkey" - Column | Type | Modifiers ---------+---------+----------- - col1 | integer | not null - ,") | text | -Indexes: - "tbl_only_pkey_pkey" PRIMARY KEY, btree (col1) - -\d tbl_with_dropped_column -Table "public.tbl_with_dropped_column" - Column | Type | Modifiers ---------+---------+----------- - c1 | text | - id | integer | not null - c2 | text | - c3 | text | -Indexes: - "tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor=75) CLUSTER - "idx_c1c2" btree (c1, c2) WITH (fillfactor=75) - "idx_c2c1" btree (c2, c1) - -\d tbl_with_dropped_toast -Table "public.tbl_with_dropped_toast" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - j | integer | not null -Indexes: - "tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER - -\d tbl_idxopts - Table "public.tbl_idxopts" - Column | Type | Modifiers ---------+---------+----------- - i | integer | not null - t | text | -Indexes: - "tbl_idxopts_pkey" PRIMARY KEY, btree (i) - "idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/sql/after-schema.sql b/regress/sql/after-schema.sql new file mode 100644 index 0000000..161cf74 --- /dev/null +++ b/regress/sql/after-schema.sql @@ -0,0 +1,11 @@ +-- +-- tables schema after running repack +-- + +\d tbl_cluster +\d tbl_gistkey +\d tbl_only_ckey +\d tbl_only_pkey +\d tbl_with_dropped_column +\d tbl_with_dropped_toast +\d tbl_idxopts diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index cb744aa..2f0a0ac 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -147,6 +147,7 @@ INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); 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 -- @@ -163,18 +164,6 @@ SELECT * FROM tbl_with_dropped_toast; \! pg_repack --dbname=contrib_regression --table=tbl_badindex \! pg_repack --dbname=contrib_regression --- --- after --- - -\d tbl_cluster -\d tbl_gistkey -\d tbl_only_ckey -\d tbl_only_pkey -\d tbl_with_dropped_column -\d tbl_with_dropped_toast -\d tbl_idxopts - SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; SELECT * FROM tbl_only_ckey ORDER BY 1; SELECT * FROM tbl_only_pkey ORDER BY 1; From 6dfbfffe5913a37622dd6062d8fa0aedd94b1594 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 12:20:06 +0000 Subject: [PATCH 2/5] Dropped duplicate test output files --- regress/expected/repack.out | 8 +- regress/expected/repack_1.out | 8 +- regress/expected/repack_2.out | 530 ---------------------------------- regress/expected/repack_3.out | 8 +- regress/expected/repack_4.out | 530 ---------------------------------- regress/expected/repack_5.out | 8 +- regress/expected/repack_6.out | 528 --------------------------------- regress/sql/repack.sql | 8 +- 8 files changed, 20 insertions(+), 1608 deletions(-) delete mode 100644 regress/expected/repack_2.out delete mode 100644 regress/expected/repack_4.out delete mode 100644 regress/expected/repack_6.out diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 07fc022..1c0a370 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -1,15 +1,15 @@ -- Test output file identifier. select filename from (values ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), + ( 90300, 90322, 'repack_1.out'), ( 90322, 90400, 'repack_5.out'), ( 90400, 90417, 'repack_1.out'), ( 90417, 90500, 'repack_5.out'), ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), + ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), + ( 90608, 100000, 'repack_3.out'), + (100000, 100003, 'repack.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) where current_setting('server_version_num')::int between min and max - 1; diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index e2047f7..6b0ecf6 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -1,15 +1,15 @@ -- Test output file identifier. select filename from (values ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), + ( 90300, 90322, 'repack_1.out'), ( 90322, 90400, 'repack_5.out'), ( 90400, 90417, 'repack_1.out'), ( 90417, 90500, 'repack_5.out'), ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), + ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), + ( 90608, 100000, 'repack_3.out'), + (100000, 100003, 'repack.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) where current_setting('server_version_num')::int between min and max - 1; diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out deleted file mode 100644 index 796b37e..0000000 --- a/regress/expected/repack_2.out +++ /dev/null @@ -1,530 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_2.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index fbe6b91..d619fe9 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -1,15 +1,15 @@ -- Test output file identifier. select filename from (values ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), + ( 90300, 90322, 'repack_1.out'), ( 90322, 90400, 'repack_5.out'), ( 90400, 90417, 'repack_1.out'), ( 90417, 90500, 'repack_5.out'), ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), + ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), + ( 90608, 100000, 'repack_3.out'), + (100000, 100003, 'repack.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) where current_setting('server_version_num')::int between min and max - 1; diff --git a/regress/expected/repack_4.out b/regress/expected/repack_4.out deleted file mode 100644 index 6aa7cc2..0000000 --- a/regress/expected/repack_4.out +++ /dev/null @@ -1,530 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_4.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out index b561e20..3a30ee6 100644 --- a/regress/expected/repack_5.out +++ b/regress/expected/repack_5.out @@ -1,15 +1,15 @@ -- Test output file identifier. select filename from (values ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), + ( 90300, 90322, 'repack_1.out'), ( 90322, 90400, 'repack_5.out'), ( 90400, 90417, 'repack_1.out'), ( 90417, 90500, 'repack_5.out'), ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), + ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), + ( 90608, 100000, 'repack_3.out'), + (100000, 100003, 'repack.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) where current_setting('server_version_num')::int between min and max - 1; diff --git a/regress/expected/repack_6.out b/regress/expected/repack_6.out deleted file mode 100644 index 7d6c159..0000000 --- a/regress/expected/repack_6.out +++ /dev/null @@ -1,528 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_6.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 -DROP ROLE IF EXISTS nosuper; --- --- exclude extension check --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 2f0a0ac..04b1a79 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -1,15 +1,15 @@ -- Test output file identifier. select filename from (values ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_6.out'), + ( 90300, 90322, 'repack_1.out'), ( 90322, 90400, 'repack_5.out'), ( 90400, 90417, 'repack_1.out'), ( 90417, 90500, 'repack_5.out'), ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_4.out'), + ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_4.out'), - (100000, 100003, 'repack_2.out'), + ( 90608, 100000, 'repack_3.out'), + (100000, 100003, 'repack.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) where current_setting('server_version_num')::int between min and max - 1; From a5509c7415e29a1f865651aa9ac73ede26af376d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 12:28:16 +0000 Subject: [PATCH 3/5] No superuser check separated from other tests The output differs across versions because it can include the context. This made: - repack.out = repack_1.out - repack_3.out = repack_5.out --- regress/Makefile | 2 +- regress/expected/nosuper.out | 19 +++++++++++++++++++ regress/expected/nosuper_1.out | 17 +++++++++++++++++ regress/expected/repack.out | 17 ----------------- regress/expected/repack_1.out | 15 --------------- regress/expected/repack_3.out | 17 ----------------- regress/expected/repack_5.out | 15 --------------- regress/sql/nosuper.sql | 14 ++++++++++++++ regress/sql/repack.sql | 13 ------------- 9 files changed, 51 insertions(+), 78 deletions(-) create mode 100644 regress/expected/nosuper.out create mode 100644 regress/expected/nosuper_1.out create mode 100644 regress/sql/nosuper.sql diff --git a/regress/Makefile b/regress/Makefile index 28b4663..81a0d53 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -17,7 +17,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\} # Test suite # -REGRESS := init-extension repack after-schema tablespace issue3 +REGRESS := init-extension repack after-schema nosuper tablespace issue3 USE_PGXS = 1 # use pgxs if not in contrib directory PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/regress/expected/nosuper.out b/regress/expected/nosuper.out new file mode 100644 index 0000000..b16f4b1 --- /dev/null +++ b/regress/expected/nosuper.out @@ -0,0 +1,19 @@ +-- +-- no superuser check +-- +SET client_min_messages = error; +DROP ROLE IF EXISTS nosuper; +SET client_min_messages = warning; +CREATE ROLE nosuper WITH LOGIN; +-- => OK +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check +INFO: repacking table "tbl_cluster" +-- => ERROR +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper +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; diff --git a/regress/expected/nosuper_1.out b/regress/expected/nosuper_1.out new file mode 100644 index 0000000..d227516 --- /dev/null +++ b/regress/expected/nosuper_1.out @@ -0,0 +1,17 @@ +-- +-- no superuser check +-- +SET client_min_messages = error; +DROP ROLE IF EXISTS nosuper; +SET client_min_messages = warning; +CREATE ROLE nosuper WITH LOGIN; +-- => OK +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check +INFO: repacking table "tbl_cluster" +-- => ERROR +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper +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 +DROP ROLE IF EXISTS nosuper; diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 1c0a370..5e62ffb 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -433,23 +433,6 @@ ERROR: cannot repack specific schema(s) in all databases \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend INFO: repacking table "tbl_cluster" -- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 -- CREATE SCHEMA exclude_extension_schema; diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 6b0ecf6..dd08837 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -433,21 +433,6 @@ ERROR: cannot repack specific schema(s) in all databases \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend INFO: repacking table "tbl_cluster" -- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 -DROP ROLE IF EXISTS nosuper; --- -- exclude extension check -- CREATE SCHEMA exclude_extension_schema; diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index d619fe9..96818f5 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -433,23 +433,6 @@ ERROR: cannot repack specific schema(s) in all databases \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend INFO: repacking table "tbl_cluster" -- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 -- CREATE SCHEMA exclude_extension_schema; diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out index 3a30ee6..b7e6efc 100644 --- a/regress/expected/repack_5.out +++ b/regress/expected/repack_5.out @@ -433,21 +433,6 @@ ERROR: cannot repack specific schema(s) in all databases \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend INFO: repacking table "tbl_cluster" -- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -INFO: repacking table "tbl_cluster" --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper -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 -DROP ROLE IF EXISTS nosuper; --- -- exclude extension check -- CREATE SCHEMA exclude_extension_schema; diff --git a/regress/sql/nosuper.sql b/regress/sql/nosuper.sql new file mode 100644 index 0000000..198f345 --- /dev/null +++ b/regress/sql/nosuper.sql @@ -0,0 +1,14 @@ +-- +-- no superuser check +-- +SET client_min_messages = error; +DROP ROLE IF EXISTS nosuper; +SET client_min_messages = warning; +CREATE ROLE nosuper WITH LOGIN; +-- => OK +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check +-- => ERROR +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper +-- => ERROR +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check +DROP ROLE IF EXISTS nosuper; diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 04b1a79..63b38c8 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -291,19 +291,6 @@ CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); -- \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend --- --- no superuser check --- -DROP ROLE IF EXISTS nosuper; -CREATE ROLE nosuper WITH LOGIN; --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --- => ERROR -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check -DROP ROLE IF EXISTS nosuper; - -- -- exclude extension check -- From 74d56ef4d6f47e63fb2bb8dc39bfcc67acf4117e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 12:31:39 +0000 Subject: [PATCH 4/5] Dropped now equivalent test output files --- regress/expected/repack.out | 10 +- regress/expected/repack_1.out | 513 ---------------------------------- regress/expected/repack_3.out | 10 +- regress/expected/repack_5.out | 513 ---------------------------------- regress/sql/repack.sql | 10 +- 5 files changed, 15 insertions(+), 1041 deletions(-) delete mode 100644 regress/expected/repack_1.out delete mode 100644 regress/expected/repack_5.out diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 5e62ffb..1e9982d 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -1,10 +1,10 @@ -- Test output file identifier. select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_1.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), + ( 90100, 90300, 'repack.out'), + ( 90300, 90322, 'repack.out'), + ( 90322, 90400, 'repack_3.out'), + ( 90400, 90417, 'repack.out'), + ( 90417, 90500, 'repack_3.out'), ( 90500, 90512, 'repack.out'), ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out deleted file mode 100644 index dd08837..0000000 --- a/regress/expected/repack_1.out +++ /dev/null @@ -1,513 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_1.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_3.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_3.out'), - (100000, 100003, 'repack.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_1.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- exclude extension check --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index 96818f5..3c600bd 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -1,10 +1,10 @@ -- Test output file identifier. select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_1.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), + ( 90100, 90300, 'repack.out'), + ( 90300, 90322, 'repack.out'), + ( 90322, 90400, 'repack_3.out'), + ( 90400, 90417, 'repack.out'), + ( 90417, 90500, 'repack_3.out'), ( 90500, 90512, 'repack.out'), ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out deleted file mode 100644 index b7e6efc..0000000 --- a/regress/expected/repack_5.out +++ /dev/null @@ -1,513 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_1.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_3.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_3.out'), - (100000, 100003, 'repack.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_5.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- exclude extension check --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 63b38c8..456c625 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -1,10 +1,10 @@ -- Test output file identifier. select filename from (values - ( 90100, 90300, 'repack_1.out'), - ( 90300, 90322, 'repack_1.out'), - ( 90322, 90400, 'repack_5.out'), - ( 90400, 90417, 'repack_1.out'), - ( 90417, 90500, 'repack_5.out'), + ( 90100, 90300, 'repack.out'), + ( 90300, 90322, 'repack.out'), + ( 90322, 90400, 'repack_3.out'), + ( 90400, 90417, 'repack.out'), + ( 90417, 90500, 'repack_3.out'), ( 90500, 90512, 'repack.out'), ( 90512, 90600, 'repack_3.out'), ( 90600, 90608, 'repack.out'), From 73851d2e5c1abf64bde8669e034a18d6cc06887b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 12:49:15 +0000 Subject: [PATCH 5/5] Test file separated in setup - run - check The run part has different output across minor versions, the others not. Dropped test files identification statement as now the variable part is in small chunks. --- regress/Makefile | 2 +- .../expected/{repack.out => repack-check.out} | 178 ------ regress/expected/repack-run.out | 20 + regress/expected/repack-run_1.out | 20 + regress/expected/repack-setup.out | 139 +++++ regress/expected/repack_3.out | 513 ------------------ regress/sql/{repack.sql => repack-check.sql} | 164 ------ regress/sql/repack-run.sql | 7 + regress/sql/repack-setup.sql | 143 +++++ 9 files changed, 330 insertions(+), 856 deletions(-) rename regress/expected/{repack.out => repack-check.out} (73%) create mode 100644 regress/expected/repack-run.out create mode 100644 regress/expected/repack-run_1.out create mode 100644 regress/expected/repack-setup.out delete mode 100644 regress/expected/repack_3.out rename regress/sql/{repack.sql => repack-check.sql} (54%) create mode 100644 regress/sql/repack-run.sql create mode 100644 regress/sql/repack-setup.sql diff --git a/regress/Makefile b/regress/Makefile index 81a0d53..0365c9a 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -17,7 +17,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\} # Test suite # -REGRESS := init-extension repack after-schema nosuper tablespace issue3 +REGRESS := init-extension repack-setup repack-run after-schema repack-check nosuper tablespace issue3 USE_PGXS = 1 # use pgxs if not in contrib directory PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/regress/expected/repack.out b/regress/expected/repack-check.out similarity index 73% rename from regress/expected/repack.out rename to regress/expected/repack-check.out index 1e9982d..010c920 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack-check.out @@ -1,182 +1,4 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack.out'), - ( 90300, 90322, 'repack.out'), - ( 90322, 90400, 'repack_3.out'), - ( 90400, 90417, 'repack.out'), - ( 90417, 90500, 'repack_3.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_3.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_3.out'), - (100000, 100003, 'repack.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename ------------- - repack.out -(1 row) - SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; col1 | to_char | ,") ------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/regress/expected/repack-run.out b/regress/expected/repack-run.out new file mode 100644 index 0000000..cd28202 --- /dev/null +++ b/regress/expected/repack-run.out @@ -0,0 +1,20 @@ +-- +-- do repack +-- +\! pg_repack --dbname=contrib_regression --table=tbl_cluster +INFO: repacking table "tbl_cluster" +\! pg_repack --dbname=contrib_regression --table=tbl_badindex +INFO: repacking table "tbl_badindex" +WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) +\! pg_repack --dbname=contrib_regression +INFO: repacking table "tbl_cluster" +INFO: repacking table "tbl_only_pkey" +INFO: repacking table "tbl_gistkey" +INFO: repacking table "tbl_with_dropped_column" +INFO: repacking table "tbl_with_dropped_toast" +INFO: repacking table "tbl_badindex" +WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) +INFO: repacking table "tbl_idxopts" +INFO: repacking table "tbl_with_toast" +INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" diff --git a/regress/expected/repack-run_1.out b/regress/expected/repack-run_1.out new file mode 100644 index 0000000..a15d6b0 --- /dev/null +++ b/regress/expected/repack-run_1.out @@ -0,0 +1,20 @@ +-- +-- do repack +-- +\! pg_repack --dbname=contrib_regression --table=tbl_cluster +INFO: repacking table "tbl_cluster" +\! pg_repack --dbname=contrib_regression --table=tbl_badindex +INFO: repacking table "tbl_badindex" +WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) +\! pg_repack --dbname=contrib_regression +INFO: repacking table "tbl_cluster" +INFO: repacking table "tbl_only_pkey" +INFO: repacking table "tbl_gistkey" +INFO: repacking table "tbl_with_dropped_column" +INFO: repacking table "tbl_with_dropped_toast" +INFO: repacking table "tbl_badindex" +WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) +INFO: repacking table "tbl_idxopts" +INFO: repacking table "tbl_with_toast" +INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" diff --git a/regress/expected/repack-setup.out b/regress/expected/repack-setup.out new file mode 100644 index 0000000..e9a6351 --- /dev/null +++ b/regress/expected/repack-setup.out @@ -0,0 +1,139 @@ +SET client_min_messages = warning; +-- +-- create table. +-- +CREATE TABLE tbl_cluster ( + col1 int, + "time" timestamp, + ","")" text, + PRIMARY KEY (","")", col1) WITH (fillfactor = 75) +) WITH (fillfactor = 70); +CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); +ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; +CREATE TABLE tbl_only_pkey ( + col1 int PRIMARY KEY, + ","")" text +); +CREATE TABLE tbl_only_ckey ( + col1 int, + col2 timestamp, + ","")" text +) WITH (fillfactor = 70); +CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); +ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; +CREATE TABLE tbl_gistkey ( + id integer PRIMARY KEY, + c circle +); +CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); +ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; +CREATE TABLE tbl_with_dropped_column ( + d1 text, + c1 text, + id integer PRIMARY KEY, + d2 text, + c2 text, + d3 text +); +ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); +ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; +CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); +CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); +CREATE TABLE tbl_with_dropped_toast ( + i integer, + j integer, + t text, + PRIMARY KEY (i, j) +); +ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; +CREATE TABLE tbl_badindex ( + id integer PRIMARY KEY, + n integer +); +CREATE TABLE tbl_idxopts ( + i integer PRIMARY KEY, + t text +); +CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); +-- Use this table to play with attribute options too +ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; +ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); +CREATE TABLE tbl_with_toast ( + i integer PRIMARY KEY, + c text +); +ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); +ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); +CREATE TABLE tbl_with_mod_column_storage ( + id integer PRIMARY KEY, + c text +); +ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); +-- +-- insert data +-- +INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); +INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); +INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); +INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); +INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); +INSERT INTO tbl_only_pkey VALUES(1, 'abc'); +INSERT INTO tbl_only_pkey VALUES(2, 'def'); +INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); +INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); +INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); +INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); +INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); +INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); +ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; +ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; +ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; +ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; +CREATE VIEW view_for_dropped_column AS + SELECT * FROM tbl_with_dropped_column; +INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); +INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); +ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; +INSERT INTO tbl_badindex VALUES(1, 10); +INSERT INTO tbl_badindex VALUES(2, 10); +-- insert data that is always stored into the toast table if column type is extended. +SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); + setseed +--------- + +(1 row) + +-- This will fail. Silence the message as it's different across PG versions. +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 +-- +SELECT * FROM tbl_with_dropped_column; + c1 | id | c2 | c3 +----+----+----+---- + c1 | 2 | c2 | + c1 | 1 | c2 | +(2 rows) + +SELECT * FROM view_for_dropped_column; + c1 | id | c2 | c3 +----+----+----+---- + c1 | 2 | c2 | + c1 | 1 | c2 | +(2 rows) + +SELECT * FROM tbl_with_dropped_toast; + i | j +---+---- + 1 | 10 + 2 | 20 +(2 rows) + diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out deleted file mode 100644 index 3c600bd..0000000 --- a/regress/expected/repack_3.out +++ /dev/null @@ -1,513 +0,0 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack.out'), - ( 90300, 90322, 'repack.out'), - ( 90322, 90400, 'repack_3.out'), - ( 90400, 90417, 'repack.out'), - ( 90417, 90500, 'repack_3.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_3.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_3.out'), - (100000, 100003, 'repack.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - filename --------------- - repack_3.out -(1 row) - -SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - setseed ---------- - -(1 row) - --- This will fail. Silence the message as it's different across PG versions. -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 --- -SELECT * FROM tbl_with_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 2 | c2 | - c1 | 1 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - --- --- do repack --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -\! pg_repack --dbname=contrib_regression -INFO: repacking table "tbl_cluster" -INFO: repacking table "tbl_only_pkey" -INFO: repacking table "tbl_gistkey" -INFO: repacking table "tbl_with_dropped_column" -INFO: repacking table "tbl_with_dropped_toast" -INFO: repacking table "tbl_badindex" -WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON public.tbl_badindex USING btree (n) -INFO: repacking table "tbl_idxopts" -INFO: repacking table "tbl_with_toast" -INFO: repacking table "tbl_with_mod_column_storage" -INFO: repacking table "tbl_order" -SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; - col1 | to_char | ,") -------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - 1 | 2008-12-31 10:00:00 | admin - 2 | 2008-01-01 00:00:00 | king - 3 | 2008-03-04 12:00:00 | joker - 4 | 2008-03-05 15:00:00 | queen - 5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938 -(5 rows) - -SELECT * FROM tbl_only_ckey ORDER BY 1; - col1 | col2 | ,") -------+--------------------------+----- - 1 | Tue Jan 01 00:00:00 2008 | abc - 2 | Fri Feb 01 00:00:00 2008 | def -(2 rows) - -SELECT * FROM tbl_only_pkey ORDER BY 1; - col1 | ,") -------+----- - 1 | abc - 2 | def -(2 rows) - -SELECT * FROM tbl_gistkey ORDER BY 1; - id | c -----+----------- - 1 | <(1,2),3> - 2 | <(4,5),6> -(2 rows) - -SET enable_seqscan = on; -SET enable_indexscan = off; -SELECT * FROM tbl_with_dropped_column ; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -SET enable_seqscan = off; -SET enable_indexscan = on; -SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM view_for_dropped_column; - c1 | id | c2 | c3 -----+----+----+---- - c1 | 1 | c2 | - c1 | 2 | c2 | -(2 rows) - -SELECT * FROM tbl_with_dropped_toast; - i | j ----+---- - 1 | 10 - 2 | 20 -(2 rows) - -RESET enable_seqscan; -RESET enable_indexscan; --- check if storage option for both table and TOAST table didn't go away. -SELECT CASE relkind - WHEN 'r' THEN relname - WHEN 't' THEN 'toast_table' - END as table, - reloptions -FROM pg_class -WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid -ORDER BY 1; - table | reloptions -----------------+--------------------------------------------------------------------- - tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300} - toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400} -(2 rows) - -SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage'; - check_toast_rel_size ----------------------- - t -(1 row) - --- --- check broken links or orphan toast relations --- -SELECT oid, relname - FROM pg_class - WHERE relkind = 't' - AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r'); - oid | relname ------+--------- -(0 rows) - -SELECT oid, relname - FROM pg_class - WHERE relkind = 'r' - AND reltoastrelid <> 0 - AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't'); - oid | relname ------+--------- -(0 rows) - --- check columns options -SELECT attname, attstattarget, attoptions -FROM pg_attribute -WHERE attrelid = 'tbl_idxopts'::regclass -AND attnum > 0 -ORDER BY attnum; - attname | attstattarget | attoptions ----------+---------------+------------------- - i | 1 | - t | -1 | {n_distinct=-0.5} -(2 rows) - --- --- NOT NULL UNIQUE --- -CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL); -CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2)); -CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)); -CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1)); -CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); -CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -\! pg_repack --dbname=contrib_regression --table=tbl_nn -WARNING: relation "tbl_nn" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_uk -WARNING: relation "tbl_uk" must have a primary key or not-null unique keys --- => WARNING -\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk -INFO: repacking table "tbl_nn_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes -INFO: repacking indexes of "tbl_pk_uk" -INFO: repacking index "public"."tbl_pk_uk_col2_col1_key" -INFO: repacking index "public"."tbl_pk_uk_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys --- => WARNING --- --- Triggers handling --- -CREATE FUNCTION trgtest() RETURNS trigger AS -$$BEGIN RETURN NEW; END$$ -LANGUAGE plpgsql; -CREATE TABLE trg1 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg1 -INFO: repacking table "trg1" -CREATE TABLE trg2 (id integer PRIMARY KEY); -CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); -\! pg_repack --dbname=contrib_regression --table=trg2 -INFO: repacking table "trg2" -WARNING: the table "trg2" already has a trigger called "repack_trigger" -DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. -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 --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run -INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" --- Test --schema --- -CREATE SCHEMA test_schema1; -CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY); -CREATE SCHEMA test_schema2; -CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY); -CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY); --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" --- => OK -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2 -INFO: repacking table "test_schema1.tbl1" -INFO: repacking table "test_schema1.tbl2" -INFO: repacking table "test_schema2.tbl1" -INFO: repacking table "test_schema2.tbl2" --- => ERROR -\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1 -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --all --schema=test_schema1 -ERROR: cannot repack specific schema(s) in all databases --- --- don't kill backend --- -\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend -INFO: repacking table "tbl_cluster" --- --- exclude extension check --- -CREATE SCHEMA exclude_extension_schema; -CREATE TABLE exclude_extension_schema.tbl(val integer primary key); --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -ERROR: cannot specify --table (-t) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x -ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C) --- => ERROR -\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension -ERROR: cannot specify --index (-i) and --exclude-extension (-C) --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- => OK -\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension -INFO: repacking table "exclude_extension_schema.tbl" --- --- table inheritance check --- -CREATE TABLE parent_a(val integer primary key); -CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a); -CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a); -CREATE TABLE parent_b(val integer primary key); -CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b); -CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table -ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index -ERROR: cannot specify --index (-i) and --parent-table (-I) --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema -ERROR: cannot repack specific table(s) in schema, use schema.table notation instead --- => ERROR -\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all -ERROR: cannot repack specific table(s) in all databases --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b -INFO: repacking table "parent_a" -INFO: repacking table "child_a_1" -INFO: repacking table "child_a_2" -INFO: repacking table "parent_b" -INFO: repacking table "child_b_1" -INFO: repacking table "child_b_2" --- => OK -\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" --- => OK -\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes -INFO: repacking indexes of "public.child_a_1" -INFO: repacking index "public"."child_a_1_pkey" -INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" -INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" -INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" -INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" -INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" diff --git a/regress/sql/repack.sql b/regress/sql/repack-check.sql similarity index 54% rename from regress/sql/repack.sql rename to regress/sql/repack-check.sql index 456c625..0730b1e 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack-check.sql @@ -1,168 +1,4 @@ --- Test output file identifier. -select filename from (values - ( 90100, 90300, 'repack.out'), - ( 90300, 90322, 'repack.out'), - ( 90322, 90400, 'repack_3.out'), - ( 90400, 90417, 'repack.out'), - ( 90417, 90500, 'repack_3.out'), - ( 90500, 90512, 'repack.out'), - ( 90512, 90600, 'repack_3.out'), - ( 90600, 90608, 'repack.out'), - ( 90608, 100000, 'repack_3.out'), - (100000, 100003, 'repack.out'), - (100003, 110000, 'repack_3.out') -) as x (min, max, filename) -where current_setting('server_version_num')::int between min and max - 1; - SET client_min_messages = warning; --- --- create table. --- -CREATE TABLE tbl_cluster ( - col1 int, - "time" timestamp, - ","")" text, - PRIMARY KEY (","")", col1) WITH (fillfactor = 75) -) WITH (fillfactor = 70); - -CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); -ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; - -CREATE TABLE tbl_only_pkey ( - col1 int PRIMARY KEY, - ","")" text -); - -CREATE TABLE tbl_only_ckey ( - col1 int, - col2 timestamp, - ","")" text -) WITH (fillfactor = 70); - -CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); -ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; - -CREATE TABLE tbl_gistkey ( - id integer PRIMARY KEY, - c circle -); - -CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); -ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; - -CREATE TABLE tbl_with_dropped_column ( - d1 text, - c1 text, - id integer PRIMARY KEY, - d2 text, - c2 text, - d3 text -); -ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); -ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; -CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); -CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); - -CREATE TABLE tbl_with_dropped_toast ( - i integer, - j integer, - t text, - PRIMARY KEY (i, j) -); -ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; - -CREATE TABLE tbl_badindex ( - id integer PRIMARY KEY, - n integer -); - -CREATE TABLE tbl_idxopts ( - i integer PRIMARY KEY, - t text -); -CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); - --- Use this table to play with attribute options too -ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; -ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); -CREATE TABLE tbl_with_toast ( - i integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); -ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); -CREATE TABLE tbl_with_mod_column_storage ( - id integer PRIMARY KEY, - c text -); -ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; - -CREATE TABLE tbl_order (c int primary key); --- --- insert data --- - -INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); -INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); -INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); -INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); -INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); - -INSERT INTO tbl_only_pkey VALUES(1, 'abc'); -INSERT INTO tbl_only_pkey VALUES(2, 'def'); - -INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); -INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); - -INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); -INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); - -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); -INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); -ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; -ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; -ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; -CREATE VIEW view_for_dropped_column AS - SELECT * FROM tbl_with_dropped_column; - -INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); -INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); -ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; - -INSERT INTO tbl_badindex VALUES(1, 10); -INSERT INTO tbl_badindex VALUES(2, 10); - --- insert data that is always stored into the toast table if column type is extended. -SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); - --- This will fail. Silence the message as it's different across PG versions. -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 --- - -SELECT * FROM tbl_with_dropped_column; -SELECT * FROM view_for_dropped_column; -SELECT * FROM tbl_with_dropped_toast; - --- --- do repack --- - -\! pg_repack --dbname=contrib_regression --table=tbl_cluster -\! pg_repack --dbname=contrib_regression --table=tbl_badindex -\! pg_repack --dbname=contrib_regression SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2; SELECT * FROM tbl_only_ckey ORDER BY 1; diff --git a/regress/sql/repack-run.sql b/regress/sql/repack-run.sql new file mode 100644 index 0000000..0db7712 --- /dev/null +++ b/regress/sql/repack-run.sql @@ -0,0 +1,7 @@ +-- +-- do repack +-- + +\! pg_repack --dbname=contrib_regression --table=tbl_cluster +\! pg_repack --dbname=contrib_regression --table=tbl_badindex +\! pg_repack --dbname=contrib_regression diff --git a/regress/sql/repack-setup.sql b/regress/sql/repack-setup.sql new file mode 100644 index 0000000..abe00cf --- /dev/null +++ b/regress/sql/repack-setup.sql @@ -0,0 +1,143 @@ +SET client_min_messages = warning; + +-- +-- create table. +-- + +CREATE TABLE tbl_cluster ( + col1 int, + "time" timestamp, + ","")" text, + PRIMARY KEY (","")", col1) WITH (fillfactor = 75) +) WITH (fillfactor = 70); + +CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75); +ALTER TABLE tbl_cluster CLUSTER ON ","") cluster"; + +CREATE TABLE tbl_only_pkey ( + col1 int PRIMARY KEY, + ","")" text +); + +CREATE TABLE tbl_only_ckey ( + col1 int, + col2 timestamp, + ","")" text +) WITH (fillfactor = 70); + +CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")"); +ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey; + +CREATE TABLE tbl_gistkey ( + id integer PRIMARY KEY, + c circle +); + +CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c); +ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle; + +CREATE TABLE tbl_with_dropped_column ( + d1 text, + c1 text, + id integer PRIMARY KEY, + d2 text, + c2 text, + d3 text +); +ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75); +ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey; +CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75); +CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1); + +CREATE TABLE tbl_with_dropped_toast ( + i integer, + j integer, + t text, + PRIMARY KEY (i, j) +); +ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey; + +CREATE TABLE tbl_badindex ( + id integer PRIMARY KEY, + n integer +); + +CREATE TABLE tbl_idxopts ( + i integer PRIMARY KEY, + t text +); +CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa'); + +-- Use this table to play with attribute options too +ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1; +ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5); +CREATE TABLE tbl_with_toast ( + i integer PRIMARY KEY, + c text +); +ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300); +ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400); +CREATE TABLE tbl_with_mod_column_storage ( + id integer PRIMARY KEY, + c text +); +ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; + +CREATE TABLE tbl_order (c int primary key); +-- +-- insert data +-- + +INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin'); +INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king'); +INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker'); +INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen'); +INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); + +INSERT INTO tbl_only_pkey VALUES(1, 'abc'); +INSERT INTO tbl_only_pkey VALUES(2, 'def'); + +INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc'); +INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def'); + +INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>'); +INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>'); + +INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3'); +INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3'); +ALTER TABLE tbl_with_dropped_column DROP COLUMN d1; +ALTER TABLE tbl_with_dropped_column DROP COLUMN d2; +ALTER TABLE tbl_with_dropped_column DROP COLUMN d3; +ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text; +CREATE VIEW view_for_dropped_column AS + SELECT * FROM tbl_with_dropped_column; + +INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc'); +INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text); +ALTER TABLE tbl_with_dropped_toast DROP COLUMN t; + +INSERT INTO tbl_badindex VALUES(1, 10); +INSERT INTO tbl_badindex VALUES(2, 10); + +-- insert data that is always stored into the toast table if column type is extended. +SELECT setseed(0); INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr((random() * (127 - 32) + 32)::int) FROM generate_series(1, 3 * 1024) code), ''); + +-- This will fail. Silence the message as it's different across PG versions. +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 +-- + +SELECT * FROM tbl_with_dropped_column; +SELECT * FROM view_for_dropped_column; +SELECT * FROM tbl_with_dropped_toast;