| 1 |
-- predictability |
| 2 |
SET synchronous_commit = on; |
| 3 |
DROP TABLE IF EXISTS replication_example; |
| 4 |
-- Ensure there's tables with toast datums. To do so, we dynamically |
| 5 |
-- create a function returning a large textblob. We want tables of |
| 6 |
-- different kinds: mapped catalog table, unmapped catalog table, |
| 7 |
-- shared catalog table and usertable. |
| 8 |
CREATE FUNCTION exec(text) returns void language plpgsql volatile |
| 9 |
AS $f$ |
| 10 |
BEGIN |
| 11 |
EXECUTE $1; |
| 12 |
END; |
| 13 |
$f$; |
| 14 |
CREATE ROLE regress_justforcomments NOLOGIN; |
| 15 |
SELECT exec( |
| 16 |
format($outer$CREATE FUNCTION iamalongfunction() RETURNS TEXT IMMUTABLE LANGUAGE SQL AS $f$SELECT text %L$f$$outer$, |
| 17 |
(SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50) FROM generate_series(1, 500) g(i)))); |
| 18 |
exec |
| 19 |
------ |
| 20 |
|
| 21 |
(1 row) |
| 22 |
|
| 23 |
SELECT exec( |
| 24 |
format($outer$COMMENT ON FUNCTION iamalongfunction() IS %L$outer$, |
| 25 |
iamalongfunction())); |
| 26 |
exec |
| 27 |
------ |
| 28 |
|
| 29 |
(1 row) |
| 30 |
|
| 31 |
SELECT exec( |
| 32 |
format($outer$COMMENT ON ROLE REGRESS_JUSTFORCOMMENTS IS %L$outer$, |
| 33 |
iamalongfunction())); |
| 34 |
exec |
| 35 |
------ |
| 36 |
|
| 37 |
(1 row) |
| 38 |
|
| 39 |
CREATE TABLE iamalargetable AS SELECT iamalongfunction() longfunctionoutput; |
| 40 |
-- verify toast usage |
| 41 |
SELECT pg_relation_size((SELECT reltoastrelid FROM pg_class WHERE oid = 'pg_proc'::regclass)) > 0; |
| 42 |
?column? |
| 43 |
---------- |
| 44 |
t |
| 45 |
(1 row) |
| 46 |
|
| 47 |
SELECT pg_relation_size((SELECT reltoastrelid FROM pg_class WHERE oid = 'pg_description'::regclass)) > 0; |
| 48 |
?column? |
| 49 |
---------- |
| 50 |
t |
| 51 |
(1 row) |
| 52 |
|
| 53 |
SELECT pg_relation_size((SELECT reltoastrelid FROM pg_class WHERE oid = 'pg_shdescription'::regclass)) > 0; |
| 54 |
?column? |
| 55 |
---------- |
| 56 |
t |
| 57 |
(1 row) |
| 58 |
|
| 59 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 60 |
?column? |
| 61 |
---------- |
| 62 |
init |
| 63 |
(1 row) |
| 64 |
|
| 65 |
CREATE TABLE replication_example(id SERIAL PRIMARY KEY, somedata int, text varchar(120)); |
| 66 |
INSERT INTO replication_example(somedata) VALUES (1); |
| 67 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 68 |
data |
| 69 |
---------------------------------------------------------------------------------------------------------- |
| 70 |
BEGIN |
| 71 |
table public.replication_example: INSERT: id[integer]:1 somedata[integer]:1 text[character varying]:null |
| 72 |
COMMIT |
| 73 |
(3 rows) |
| 74 |
|
| 75 |
BEGIN; |
| 76 |
INSERT INTO replication_example(somedata) VALUES (2); |
| 77 |
ALTER TABLE replication_example ADD COLUMN testcolumn1 int; |
| 78 |
INSERT INTO replication_example(somedata, testcolumn1) VALUES (3, 1); |
| 79 |
COMMIT; |
| 80 |
BEGIN; |
| 81 |
INSERT INTO replication_example(somedata) VALUES (3); |
| 82 |
ALTER TABLE replication_example ADD COLUMN testcolumn2 int; |
| 83 |
INSERT INTO replication_example(somedata, testcolumn1, testcolumn2) VALUES (4, 2, 1); |
| 84 |
COMMIT; |
| 85 |
VACUUM FULL pg_am; |
| 86 |
VACUUM FULL pg_amop; |
| 87 |
VACUUM FULL pg_proc; |
| 88 |
VACUUM FULL pg_opclass; |
| 89 |
VACUUM FULL pg_type; |
| 90 |
VACUUM FULL pg_index; |
| 91 |
VACUUM FULL pg_database; |
| 92 |
-- repeated rewrites that fail |
| 93 |
BEGIN; |
| 94 |
CLUSTER pg_class USING pg_class_oid_index; |
| 95 |
CLUSTER pg_class USING pg_class_oid_index; |
| 96 |
ROLLBACK; |
| 97 |
-- repeated rewrites that succeed |
| 98 |
BEGIN; |
| 99 |
CLUSTER pg_class USING pg_class_oid_index; |
| 100 |
CLUSTER pg_class USING pg_class_oid_index; |
| 101 |
CLUSTER pg_class USING pg_class_oid_index; |
| 102 |
COMMIT; |
| 103 |
-- repeated rewrites in different transactions |
| 104 |
VACUUM FULL pg_class; |
| 105 |
VACUUM FULL pg_class; |
| 106 |
-- reindexing of important relations / indexes |
| 107 |
REINDEX TABLE pg_class; |
| 108 |
REINDEX INDEX pg_class_oid_index; |
| 109 |
REINDEX INDEX pg_class_tblspc_relfilenode_index; |
| 110 |
INSERT INTO replication_example(somedata, testcolumn1) VALUES (5, 3); |
| 111 |
BEGIN; |
| 112 |
INSERT INTO replication_example(somedata, testcolumn1) VALUES (6, 4); |
| 113 |
ALTER TABLE replication_example ADD COLUMN testcolumn3 int; |
| 114 |
INSERT INTO replication_example(somedata, testcolumn1, testcolumn3) VALUES (7, 5, 1); |
| 115 |
COMMIT; |
| 116 |
-- make old files go away |
| 117 |
CHECKPOINT; |
| 118 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 119 |
data |
| 120 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 121 |
BEGIN |
| 122 |
table public.replication_example: INSERT: id[integer]:2 somedata[integer]:2 text[character varying]:null |
| 123 |
table public.replication_example: INSERT: id[integer]:3 somedata[integer]:3 text[character varying]:null testcolumn1[integer]:1 |
| 124 |
COMMIT |
| 125 |
BEGIN |
| 126 |
table public.replication_example: INSERT: id[integer]:4 somedata[integer]:3 text[character varying]:null testcolumn1[integer]:null |
| 127 |
table public.replication_example: INSERT: id[integer]:5 somedata[integer]:4 text[character varying]:null testcolumn1[integer]:2 testcolumn2[integer]:1 |
| 128 |
COMMIT |
| 129 |
BEGIN |
| 130 |
table public.replication_example: INSERT: id[integer]:6 somedata[integer]:5 text[character varying]:null testcolumn1[integer]:3 testcolumn2[integer]:null |
| 131 |
COMMIT |
| 132 |
BEGIN |
| 133 |
table public.replication_example: INSERT: id[integer]:7 somedata[integer]:6 text[character varying]:null testcolumn1[integer]:4 testcolumn2[integer]:null |
| 134 |
table public.replication_example: INSERT: id[integer]:8 somedata[integer]:7 text[character varying]:null testcolumn1[integer]:5 testcolumn2[integer]:null testcolumn3[integer]:1 |
| 135 |
COMMIT |
| 136 |
(15 rows) |
| 137 |
|
| 138 |
-- trigger repeated rewrites of a system catalog with a toast table, |
| 139 |
-- that previously was buggy: [email protected] |
| 140 |
VACUUM FULL pg_proc; VACUUM FULL pg_description; VACUUM FULL pg_shdescription; VACUUM FULL iamalargetable; |
| 141 |
INSERT INTO replication_example(somedata, testcolumn1, testcolumn3) VALUES (8, 6, 1); |
| 142 |
VACUUM FULL pg_proc; VACUUM FULL pg_description; VACUUM FULL pg_shdescription; VACUUM FULL iamalargetable; |
| 143 |
INSERT INTO replication_example(somedata, testcolumn1, testcolumn3) VALUES (9, 7, 1); |
| 144 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 145 |
data |
| 146 |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 147 |
BEGIN |
| 148 |
table public.replication_example: INSERT: id[integer]:9 somedata[integer]:8 text[character varying]:null testcolumn1[integer]:6 testcolumn2[integer]:null testcolumn3[integer]:1 |
| 149 |
COMMIT |
| 150 |
BEGIN |
| 151 |
table public.replication_example: INSERT: id[integer]:10 somedata[integer]:9 text[character varying]:null testcolumn1[integer]:7 testcolumn2[integer]:null testcolumn3[integer]:1 |
| 152 |
COMMIT |
| 153 |
(6 rows) |
| 154 |
|
| 155 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 156 |
pg_drop_replication_slot |
| 157 |
-------------------------- |
| 158 |
|
| 159 |
(1 row) |
| 160 |
|
| 161 |
DROP TABLE IF EXISTS replication_example; |
| 162 |
DROP FUNCTION iamalongfunction(); |
| 163 |
DROP FUNCTION exec(text); |
| 164 |
DROP ROLE regress_justforcomments; |