diff --git a/src/test/regress/expected/pg_dist_database_size.out b/src/test/regress/expected/pg_dist_database_size.out index c04c3b667..f2581c953 100644 --- a/src/test/regress/expected/pg_dist_database_size.out +++ b/src/test/regress/expected/pg_dist_database_size.out @@ -8,6 +8,15 @@ -- 4. Check the size of each database. Ensure each size is distinct and that -- pg_dist_database_size returns the size from the correct node. -- 5. Release the resources. +CREATE OR REPLACE FUNCTION round_to_nearest_ten(size_in_byte BIGINT) +RETURNS INT AS $$ +DECLARE + size_in_mb INT; +BEGIN + size_in_mb := size_in_byte / 1024 / 1024; + RETURN (size_in_mb + 5) / 10 * 10; +END; +$$ LANGUAGE plpgsql; set citus.enable_create_database_propagation to true; -- Step 1 creates the databases on all nodes. create database test_group0; @@ -56,58 +65,69 @@ create table test_table2 (a int); insert into test_table2 select generate_series(1,1000000); \c - - - :master_port; \c regression; -select * from pg_dist_database; - databaseid | groupid ---------------------------------------------------------------------- - 17352 | 0 - 17353 | 14 - 17354 | 16 -(3 rows) - -- Step 4 checks the size of each database. Ensure each size is distinct and that pg_dist_database_size returns the size from the correct node. -SET client_min_messages TO DEBUG1; -select * from pg_dist_node; - nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster | metadatasynced | shouldhaveshards +-- Below queries shows the size of each database on each node. Databases with lower sizes are shell databases. +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group0'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group0'') order by groupid;'); + result --------------------------------------------------------------------- - 18 | 16 | localhost | 57638 | default | t | t | primary | default | t | t - 16 | 14 | localhost | 57637 | default | t | t | primary | default | t | t - 17 | 0 | localhost | 57636 | default | t | t | primary | default | t | f + 40 + 10 + 10 (3 rows) -select pg_size_pretty(pg_dist_database_size('test_group0')); -DEBUG: Initiating process to get the size of the local database. -Database Name: test_group0 -Server Group ID: 0 -Worker Node Name: localhost -Worker Node Port: 57636 - pg_size_pretty +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group1'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group1'') order by groupid;'); + result --------------------------------------------------------------------- - 42 MB + 10 + 40 + 10 +(3 rows) + +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group2'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group2'') order by groupid;'); + result +--------------------------------------------------------------------- + 10 + 10 + 40 +(3 rows) + +SET citus.log_remote_commands = true; +--Below queries shows the non-shell databases, which has greater size than others. +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group0') as size) as size; + case +--------------------------------------------------------------------- + CORRECT DATABASE (1 row) -select pg_size_pretty(pg_dist_database_size('test_group1')); -DEBUG: Initiating process to get the size of the remote database. -Database Name: test_group1 -Server Group ID: 14 -Worker Node Name: localhost -Worker Node Port: 57637 - pg_size_pretty +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group1') as size) as size; +NOTICE: issuing SELECT citus_internal.pg_database_size_local('test_group1') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx + case --------------------------------------------------------------------- - 42 MB + CORRECT DATABASE (1 row) -select pg_size_pretty(pg_dist_database_size('test_group2')); -DEBUG: Initiating process to get the size of the remote database. -Database Name: test_group2 -Server Group ID: 16 -Worker Node Name: localhost -Worker Node Port: 57638 - pg_size_pretty +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group2') as size) as size; +NOTICE: issuing SELECT citus_internal.pg_database_size_local('test_group2') +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx + case --------------------------------------------------------------------- - 42 MB + CORRECT DATABASE (1 row) +--release the resources and reset the parameters. RESET client_min_messages; +reset citus.log_remote_commands; +drop function round_to_nearest_ten(BIGINT); drop DATABASE test_group0; drop DATABASE test_group1; drop DATABASE test_group2; diff --git a/src/test/regress/sql/pg_dist_database_size.sql b/src/test/regress/sql/pg_dist_database_size.sql index 8992d0e47..4841df516 100644 --- a/src/test/regress/sql/pg_dist_database_size.sql +++ b/src/test/regress/sql/pg_dist_database_size.sql @@ -9,6 +9,16 @@ -- pg_dist_database_size returns the size from the correct node. -- 5. Release the resources. +CREATE OR REPLACE FUNCTION round_to_nearest_ten(size_in_byte BIGINT) +RETURNS INT AS $$ +DECLARE + size_in_mb INT; +BEGIN + size_in_mb := size_in_byte / 1024 / 1024; + RETURN (size_in_mb + 5) / 10 * 10; +END; +$$ LANGUAGE plpgsql; + set citus.enable_create_database_propagation to true; -- Step 1 creates the databases on all nodes. @@ -53,19 +63,39 @@ insert into test_table2 select generate_series(1,1000000); \c regression; -select * from pg_dist_database; + + -- Step 4 checks the size of each database. Ensure each size is distinct and that pg_dist_database_size returns the size from the correct node. -SET client_min_messages TO DEBUG1; -select * from pg_dist_node; -select pg_size_pretty(pg_dist_database_size('test_group0')); -select pg_size_pretty(pg_dist_database_size('test_group1')); +-- Below queries shows the size of each database on each node. Databases with lower sizes are shell databases. +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group0'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group0'') order by groupid;'); +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group1'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group1'') order by groupid;'); +SELECT result FROM run_command_on_all_nodes('SELECT round_to_nearest_ten(pg_database_size(''test_group2'')) FROM pg_dist_database WHERE databaseid IN (SELECT oid FROM pg_database WHERE datname = ''test_group2'') order by groupid;'); +SET citus.log_remote_commands = true; -select pg_size_pretty(pg_dist_database_size('test_group2')); +--Below queries shows the non-shell databases, which has greater size than others. +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group0') as size) as size; + +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group1') as size) as size; + +select CASE + WHEN size > 35000001 THEN 'CORRECT DATABASE' + ELSE 'SHELL DATABASE' end +from (select pg_dist_database_size('test_group2') as size) as size; + +--release the resources and reset the parameters. RESET client_min_messages; +reset citus.log_remote_commands; +drop function round_to_nearest_ten(BIGINT); drop DATABASE test_group0; drop DATABASE test_group1;