Skip to content

Commit d64f679

Browse files
Minor cleanup in admin command (#126)
* Minor cleanup in admin command * Typo correction * fix when the admin query is ending with semicolon
1 parent cea35db commit d64f679

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

examples/docker/pgcat.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ password = "postgres"
9292
# is the sum of pool_size across all users.
9393
pool_size = 9
9494

95+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
96+
statement_timeout = 0
97+
9598
[pools.sharded.users.1]
9699
username = "postgres"
97100
password = "postgres"
98101
pool_size = 21
102+
statement_timeout = 15000
99103

100104
# Shard 0
101105
[pools.sharded.shards.0]
@@ -133,6 +137,7 @@ sharding_function = "pg_bigint_hash"
133137
username = "postgres"
134138
password = "postgres"
135139
pool_size = 5
140+
statement_timeout = 0
136141

137142
[pools.simple_db.shards.0]
138143
servers = [

pgcat.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ password = "sharding_user"
9292
# is the sum of pool_size across all users.
9393
pool_size = 9
9494

95-
# Maximum query duration. Dangerous, but protetcts against DBs that died and a non-obvious way.
95+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
9696
statement_timeout = 0
9797

9898
[pools.sharded_db.users.1]

src/admin.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,45 @@ where
4444

4545
trace!("Admin query: {}", query);
4646

47-
if query.starts_with("SHOW STATS") {
48-
trace!("SHOW STATS");
49-
show_stats(stream).await
50-
} else if query.starts_with("RELOAD") {
51-
trace!("RELOAD");
52-
reload(stream, client_server_map).await
53-
} else if query.starts_with("SHOW CONFIG") {
54-
trace!("SHOW CONFIG");
55-
show_config(stream).await
56-
} else if query.starts_with("SHOW DATABASES") {
57-
trace!("SHOW DATABASES");
58-
show_databases(stream).await
59-
} else if query.starts_with("SHOW POOLS") {
60-
trace!("SHOW POOLS");
61-
show_pools(stream).await
62-
} else if query.starts_with("SHOW LISTS") {
63-
trace!("SHOW LISTS");
64-
show_lists(stream).await
65-
} else if query.starts_with("SHOW VERSION") {
66-
trace!("SHOW VERSION");
67-
show_version(stream).await
68-
} else if query.starts_with("SET ") {
69-
trace!("SET");
70-
ignore_set(stream).await
71-
} else {
72-
error_response(stream, "Unsupported query against the admin database").await
47+
let query_parts: Vec<&str> = query.trim_end_matches(';').split_whitespace().collect();
48+
49+
match query_parts[0] {
50+
"RELOAD" => {
51+
trace!("RELOAD");
52+
reload(stream, client_server_map).await
53+
}
54+
"SET" => {
55+
trace!("SET");
56+
ignore_set(stream).await
57+
}
58+
"SHOW" => match query_parts[1] {
59+
"CONFIG" => {
60+
trace!("SHOW CONFIG");
61+
show_config(stream).await
62+
}
63+
"DATABASES" => {
64+
trace!("SHOW DATABASES");
65+
show_databases(stream).await
66+
}
67+
"LISTS" => {
68+
trace!("SHOW LISTS");
69+
show_lists(stream).await
70+
}
71+
"POOLS" => {
72+
trace!("SHOW POOLS");
73+
show_pools(stream).await
74+
}
75+
"STATS" => {
76+
trace!("SHOW STATS");
77+
show_stats(stream).await
78+
}
79+
"VERSION" => {
80+
trace!("SHOW VERSION");
81+
show_version(stream).await
82+
}
83+
_ => error_response(stream, "Unsupported SHOW query against the admin database").await,
84+
},
85+
_ => error_response(stream, "Unsupported query against the admin database").await,
7386
}
7487
}
7588

0 commit comments

Comments
 (0)