Merge pull request #123 from MasahikoSawada/toast_storage_param
Specify the storage option for TOAST table when create table.
This commit is contained in:
commit
4d59be0a66
@ -469,6 +469,7 @@ Releases
|
||||
* added ``--no-kill-backend`` option (issue #108)
|
||||
* added ``--no-superuser-check`` option (issue #114)
|
||||
* added ``--exclude-extension`` option (#97)
|
||||
* restore TOAST storage parameters on repacked tables (issue #10)
|
||||
* restore columns storage types in repacked tables (issue #94)
|
||||
|
||||
* pg_repack 1.3.4
|
||||
|
@ -862,6 +862,7 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A
|
||||
.. * added ``--no-kill-backend`` option (issue #108)
|
||||
.. * added ``--no-superuser-check`` option (issue #114)
|
||||
.. * added ``--exclude-extension`` option (#97)
|
||||
.. * restore TOAST storage parameters on repacked tables (issue #10)
|
||||
.. * restore columns storage types in repacked tables (issue #94)
|
||||
|
||||
* pg_repack 1.4
|
||||
@ -872,7 +873,8 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A
|
||||
* ``--no-kill-backend`` オプションを追加しました (issue #108)
|
||||
* ``--no-superuser-check`` オプションを追加しました (issue #114)
|
||||
* ``--exclude-extension`` オプションを追加しました (#97)
|
||||
* 列の格納タイプを再編成後のテーブルに再設定する様にしました (issue #94)
|
||||
* TOASTテーブルの格納オプションを再編成後のテーブルに再設定するようにしました (issue #10)
|
||||
* 列の格納タイプを再編成後のテーブルに再設定するようにしました (issue #94)
|
||||
|
||||
.. * pg_repack 1.3.4
|
||||
.. * grab exclusive lock before dropping original table (#81)
|
||||
|
@ -152,6 +152,41 @@ WHERE
|
||||
$$
|
||||
LANGUAGE sql STABLE STRICT;
|
||||
|
||||
-- Get a comma-separated storage paramter for the table including
|
||||
-- paramters for the corresponding TOAST table.
|
||||
-- Note that since oid setting is always not NULL, this function
|
||||
-- never returns NULL
|
||||
CREATE FUNCTION repack.get_storage_param(oid)
|
||||
RETURNS TEXT AS
|
||||
$$
|
||||
SELECT array_to_string(array_agg(param), ', ')
|
||||
FROM (
|
||||
-- table storage parameter
|
||||
SELECT unnest(reloptions) as param
|
||||
FROM pg_class
|
||||
WHERE oid = $1
|
||||
UNION ALL
|
||||
-- TOAST table storage parameter
|
||||
SELECT ('toast.' || unnest(reloptions)) as param
|
||||
FROM (
|
||||
SELECT reltoastrelid from pg_class where oid = $1
|
||||
) as t,
|
||||
pg_class as c
|
||||
WHERE c.oid = t.reltoastrelid
|
||||
UNION ALL
|
||||
-- table oid
|
||||
SELECT 'oids = ' ||
|
||||
CASE WHEN relhasoids
|
||||
THEN 'true'
|
||||
ELSE 'false'
|
||||
END
|
||||
FROM pg_class
|
||||
WHERE oid = $1
|
||||
|
||||
) as t
|
||||
$$
|
||||
LANGUAGE sql STABLE STRICT;
|
||||
|
||||
-- GET a SQL text to set column storage option for the table.
|
||||
CREATE FUNCTION repack.get_alter_col_storage(oid)
|
||||
RETURNS text AS
|
||||
@ -214,7 +249,7 @@ CREATE VIEW repack.tables AS
|
||||
'CREATE TABLE repack.log_' || R.oid || ' (id bigserial PRIMARY KEY, pk repack.pk_' || R.oid || ', row ' || repack.oid2text(R.oid) || ')' AS create_log,
|
||||
repack.get_create_trigger(R.oid, PK.indexrelid) AS create_trigger,
|
||||
repack.get_enable_trigger(R.oid) as enable_trigger,
|
||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || array_to_string(array_append(R.reloptions, 'oids=' || CASE WHEN R.relhasoids THEN 'true' ELSE 'false' END), ',') || ') TABLESPACE ' AS create_table_1,
|
||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || repack.get_storage_param(R.oid) || ') TABLESPACE ' AS create_table_1,
|
||||
coalesce(quote_ident(S.spcname), 'pg_default') as tablespace_orig,
|
||||
' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table_2,
|
||||
'INSERT INTO repack.table_' || R.oid || ' SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS copy_data,
|
||||
|
@ -58,6 +58,12 @@ 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
|
||||
@ -138,6 +144,7 @@ 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
|
||||
@ -293,6 +300,21 @@ SELECT * FROM tbl_with_dropped_toast;
|
||||
|
||||
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
|
||||
----------------------
|
||||
|
@ -58,6 +58,12 @@ 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
|
||||
@ -138,6 +144,7 @@ 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
|
||||
@ -293,6 +300,21 @@ SELECT * FROM tbl_with_dropped_toast;
|
||||
|
||||
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
|
||||
----------------------
|
||||
|
@ -69,6 +69,12 @@ 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
|
||||
@ -165,6 +171,15 @@ SELECT * FROM view_for_dropped_column;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
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;
|
||||
SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage';
|
||||
|
||||
--
|
||||
|
Loading…
x
Reference in New Issue
Block a user