From e56513a59667132253ede09504e85c67b116d357 Mon Sep 17 00:00:00 2001 From: Sean Wu <111744549+VWagen1989@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:13:20 +0800 Subject: [PATCH] fix: switch to schema 'public' instead of 'main' for each PostgreSQL protocol connection (#187) --- docs/tutorial/pg-htap-pgpool-setup.md | 26 +++++++++++++++++++++++--- pgserver/connection_handler.go | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/tutorial/pg-htap-pgpool-setup.md b/docs/tutorial/pg-htap-pgpool-setup.md index 383fecf6..1c961263 100644 --- a/docs/tutorial/pg-htap-pgpool-setup.md +++ b/docs/tutorial/pg-htap-pgpool-setup.md @@ -27,6 +27,26 @@ The HTAP service can be accessed by docker exec -ti htap-pgpool bash -c "PGPASSWORD=postgres psql -h localhost -U postgres -d postgres" ``` +And a table `test` with one row data is replicated from the primary PostreSQL to MyDuck server. + +```sql +psql (17.1) +Type "help" for help. + +postgres=# \d + List of relations + Schema | Name | Type | Owner +--------+------+-------+---------- + public | test | table | postgres +(1 row) + +postgres=# select * from test; + id | name +----+------ + 1 | test +(1 row) +``` + # Monitor status * The status of proxy `PGPool-II` can be retrieved by the built-in statement [SHOW POOL_NODES](https://www.pgpool.net/docs/latest/en/html/sql-show-pool-nodes.html). e.g. You can get the status of the servers by executing the statement `SHOW POOL_NODES;` on the connection to PGPool server. @@ -53,7 +73,7 @@ postgres=# show pool_nodes; after executing the `READ` statement. As you can see, the `select_cnt` has been increased by 1, indicating that the read statement has been routed to MyDuck server. ```sql -postgres=# select * from public.test; +postgres=# select * from test; id | name ----+------ 1 | test @@ -70,9 +90,9 @@ postgres=# show pool_nodes; Let's insert a new row and then query the table. Without surprise, the data has been replicated to our MyDuck server. ```sql postgres=# -postgres=# insert into public.test values (2, 'test again'); +postgres=# insert into test values (2, 'test again'); INSERT 0 1 -postgres=# select * from public.test; +postgres=# select * from test; id | name ----+------------ 1 | test diff --git a/pgserver/connection_handler.go b/pgserver/connection_handler.go index ed42bc83..e70fcbdf 100644 --- a/pgserver/connection_handler.go +++ b/pgserver/connection_handler.go @@ -316,7 +316,7 @@ func (h *ConnectionHandler) chooseInitialDatabase(startupMessage *pgproto3.Start } } - useStmt := fmt.Sprintf("USE %s;", db) + useStmt := fmt.Sprintf("USE %s.public;", db) setStmt := fmt.Sprintf("SET database TO %s;", db) parsed, err := parser.ParseOne(setStmt) if err != nil {