mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-27 02:36:29 +00:00
Fix local dev (#112)
* Fix Dev env * Update tests/sharding/query_routing_setup.sql * Update tests/sharding/query_routing_setup.sql * bring pgcat.toml on ci and local dev to parity * more parity * pool names * pool names * less diff * fix tests * fmt * add other user to setup Co-authored-by: Lev Kokotov <levkk@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b79f55abd6
commit
106ebee71c
@@ -35,7 +35,7 @@ admin_password = "admin_pass"
|
|||||||
# pool
|
# pool
|
||||||
# configs are structured as pool.<pool_name>
|
# configs are structured as pool.<pool_name>
|
||||||
# the pool_name is what clients use as database name when connecting
|
# the pool_name is what clients use as database name when connecting
|
||||||
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
|
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
|
||||||
[pools.sharded_db]
|
[pools.sharded_db]
|
||||||
# Pool mode (see PgBouncer docs for more).
|
# Pool mode (see PgBouncer docs for more).
|
||||||
# session: one server connection per connected client
|
# session: one server connection per connected client
|
||||||
@@ -80,6 +80,11 @@ password = "sharding_user"
|
|||||||
# is the sum of pool_size across all users.
|
# is the sum of pool_size across all users.
|
||||||
pool_size = 9
|
pool_size = 9
|
||||||
|
|
||||||
|
[pools.sharded_db.users.1]
|
||||||
|
username = "other_user"
|
||||||
|
password = "other_user"
|
||||||
|
pool_size = 21
|
||||||
|
|
||||||
# Shard 0
|
# Shard 0
|
||||||
[pools.sharded_db.shards.0]
|
[pools.sharded_db.shards.0]
|
||||||
# [ host, port, role ]
|
# [ host, port, role ]
|
||||||
@@ -103,3 +108,23 @@ servers = [
|
|||||||
[ "localhost", 5432, "replica" ],
|
[ "localhost", 5432, "replica" ],
|
||||||
]
|
]
|
||||||
database = "shard2"
|
database = "shard2"
|
||||||
|
|
||||||
|
|
||||||
|
[pools.simple_db]
|
||||||
|
pool_mode = "session"
|
||||||
|
default_role = "primary"
|
||||||
|
query_parser_enabled = true
|
||||||
|
primary_reads_enabled = true
|
||||||
|
sharding_function = "pg_bigint_hash"
|
||||||
|
|
||||||
|
[pools.simple_db.users.0]
|
||||||
|
username = "simple_user"
|
||||||
|
password = "simple_user"
|
||||||
|
pool_size = 5
|
||||||
|
|
||||||
|
[pools.simple_db.shards.0]
|
||||||
|
servers = [
|
||||||
|
[ "127.0.0.1", 5432, "primary" ],
|
||||||
|
[ "localhost", 5432, "replica" ]
|
||||||
|
]
|
||||||
|
database = "some_db"
|
||||||
|
|||||||
20
pgcat.toml
20
pgcat.toml
@@ -14,7 +14,7 @@ port = 6432
|
|||||||
# How long to wait before aborting a server connection (ms).
|
# How long to wait before aborting a server connection (ms).
|
||||||
connect_timeout = 5000
|
connect_timeout = 5000
|
||||||
|
|
||||||
# How much time to give `SELECT 1` health check query to return with a result (ms).
|
# How much time to give the health check query to return with a result (ms).
|
||||||
healthcheck_timeout = 1000
|
healthcheck_timeout = 1000
|
||||||
|
|
||||||
# For how long to ban a server if it fails a health check (seconds).
|
# For how long to ban a server if it fails a health check (seconds).
|
||||||
@@ -29,14 +29,14 @@ autoreload = false
|
|||||||
|
|
||||||
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
|
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
|
||||||
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
|
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
|
||||||
admin_username = "user"
|
admin_username = "admin_user"
|
||||||
admin_password = "pass"
|
admin_password = "admin_pass"
|
||||||
|
|
||||||
# pool
|
# pool
|
||||||
# configs are structured as pool.<pool_name>
|
# configs are structured as pool.<pool_name>
|
||||||
# the pool_name is what clients use as database name when connecting
|
# the pool_name is what clients use as database name when connecting
|
||||||
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
|
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
|
||||||
[pools.sharded]
|
[pools.sharded_db]
|
||||||
# Pool mode (see PgBouncer docs for more).
|
# Pool mode (see PgBouncer docs for more).
|
||||||
# session: one server connection per connected client
|
# session: one server connection per connected client
|
||||||
# transaction: one server connection per client transaction
|
# transaction: one server connection per client transaction
|
||||||
@@ -72,7 +72,7 @@ primary_reads_enabled = true
|
|||||||
sharding_function = "pg_bigint_hash"
|
sharding_function = "pg_bigint_hash"
|
||||||
|
|
||||||
# Credentials for users that may connect to this cluster
|
# Credentials for users that may connect to this cluster
|
||||||
[pools.sharded.users.0]
|
[pools.sharded_db.users.0]
|
||||||
username = "sharding_user"
|
username = "sharding_user"
|
||||||
password = "sharding_user"
|
password = "sharding_user"
|
||||||
# Maximum number of server connections that can be established for this user
|
# Maximum number of server connections that can be established for this user
|
||||||
@@ -80,13 +80,13 @@ password = "sharding_user"
|
|||||||
# is the sum of pool_size across all users.
|
# is the sum of pool_size across all users.
|
||||||
pool_size = 9
|
pool_size = 9
|
||||||
|
|
||||||
[pools.sharded.users.1]
|
[pools.sharded_db.users.1]
|
||||||
username = "other_user"
|
username = "other_user"
|
||||||
password = "other_user"
|
password = "other_user"
|
||||||
pool_size = 21
|
pool_size = 21
|
||||||
|
|
||||||
# Shard 0
|
# Shard 0
|
||||||
[pools.sharded.shards.0]
|
[pools.sharded_db.shards.0]
|
||||||
# [ host, port, role ]
|
# [ host, port, role ]
|
||||||
servers = [
|
servers = [
|
||||||
[ "127.0.0.1", 5432, "primary" ],
|
[ "127.0.0.1", 5432, "primary" ],
|
||||||
@@ -95,14 +95,14 @@ servers = [
|
|||||||
# Database name (e.g. "postgres")
|
# Database name (e.g. "postgres")
|
||||||
database = "shard0"
|
database = "shard0"
|
||||||
|
|
||||||
[pools.sharded.shards.1]
|
[pools.sharded_db.shards.1]
|
||||||
servers = [
|
servers = [
|
||||||
[ "127.0.0.1", 5432, "primary" ],
|
[ "127.0.0.1", 5432, "primary" ],
|
||||||
[ "localhost", 5432, "replica" ],
|
[ "localhost", 5432, "replica" ],
|
||||||
]
|
]
|
||||||
database = "shard1"
|
database = "shard1"
|
||||||
|
|
||||||
[pools.sharded.shards.2]
|
[pools.sharded_db.shards.2]
|
||||||
servers = [
|
servers = [
|
||||||
[ "127.0.0.1", 5432, "primary" ],
|
[ "127.0.0.1", 5432, "primary" ],
|
||||||
[ "localhost", 5432, "replica" ],
|
[ "localhost", 5432, "replica" ],
|
||||||
|
|||||||
@@ -521,30 +521,33 @@ mod test {
|
|||||||
|
|
||||||
assert_eq!(get_config().general.ban_time, 60);
|
assert_eq!(get_config().general.ban_time, 60);
|
||||||
assert_eq!(get_config().pools.len(), 2);
|
assert_eq!(get_config().pools.len(), 2);
|
||||||
assert_eq!(get_config().pools["sharded"].shards.len(), 3);
|
assert_eq!(get_config().pools["sharded_db"].shards.len(), 3);
|
||||||
assert_eq!(get_config().pools["simple_db"].shards.len(), 1);
|
assert_eq!(get_config().pools["simple_db"].shards.len(), 1);
|
||||||
assert_eq!(get_config().pools["sharded"].users.len(), 2);
|
assert_eq!(get_config().pools["sharded_db"].users.len(), 2);
|
||||||
assert_eq!(get_config().pools["simple_db"].users.len(), 1);
|
assert_eq!(get_config().pools["simple_db"].users.len(), 1);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_config().pools["sharded"].shards["0"].servers[0].0,
|
get_config().pools["sharded_db"].shards["0"].servers[0].0,
|
||||||
"127.0.0.1"
|
"127.0.0.1"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_config().pools["sharded"].shards["1"].servers[0].2,
|
get_config().pools["sharded_db"].shards["1"].servers[0].2,
|
||||||
"primary"
|
"primary"
|
||||||
);
|
);
|
||||||
assert_eq!(get_config().pools["sharded"].shards["1"].database, "shard1");
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_config().pools["sharded"].users["0"].username,
|
get_config().pools["sharded_db"].shards["1"].database,
|
||||||
|
"shard1"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
get_config().pools["sharded_db"].users["0"].username,
|
||||||
"sharding_user"
|
"sharding_user"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_config().pools["sharded"].users["1"].password,
|
get_config().pools["sharded_db"].users["1"].password,
|
||||||
"other_user"
|
"other_user"
|
||||||
);
|
);
|
||||||
assert_eq!(get_config().pools["sharded"].users["1"].pool_size, 21);
|
assert_eq!(get_config().pools["sharded_db"].users["1"].pool_size, 21);
|
||||||
assert_eq!(get_config().pools["sharded"].default_role, "any");
|
assert_eq!(get_config().pools["sharded_db"].default_role, "any");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_config().pools["simple_db"].shards["0"].servers[0].0,
|
get_config().pools["simple_db"].shards["0"].servers[0].0,
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
|
||||||
DROP DATABASE IF EXISTS shard0;
|
DROP DATABASE IF EXISTS shard0;
|
||||||
DROP DATABASE IF EXISTS shard1;
|
DROP DATABASE IF EXISTS shard1;
|
||||||
DROP DATABASE IF EXISTS shard2;
|
DROP DATABASE IF EXISTS shard2;
|
||||||
|
DROP DATABASE IF EXISTS some_db;
|
||||||
|
|
||||||
CREATE DATABASE shard0;
|
CREATE DATABASE shard0;
|
||||||
CREATE DATABASE shard1;
|
CREATE DATABASE shard1;
|
||||||
CREATE DATABASE shard2;
|
CREATE DATABASE shard2;
|
||||||
|
CREATE DATABASE some_db;
|
||||||
|
|
||||||
\c shard0
|
\c shard0
|
||||||
|
|
||||||
@@ -41,21 +42,51 @@ CREATE TABLE data (
|
|||||||
|
|
||||||
CREATE TABLE data_shard_2 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 2);
|
CREATE TABLE data_shard_2 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 2);
|
||||||
|
|
||||||
DROP ROLE IF EXISTS sharding_user;
|
|
||||||
CREATE ROLE sharding_user ENCRYPTED PASSWORD 'sharding_user' LOGIN;
|
|
||||||
|
|
||||||
GRANT CONNECT ON DATABASE shard0 TO sharding_user;
|
\c some_db
|
||||||
GRANT CONNECT ON DATABASE shard1 TO sharding_user;
|
|
||||||
GRANT CONNECT ON DATABASE shard2 TO sharding_user;
|
DROP TABLE IF EXISTS data CASCADE;
|
||||||
|
|
||||||
|
CREATE TABLE data (
|
||||||
|
id BIGINT,
|
||||||
|
value VARCHAR
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP ROLE IF EXISTS sharding_user;
|
||||||
|
DROP ROLE IF EXISTS other_user;
|
||||||
|
DROP ROLE IF EXISTS simple_user;
|
||||||
|
CREATE ROLE sharding_user ENCRYPTED PASSWORD 'sharding_user' LOGIN;
|
||||||
|
CREATE ROLE other_user ENCRYPTED PASSWORD 'other_user' LOGIN;
|
||||||
|
CREATE ROLE simple_user ENCRYPTED PASSWORD 'simple_user' LOGIN;
|
||||||
|
|
||||||
|
GRANT CONNECT ON DATABASE shard0 TO sharding_user;
|
||||||
|
GRANT CONNECT ON DATABASE shard1 TO sharding_user;
|
||||||
|
GRANT CONNECT ON DATABASE shard2 TO sharding_user;
|
||||||
|
|
||||||
|
GRANT CONNECT ON DATABASE shard0 TO other_user;
|
||||||
|
GRANT CONNECT ON DATABASE shard1 TO other_user;
|
||||||
|
GRANT CONNECT ON DATABASE shard2 TO other_user;
|
||||||
|
|
||||||
|
GRANT CONNECT ON DATABASE some_db TO simple_user;
|
||||||
|
|
||||||
\c shard0
|
\c shard0
|
||||||
GRANT ALL ON SCHEMA public TO sharding_user;
|
GRANT ALL ON SCHEMA public TO sharding_user;
|
||||||
GRANT ALL ON TABLE data TO sharding_user;
|
GRANT ALL ON TABLE data TO sharding_user;
|
||||||
|
GRANT ALL ON SCHEMA public TO other_user;
|
||||||
|
GRANT ALL ON TABLE data TO other_user;
|
||||||
|
|
||||||
\c shard1
|
\c shard1
|
||||||
GRANT ALL ON SCHEMA public TO sharding_user;
|
GRANT ALL ON SCHEMA public TO sharding_user;
|
||||||
GRANT ALL ON TABLE data TO sharding_user;
|
GRANT ALL ON TABLE data TO sharding_user;
|
||||||
|
GRANT ALL ON SCHEMA public TO other_user;
|
||||||
|
GRANT ALL ON TABLE data TO other_user;
|
||||||
|
|
||||||
\c shard2
|
\c shard2
|
||||||
GRANT ALL ON SCHEMA public TO sharding_user;
|
GRANT ALL ON SCHEMA public TO sharding_user;
|
||||||
GRANT ALL ON TABLE data TO sharding_user;
|
GRANT ALL ON TABLE data TO sharding_user;
|
||||||
|
GRANT ALL ON SCHEMA public TO other_user;
|
||||||
|
GRANT ALL ON TABLE data TO other_user;
|
||||||
|
|
||||||
|
\c some_db
|
||||||
|
GRANT ALL ON SCHEMA public TO simple_user;
|
||||||
|
GRANT ALL ON TABLE data TO simple_user;
|
||||||
|
|||||||
Reference in New Issue
Block a user