2 SET synchronous_commit = on;
4 DROP TABLE IF EXISTS xpto;
6 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
8 CREATE SEQUENCE xpto_rand_seq START 79 INCREMENT 1499; -- portable "random"
10 id serial primary key,
12 rand1 float8 DEFAULT nextval('xpto_rand_seq'),
14 rand2 float8 DEFAULT nextval('xpto_rand_seq')
17 -- uncompressed external toast data
18 INSERT INTO xpto (toasted_col1, toasted_col2) SELECT string_agg(g.i::text, ''), string_agg((g.i*2)::text, '') FROM generate_series(1, 2000) g(i);
20 -- compressed external toast data
21 INSERT INTO xpto (toasted_col2) SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50) FROM generate_series(1, 500) g(i);
23 -- update of existing column
24 UPDATE xpto SET toasted_col1 = (SELECT string_agg(g.i::text, '') FROM generate_series(1, 2000) g(i)) WHERE id = 1;
26 UPDATE xpto SET rand1 = 123.456 WHERE id = 1;
28 -- updating external via INSERT ... ON CONFLICT DO UPDATE
29 INSERT INTO xpto(id, toasted_col2) VALUES (2, 'toasted2-upsert')
31 DO UPDATE SET toasted_col2 = EXCLUDED.toasted_col2 || xpto.toasted_col2;
33 DELETE FROM xpto WHERE id = 1;
35 DROP TABLE IF EXISTS toasted_key;
36 CREATE TABLE toasted_key (
38 toasted_key text PRIMARY KEY,
43 ALTER TABLE toasted_key ALTER COLUMN toasted_key SET STORAGE EXTERNAL;
44 ALTER TABLE toasted_key ALTER COLUMN toasted_col1 SET STORAGE EXTERNAL;
46 INSERT INTO toasted_key(toasted_key, toasted_col1) VALUES(repeat('1234567890', 200), repeat('9876543210', 200));
48 -- test update of a toasted key without changing it
49 UPDATE toasted_key SET toasted_col2 = toasted_col1;
50 -- test update of a toasted key, changing it
51 UPDATE toasted_key SET toasted_key = toasted_key || '1';
53 DELETE FROM toasted_key;
55 -- Test that HEAP2_MULTI_INSERT insertions with and without toasted
56 -- columns are handled correctly
57 CREATE TABLE toasted_copy (
58 id int primary key, -- no default, copy didn't use to handle that with multi inserts
61 ALTER TABLE toasted_copy ALTER COLUMN data SET STORAGE EXTERNAL;
62 \copy toasted_copy FROM STDIN
64 2 toasted1-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
66 4 toasted2-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
263 201 toasted3-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
267 SELECT substr(data, 1, 200) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
269 -- test we can decode "old" tuples bigger than the max heap tuple size correctly
270 DROP TABLE IF EXISTS toasted_several;
271 CREATE TABLE toasted_several (
272 id serial unique not null,
273 toasted_key text primary key,
277 ALTER TABLE toasted_several REPLICA IDENTITY FULL;
278 ALTER TABLE toasted_several ALTER COLUMN toasted_key SET STORAGE EXTERNAL;
279 ALTER TABLE toasted_several ALTER COLUMN toasted_col1 SET STORAGE EXTERNAL;
280 ALTER TABLE toasted_several ALTER COLUMN toasted_col2 SET STORAGE EXTERNAL;
282 -- Change the storage of the index back to EXTENDED, separately from
283 -- the table. This is currently not doable via DDL, but it is
284 -- supported internally.
285 UPDATE pg_attribute SET attstorage = 'x' WHERE attrelid = 'toasted_several_pkey'::regclass AND attname = 'toasted_key';
287 INSERT INTO toasted_several(toasted_key) VALUES(repeat('9876543210', 10000));
288 SELECT pg_column_size(toasted_key) > 2^16 FROM toasted_several;
290 SELECT regexp_replace(data, '^(.{100}).*(.{100})$', '\1..\2') FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
292 -- test update of a toasted key without changing it
293 UPDATE toasted_several SET toasted_col1 = toasted_key;
294 UPDATE toasted_several SET toasted_col2 = toasted_col1;
296 SELECT regexp_replace(data, '^(.{100}).*(.{100})$', '\1..\2') FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
299 * update with large tuplebuf, in a transaction large enough to force to spool to disk
302 INSERT INTO toasted_several(toasted_key) SELECT * FROM generate_series(1, 10234);
303 UPDATE toasted_several SET toasted_col1 = toasted_col2 WHERE id = 1;
304 DELETE FROM toasted_several WHERE id = 1;
307 DROP TABLE toasted_several;
309 SELECT regexp_replace(data, '^(.{100}).*(.{100})$', '\1..\2') FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1')
310 WHERE data NOT LIKE '%INSERT: %';
313 * Test decoding relation rewrite with toast. The insert into tbl2 within the
314 * same transaction is there to check that there is no remaining toast_hash not
317 CREATE TABLE tbl1 (a INT, b TEXT);
318 CREATE TABLE tbl2 (a INT);
319 ALTER TABLE tbl1 ALTER COLUMN b SET STORAGE EXTERNAL;
321 INSERT INTO tbl1 VALUES(1, repeat('a', 4000)) ;
322 ALTER TABLE tbl1 ADD COLUMN id serial primary key;
323 INSERT INTO tbl2 VALUES(1);
325 SELECT substr(data, 1, 200) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
327 SELECT pg_drop_replication_slot('regression_slot');