resource-limits.td 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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-connect name=mz_system url=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  10. $ postgres-connect name=mz_analytics url=postgres://mz_analytics:materialize@${testdrive.materialize-internal-sql-addr}
  11. ! ALTER SYSTEM SET max_tables TO 42
  12. contains:permission denied to alter system
  13. $ postgres-execute connection=mz_system
  14. ALTER SYSTEM SET max_tables = 2
  15. > SHOW max_tables
  16. 2
  17. > CREATE TABLE t1 (a INT)
  18. > CREATE TABLE t2 (a INT)
  19. ! CREATE TABLE t3 (a INT)
  20. contains:creating table would violate max_tables limit (desired: 3, limit: 2, current: 2)
  21. > DROP TABLE t2;
  22. > CREATE TABLE t3 (a INT)
  23. ! CREATE TABLE t4 (a INT)
  24. contains:creating table would violate max_tables limit (desired: 3, limit: 2, current: 2)
  25. $ postgres-execute connection=mz_system
  26. ALTER SYSTEM SET max_tables = 25
  27. > SHOW max_tables
  28. 25
  29. > CREATE TABLE t4 (a INT)
  30. $ postgres-execute connection=mz_system
  31. ALTER SYSTEM SET max_objects_per_schema = 2
  32. > SHOW max_objects_per_schema
  33. 2
  34. ! CREATE TABLE t5 (a INT)
  35. contains:creating object would violate max_objects_per_schema limit (desired: 4, limit: 2, current: 3)
  36. ! CREATE VIEW v as SELECT 1
  37. contains:creating object would violate max_objects_per_schema limit (desired: 4, limit: 2, current: 3)
  38. ! CREATE INDEX ind on t1 (a)
  39. contains:creating object would violate max_objects_per_schema limit (desired: 4, limit: 2, current: 3)
  40. ! CREATE TYPE t AS (a float8)
  41. contains:creating object would violate max_objects_per_schema limit (desired: 4, limit: 2, current: 3)
  42. > CREATE SCHEMA s1;
  43. > CREATE TABLE s1.t4 (a INT)
  44. $ postgres-execute connection=mz_system
  45. ALTER SYSTEM SET max_objects_per_schema = 20
  46. > SHOW max_objects_per_schema
  47. 20
  48. > CREATE VIEW v as SELECT 1
  49. $ postgres-execute connection=mz_system
  50. ALTER SYSTEM SET max_clusters = 3
  51. > SHOW max_clusters
  52. 3
  53. > CREATE CLUSTER c1 REPLICAS (r1 (size '1'))
  54. > CREATE CLUSTER c2 REPLICAS (r (SIZE '1'));
  55. ! CREATE CLUSTER c3 REPLICAS (r (SIZE '1'));
  56. contains:creating cluster would violate max_clusters limit (desired: 4, limit: 3, current: 3)
  57. > DROP CLUSTER c2 CASCADE;
  58. > CREATE CLUSTER c3 REPLICAS (r (SIZE '1'));
  59. ! CREATE CLUSTER c4 REPLICAS (r (SIZE '1'));
  60. contains:creating cluster would violate max_clusters limit (desired: 4, limit: 3, current: 3)
  61. $ postgres-execute connection=mz_system
  62. ALTER SYSTEM SET max_clusters = 4
  63. > SHOW max_clusters
  64. 4
  65. > CREATE CLUSTER c4 REPLICAS (r (SIZE '1'));
  66. $ postgres-execute connection=mz_system
  67. ALTER SYSTEM SET max_replicas_per_cluster = 1
  68. > SHOW max_replicas_per_cluster
  69. 1
  70. ! CREATE CLUSTER REPLICA c1.r2 SIZE '1'
  71. contains:creating cluster replica would violate max_replicas_per_cluster limit (desired: 2, limit: 1, current: 1)
  72. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  73. 0
  74. $ postgres-execute connection=mz_analytics
  75. ALTER CLUSTER mz_analytics SET (REPLICATION FACTOR = 2)
  76. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  77. 2
  78. $ postgres-execute connection=mz_analytics
  79. ALTER CLUSTER mz_analytics SET (REPLICATION FACTOR = 0)
  80. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  81. 0
  82. $ postgres-execute connection=mz_system
  83. ALTER SYSTEM SET max_replicas_per_cluster = 100
  84. > SHOW max_replicas_per_cluster
  85. 100
  86. #> CREATE CLUSTER REPLICA c1.r2 SIZE '1'
  87. $ postgres-execute connection=mz_system
  88. ALTER SYSTEM SET allowed_cluster_replica_sizes = '2', 4
  89. > SHOW allowed_cluster_replica_sizes
  90. "\"2\", \"4\""
  91. $ postgres-execute connection=mz_system
  92. ALTER SYSTEM SET allowed_cluster_replica_sizes = "2, 4"
  93. > SHOW allowed_cluster_replica_sizes
  94. "\"2, 4\""
  95. $ postgres-execute connection=mz_system
  96. ALTER SYSTEM SET allowed_cluster_replica_sizes = '2, 4'
  97. > SHOW allowed_cluster_replica_sizes
  98. "\"2, 4\""
  99. ! CREATE CLUSTER REPLICA c1.r3 SIZE '1'
  100. contains:unknown cluster replica size 1
  101. $ postgres-execute connection=mz_system
  102. ALTER SYSTEM RESET allowed_cluster_replica_sizes
  103. > SHOW allowed_cluster_replica_sizes
  104. ""
  105. > CREATE CLUSTER REPLICA c1.r3 SIZE '1'
  106. > DROP CLUSTER REPLICA c1.r3
  107. $ postgres-execute connection=mz_system
  108. ALTER SYSTEM SET max_databases = 1
  109. > SHOW max_databases
  110. 1
  111. ! CREATE DATABASE d1
  112. contains:creating database would violate max_databases limit (desired: 2, limit: 1, current: 1)
  113. $ postgres-execute connection=mz_system
  114. ALTER SYSTEM SET max_databases = 42
  115. > SHOW max_databases
  116. 42
  117. > CREATE DATABASE d1
  118. $ postgres-execute connection=mz_system
  119. ALTER SYSTEM SET max_schemas_per_database = 2
  120. > SHOW max_schemas_per_database
  121. 2
  122. ! CREATE SCHEMA s2
  123. contains:creating schema would violate max_schemas_per_database limit (desired: 3, limit: 2, current: 2)
  124. > CREATE SCHEMA d1.s2
  125. $ postgres-execute connection=mz_system
  126. ALTER SYSTEM SET max_schemas_per_database = 3
  127. > SHOW max_schemas_per_database
  128. 3
  129. > CREATE SCHEMA s2
  130. $ postgres-execute connection=mz_system
  131. ALTER SYSTEM SET max_roles = 2;
  132. > SHOW max_roles
  133. 2
  134. > CREATE ROLE joe
  135. ! CREATE ROLE mike
  136. contains:creating role would violate max_roles limit (desired: 3, limit: 2, current: 2)
  137. $ postgres-execute connection=mz_system
  138. ALTER SYSTEM SET max_roles = 3;
  139. > SHOW max_roles
  140. 3
  141. > CREATE ROLE mike
  142. $ postgres-execute connection=mz_system
  143. ALTER SYSTEM SET max_secrets = 1
  144. > SHOW max_secrets
  145. 1
  146. > CREATE SECRET secret AS 'secure_password'
  147. ! CREATE SECRET password AS 'pass'
  148. contains:creating secret would violate max_secrets limit (desired: 2, limit: 1, current: 1)
  149. $ postgres-execute connection=mz_system
  150. ALTER SYSTEM SET max_secrets = 50000
  151. > SHOW max_secrets
  152. 50000
  153. > CREATE SECRET password AS 'pass'
  154. $ postgres-execute connection=mz_system
  155. ALTER SYSTEM SET max_materialized_views = 1
  156. > SHOW max_materialized_views
  157. 1
  158. > CREATE MATERIALIZED VIEW mv1 AS SELECT 1
  159. ! CREATE MATERIALIZED VIEW mv2 AS SELECT 2
  160. contains:creating materialized view would violate max_materialized_views limit (desired: 2, limit: 1, current: 1)
  161. $ postgres-execute connection=mz_system
  162. ALTER SYSTEM SET max_materialized_views = 2
  163. > SHOW max_materialized_views
  164. 2
  165. > CREATE MATERIALIZED VIEW mv2 AS SELECT 2
  166. $ postgres-execute connection=mz_system
  167. ALTER SYSTEM SET max_sources = 667
  168. > SHOW max_sources
  169. 667
  170. $ postgres-execute connection=mz_system
  171. ALTER SYSTEM SET max_sinks = 44
  172. > SHOW max_sinks
  173. 44
  174. $ postgres-execute connection=mz_system
  175. ALTER SYSTEM SET max_tables = 0
  176. > DROP TABLE t1
  177. $ postgres-execute connection=mz_system
  178. ALTER SYSTEM RESET max_tables
  179. > SHOW max_tables
  180. 200
  181. $ postgres-execute connection=mz_system
  182. ALTER SYSTEM RESET ALL
  183. > SHOW max_databases
  184. 1000
  185. > SHOW max_schemas_per_database
  186. 1000
  187. > DROP CLUSTER c1 CASCADE
  188. > DROP CLUSTER c3 CASCADE
  189. > DROP CLUSTER c4 CASCADE
  190. # Cleanup
  191. > DROP TABLE s1.t4;
  192. # Test sub-sources are excluded from source counts
  193. > DROP TABLE t3;
  194. > DROP TABLE t4;
  195. # Insert Postgres data
  196. $ postgres-execute connection=postgres://postgres:postgres@postgres
  197. ALTER USER postgres WITH replication;
  198. DROP SCHEMA IF EXISTS public CASCADE;
  199. DROP PUBLICATION IF EXISTS mz_source;
  200. CREATE SCHEMA public;
  201. CREATE TABLE t1 (a INT);
  202. ALTER TABLE t1 REPLICA IDENTITY FULL;
  203. CREATE TABLE t2 (b INT);
  204. ALTER TABLE t2 REPLICA IDENTITY FULL;
  205. CREATE TABLE t3 (c INT);
  206. ALTER TABLE t3 REPLICA IDENTITY FULL;
  207. INSERT INTO t1 VALUES (1);
  208. INSERT INTO t2 VALUES (2);
  209. INSERT INTO t3 VALUES (3);
  210. CREATE PUBLICATION mz_source FOR ALL TABLES;
  211. > CREATE SECRET pgpass AS 'postgres'
  212. > CREATE CONNECTION pg TO POSTGRES (
  213. HOST postgres,
  214. DATABASE postgres,
  215. USER postgres,
  216. PASSWORD SECRET pgpass
  217. )
  218. $ postgres-execute connection=mz_system
  219. ALTER SYSTEM SET max_sources = 2
  220. ALTER SYSTEM SET max_tables = 2
  221. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  222. > CREATE SOURCE mz_source2 FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  223. # TODO: database-issues#8556 (source limit not applied)
  224. # ! CREATE SOURCE mz_source3 FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  225. # contains:creating source would violate max_sources limit (desired: 3, limit: 2, current: 0)
  226. # Creating 3 subsources is equivalent to 3 shards
  227. > SELECT count(*) FROM mz_tables WHERE schema_id like 'u%';
  228. 0
  229. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  230. > CREATE TABLE t2 FROM SOURCE mz_source (REFERENCE t2);
  231. ! CREATE TABLE t3 FROM SOURCE mz_source (REFERENCE t3);
  232. contains:creating table would violate max_tables limit (desired: 3, limit: 2, current: 2)
  233. $ postgres-execute connection=mz_system
  234. ALTER SYSTEM SET max_sources = 3
  235. ALTER SYSTEM SET max_tables = 3
  236. > CREATE SOURCE mz_source3 FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  237. > CREATE TABLE t3 FROM SOURCE mz_source (REFERENCE t3);
  238. > SELECT * FROM t1
  239. 1
  240. > SELECT * FROM t2
  241. 2
  242. > SELECT * FROM t3
  243. 3
  244. # Insert more Postgres data
  245. $ postgres-execute connection=postgres://postgres:postgres@postgres
  246. DROP PUBLICATION IF EXISTS mz_source2;
  247. CREATE TABLE t4 (d INT);
  248. ALTER TABLE t4 REPLICA IDENTITY FULL;
  249. INSERT INTO t4 VALUES (4);
  250. CREATE PUBLICATION mz_source2 FOR TABLE t4;
  251. # Show that we're at limit
  252. # TODO: database-issues#8556 (source limit not applied)
  253. # ! CREATE SOURCE mz_source4
  254. # FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source2');
  255. # contains:creating source would violate max_sources limit (desired: 4, limit: 3, current: 3)
  256. # Show that dropping source does proper accounting
  257. > DROP SOURCE mz_source2 CASCADE
  258. > CREATE SOURCE mz_source2
  259. FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source2');
  260. # TODO: database-issues#8556 (source limit not applied)
  261. # ! CREATE SOURCE mz_source5
  262. # FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  263. # contains:creating source would violate max_sources limit (desired: 4, limit: 3, current: 3)
  264. > DROP SOURCE mz_source CASCADE;
  265. > CREATE TABLE t4 FROM SOURCE mz_source2 (REFERENCE t4);
  266. > SELECT * FROM t4
  267. 4
  268. $ postgres-execute connection=postgres://postgres:postgres@postgres
  269. ALTER PUBLICATION mz_source2 ADD TABLE t1, t2, t3;
  270. > CREATE TABLE t1 FROM SOURCE mz_source2 (REFERENCE t1);
  271. > CREATE TABLE t2 FROM SOURCE mz_source2 (REFERENCE t2);
  272. ! CREATE TABLE t3 FROM SOURCE mz_source2 (REFERENCE t3);
  273. contains:creating table would violate max_tables limit (desired: 4, limit: 3, current: 3)
  274. > DROP TABLE t1;
  275. > DROP TABLE t2;
  276. # Can add them in smaller quantities
  277. > CREATE TABLE t1 FROM SOURCE mz_source2 (REFERENCE t1);
  278. > CREATE TABLE t2 FROM SOURCE mz_source2 (REFERENCE t2);
  279. > DROP TABLE t1;
  280. > CREATE TABLE t1 FROM SOURCE mz_source2 (REFERENCE t1);
  281. ! CREATE TABLE t3 FROM SOURCE mz_source2 (REFERENCE t3);
  282. contains:creating table would violate max_tables limit (desired: 4, limit: 3, current: 3)
  283. > DROP SOURCE mz_source2 CASCADE
  284. > SHOW max_aws_privatelink_connections
  285. 0
  286. $ postgres-execute connection=mz_system
  287. ALTER SYSTEM SET max_aws_privatelink_connections = 42
  288. > SHOW max_aws_privatelink_connections
  289. 42
  290. $ postgres-execute connection=mz_system
  291. DROP CLUSTER quickstart CASCADE
  292. $ postgres-execute connection=mz_system
  293. ALTER SYSTEM SET max_replicas_per_cluster = 100
  294. $ postgres-execute connection=mz_system
  295. ALTER SYSTEM SET max_credit_consumption_rate = 3
  296. > SHOW max_credit_consumption_rate
  297. 3
  298. # Size 1 has 1 credit and size 2-1 has 2 credits
  299. > CREATE CLUSTER c1 REPLICAS (r1 (size '1'), r2 (size '2-1'))
  300. ! CREATE CLUSTER REPLICA c1.r3 SIZE '1'
  301. contains:creating cluster replica would violate max_credit_consumption_rate limit (desired: 4, limit: 3, current: 3)
  302. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  303. 0
  304. $ postgres-execute connection=mz_analytics
  305. ALTER CLUSTER mz_analytics SET (REPLICATION FACTOR = 1)
  306. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  307. 1
  308. $ postgres-execute connection=mz_analytics
  309. ALTER CLUSTER mz_analytics SET (REPLICATION FACTOR = 0)
  310. > SELECT COUNT(*) FROM mz_cluster_replicas JOIN mz_clusters ON mz_cluster_replicas.cluster_id = mz_clusters.id WHERE mz_clusters.name = 'mz_analytics'
  311. 0
  312. $ postgres-execute connection=mz_system
  313. ALTER SYSTEM SET max_credit_consumption_rate = 4.0
  314. > SHOW max_credit_consumption_rate
  315. 4.0
  316. > CREATE CLUSTER REPLICA c1.r3 SIZE '1'
  317. ! CREATE CLUSTER REPLICA c1.r4 SIZE '2-1'
  318. contains:creating cluster replica would violate max_credit_consumption_rate limit (desired: 6, limit: 4.0, current: 4)
  319. > DROP CLUSTER REPLICA c1.r2
  320. > CREATE CLUSTER REPLICA c1.r4 SIZE '2-1'
  321. > DROP CLUSTER c1 CASCADE
  322. $ postgres-execute connection=mz_system
  323. ALTER SYSTEM RESET ALL