2015-02-17 22:40:26 +08:00
|
|
|
set client_min_messages to error;
|
2017-10-24 23:38:53 +08:00
|
|
|
\set VERBOSITY TERSE
|
2019-10-24 17:15:15 +08:00
|
|
|
-- Runs a query and returns whether an error was thrown
|
|
|
|
-- Useful when the error message depends on the execution plan or db settings
|
|
|
|
-- The error message outputs the extra quota, and this might depend on the database setup and version
|
|
|
|
CREATE OR REPLACE FUNCTION catch_error(query text)
|
|
|
|
RETURNS bool
|
|
|
|
AS $$
|
|
|
|
BEGIN
|
|
|
|
EXECUTE query;
|
|
|
|
RETURN FALSE;
|
|
|
|
EXCEPTION
|
|
|
|
WHEN OTHERS THEN
|
|
|
|
RETURN TRUE;
|
|
|
|
END
|
|
|
|
$$ LANGUAGE 'plpgsql';
|
2015-02-17 22:40:26 +08:00
|
|
|
|
2014-05-08 23:14:06 +08:00
|
|
|
CREATE TABLE big(a int);
|
2014-05-09 18:55:41 +08:00
|
|
|
-- Try the legacy interface
|
|
|
|
-- See https://github.com/CartoDB/cartodb-postgresql/issues/13
|
|
|
|
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
|
2019-10-23 22:49:57 +08:00
|
|
|
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
|
2014-05-09 18:55:41 +08:00
|
|
|
INSERT INTO big VALUES (1); -- allowed, check runs before
|
2019-10-24 17:15:15 +08:00
|
|
|
SELECT 'excess1', catch_error($$INSERT INTO big VALUES (2); $$); -- disallowed, quota exceeds before
|
2019-10-23 22:49:57 +08:00
|
|
|
SELECT cartodb.CDB_SetUserQuotaInBytes(0);
|
|
|
|
SELECT cartodb.CDB_CartodbfyTable('big');
|
|
|
|
-- Creating the trigger should fail as it was created by CDB_CartodbfyTable
|
|
|
|
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
|
|
|
|
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
|
|
|
|
-- Drop the trigger and recreate it forcing a 100% checks
|
|
|
|
DROP TRIGGER test_quota ON big;
|
|
|
|
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
|
|
|
|
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
|
2015-08-14 06:59:45 +08:00
|
|
|
INSERT INTO big SELECT generate_series(2049,4096);
|
|
|
|
INSERT INTO big SELECT generate_series(4097,6144);
|
|
|
|
INSERT INTO big SELECT generate_series(6145,8192);
|
2015-08-13 19:23:35 +08:00
|
|
|
-- Test for #108: https://github.com/CartoDB/cartodb-postgresql/issues/108
|
2019-10-24 17:15:15 +08:00
|
|
|
SELECT cartodb.CDB_UserDataSize() < 500000 AND cartodb.CDB_UserDataSize() > 0;
|
|
|
|
SELECT cartodb._CDB_total_relation_size('public', 'big') < 1000000;
|
2015-08-13 19:23:35 +08:00
|
|
|
SELECT cartodb._CDB_total_relation_size('public', 'nonexistent_table_name');
|
|
|
|
-- END Test for #108
|
2019-10-24 17:15:15 +08:00
|
|
|
|
2019-10-23 22:49:57 +08:00
|
|
|
SELECT cartodb.CDB_SetUserQuotaInBytes(2);
|
2019-10-24 17:15:15 +08:00
|
|
|
SELECT 'excess2', catch_error($$INSERT INTO big VALUES (8193);$$);
|
2019-10-23 22:49:57 +08:00
|
|
|
SELECT cartodb.CDB_SetUserQuotaInBytes(0);
|
2015-08-14 06:59:45 +08:00
|
|
|
INSERT INTO big VALUES (8194);
|
2014-05-08 23:14:06 +08:00
|
|
|
DROP TABLE big;
|
2016-10-14 16:56:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
--analysis tables should be excluded from quota:
|
|
|
|
CREATE TABLE big(a int);
|
|
|
|
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
|
2019-10-23 22:49:57 +08:00
|
|
|
EXECUTE PROCEDURE cartodb.CDB_CheckQuota(2, 1, 'public');
|
|
|
|
SELECT cartodb.CDB_SetUserQuotaInBytes(1);
|
2016-10-14 16:56:14 +08:00
|
|
|
CREATE TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id int);
|
|
|
|
INSERT INTO analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id) VALUES (1),(2),(3),(4),(5);
|
|
|
|
INSERT INTO big VALUES (1); -- allowed, check runs before
|
|
|
|
DROP TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4;
|
2019-10-24 17:15:15 +08:00
|
|
|
SELECT 'excess3', catch_error($$INSERT INTO big VALUES (3);$$); -- disallowed, quota exceeds before
|
2016-10-14 16:56:14 +08:00
|
|
|
DROP TABLE big;
|
|
|
|
SELECT CDB_SetUserQuotaInBytes(0);
|
|
|
|
|
2019-12-24 21:14:26 +08:00
|
|
|
CREATE SCHEMA "complex-name%_with'quotes""";
|
|
|
|
SELECT CDB_UserDataSize('"complex-name%_with''quotes"');
|
|
|
|
DROP SCHEMA "complex-name%_with'quotes""";
|
2016-10-14 16:56:14 +08:00
|
|
|
|
2014-05-08 23:14:06 +08:00
|
|
|
set client_min_messages to NOTICE;
|
2019-10-24 17:15:15 +08:00
|
|
|
DROP FUNCTION catch_error(text);
|
2014-05-12 19:07:47 +08:00
|
|
|
DROP FUNCTION _CDB_UserQuotaInBytes();
|