I would like to propose a new table level option, compress_tuple_target, which can be set independently of toast_tuple_target, and is checked while deciding whether to compress the new tuple or not.
CREATE TABLE compresstest250 (a int, b text) WITH (compress_tuple_target = 250);
CREATE TABLE compresstest2040 (a int, b text) WITH (compress_tuple_target = 2040);
-- shouldn't get compressed nor toasted
INSERT INTO compresstest250 VALUES (1, repeat('1234567890',20));
-- should get compressed, but not toasted
INSERT INTO compresstest250 VALUES (2, repeat('1234567890',30));
-- shouldn't get compressed nor toasted
INSERT INTO compresstest2040 VALUES (1, repeat('1234567890',20));
INSERT INTO compresstest2040 VALUES (2, repeat('1234567890',30));
Without this patch, the second INSERT will not compress the tuple since its length is less than the toast threshold. With the patch and after setting table level option, one can compress such tuples.