From b9b8e60bda7129b74fa7d509b125163d4317330d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 29 Mar 2017 03:02:04 +0100 Subject: [PATCH 01/45] Set up travis tests to run with postgres 10 --- .travis.yml | 1 + regress/travis_prepare.sh | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index cb55e29..ed94cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ dist: trusty sudo: required env: + - PGVER=10 - PGVER=9.6 - PGVER=9.5 - PGVER=9.4 diff --git a/regress/travis_prepare.sh b/regress/travis_prepare.sh index 5644ed5..1656147 100755 --- a/regress/travis_prepare.sh +++ b/regress/travis_prepare.sh @@ -38,9 +38,16 @@ fi # Go somewhere else or sudo will fail cd / + # Already started because of installing posgresql-$PGVER # sudo -u postgres "$PGBIN/pg_ctl" -w -l /dev/null -D "$CONFDIR" start sudo -u postgres mkdir -p /var/lib/postgresql/testts sudo -u postgres "$PGBIN/psql" \ -c "create tablespace testts location '/var/lib/postgresql/testts'" + +if [ $PGVER -eq "10" ]; then + sudo -u postgres "$PGBIN/psql" -c "create user travis superuser" +fi + +# Go back to the build dir cd - From 19e34a3202da21150c61d8ff1e86b105723c05bb Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 12:24:12 +0100 Subject: [PATCH 02/45] Added PG 10 compatibility wrapper to simple_prompt() Also checking for malloc failure into previous version's simple_prompt() calls. --- bin/pgut/pgut.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/pgut/pgut.c b/bin/pgut/pgut.c index 66db463..3a3f5ef 100644 --- a/bin/pgut/pgut.c +++ b/bin/pgut/pgut.c @@ -434,7 +434,26 @@ simple_string_list_size(SimpleStringList list) static char * prompt_for_password(void) { - return simple_prompt("Password: ", 100, false); + char *buf; +#define BUFSIZE 100 + +#if PG_VERSION_NUM < 100000 + buf = simple_prompt("Password: ", BUFSIZE, false); +#else + buf = (char *)malloc(BUFSIZE); + if (buf != NULL) + simple_prompt("Password: ", buf, BUFSIZE, false); +#endif + + if (buf == NULL) + ereport(FATAL, + (errcode_errno(), + errmsg("could not allocate memory (" UINT64_FORMAT " bytes): ", + (unsigned long) BUFSIZE))); + + return buf; + +#undef BUFSIZE } From 773dc5349d73af344743236bc741915556f83766 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 12:41:14 +0100 Subject: [PATCH 03/45] Work around CatalogIndexInsert no more exported in PG 10 The CatalogTupleUpdateWithInfo performs the two operation simple_heap_update and CatalogIndexInsert. --- lib/repack.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/repack.c b/lib/repack.c index 6ba7535..43f7e80 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -1156,14 +1156,25 @@ swap_heap_or_index_files(Oid r1, Oid r2) relform2->reltuples = swap_tuples; } + indstate = CatalogOpenIndexes(relRelation); + +#if PG_VERSION_NUM < 100000 + /* Update the tuples in pg_class */ simple_heap_update(relRelation, &reltup1->t_self, reltup1); simple_heap_update(relRelation, &reltup2->t_self, reltup2); /* Keep system catalogs current */ - indstate = CatalogOpenIndexes(relRelation); CatalogIndexInsert(indstate, reltup1); CatalogIndexInsert(indstate, reltup2); + +#else + + CatalogTupleUpdateWithInfo(relRelation, &reltup1->t_self, reltup1, indstate); + CatalogTupleUpdateWithInfo(relRelation, &reltup2->t_self, reltup2, indstate); + +#endif + CatalogCloseIndexes(indstate); /* From a5a5f3447a5934d2c7e314cc120b6c94e4b2ae4a Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 13:21:17 +0100 Subject: [PATCH 04/45] Added expected test for postgres 10 The \d output format changed --- regress/expected/repack_2.out | 535 ++++++++++++++++++++++++++++++++++ 1 file changed, 535 insertions(+) create mode 100644 regress/expected/repack_2.out diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out new file mode 100644 index 0000000..4bd6e89 --- /dev/null +++ b/regress/expected/repack_2.out @@ -0,0 +1,535 @@ +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; +-- +-- 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. +INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) 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'); +-- +-- 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" +-- +-- 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 | ,") +------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + 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 | 2 | c2 | + c1 | 1 | 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 | 2 | c2 | + c1 | 1 | 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" +-- +-- 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" From 8bdba99642e9fb2eb0e2302d9b066daf19493401 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 13:23:44 +0100 Subject: [PATCH 05/45] Fixed hba configuration to test on PG 10 Use env vars instead of hardcoded PG version to select config options. --- .travis.yml | 1 + regress/travis_prepare.sh | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ed94cad..2ffb09c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ sudo: required env: - PGVER=10 + PGTESTING=1 - PGVER=9.6 - PGVER=9.5 - PGVER=9.4 diff --git a/regress/travis_prepare.sh b/regress/travis_prepare.sh index 1656147..dbb1b40 100755 --- a/regress/travis_prepare.sh +++ b/regress/travis_prepare.sh @@ -30,6 +30,12 @@ else # See https://github.com/reorg/pg_repack/issues/63 sudo sed -i "s/main[[:space:]]*$/main ${PGVER}/" \ /etc/apt/sources.list.d/pgdg.list + + if [ "$PGTESTING" != "" ]; then + sudo sed -i "s/trusty-pgdg/trusty-pgdg-testing/" \ + /etc/apt/sources.list.d/pgdg.list + fi + sudo apt-get update sudo apt-get install -y "libpq5=${PGVER}*" "libpq-dev=${PGVER}*" sudo apt-mark hold libpq5 @@ -45,7 +51,15 @@ sudo -u postgres mkdir -p /var/lib/postgresql/testts sudo -u postgres "$PGBIN/psql" \ -c "create tablespace testts location '/var/lib/postgresql/testts'" -if [ $PGVER -eq "10" ]; then +# If the database was not provided by Travis it needs some customization +if [ "$PGTESTING" != "" ]; then + + # Allow local connections with no password + sudo sed -i \ + 's/\(^local[[:space:]]\+all[[:space:]]\+all[[:space:]]\+\).*/\1trust/' \ + "$CONFDIR/pg_hba.conf" + sudo -u postgres "$PGBIN/pg_ctl" -D "$DATADIR" reload + sudo -u postgres "$PGBIN/psql" -c "create user travis superuser" fi From a7e0b6748e116da9f8e638acefd3a20011d435ae Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 15:26:35 +0100 Subject: [PATCH 06/45] Added identifier to recognize the test output file --- regress/expected/repack.out | 15 +++++++++++++++ regress/expected/repack_1.out | 15 +++++++++++++++ regress/expected/repack_2.out | 15 +++++++++++++++ regress/sql/repack.sql | 11 +++++++++++ 4 files changed, 56 insertions(+) diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 5934f65..ee0c603 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -1,3 +1,18 @@ +-- Test output file identifier. +SELECT CASE + WHEN split_part(version(), ' ', 2) ~ '^(10)' + THEN 'repack_2.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' + THEN 'repack.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' + THEN 'repack_1.out' + ELSE version() +END AS testfile; + testfile +------------ + repack.out +(1 row) + SET client_min_messages = warning; -- -- create table. diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 98360ee..83878f4 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -1,3 +1,18 @@ +-- Test output file identifier. +SELECT CASE + WHEN split_part(version(), ' ', 2) ~ '^(10)' + THEN 'repack_2.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' + THEN 'repack.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' + THEN 'repack_1.out' + ELSE version() +END AS testfile; + testfile +-------------- + repack_1.out +(1 row) + SET client_min_messages = warning; -- -- create table. diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 4bd6e89..805f980 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -1,3 +1,18 @@ +-- Test output file identifier. +SELECT CASE + WHEN split_part(version(), ' ', 2) ~ '^(10)' + THEN 'repack_2.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' + THEN 'repack.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' + THEN 'repack_1.out' + ELSE version() +END AS testfile; + testfile +-------------- + repack_2.out +(1 row) + SET client_min_messages = warning; -- -- create table. diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 9f58c09..65eea3c 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -1,3 +1,14 @@ +-- Test output file identifier. +SELECT CASE + WHEN split_part(version(), ' ', 2) ~ '^(10)' + THEN 'repack_2.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' + THEN 'repack.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' + THEN 'repack_1.out' + ELSE version() +END AS testfile; + SET client_min_messages = warning; -- -- create table. From c2ed98a85b0070d5ffc0a4a3a882f008bce6adf5 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Wed, 12 Jul 2017 17:04:33 -0700 Subject: [PATCH 07/45] Fix a small memory leak in repack_one_database function. Noticed by coverity scan. --- bin/pg_repack.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index f8988e0..46bdeb0 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -852,6 +852,7 @@ cleanup: CLEARPGRES(res); disconnect(); termStringInfo(&sql); + free(params); return ret; } From 33f4c30563197511d1a3fcefc3426df13751331a Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 02:31:47 +0900 Subject: [PATCH 08/45] Fix reorganize table without sorting. Commit 5adff6ff0b88d6f162719eff7176069730537c2a separated the data copy from creating table. This is a cause of bug that pg_repack doesn't actually sort table during reorganization. This commit fixes this issue by adding ORDER BY clause to Copy SQL rather than CREATE TABLE SQL. Reported by acmzero on issue #138. --- bin/pg_repack.c | 24 +++++++++++------ regress/expected/repack.out | 49 +++++++++++++++++++++++++++++++-- regress/expected/repack_1.out | 51 +++++++++++++++++++++++++++++++++-- regress/sql/repack.sql | 18 +++++++++++++ 4 files changed, 130 insertions(+), 12 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 46bdeb0..43e3f23 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -772,6 +772,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) for (i = 0; i < num; i++) { repack_table table; + StringInfoData copy_sql; const char *create_table_1; const char *create_table_2; const char *tablespace; @@ -814,17 +815,27 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) table.sql_pop = getstr(res, i, c++); tablespace = getstr(res, i, c++); + /* Craft CREATE TABLE SQL */ resetStringInfo(&sql); appendStringInfoString(&sql, create_table_1); appendStringInfoString(&sql, tablespace); appendStringInfoString(&sql, create_table_2); + + /* Always append WITH NOT DATA to CREATE TABLE SQL*/ + appendStringInfoString(&sql, " WITH NO DATA"); + table.create_table = sql.data; + + /* Craft Copy SQL */ + initStringInfo(©_sql); + appendStringInfoString(©_sql, table.copy_data); if (!orderby) + { if (ckey != NULL) { /* CLUSTER mode */ - appendStringInfoString(&sql, " ORDER BY "); - appendStringInfoString(&sql, ckey); + appendStringInfoString(©_sql, " ORDER BY "); + appendStringInfoString(©_sql, ckey); } /* else, VACUUM FULL mode (non-clustered tables) */ @@ -836,13 +847,10 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) else { /* User specified ORDER BY */ - appendStringInfoString(&sql, " ORDER BY "); - appendStringInfoString(&sql, orderby); + appendStringInfoString(©_sql, " ORDER BY "); + appendStringInfoString(©_sql, orderby); } - - /* Always append WITH NOT DATA */ - appendStringInfoString(&sql, " WITH NO DATA"); - table.create_table = sql.data; + table.copy_data = copy_sql.data; repack_one_table(&table, orderby); } diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 5934f65..7417f48 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -69,6 +69,7 @@ CREATE TABLE tbl_with_mod_column_storage ( c text ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -103,6 +104,10 @@ SET client_min_messages = fatal; CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); SET client_min_messages = warning; INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); +-- Insert no-ordered data +INSERT INTO tbl_order SELECT generate_series(100, 51, -1); +CLUSTER tbl_order USING tbl_order_pkey; +INSERT INTO tbl_order SELECT generate_series(50, 1, -1); -- -- before -- @@ -146,6 +151,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" -- -- after -- @@ -257,8 +263,8 @@ SET enable_indexscan = off; SELECT * FROM tbl_with_dropped_column ; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM view_for_dropped_column ORDER BY 1, 2; @@ -287,8 +293,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM tbl_with_dropped_toast; @@ -402,6 +408,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! pg_repack --dbname=contrib_regression --table=trg3 INFO: repacking table "trg3" +-- +-- Table re-organization using specific column +-- +-- reorganize table using cluster key. Sort in ascending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order +INFO: repacking table "tbl_order" +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + ctid | c +--------+---- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 + (0,6) | 6 + (0,7) | 7 + (0,8) | 8 + (0,9) | 9 + (0,10) | 10 +(10 rows) + +-- reorganize table using specific column order. Sort in descending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC" +INFO: repacking table "tbl_order" +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + ctid | c +--------+----- + (0,1) | 100 + (0,2) | 99 + (0,3) | 98 + (0,4) | 97 + (0,5) | 96 + (0,6) | 95 + (0,7) | 94 + (0,8) | 93 + (0,9) | 92 + (0,10) | 91 +(10 rows) + -- -- Dry run -- diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 98360ee..7417f48 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -69,6 +69,7 @@ CREATE TABLE tbl_with_mod_column_storage ( c text ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -103,6 +104,10 @@ SET client_min_messages = fatal; CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); SET client_min_messages = warning; INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); +-- Insert no-ordered data +INSERT INTO tbl_order SELECT generate_series(100, 51, -1); +CLUSTER tbl_order USING tbl_order_pkey; +INSERT INTO tbl_order SELECT generate_series(50, 1, -1); -- -- before -- @@ -146,6 +151,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" -- -- after -- @@ -257,8 +263,8 @@ SET enable_indexscan = off; SELECT * FROM tbl_with_dropped_column ; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM view_for_dropped_column ORDER BY 1, 2; @@ -287,8 +293,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM tbl_with_dropped_toast; @@ -402,6 +408,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! pg_repack --dbname=contrib_regression --table=trg3 INFO: repacking table "trg3" +-- +-- Table re-organization using specific column +-- +-- reorganize table using cluster key. Sort in ascending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order +INFO: repacking table "tbl_order" +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + ctid | c +--------+---- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 + (0,6) | 6 + (0,7) | 7 + (0,8) | 8 + (0,9) | 9 + (0,10) | 10 +(10 rows) + +-- reorganize table using specific column order. Sort in descending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC" +INFO: repacking table "tbl_order" +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + ctid | c +--------+----- + (0,1) | 100 + (0,2) | 99 + (0,3) | 98 + (0,4) | 97 + (0,5) | 96 + (0,6) | 95 + (0,7) | 94 + (0,8) | 93 + (0,9) | 92 + (0,10) | 91 +(10 rows) + -- -- Dry run -- @@ -451,6 +496,8 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack +LINE 1: select repack.version(), repack.version_sql() + ^ DROP ROLE IF EXISTS nosuper; -- -- exclude extension check diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 9f58c09..ce7c386 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -81,6 +81,7 @@ CREATE TABLE tbl_with_mod_column_storage ( ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -126,6 +127,10 @@ SET client_min_messages = warning; INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); +-- Insert no-ordered data +INSERT INTO tbl_order SELECT generate_series(100, 51, -1); +CLUSTER tbl_order USING tbl_order_pkey; +INSERT INTO tbl_order SELECT generate_series(50, 1, -1); -- -- before -- @@ -241,6 +246,19 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! pg_repack --dbname=contrib_regression --table=trg3 +-- +-- Table re-organization using specific column +-- + +-- reorganize table using cluster key. Sort in ascending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + +-- reorganize table using specific column order. Sort in descending order. +\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC" +SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; + + -- -- Dry run -- From f8ba09fd3107f40e8d3e63c21e6365a575102f05 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 02:49:56 +0900 Subject: [PATCH 09/45] Get rid of unnecessary lines in expected file. --- regress/expected/repack_1.out | 2 -- 1 file changed, 2 deletions(-) diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 7417f48..62fc8dd 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -496,8 +496,6 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack -LINE 1: select repack.version(), repack.version_sql() - ^ DROP ROLE IF EXISTS nosuper; -- -- exclude extension check From 34e71adbbd82191a3f179b89007f26e14e81766c Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sat, 5 Aug 2017 20:16:31 +0900 Subject: [PATCH 10/45] Fix a typo in pg_repack.c file. --- bin/pg_repack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 43e3f23..2be03cd 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -821,7 +821,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) appendStringInfoString(&sql, tablespace); appendStringInfoString(&sql, create_table_2); - /* Always append WITH NOT DATA to CREATE TABLE SQL*/ + /* Always append WITH NO DATA to CREATE TABLE SQL*/ appendStringInfoString(&sql, " WITH NO DATA"); table.create_table = sql.data; From b2be4741c933abfae1ccde453d9cc432e2549eb5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 12 Aug 2017 11:39:04 +0100 Subject: [PATCH 11/45] Preparing release 1.4.1 --- META.json | 4 ++-- doc/pg_repack.rst | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/META.json b/META.json index afb0a4b..9ab89fd 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.4.0", + "version": "1.4.1", "maintainer": [ "Beena Emerson ", "Josh Kupershmidt ", @@ -15,7 +15,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.4.0", + "version": "1.4.1", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index 0969676..c8b1492 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -466,6 +466,10 @@ Creating indexes concurrently comes with a few caveats, please see `the document Releases -------- +* pg_repack 1.4.1 + + * fixed broken ``--ordery-by`` option (issue #138) + * pg_repack 1.4 * added support for PostgreSQL 9.6, dropped support for versions before 9.1 From ea27a94578be7853f589ba81c603f5c4355cd145 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 12 Aug 2017 13:15:14 +0100 Subject: [PATCH 12/45] Typo fixed (after releasing, of course...) --- doc/pg_repack.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index c8b1492..d32a48d 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -468,7 +468,7 @@ Releases * pg_repack 1.4.1 - * fixed broken ``--ordery-by`` option (issue #138) + * fixed broken ``--order-by`` option (issue #138) * pg_repack 1.4 From 20f5bf4878317143963f6cbeadbe520b4ef4b195 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Sun, 13 Aug 2017 00:32:13 +0900 Subject: [PATCH 13/45] Update pg_repack_jp.rst for release 1.4.1. --- doc/pg_repack_jp.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index b958400..5ed4469 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -864,6 +864,12 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A リリースノート --------------- +.. * pg_repack 1.4.1 +.. * fixed broken ``--order-by`` option (issue #138) + +* pg_repack 1.4.1 + * 壊れていた ``--order-by`` オプションを修正しました (issue #138) + .. * pg_repack 1.4 .. * added support for PostgreSQL 9.6 .. * use ``AFTER`` trigger to solve concurrency problems with ``INSERT From 1b651bd3d9e4216a8b30ee9faabbcba61302481f Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 3 Jun 2017 23:53:03 -0400 Subject: [PATCH 14/45] Avoid return from lock_exclusive() while in transaction .. ..causing "ERROR: DROP INDEX CONCURRENTLY cannot run inside a transaction block" github#129 --- bin/pg_repack.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 2be03cd..0316d98 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -1780,6 +1780,7 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta { elog(WARNING, "timed out, do not cancel conflicting backends"); ret = false; + pgut_rollback(conn); break; } else From 900bb8369bd3e28d14e67f017325e1109a12418c Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 18 Aug 2017 15:13:20 +0900 Subject: [PATCH 15/45] Reset the transcation state before exiting from lock_exclusive. Previously we exited from lock_exclusive() while opening the transaction that started at beggning if --no-kill-backend option is specified. This caused that DROP INDEX CONCURRENTLY fails because it cannot be executed within a user transaction block. Fixed issue #129. --- bin/pg_repack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 0316d98..9a62a47 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -1780,7 +1780,12 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta { elog(WARNING, "timed out, do not cancel conflicting backends"); ret = false; - pgut_rollback(conn); + + /* Before exit the loop reset the transaction */ + if (start_xact) + pgut_rollback(conn); + else + pgut_command(conn, "ROLLBACK TO SAVEPOINT repack_sp1", 0, NULL); break; } else From f996fd8fb3b9b30444988d905217bbacfcc9355e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 25 Sep 2017 02:21:13 +0100 Subject: [PATCH 16/45] Allow building with PostgreSQL 10rc1 This is what we get: $ pg_config --version PostgreSQL 10rc1 --- Makefile | 4 ++-- lib/Makefile | 4 ++-- regress/Makefile | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 445575a..0962722 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,13 @@ EXTENSION = pg_repack .PHONY: dist/$(EXTENSION)-$(EXTVERSION).zip # Pull out PostgreSQL version number from pg_config -VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') +VERSION := $(shell $(PG_CONFIG) --version | sed 's/.* \([[:digit:].]\{1,\}\).*/\1/') ifeq ("$(VERSION)","") $(error pg_config not found) endif # PostgreSQL version as a number, e.g. 9.1.4 -> 901 -INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/')))) +INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/')))) # The version number of the library EXTVERSION = $(shell grep '"version":' META.json | head -1 \ diff --git a/lib/Makefile b/lib/Makefile index db2aeda..bcea169 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -9,8 +9,8 @@ PG_CONFIG ?= pg_config # version as a number, e.g. 9.1.4 -> 901 -VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') -INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/')))) +VERSION := $(shell $(PG_CONFIG) --version | sed 's/.* \([[:digit:].]\{1,\}\).*/\1/') +INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/')))) EXTENSION = pg_repack MODULE_big = $(EXTENSION) diff --git a/regress/Makefile b/regress/Makefile index 943f440..006c332 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -9,8 +9,8 @@ PG_CONFIG ?= pg_config # version as a number, e.g. 9.1.4 -> 901 -VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') -INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/' )))) +VERSION := $(shell $(PG_CONFIG) --version | sed 's/.* \([[:digit:].]\{1,\}\).*/\1/') +INTVERSION := $(shell echo $$(($$(echo $(VERSION).0 | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/')))) # From 9e4dd00415e3d126a52236c00bc98cdc9bf17bf9 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 25 Sep 2017 02:37:29 +0100 Subject: [PATCH 17/45] Dropped compiler warning Probably only raised compiling on 32 bits platforms. --- bin/pgut/pgut.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/pgut/pgut.c b/bin/pgut/pgut.c index 3a3f5ef..14ee762 100644 --- a/bin/pgut/pgut.c +++ b/bin/pgut/pgut.c @@ -449,7 +449,7 @@ prompt_for_password(void) ereport(FATAL, (errcode_errno(), errmsg("could not allocate memory (" UINT64_FORMAT " bytes): ", - (unsigned long) BUFSIZE))); + (uint64) BUFSIZE))); return buf; @@ -1325,7 +1325,7 @@ pgut_malloc(size_t size) ereport(FATAL, (errcode_errno(), errmsg("could not allocate memory (" UINT64_FORMAT " bytes): ", - (unsigned long) size))); + (uint64) size))); return ret; } @@ -1338,7 +1338,7 @@ pgut_realloc(void *p, size_t size) ereport(FATAL, (errcode_errno(), errmsg("could not re-allocate memory (" UINT64_FORMAT " bytes): ", - (unsigned long) size))); + (uint64) size))); return ret; } From d7b4e75c107390185d350b91b59dab1dde49b3db Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 25 Sep 2017 02:53:11 +0100 Subject: [PATCH 18/45] PG 10 expected test result fixed with changes added in 1.4.1 --- regress/expected/repack_2.out | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 805f980..6cee6ac 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -84,6 +84,7 @@ CREATE TABLE tbl_with_mod_column_storage ( c text ); ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN; +CREATE TABLE tbl_order (c int primary key); -- -- insert data -- @@ -118,6 +119,10 @@ SET client_min_messages = fatal; CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n); SET client_min_messages = warning; INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb'); +-- Insert no-ordered data +INSERT INTO tbl_order SELECT generate_series(100, 51, -1); +CLUSTER tbl_order USING tbl_order_pkey; +INSERT INTO tbl_order SELECT generate_series(50, 1, -1); -- -- before -- @@ -161,6 +166,7 @@ WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badin INFO: repacking table "tbl_idxopts" INFO: repacking table "tbl_with_toast" INFO: repacking table "tbl_with_mod_column_storage" +INFO: repacking table "tbl_order" -- -- after -- @@ -272,8 +278,8 @@ SET enable_indexscan = off; SELECT * FROM tbl_with_dropped_column ; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM view_for_dropped_column ORDER BY 1, 2; @@ -302,8 +308,8 @@ SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2; SELECT * FROM view_for_dropped_column; c1 | id | c2 | c3 ----+----+----+---- - c1 | 2 | c2 | c1 | 1 | c2 | + c1 | 2 | c2 | (2 rows) SELECT * FROM tbl_with_dropped_toast; @@ -417,6 +423,45 @@ CREATE TABLE trg3 (id integer PRIMARY KEY); CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); \! 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 -- From 1cb3a52ccb259f1551b1004d283062a2355b3e73 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 25 Sep 2017 03:15:58 +0100 Subject: [PATCH 19/45] Changelog updated with last developments --- doc/pg_repack.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index d32a48d..2174630 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -40,7 +40,7 @@ Requirements ------------ PostgreSQL versions - PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6 + PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 10 Disks Performing a full-table repack requires free disk space about twice as @@ -466,6 +466,12 @@ Creating indexes concurrently comes with a few caveats, please see `the document Releases -------- +* pg_repack 1.4.2 + + * added PostgreSQL 10 support (issue #120) + * fixed error DROP INDEX CONCURRENTLY cannot run inside a transaction block + (issue #129) + * pg_repack 1.4.1 * fixed broken ``--order-by`` option (issue #138) From 66f5da58c935cd1e01ea507be7780b17d5f9543a Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Mon, 25 Sep 2017 11:19:22 -0700 Subject: [PATCH 20/45] Update Japanese doc for the recent changes. --- doc/pg_repack_jp.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index 5ed4469..0c7e931 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -62,7 +62,7 @@ pg_repackでは再編成する方法として次のものが選択できます ------------ PostgreSQL versions - PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6 + PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 10 Disks Performing a full-table repack requires free disk space about twice as @@ -864,6 +864,16 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A リリースノート --------------- +.. * pg_repack 1.4.2 +.. * added PostgreSQL 10 support (issue #120) +.. * fixed error DROP INDEX CONCURRENTLY cannot run inside a transaction block + (issue #129) + +* pg_repack 1.4.2 + * PostgreSQL 10をサポートしました (issue #120) + * エラー「DROP INDEX CONCURRENTLY cannot run inside a transaction block」が発生する事象を + 修正しました (issue #129) + .. * pg_repack 1.4.1 .. * fixed broken ``--order-by`` option (issue #138) From f789bc965d9ea1949a64ba3107de2a8b86bcce7d Mon Sep 17 00:00:00 2001 From: Craig de Stigter Date: Fri, 29 Sep 2017 14:03:02 +1300 Subject: [PATCH 21/45] Clarify note about GiST indexes As per http://lists.pgfoundry.org/pipermail/reorg-general/2015-May/000306.html --- doc/pg_repack.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index 2174630..d8c1843 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -410,7 +410,7 @@ pg_repack cannot reorganize temp tables. GiST indexes ^^^^^^^^^^^^ -pg_repack cannot reorganize tables using GiST indexes. +pg_repack cannot cluster tables by GiST indexes. DDL commands ^^^^^^^^^^^^ From f690ada80f7293aef9440ec5069425e806bf3777 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Tue, 3 Oct 2017 11:51:07 -0700 Subject: [PATCH 22/45] Change to use only the characters that are printable ASCII. The regression test could fail on some environments such as where the encoding is SQL_ASCII. Fixed issue #130. --- regress/expected/repack.out | 7 ++++++- regress/expected/repack_1.out | 7 ++++++- regress/expected/repack_2.out | 7 ++++++- regress/sql/repack.sql | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 205cd1b..25d4751 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -113,7 +113,12 @@ 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. -INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), ''); +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); diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 85d665f..595aab6 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -113,7 +113,12 @@ 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. -INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), ''); +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); diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 6cee6ac..3b5d72e 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -113,7 +113,12 @@ 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. -INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), ''); +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); diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 917d79f..f79022e 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -129,7 +129,7 @@ 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. -INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), ''); +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; From 7166a0ee8cecf11bab626adcbab55fdd03da8990 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 13 Oct 2017 09:16:37 +0100 Subject: [PATCH 23/45] Preparing release 1.4.2 --- META.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/META.json b/META.json index 9ab89fd..ad0425b 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.4.1", + "version": "1.4.2", "maintainer": [ "Beena Emerson ", "Josh Kupershmidt ", @@ -15,7 +15,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.4.1", + "version": "1.4.2", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, From fdad0b87a2c61d1ff02a6c423af4545a87193a8e Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Tue, 17 Oct 2017 18:03:07 +0900 Subject: [PATCH 24/45] Fix Japanese doc. --- doc/pg_repack_jp.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index 0c7e931..f129c45 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -871,8 +871,7 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A * pg_repack 1.4.2 * PostgreSQL 10をサポートしました (issue #120) - * エラー「DROP INDEX CONCURRENTLY cannot run inside a transaction block」が発生する事象を - 修正しました (issue #129) + * エラー「DROP INDEX CONCURRENTLY cannot run inside a transaction block」が発生する事象を修正しました (issue #129) .. * pg_repack 1.4.1 .. * fixed broken ``--order-by`` option (issue #138) From 4fa4f8945ed6ef0f9122f685a5d2d63ed623fb4a Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Tue, 17 Oct 2017 12:11:28 +0900 Subject: [PATCH 25/45] Fix change logs of version 1.4.1 and 1.4.2. --- doc/pg_repack_jp.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index f129c45..7161762 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -864,12 +864,13 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A リリースノート --------------- + .. * pg_repack 1.4.2 .. * added PostgreSQL 10 support (issue #120) -.. * fixed error DROP INDEX CONCURRENTLY cannot run inside a transaction block - (issue #129) +.. * fixed error DROP INDEX CONCURRENTLY cannot run inside a transaction block (issue #129) * pg_repack 1.4.2 + * PostgreSQL 10をサポートしました (issue #120) * エラー「DROP INDEX CONCURRENTLY cannot run inside a transaction block」が発生する事象を修正しました (issue #129) @@ -877,6 +878,7 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A .. * fixed broken ``--order-by`` option (issue #138) * pg_repack 1.4.1 + * 壊れていた ``--order-by`` オプションを修正しました (issue #138) .. * pg_repack 1.4 From bf61feefc4140041bcb2a473c72d4ef67f74b2c5 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Tue, 17 Oct 2017 12:16:44 +0900 Subject: [PATCH 26/45] Fix Japanese doc. --- doc/pg_repack_jp.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index 7161762..1a5a735 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -879,7 +879,7 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A * pg_repack 1.4.1 - * 壊れていた ``--order-by`` オプションを修正しました (issue #138) + * 壊れていた ``--order-by`` オプションを修正しました (issue #138) .. * pg_repack 1.4 .. * added support for PostgreSQL 9.6 From 731c4ee405730c480d5b3bc88856e358f3d5c4f5 Mon Sep 17 00:00:00 2001 From: Alexey Bashtanov Date: Wed, 17 Jan 2018 11:09:21 +0000 Subject: [PATCH 27/45] Avoid excessive locking when table already being repacked by another instance --- lib/repack.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/repack.c b/lib/repack.c index 43f7e80..54a5ac6 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -971,11 +971,21 @@ repack_drop(PG_FUNCTION_ARGS) * which in turn, is waiting for lock on log_%u table. * * Fixes deadlock mentioned in the Github issue #55. + * + * Skip the lock if we are not going to do anything. + * Otherwise, if repack gets accidentally run twice for the same table + * at the same time, the second repack, in order to perform + * a pointless cleanup, has to wait until the first one completes. + * This adds an ACCESS EXCLUSIVE lock request into the queue + * making the table effectively inaccessible for any other backend. */ - execute_with_format( - SPI_OK_UTILITY, - "LOCK TABLE %s.%s IN ACCESS EXCLUSIVE MODE", - nspname, relname); + if (numobj > 0) + { + execute_with_format( + SPI_OK_UTILITY, + "LOCK TABLE %s.%s IN ACCESS EXCLUSIVE MODE", + nspname, relname); + } /* drop log table: must be done before dropping the pk type, * since the log table is dependent on the pk type. (That's From 2f6196d6546dc884c4b907bd80388f632ab4694f Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 9 Mar 2018 10:53:43 +0900 Subject: [PATCH 28/45] Always qualify relation names. Due to change at PostgreSQL 10.3, 9.6.8, 9.5.12, 9.4.17 and 9.3.22, relation names passed by PostgreSQL function such as pg_get_indexdef_string() are schema-qualified, which could be cause of a parse error. --- lib/repack.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/repack.c b/lib/repack.c index 43f7e80..801ff8d 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -354,11 +354,27 @@ get_relation_name(Oid relid) Oid nsp = get_rel_namespace(relid); char *nspname; + /* + * Relation names given by PostgreSQL core are always + * qualified since some minor releases. + */ +#if ((PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 100003) || \ + (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90608) || \ + (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90512) || \ + (PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90417) || \ + (PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322)) /* Qualify the name if not visible in search path */ if (RelationIsVisible(relid)) nspname = NULL; else nspname = get_namespace_name(nsp); +#else + /* Qualify the name */ + if (OidIsValid(nsp)) + nspname = get_namespace_name(nsp); + else + nspname = NULL; +#endif return quote_qualified_identifier(nspname, get_rel_name(relid)); } From a0fe223f8b59b8109b208a3ecb56dc969abb2eaa Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 9 Mar 2018 11:00:42 +0900 Subject: [PATCH 29/45] Forgot to add expected files of regression tests. --- regress/expected/repack_3.out | 600 ++++++++++++++++++++++++++++++ regress/expected/tablespace_2.out | 234 ++++++++++++ 2 files changed, 834 insertions(+) create mode 100644 regress/expected/repack_3.out create mode 100644 regress/expected/tablespace_2.out diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out new file mode 100644 index 0000000..cb1dfb3 --- /dev/null +++ b/regress/expected/repack_3.out @@ -0,0 +1,600 @@ +-- Test output file identifier. +SELECT CASE + WHEN split_part(version(), ' ', 2) ~ '^(10)' + THEN 'repack_2.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' + THEN 'repack.out' + WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' + THEN 'repack_1.out' + ELSE version() +END AS testfile; + testfile +-------------- + 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 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" +-- +-- 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 | ,") +------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + 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/tablespace_2.out b/regress/expected/tablespace_2.out new file mode 100644 index 0000000..dcc5542 --- /dev/null +++ b/regress/expected/tablespace_2.out @@ -0,0 +1,234 @@ +SET client_min_messages = warning; +-- +-- Tablespace features tests +-- +-- Note: in order to pass this test you must create a tablespace called 'testts' +-- +SELECT spcname FROM pg_tablespace WHERE spcname = 'testts'; + spcname +--------- + testts +(1 row) + +-- If the query above failed you must create the 'testts' tablespace; +CREATE TABLE testts1 (id serial primary key, data text); +CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0); +CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80); +INSERT INTO testts1 (data) values ('a'); +INSERT INTO testts1 (data) values ('b'); +INSERT INTO testts1 (data) values ('c'); +-- check the indexes definitions +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, false), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +---------------------------------------------------------------------------------------------------------- + CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default WHERE (id > 0) + CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default + CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', false), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +--------------------------------------------------------------------------------------------------- + CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo WHERE (id > 0) + CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo + CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE foo +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, true), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +--------------------------------------------------------------------------------------------------------------------- + CREATE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) TABLESPACE pg_default WHERE (id > 0) + CREATE UNIQUE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) TABLESPACE pg_default + CREATE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', true), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +-------------------------------------------------------------------------------------------------------------- + CREATE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) TABLESPACE foo WHERE (id > 0) + CREATE UNIQUE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) TABLESPACE foo + CREATE INDEX CONCURRENTLY index_OID ON public.testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE foo +(3 rows) + +-- can move the tablespace from default +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- + testts1 | testts +(1 row) + +SELECT * from testts1 order by id; + id | data +----+------ + 1 | a + 2 | b + 3 | c +(3 rows) + +-- tablespace stays where it is +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- + testts1 | testts +(1 row) + +-- can move the ts back to default +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +-- can move the table together with the indexes +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | testts + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(4 rows) + +-- can't specify --moveidx without --tablespace +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx +ERROR: cannot specify --moveidx (-S) without --tablespace (-s) +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S +ERROR: cannot specify --moveidx (-S) without --tablespace (-s) +-- not broken with order +\! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx +INFO: repacking table "testts1" +--move all indexes of the table to a tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(3 rows) + +--all indexes of tablespace remain in same tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(3 rows) + +--move all indexes of the table to pg_default +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +--move one index to a tablespace +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +--------------+--------- + testts1_pkey | testts +(1 row) + +--index tablespace stays as is +\! pg_repack --dbname=contrib_regression --index=testts1_pkey +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +--------------+--------- + testts1_pkey | testts +(1 row) + +--move index to pg_default +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +--using multiple --index option +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +------------------+--------- + testts1_pkey | testts + testts1_with_idx | testts +(2 rows) + +--using --indexes-only and --index option together +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey +ERROR: cannot specify --index (-i) and --table (-t) From 64c22ffc5f12b76b2b63c4ac3fcc588395e728d3 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 9 Mar 2018 13:43:04 +0900 Subject: [PATCH 30/45] Add expected files for regression tests. Due to compatibility break by the recent PostgreSQL core code changes we need to split expected files into each minor releases rather than each major releases. Now the mapping between PostgreSQL version and expected file is complicated as follows. * version 10 * >= 10.3 : repack_3.out, tablespace_2.out * < 10.3 : repack_2.out, tablespace.out * version 9.6 * >= 9.6.8 : repack_4.out, tablespace_2.out * < 9.6.8 : repack.out, tablespace.out * version 9.5 * >= 9.5.12 : repack_4.out, tablespace_2.out * < 9.5.12 : repack.out, tablespace_1.out * version 9.4 * >= 9.4.17 : repack_5.out, tablespace_2.out * < 9.4.17 : repack_1.out, tablespace_1.out * version 9.3 * >= 9.3.22 : repack_6.out, tablespace_3.out * < 9.3.22 : repack_1.out, tablespace_1.out * version 9.2 : repack_1.out, tablespace_1.out * version 9.1 : repack_1.out, tablespace_1.out --- lib/repack.c | 7 +- regress/expected/repack.out | 74 +++- regress/expected/repack_1.out | 74 +++- regress/expected/repack_2.out | 74 +++- regress/expected/repack_3.out | 76 +++- regress/expected/repack_4.out | 654 ++++++++++++++++++++++++++++++ regress/expected/repack_5.out | 652 +++++++++++++++++++++++++++++ regress/expected/repack_6.out | 652 +++++++++++++++++++++++++++++ regress/expected/tablespace_3.out | 234 +++++++++++ regress/sql/repack.sql | 73 +++- 10 files changed, 2518 insertions(+), 52 deletions(-) create mode 100644 regress/expected/repack_4.out create mode 100644 regress/expected/repack_5.out create mode 100644 regress/expected/repack_6.out create mode 100644 regress/expected/tablespace_3.out diff --git a/lib/repack.c b/lib/repack.c index 801ff8d..036e310 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -356,13 +356,16 @@ get_relation_name(Oid relid) /* * Relation names given by PostgreSQL core are always - * qualified since some minor releases. + * qualified since some minor releases. Note that this change + * doesn't introduce to PostgreSQL 9.2 and 9.1 releases. */ #if ((PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 100003) || \ (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90608) || \ (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90512) || \ (PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90417) || \ - (PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322)) + (PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322) || \ + (PG_VERSION_NUM >= 90200 && PG_VERSION_NUM < 90300) || \ + (PG_VERSION_NUM >= 90100 && PG_VERSION_NUM < 90200)) /* Qualify the name if not visible in search path */ if (RelationIsVisible(relid)) nspname = NULL; diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 25d4751..8001c1d 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -1,14 +1,68 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT CASE - WHEN split_part(version(), ' ', 2) ~ '^(10)' - THEN 'repack_2.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' - THEN 'repack.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' - THEN 'repack_1.out' - ELSE version() -END AS testfile; - testfile +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case ------------ repack.out (1 row) diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 595aab6..48690cb 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -1,14 +1,68 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT CASE - WHEN split_part(version(), ' ', 2) ~ '^(10)' - THEN 'repack_2.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' - THEN 'repack.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' - THEN 'repack_1.out' - ELSE version() -END AS testfile; - testfile +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case -------------- repack_1.out (1 row) diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 3b5d72e..1637dd6 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -1,14 +1,68 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT CASE - WHEN split_part(version(), ' ', 2) ~ '^(10)' - THEN 'repack_2.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' - THEN 'repack.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' - THEN 'repack_1.out' - ELSE version() -END AS testfile; - testfile +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case -------------- repack_2.out (1 row) diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index cb1dfb3..4a23973 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -1,16 +1,70 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT CASE - WHEN split_part(version(), ' ', 2) ~ '^(10)' - THEN 'repack_2.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' - THEN 'repack.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' - THEN 'repack_1.out' - ELSE version() -END AS testfile; - testfile +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case -------------- - repack_2.out + repack_3.out (1 row) SET client_min_messages = warning; diff --git a/regress/expected/repack_4.out b/regress/expected/repack_4.out new file mode 100644 index 0000000..099d1ad --- /dev/null +++ b/regress/expected/repack_4.out @@ -0,0 +1,654 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; +-- Test output file identifier. +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case +-------------- + 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" +-- +-- 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 | ,") +------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + 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 new file mode 100644 index 0000000..f266ca1 --- /dev/null +++ b/regress/expected/repack_5.out @@ -0,0 +1,652 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; +-- Test output file identifier. +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case +-------------- + 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" +-- +-- 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 | ,") +------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + 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/expected/repack_6.out b/regress/expected/repack_6.out new file mode 100644 index 0000000..eb084a1 --- /dev/null +++ b/regress/expected/repack_6.out @@ -0,0 +1,652 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; +-- Test output file identifier. +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; + case +-------------- + 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" +-- +-- 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 | ,") +------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + 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/expected/tablespace_3.out b/regress/expected/tablespace_3.out new file mode 100644 index 0000000..ef0424e --- /dev/null +++ b/regress/expected/tablespace_3.out @@ -0,0 +1,234 @@ +SET client_min_messages = warning; +-- +-- Tablespace features tests +-- +-- Note: in order to pass this test you must create a tablespace called 'testts' +-- +SELECT spcname FROM pg_tablespace WHERE spcname = 'testts'; + spcname +--------- + testts +(1 row) + +-- If the query above failed you must create the 'testts' tablespace; +CREATE TABLE testts1 (id serial primary key, data text); +CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0); +CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80); +INSERT INTO testts1 (data) values ('a'); +INSERT INTO testts1 (data) values ('b'); +INSERT INTO testts1 (data) values ('c'); +-- check the indexes definitions +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, false), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +---------------------------------------------------------------------------------- + CREATE INDEX index_OID ON repack.table_OID USING btree (id) WHERE (id > 0) + CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) + CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor=80) +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', false), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +------------------------------------------------------------------------------------------------- + CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo WHERE (id > 0) + CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo + CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor=80) TABLESPACE foo +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, true), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +-------------------------------------------------------------------------------------- + CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WHERE (id > 0) + CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) + CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor=80) +(3 rows) + +SELECT regexp_replace( + repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', true), + '_[0-9]+', '_OID', 'g') +FROM pg_index i join pg_class c ON c.oid = indexrelid +WHERE indrelid = 'testts1'::regclass ORDER BY relname; + regexp_replace +----------------------------------------------------------------------------------------------------- + CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo WHERE (id > 0) + CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo + CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor=80) TABLESPACE foo +(3 rows) + +-- can move the tablespace from default +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- + testts1 | testts +(1 row) + +SELECT * from testts1 order by id; + id | data +----+------ + 1 | a + 2 | b + 3 | c +(3 rows) + +-- tablespace stays where it is +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- + testts1 | testts +(1 row) + +-- can move the ts back to default +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +-- can move the table together with the indexes +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx +INFO: repacking table "testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | testts + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(4 rows) + +-- can't specify --moveidx without --tablespace +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx +ERROR: cannot specify --moveidx (-S) without --tablespace (-s) +\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S +ERROR: cannot specify --moveidx (-S) without --tablespace (-s) +-- not broken with order +\! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx +INFO: repacking table "testts1" +--move all indexes of the table to a tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(3 rows) + +--all indexes of tablespace remain in same tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1_partial_idx | testts + testts1_pkey | testts + testts1_with_idx | testts +(3 rows) + +--move all indexes of the table to pg_default +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default +INFO: repacking indexes of "testts1" +INFO: repacking index "public"."testts1_partial_idx" +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +--move one index to a tablespace +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +--------------+--------- + testts1_pkey | testts +(1 row) + +--index tablespace stays as is +\! pg_repack --dbname=contrib_regression --index=testts1_pkey +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +--------------+--------- + testts1_pkey | testts +(1 row) + +--move index to pg_default +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default +INFO: repacking index "public"."testts1_pkey" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------+--------- +(0 rows) + +--using multiple --index option +\! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts +INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public"."testts1_with_idx" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +------------------+--------- + testts1_pkey | testts + testts1_with_idx | testts +(2 rows) + +--using --indexes-only and --index option together +\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey +ERROR: cannot specify --index (-i) and --table (-t) diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index f79022e..3f73daf 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -1,13 +1,68 @@ +-- Setup function to get version number. +-- This function returns a value same as PG_VERSION_NUM. +CREATE OR REPLACE FUNCTION version_num() RETURNS int AS +$$ +DECLARE + version_int int[]; + version_str text; +BEGIN + SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; + IF array_length(version_int, 1) = 2 THEN -- version 10 or higher + SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; + ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower + SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; + ELSE + RAISE 'invalid version'; + END IF; + RETURN version_str::int; +END; +$$ +LANGUAGE plpgsql IMMUTABLE STRICT; + -- Test output file identifier. -SELECT CASE - WHEN split_part(version(), ' ', 2) ~ '^(10)' - THEN 'repack_2.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.6|9\.5)' - THEN 'repack.out' - WHEN split_part(version(), ' ', 2) ~ '^(9\.4|9\.3|9\.2|9\.1)' - THEN 'repack_1.out' - ELSE version() -END AS testfile; +SELECT + CASE + WHEN version_num >= 100000 THEN -- PostgreSQL 10 + CASE + WHEN version_num >= 100003 THEN + 'repack_3.out' + ELSE + 'repack_2.out' + END + WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 + CASE + WHEN version_num >= 90608 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 + CASE + WHEN version_num >= 90512 THEN + 'repack_4.out' + ELSE + 'repack.out' + END + WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 + CASE + WHEN version_num >= 90417 THEN + 'repack_5.out' + ELSE + 'repack_1.out' + END + WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 + CASE + WHEN version_num >= 90322 THEN + 'repack_5.out' + ELSE + 'repack_6.out' + END + WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 + 'repack_1.out' + WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 + 'repack_1.out' + END +FROM version_num() as version_num; SET client_min_messages = warning; -- From 2fd0eb050a2256a4454ecc48f2b23cc5551cb04b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 9 Mar 2018 13:03:36 +0000 Subject: [PATCH 31/45] A more compact way to verify the identity of the test files --- lib/pg_repack.sql.in | 24 +++++++++++ regress/expected/repack.out | 79 +++++++---------------------------- regress/expected/repack_1.out | 79 +++++++---------------------------- regress/expected/repack_2.out | 79 +++++++---------------------------- regress/expected/repack_3.out | 79 +++++++---------------------------- regress/expected/repack_4.out | 79 +++++++---------------------------- regress/expected/repack_5.out | 79 +++++++---------------------------- regress/expected/repack_6.out | 79 +++++++---------------------------- regress/sql/repack.sql | 78 +++++++--------------------------- 9 files changed, 143 insertions(+), 512 deletions(-) diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index 249547c..8a68b60 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -16,6 +16,30 @@ CREATE FUNCTION repack.version_sql() RETURNS text AS $$SELECT 'pg_repack REPACK_VERSION'::text$$ LANGUAGE SQL IMMUTABLE STRICT; +CREATE FUNCTION repack.pg_version(version_str text DEFAULT NULL) RETURNS integer +AS $$ + -- Return the server version number in a format similar to PG_VERSION_NUM. + -- Call with no argument for the server version, pass an argument for testing + select (case + when array_length(tokens, 1) = 2 then + to_char(tokens[1], 'FM00') || + '00' || to_char(tokens[2], 'FM00') + when array_length(tokens, 1) = 3 then + to_char(tokens[1], 'FM00') || + to_char(tokens[2], 'FM00') || + to_char(tokens[3], 'FM00') + else + -- This will raise an error which we can read + 'unexpected version string: ' || coalesce($1, version()) + end)::int + from ( + select string_to_array(substring( + split_part(coalesce($1, version()), ' ', 2) + from '\d+\.\d+(?:\.\d+)?'), '.')::int[] + ) as x (tokens); +$$ +LANGUAGE SQL IMMUTABLE; + CREATE AGGREGATE repack.array_accum ( sfunc = array_append, basetype = anyelement, diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 8001c1d..3306ab0 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename ------------ repack.out (1 row) diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index 48690cb..df04ca8 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_1.out (1 row) diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 1637dd6..0654079 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_2.out (1 row) diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index 4a23973..fea2c29 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_3.out (1 row) diff --git a/regress/expected/repack_4.out b/regress/expected/repack_4.out index 099d1ad..62a137e 100644 --- a/regress/expected/repack_4.out +++ b/regress/expected/repack_4.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_4.out (1 row) diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out index f266ca1..d64771f 100644 --- a/regress/expected/repack_5.out +++ b/regress/expected/repack_5.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_5.out (1 row) diff --git a/regress/expected/repack_6.out b/regress/expected/repack_6.out index eb084a1..3d57ffb 100644 --- a/regress/expected/repack_6.out +++ b/regress/expected/repack_6.out @@ -1,68 +1,19 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; - case +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 min <= repack.pg_version() and repack.pg_version() < max; + filename -------------- repack_6.out (1 row) diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index 3f73daf..cdb35bd 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -1,68 +1,18 @@ --- Setup function to get version number. --- This function returns a value same as PG_VERSION_NUM. -CREATE OR REPLACE FUNCTION version_num() RETURNS int AS -$$ -DECLARE - version_int int[]; - version_str text; -BEGIN - SELECT string_to_array(split_part(version(), ' ', 2), '.')::int[] INTO version_int; - IF array_length(version_int, 1) = 2 THEN -- version 10 or higher - SELECT to_char(version_int[1], 'FM00') || '00' || to_char(version_int[2], 'FM00') INTO version_str; - ELSIF array_length(version_int, 1) = 3 THEN --version 9.6 or lower - SELECT to_char(version_int[1], 'FM00') || to_char(version_int[2], 'FM00') || to_char(version_int[3], 'FM00') INTO version_str; - ELSE - RAISE 'invalid version'; - END IF; - RETURN version_str::int; -END; -$$ -LANGUAGE plpgsql IMMUTABLE STRICT; - -- Test output file identifier. -SELECT - CASE - WHEN version_num >= 100000 THEN -- PostgreSQL 10 - CASE - WHEN version_num >= 100003 THEN - 'repack_3.out' - ELSE - 'repack_2.out' - END - WHEN version_num >= 90600 THEN -- PostgrSQL 9.6 - CASE - WHEN version_num >= 90608 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90500 THEN -- PostgreSQL 9.5 - CASE - WHEN version_num >= 90512 THEN - 'repack_4.out' - ELSE - 'repack.out' - END - WHEN version_num >= 90400 THEN -- PostgreSQL 9.4 - CASE - WHEN version_num >= 90417 THEN - 'repack_5.out' - ELSE - 'repack_1.out' - END - WHEN version_num >= 90300 THEN -- PostgreSQL 9.3 - CASE - WHEN version_num >= 90322 THEN - 'repack_5.out' - ELSE - 'repack_6.out' - END - WHEN version_num >= 90200 THEN -- PostgreSQL 9.2 - 'repack_1.out' - WHEN version_num >= 90100 THEN -- PostgreSQL 9.1 - 'repack_1.out' - END -FROM version_num() as version_num; +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 min <= repack.pg_version() and repack.pg_version() < max; SET client_min_messages = warning; -- From 07e944d9d121b6b5ec2a8a2caa9c64a4e239257a Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 19 Mar 2018 19:06:42 +0000 Subject: [PATCH 32/45] Use the Postgres way to get the version number Unsurprisingly, there was one. --- lib/pg_repack.sql.in | 24 ------------------------ regress/expected/repack.out | 2 +- regress/expected/repack_1.out | 2 +- regress/expected/repack_2.out | 2 +- regress/expected/repack_3.out | 2 +- regress/expected/repack_4.out | 2 +- regress/expected/repack_5.out | 2 +- regress/expected/repack_6.out | 2 +- regress/sql/repack.sql | 2 +- 9 files changed, 8 insertions(+), 32 deletions(-) diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index 8a68b60..249547c 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -16,30 +16,6 @@ CREATE FUNCTION repack.version_sql() RETURNS text AS $$SELECT 'pg_repack REPACK_VERSION'::text$$ LANGUAGE SQL IMMUTABLE STRICT; -CREATE FUNCTION repack.pg_version(version_str text DEFAULT NULL) RETURNS integer -AS $$ - -- Return the server version number in a format similar to PG_VERSION_NUM. - -- Call with no argument for the server version, pass an argument for testing - select (case - when array_length(tokens, 1) = 2 then - to_char(tokens[1], 'FM00') || - '00' || to_char(tokens[2], 'FM00') - when array_length(tokens, 1) = 3 then - to_char(tokens[1], 'FM00') || - to_char(tokens[2], 'FM00') || - to_char(tokens[3], 'FM00') - else - -- This will raise an error which we can read - 'unexpected version string: ' || coalesce($1, version()) - end)::int - from ( - select string_to_array(substring( - split_part(coalesce($1, version()), ' ', 2) - from '\d+\.\d+(?:\.\d+)?'), '.')::int[] - ) as x (tokens); -$$ -LANGUAGE SQL IMMUTABLE; - CREATE AGGREGATE repack.array_accum ( sfunc = array_append, basetype = anyelement, diff --git a/regress/expected/repack.out b/regress/expected/repack.out index 3306ab0..a18c744 100644 --- a/regress/expected/repack.out +++ b/regress/expected/repack.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename ------------ repack.out diff --git a/regress/expected/repack_1.out b/regress/expected/repack_1.out index df04ca8..87cc038 100644 --- a/regress/expected/repack_1.out +++ b/regress/expected/repack_1.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_1.out diff --git a/regress/expected/repack_2.out b/regress/expected/repack_2.out index 0654079..3ceff4d 100644 --- a/regress/expected/repack_2.out +++ b/regress/expected/repack_2.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_2.out diff --git a/regress/expected/repack_3.out b/regress/expected/repack_3.out index fea2c29..a7efdf8 100644 --- a/regress/expected/repack_3.out +++ b/regress/expected/repack_3.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_3.out diff --git a/regress/expected/repack_4.out b/regress/expected/repack_4.out index 62a137e..6e868fa 100644 --- a/regress/expected/repack_4.out +++ b/regress/expected/repack_4.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_4.out diff --git a/regress/expected/repack_5.out b/regress/expected/repack_5.out index d64771f..26d02e6 100644 --- a/regress/expected/repack_5.out +++ b/regress/expected/repack_5.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_5.out diff --git a/regress/expected/repack_6.out b/regress/expected/repack_6.out index 3d57ffb..0da86a9 100644 --- a/regress/expected/repack_6.out +++ b/regress/expected/repack_6.out @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; filename -------------- repack_6.out diff --git a/regress/sql/repack.sql b/regress/sql/repack.sql index cdb35bd..cb744aa 100644 --- a/regress/sql/repack.sql +++ b/regress/sql/repack.sql @@ -12,7 +12,7 @@ select filename from (values (100000, 100003, 'repack_2.out'), (100003, 110000, 'repack_3.out') ) as x (min, max, filename) -where min <= repack.pg_version() and repack.pg_version() < max; +where current_setting('server_version_num')::int between min and max - 1; SET client_min_messages = warning; -- From c62d865c18e87d25b89067c6af0c156daf4bcc54 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 19 Mar 2018 19:39:37 +0000 Subject: [PATCH 33/45] Choose schema name visibility from running server version Guarantee the extension compiled on newer servers can be used on older ones. --- lib/repack.c | 55 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/repack.c b/lib/repack.c index 036e310..0cb5f7c 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -35,6 +35,7 @@ #include "storage/lmgr.h" #include "utils/array.h" #include "utils/builtins.h" +#include "utils/guc.h" #include "utils/lsyscache.h" #include "utils/rel.h" #include "utils/relcache.h" @@ -353,31 +354,47 @@ get_relation_name(Oid relid) { Oid nsp = get_rel_namespace(relid); char *nspname; + char *strver; + int ver; + + /* Get the version of the running server (PG_VERSION_NUM would return + * the version we compiled the extension with) */ + strver = GetConfigOptionByName("server_version_num", NULL +#if PG_VERSION_NUM >= 90600 + , false /* missing_ok */ +#endif + ); + + ver = atoi(strver); + pfree(strver); /* * Relation names given by PostgreSQL core are always * qualified since some minor releases. Note that this change - * doesn't introduce to PostgreSQL 9.2 and 9.1 releases. + * wasn't introduced in PostgreSQL 9.2 and 9.1 releases. */ -#if ((PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 100003) || \ - (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90608) || \ - (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90512) || \ - (PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90417) || \ - (PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322) || \ - (PG_VERSION_NUM >= 90200 && PG_VERSION_NUM < 90300) || \ - (PG_VERSION_NUM >= 90100 && PG_VERSION_NUM < 90200)) - /* Qualify the name if not visible in search path */ - if (RelationIsVisible(relid)) - nspname = NULL; + if ((ver >= 100000 && ver < 100003) || + (ver >= 90600 && ver < 90608) || + (ver >= 90500 && ver < 90512) || + (ver >= 90400 && ver < 90417) || + (ver >= 90300 && ver < 90322) || + (ver >= 90200 && ver < 90300) || + (ver >= 90100 && ver < 90200)) + { + /* Qualify the name if not visible in search path */ + if (RelationIsVisible(relid)) + nspname = NULL; + else + nspname = get_namespace_name(nsp); + } else - nspname = get_namespace_name(nsp); -#else - /* Qualify the name */ - if (OidIsValid(nsp)) - nspname = get_namespace_name(nsp); - else - nspname = NULL; -#endif + { + /* Always qualify the name */ + if (OidIsValid(nsp)) + nspname = get_namespace_name(nsp); + else + nspname = NULL; + } return quote_qualified_identifier(nspname, get_rel_name(relid)); } From 0cb08e5512206eb73dfd768ae258e528cc183054 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 11:37:04 +0000 Subject: [PATCH 34/45] 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 35/45] 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 36/45] 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 37/45] 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 38/45] 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; From 914537edc7827253ee2a1c4f317f6f2ceedb8ab2 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 20 Mar 2018 20:47:06 +0000 Subject: [PATCH 39/45] An attempt to restrict the search path to avoid injections An alternative way to fix #168 which is not as invasive as the changes in #171. This currently breaks the current behaviour of the program as the tables specified on command line are not found. --- bin/pgut/pgut-fe.c | 3 +++ bin/pgut/pgut.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/bin/pgut/pgut-fe.c b/bin/pgut/pgut-fe.c index 5ed4fed..2f3cba6 100644 --- a/bin/pgut/pgut-fe.c +++ b/bin/pgut/pgut-fe.c @@ -99,6 +99,9 @@ setup_workers(int num_workers) break; } + /* Hardcode a search path to avoid injections into public or pg_temp */ + pgut_command(conn, "SET search_path TO pg_catalog, pg_temp", 0, NULL); + /* Make sure each worker connection can work in non-blocking * mode. */ diff --git a/bin/pgut/pgut.c b/bin/pgut/pgut.c index 14ee762..40de8d1 100644 --- a/bin/pgut/pgut.c +++ b/bin/pgut/pgut.c @@ -504,6 +504,9 @@ pgut_connect(const char *info, YesNo prompt, int elevel) termStringInfo(&add_pass); free(passwd); + /* Hardcode a search path to avoid injections into public or pg_temp */ + pgut_command(conn, "SET search_path TO pg_catalog, pg_temp", 0, NULL); + return conn; } From 64cc2070ede65a9e64cbff8ec53682591481b962 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 6 Apr 2018 14:47:53 +0900 Subject: [PATCH 40/45] Fix the broken behavior made by restricting the search path This commit doesn't include the change of regression test files. --- bin/pg_repack.c | 11 ++++++----- lib/pg_repack.sql.in | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 9a62a47..7793f61 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -1926,6 +1926,7 @@ repack_table_indexes(PGresult *index_details) params[1] = utoa(table, buffer[1]); params[2] = tablespace; schema_name = getstr(index_details, 0, 5); + /* table_name is schema-qualified */ table_name = getstr(index_details, 0, 4); /* Keep track of which of the table's indexes we have successfully @@ -1958,7 +1959,7 @@ repack_table_indexes(PGresult *index_details) "WHERE pgc.relname = 'index_%u' " "AND nsp.nspname = $1", index); params[0] = schema_name; - elog(INFO, "repacking index \"%s\".\"%s\"", schema_name, idx_name); + elog(INFO, "repacking index \"%s\"", idx_name); res = execute(sql.data, 1, params); if (PQresultStatus(res) != PGRES_TUPLES_OK) { @@ -1990,8 +1991,8 @@ repack_table_indexes(PGresult *index_details) if (PQntuples(res) < 1) { elog(WARNING, - "unable to generate SQL to CREATE work index for %s.%s", - schema_name, getstr(index_details, i, 0)); + "unable to generate SQL to CREATE work index for %s", + getstr(index_details, i, 0)); continue; } @@ -2121,7 +2122,7 @@ repack_all_indexes(char *errbuf, size_t errsize) if (r_index.head) { appendStringInfoString(&sql, - "SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, idx.indrelid::regclass, n.nspname" + "SELECT repack.oid2text(i.oid), idx.indexrelid, idx.indisvalid, idx.indrelid, repack.oid2text(idx.indrelid), n.nspname" " FROM pg_index idx JOIN pg_class i ON i.oid = idx.indexrelid" " JOIN pg_namespace n ON n.oid = i.relnamespace" " WHERE idx.indexrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname"); @@ -2131,7 +2132,7 @@ repack_all_indexes(char *errbuf, size_t errsize) else if (table_list.head || parent_table_list.head) { appendStringInfoString(&sql, - "SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, $1::text, n.nspname" + "SELECT repack.oid2text(i.oid), idx.indexrelid, idx.indisvalid, idx.indrelid, $1::text, n.nspname" " FROM pg_index idx JOIN pg_class i ON i.oid = idx.indexrelid" " JOIN pg_namespace n ON n.oid = i.relnamespace" " WHERE idx.indrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname"); diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index 249547c..99003b6 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -23,11 +23,13 @@ CREATE AGGREGATE repack.array_accum ( initcond = '{}' ); +-- Always specify search_path to 'pg_catalog' so that we +-- always can get schema-qualified relation name CREATE FUNCTION repack.oid2text(oid) RETURNS text AS $$ SELECT textin(regclassout($1)); $$ -LANGUAGE sql STABLE STRICT; +LANGUAGE sql STABLE STRICT SET search_path to 'pg_catalog'; CREATE FUNCTION repack.get_index_columns(oid, text) RETURNS text AS $$ @@ -235,7 +237,7 @@ CREATE VIEW repack.primary_keys AS GROUP BY indrelid; CREATE VIEW repack.tables AS - SELECT R.oid::regclass AS relname, + SELECT repack.oid2text(R.oid) AS relname, R.oid AS relid, R.reltoastrelid AS reltoastrelid, CASE WHEN R.reltoastrelid = 0 THEN 0 ELSE ( From 9c1da1bff14e9c5d5b74b99345d76c9763726f9d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 19 May 2018 16:41:56 +0100 Subject: [PATCH 41/45] Fixed tests to match info messages including the public schema --- regress/expected/issue3.out | 10 ++--- regress/expected/nosuper.out | 2 +- regress/expected/nosuper_1.out | 2 +- regress/expected/repack-check.out | 70 +++++++++++++++---------------- regress/expected/repack-run.out | 24 +++++------ regress/expected/repack-run_1.out | 24 +++++------ regress/expected/tablespace.out | 38 ++++++++--------- regress/expected/tablespace_1.out | 38 ++++++++--------- regress/expected/tablespace_2.out | 38 ++++++++--------- regress/expected/tablespace_3.out | 38 ++++++++--------- 10 files changed, 142 insertions(+), 142 deletions(-) diff --git a/regress/expected/issue3.out b/regress/expected/issue3.out index ee3e9a7..edb2862 100644 --- a/regress/expected/issue3.out +++ b/regress/expected/issue3.out @@ -10,7 +10,7 @@ SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass:: (1 row) \! pg_repack --dbname=contrib_regression --table=issue3_1 -INFO: repacking table "issue3_1" +INFO: repacking table "public.issue3_1" CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); @@ -20,7 +20,7 @@ SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass:: (1 row) \! pg_repack --dbname=contrib_regression --table=issue3_2 -INFO: repacking table "issue3_2" +INFO: repacking table "public.issue3_2" CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); @@ -30,7 +30,7 @@ SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass:: (1 row) \! pg_repack --dbname=contrib_regression --table=issue3_3 -INFO: repacking table "issue3_3" +INFO: repacking table "public.issue3_3" CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); @@ -40,7 +40,7 @@ SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass:: (1 row) \! pg_repack --dbname=contrib_regression --table=issue3_4 -INFO: repacking table "issue3_4" +INFO: repacking table "public.issue3_4" CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); @@ -50,4 +50,4 @@ SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass:: (1 row) \! pg_repack --dbname=contrib_regression --table=issue3_5 -INFO: repacking table "issue3_5" +INFO: repacking table "public.issue3_5" diff --git a/regress/expected/nosuper.out b/regress/expected/nosuper.out index b16f4b1..1d2fad2 100644 --- a/regress/expected/nosuper.out +++ b/regress/expected/nosuper.out @@ -7,7 +7,7 @@ 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" +INFO: repacking table "public.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 diff --git a/regress/expected/nosuper_1.out b/regress/expected/nosuper_1.out index d227516..973ab29 100644 --- a/regress/expected/nosuper_1.out +++ b/regress/expected/nosuper_1.out @@ -7,7 +7,7 @@ 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" +INFO: repacking table "public.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 diff --git a/regress/expected/repack-check.out b/regress/expected/repack-check.out index 010c920..0da1133 100644 --- a/regress/expected/repack-check.out +++ b/regress/expected/repack-check.out @@ -141,24 +141,24 @@ CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(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: relation "public.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: relation "public.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" +INFO: repacking table "public.tbl_nn_uk" -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_pk_uk -INFO: repacking table "tbl_pk_uk" +INFO: repacking table "public.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" +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: relation "public.tbl_nn_puk" must have a primary key or not-null unique keys -- => WARNING -- -- Triggers handling @@ -169,23 +169,23 @@ 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" +INFO: repacking table "public.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" +INFO: repacking table "public.trg2" +WARNING: the table "public.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" +INFO: repacking table "public.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" +INFO: repacking table "public.tbl_order" SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; ctid | c --------+---- @@ -203,7 +203,7 @@ SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; -- reorganize table using specific column order. Sort in descending order. \! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC" -INFO: repacking table "tbl_order" +INFO: repacking table "public.tbl_order" SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; ctid | c --------+----- @@ -224,7 +224,7 @@ SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)'; -- \! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run INFO: Dry run enabled, not executing repack -INFO: repacking table "tbl_cluster" +INFO: repacking table "public.tbl_cluster" -- Test --schema -- CREATE SCHEMA test_schema1; @@ -253,7 +253,7 @@ 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" +INFO: repacking table "public.tbl_cluster" -- -- exclude extension check -- @@ -297,39 +297,39 @@ ERROR: cannot repack specific table(s) in schema, use schema.table notation inst 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" +INFO: repacking table "public.child_b_1" +INFO: repacking table "public.child_b_2" +INFO: repacking table "public.parent_a" +INFO: repacking table "public.parent_b" -- => 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" +INFO: repacking table "public.child_a_1" +INFO: repacking table "public.child_a_2" +INFO: repacking table "public.child_b_1" +INFO: repacking table "public.child_b_2" +INFO: repacking table "public.parent_a" +INFO: repacking table "public.parent_b" -- => 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 index "public.parent_a_pkey" INFO: repacking indexes of "public.child_b_1" -INFO: repacking index "public"."child_b_1_pkey" +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 index "public.child_b_2_pkey" INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" +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 index "public.child_a_1_pkey" INFO: repacking indexes of "public.child_a_2" -INFO: repacking index "public"."child_a_2_pkey" +INFO: repacking index "public.child_a_2_pkey" INFO: repacking indexes of "public.parent_a" -INFO: repacking index "public"."parent_a_pkey" +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 index "public.child_b_1_pkey" INFO: repacking indexes of "public.child_b_2" -INFO: repacking index "public"."child_b_2_pkey" +INFO: repacking index "public.child_b_2_pkey" INFO: repacking indexes of "public.parent_b" -INFO: repacking index "public"."parent_b_pkey" +INFO: repacking index "public.parent_b_pkey" diff --git a/regress/expected/repack-run.out b/regress/expected/repack-run.out index cd28202..032e47a 100644 --- a/regress/expected/repack-run.out +++ b/regress/expected/repack-run.out @@ -2,19 +2,19 @@ -- do repack -- \! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" +INFO: repacking table "public.tbl_cluster" \! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" +INFO: repacking table "public.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" +INFO: repacking table "public.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" +INFO: repacking table "public.tbl_cluster" +INFO: repacking table "public.tbl_gistkey" +INFO: repacking table "public.tbl_idxopts" +INFO: repacking table "public.tbl_only_pkey" +INFO: repacking table "public.tbl_order" +INFO: repacking table "public.tbl_with_dropped_column" +INFO: repacking table "public.tbl_with_dropped_toast" +INFO: repacking table "public.tbl_with_mod_column_storage" +INFO: repacking table "public.tbl_with_toast" diff --git a/regress/expected/repack-run_1.out b/regress/expected/repack-run_1.out index a15d6b0..54efc7b 100644 --- a/regress/expected/repack-run_1.out +++ b/regress/expected/repack-run_1.out @@ -2,19 +2,19 @@ -- do repack -- \! pg_repack --dbname=contrib_regression --table=tbl_cluster -INFO: repacking table "tbl_cluster" +INFO: repacking table "public.tbl_cluster" \! pg_repack --dbname=contrib_regression --table=tbl_badindex -INFO: repacking table "tbl_badindex" +INFO: repacking table "public.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" +INFO: repacking table "public.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" +INFO: repacking table "public.tbl_cluster" +INFO: repacking table "public.tbl_gistkey" +INFO: repacking table "public.tbl_idxopts" +INFO: repacking table "public.tbl_only_pkey" +INFO: repacking table "public.tbl_order" +INFO: repacking table "public.tbl_with_dropped_column" +INFO: repacking table "public.tbl_with_dropped_toast" +INFO: repacking table "public.tbl_with_mod_column_storage" +INFO: repacking table "public.tbl_with_toast" diff --git a/regress/expected/tablespace.out b/regress/expected/tablespace.out index d0e7e43..d41b31d 100644 --- a/regress/expected/tablespace.out +++ b/regress/expected/tablespace.out @@ -68,7 +68,7 @@ WHERE indrelid = 'testts1'::regclass ORDER BY relname; -- can move the tablespace from default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -88,7 +88,7 @@ SELECT * from testts1 order by id; -- tablespace stays where it is \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -100,7 +100,7 @@ ORDER BY relname; -- can move the ts back to default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -111,7 +111,7 @@ ORDER BY relname; -- can move the table together with the indexes \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -131,13 +131,13 @@ ERROR: cannot specify --moveidx (-S) without --tablespace (-s) ERROR: cannot specify --moveidx (-S) without --tablespace (-s) -- not broken with order \! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" --move all indexes of the table to a tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -152,9 +152,9 @@ ORDER BY relname; --all indexes of tablespace remain in same tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -169,9 +169,9 @@ ORDER BY relname; --move all indexes of the table to pg_default \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -182,7 +182,7 @@ ORDER BY relname; --move one index to a tablespace \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -194,7 +194,7 @@ ORDER BY relname; --index tablespace stays as is \! pg_repack --dbname=contrib_regression --index=testts1_pkey -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -206,7 +206,7 @@ ORDER BY relname; --move index to pg_default \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -217,8 +217,8 @@ ORDER BY relname; --using multiple --index option \! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' diff --git a/regress/expected/tablespace_1.out b/regress/expected/tablespace_1.out index 4f7456a..0256183 100644 --- a/regress/expected/tablespace_1.out +++ b/regress/expected/tablespace_1.out @@ -68,7 +68,7 @@ WHERE indrelid = 'testts1'::regclass ORDER BY relname; -- can move the tablespace from default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -88,7 +88,7 @@ SELECT * from testts1 order by id; -- tablespace stays where it is \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -100,7 +100,7 @@ ORDER BY relname; -- can move the ts back to default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -111,7 +111,7 @@ ORDER BY relname; -- can move the table together with the indexes \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -131,13 +131,13 @@ ERROR: cannot specify --moveidx (-S) without --tablespace (-s) ERROR: cannot specify --moveidx (-S) without --tablespace (-s) -- not broken with order \! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" --move all indexes of the table to a tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -152,9 +152,9 @@ ORDER BY relname; --all indexes of tablespace remain in same tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -169,9 +169,9 @@ ORDER BY relname; --move all indexes of the table to pg_default \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -182,7 +182,7 @@ ORDER BY relname; --move one index to a tablespace \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -194,7 +194,7 @@ ORDER BY relname; --index tablespace stays as is \! pg_repack --dbname=contrib_regression --index=testts1_pkey -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -206,7 +206,7 @@ ORDER BY relname; --move index to pg_default \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -217,8 +217,8 @@ ORDER BY relname; --using multiple --index option \! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' diff --git a/regress/expected/tablespace_2.out b/regress/expected/tablespace_2.out index dcc5542..e632960 100644 --- a/regress/expected/tablespace_2.out +++ b/regress/expected/tablespace_2.out @@ -68,7 +68,7 @@ WHERE indrelid = 'testts1'::regclass ORDER BY relname; -- can move the tablespace from default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -88,7 +88,7 @@ SELECT * from testts1 order by id; -- tablespace stays where it is \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -100,7 +100,7 @@ ORDER BY relname; -- can move the ts back to default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -111,7 +111,7 @@ ORDER BY relname; -- can move the table together with the indexes \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -131,13 +131,13 @@ ERROR: cannot specify --moveidx (-S) without --tablespace (-s) ERROR: cannot specify --moveidx (-S) without --tablespace (-s) -- not broken with order \! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" --move all indexes of the table to a tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -152,9 +152,9 @@ ORDER BY relname; --all indexes of tablespace remain in same tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -169,9 +169,9 @@ ORDER BY relname; --move all indexes of the table to pg_default \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -182,7 +182,7 @@ ORDER BY relname; --move one index to a tablespace \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -194,7 +194,7 @@ ORDER BY relname; --index tablespace stays as is \! pg_repack --dbname=contrib_regression --index=testts1_pkey -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -206,7 +206,7 @@ ORDER BY relname; --move index to pg_default \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -217,8 +217,8 @@ ORDER BY relname; --using multiple --index option \! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' diff --git a/regress/expected/tablespace_3.out b/regress/expected/tablespace_3.out index ef0424e..bfb9d95 100644 --- a/regress/expected/tablespace_3.out +++ b/regress/expected/tablespace_3.out @@ -68,7 +68,7 @@ WHERE indrelid = 'testts1'::regclass ORDER BY relname; -- can move the tablespace from default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -88,7 +88,7 @@ SELECT * from testts1 order by id; -- tablespace stays where it is \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -100,7 +100,7 @@ ORDER BY relname; -- can move the ts back to default \! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -111,7 +111,7 @@ ORDER BY relname; -- can move the table together with the indexes \! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -131,13 +131,13 @@ ERROR: cannot specify --moveidx (-S) without --tablespace (-s) ERROR: cannot specify --moveidx (-S) without --tablespace (-s) -- not broken with order \! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx -INFO: repacking table "testts1" +INFO: repacking table "public.testts1" --move all indexes of the table to a tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -152,9 +152,9 @@ ORDER BY relname; --all indexes of tablespace remain in same tablespace \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -169,9 +169,9 @@ ORDER BY relname; --move all indexes of the table to pg_default \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default INFO: repacking indexes of "testts1" -INFO: repacking index "public"."testts1_partial_idx" -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_partial_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -182,7 +182,7 @@ ORDER BY relname; --move one index to a tablespace \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -194,7 +194,7 @@ ORDER BY relname; --index tablespace stays as is \! pg_repack --dbname=contrib_regression --index=testts1_pkey -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -206,7 +206,7 @@ ORDER BY relname; --move index to pg_default \! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default -INFO: repacking index "public"."testts1_pkey" +INFO: repacking index "public.testts1_pkey" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' @@ -217,8 +217,8 @@ ORDER BY relname; --using multiple --index option \! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts -INFO: repacking index "public"."testts1_pkey" -INFO: repacking index "public"."testts1_with_idx" +INFO: repacking index "public.testts1_pkey" +INFO: repacking index "public.testts1_with_idx" SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' From 021d0b03933ece4c668b4bed19d2e4701d631e3c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 19 May 2018 17:08:13 +0100 Subject: [PATCH 42/45] Fixed broken library paths on recent ubuntu packages Close #179 --- bin/Makefile | 4 ++++ lib/Makefile | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index bc2f52b..2c63702 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -25,6 +25,10 @@ endif PG_LIBS = $(libpq) +# libs pgport, pgcommon moved somewhere else in some ubuntu version +# see ticket #179 +PG_LIBS += -L$(shell $(PG_CONFIG) --pkglibdir) + USE_PGXS = 1 # use pgxs if not in contrib directory PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) diff --git a/lib/Makefile b/lib/Makefile index bcea169..5730765 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -34,9 +34,7 @@ include $(PGXS) # remove dependency on libxml2, libxslt, and libpam. # XXX: find a better way to make sure we are linking with libraries # from pg_config which we actually need. -LIBS := $(filter-out -lxml2, $(LIBS)) -LIBS := $(filter-out -lxslt, $(LIBS)) -LIBS := $(filter-out -lpam, $(LIBS)) +LIBS := $(filter-out -lpam -lxml2 -lxslt, $(LIBS)) pg_repack.sql: pg_repack.sql.in echo "BEGIN;" > $@; \ From f4e010386a833c1cef9382a72cb6db307357593f Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 19 May 2018 17:27:49 +0100 Subject: [PATCH 43/45] Preparing release 1.4.3 --- META.json | 4 ++-- doc/pg_repack.rst | 7 +++++++ doc/release.rst | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/META.json b/META.json index ad0425b..1e109dd 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.4.2", + "version": "1.4.3", "maintainer": [ "Beena Emerson ", "Josh Kupershmidt ", @@ -15,7 +15,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.4.2", + "version": "1.4.3", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index d8c1843..9e26b24 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -466,6 +466,13 @@ Creating indexes concurrently comes with a few caveats, please see `the document Releases -------- +* pg_repack 1.4.3 + + * Fixed possible CVE-2018-1058 attack paths (issue #168) + * Fixed "unexpected index definition" after CVE-2018-1058 changes in + PostgreSQL (issue #169) + * Fixed build with recent Ubuntu packages (issue #179) + * pg_repack 1.4.2 * added PostgreSQL 10 support (issue #120) diff --git a/doc/release.rst b/doc/release.rst index 8e9719c..299a9cf 100644 --- a/doc/release.rst +++ b/doc/release.rst @@ -24,8 +24,8 @@ with the right privileges: contact Daniele Varrazzo to obtain them. pgxn check dist/pg_repack-$VER.zip (note that ``check`` may require the Postgres bin directory to be added to - the path; check the ``install`` log to see where ``pg_repack`` executable - was installed). + the path, e.g. ``PATH=$(pg_config --bindir):$PATH``; check the ``install`` + log to see where ``pg_repack`` executable was installed). .. __: http://pgxnclient.projects.pgfoundry.org/ From 88fe6bfa9c6094b0c2ca2d92b10622e60891a35c Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Tue, 22 May 2018 10:03:27 +0900 Subject: [PATCH 44/45] Update Japanese doc for pg_repack 1.4.3 release. --- doc/pg_repack_jp.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/pg_repack_jp.rst b/doc/pg_repack_jp.rst index 1a5a735..4f5fac6 100644 --- a/doc/pg_repack_jp.rst +++ b/doc/pg_repack_jp.rst @@ -865,6 +865,18 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A リリースノート --------------- +.. * pg_repack 1.4.3 +.. * Fixed possible CVE-2018-1058 attack paths (issue #168) +.. * Fixed "unexpected index definition" after CVE-2018-1058 changes in +.. PostgreSQL (issue #169) +.. * Fixed build with recent Ubuntu packages (issue #179) + +* pg_repack 1.4.3 + + * CVE-2018-1058を利用した攻撃の可能性を修正しました (issue #168) + * PostgreSQLでのCVE-2018-1058の修正により"unexpected index definition"エラーが発生する事象を修正しました (issue #169) + * 最近のUbuntuパッケージでビルドが失敗する事象を修正しました (issue #179) + .. * pg_repack 1.4.2 .. * added PostgreSQL 10 support (issue #120) .. * fixed error DROP INDEX CONCURRENTLY cannot run inside a transaction block (issue #129) From 705f216fcf70a7b022f8077a94f880da36cf25f5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 17 Jun 2018 20:59:13 +0100 Subject: [PATCH 45/45] Fixed docs generation with recent docutils --- doc/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 5746f34..5a179ad 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,6 +1,5 @@ RST2HTML = $(shell which rst2html || which rst2html.py) -RSTCSS = $(shell python -c 'import docutils.writers.html4css1 as m; print m.Writer.default_stylesheet_path') -RSTOPTS = --stylesheet-path=style.css,$(RSTCSS) --initial-header-level=2 +RSTOPTS = --stylesheet-path=style.css,html4css1.css --initial-header-level=2 HTML = $(patsubst %.rst,%.html,$(wildcard *.rst))