mz-setup.td 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ postgres-execute connection=postgres://postgres:postgres@postgres
  10. ALTER USER postgres WITH replication;
  11. DROP SCHEMA IF EXISTS public CASCADE;
  12. CREATE SCHEMA public;
  13. DROP PUBLICATION IF EXISTS mz_source;
  14. CREATE PUBLICATION mz_source FOR ALL TABLES;
  15. CREATE TABLE table_a (x int, y int);
  16. ALTER TABLE table_a REPLICA IDENTITY FULL;
  17. CREATE TABLE table_b (x int, y int);
  18. ALTER TABLE table_b REPLICA IDENTITY FULL;
  19. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 100);
  20. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 100);
  21. DROP PUBLICATION IF EXISTS mz_source;
  22. CREATE PUBLICATION mz_source FOR ALL TABLES;
  23. > CREATE SECRET pgpass AS 'postgres'
  24. > CREATE CONNECTION pg_conn_1 TO POSTGRES (
  25. HOST toxiproxy,
  26. PORT 5432,
  27. DATABASE postgres,
  28. USER postgres,
  29. PASSWORD SECRET pgpass
  30. )
  31. > CREATE CONNECTION pg_conn_2 TO POSTGRES (
  32. HOST toxiproxy,
  33. PORT 4432,
  34. DATABASE postgres,
  35. USER postgres,
  36. PASSWORD SECRET pgpass
  37. )
  38. > CREATE SOURCE pg_source1
  39. FROM POSTGRES CONNECTION pg_conn_1 (PUBLICATION 'mz_source');
  40. > CREATE TABLE table_a FROM SOURCE pg_source1 (REFERENCE table_a);
  41. > CREATE SOURCE pg_source2
  42. FROM POSTGRES CONNECTION pg_conn_2 (PUBLICATION 'mz_source');
  43. > CREATE TABLE table_b FROM SOURCE pg_source2 (REFERENCE table_b);
  44. > CREATE TABLE t (a int);
  45. > INSERT INTO t VALUES (1);
  46. > CREATE MATERIALIZED VIEW sum AS
  47. SELECT sum(count)
  48. FROM (
  49. SELECT count(*) FROM table_a
  50. UNION ALL SELECT count(*) FROM table_b
  51. UNION ALL SELECT count(*) FROM t
  52. ) AS x;