Skip to content

Commit e2c3839

Browse files
committed
chore: refine the replica-setup-pg and its doc
1 parent 2ae5055 commit e2c3839

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

devtools/replica-setup-pg/README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PostgreSQL to MyDuck Replication Setup
1+
# PostgreSQL to MyDuck Replication Setup (WIP)
22

33
This guide walks you through configuring MyDuck Server as a replica of a running PostgreSQL instance.
44

@@ -11,23 +11,29 @@ Before you begin, ensure that:
1111

1212
## Getting Started
1313

14-
To let MyDuck Server replicate data from an existing PostgreSQL instance, run the provided `replica_setup.sh` script. You will need to supply the PostgreSQL connection details as parameters.
14+
To let MyDuck Server replicate data from an existing PostgreSQL instance, run the provided `replica_setup.sh` script. There are two ways to run the script.
1515

16-
### Usage
16+
### Method 1: Replicate Data from a PostgreSQL Dump File
17+
18+
In this method, you will need to prepare a PostgreSQL dump file that contains the data you want to replicate.
1719

1820
```bash
1921
bash replica_setup.sh --pg_dump /path/to/pg_dump
2022
```
2123

22-
### Parameters
24+
The parameters are as follows:
2325

2426
- **`--pg_dump`**: The path to the PostgreSQL dump file.
2527
- **`--myduck_port`**: The port on which MyDuck Server is listening connections.
2628

27-
## Example
29+
For example:
2830

2931
```bash
30-
bash replica_setup.sh --pg_dump ../../backup.sql
32+
bash replica_setup.sh --pg_dump pg_dump.sql
3133
```
3234

33-
This command sets up MyDuck Server as a replica of the PostgreSQL instance running at `192.168.1.100` on port `3306` with the user `root` and password `mypassword`.
35+
This command sets up MyDuck Server as a replica of the PostgreSQL instance running at `192.168.1.100` on port `5432` with the user `root` and password `mypassword`.
36+
37+
### Method 2: Replicate Data from a Running PostgreSQL Instance
38+
39+
WIP

devtools/replica-setup-pg/install_psql.sh

-3
This file was deleted.

devtools/replica-setup-pg/replica_setup.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ if [[ -z $MYDUCK_DB ]]; then
6262
usage
6363
fi
6464

65-
# Step 1: Check if psql exists, if not, install it
65+
# Step 1: Check if psql exists
6666
if ! command -v psql &> /dev/null; then
67-
echo "psql not found, attempting to install..."
68-
bash install_psql.sh
69-
check_command "psql installation"
70-
else
71-
echo "psql is already installed."
67+
echo "Error: psql is not installed."
68+
exit 1
7269
fi
7370

7471
# Step 2: Check if replication has already been started
@@ -92,7 +89,7 @@ fi
9289
# Step 5: Load the existing data from pg_dump file
9390
if [[ -n "$PG_DUMP" ]]; then
9491
echo "Loading the snapshot from pg_dump to MyDuck Server..."
95-
source snapshot.sh
92+
source snapshot_dump.sh
9693
check_command "loading a snapshot from pg_dump"
9794
else
9895
echo "No pg_dump file specified. Skipping snapshot."

pgserver/connection_handler.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,11 @@ func (h *ConnectionHandler) sendError(err error) {
10441044
}
10451045

10461046
// convertQuery takes the given Postgres query, and converts it as an ast.ConvertedQuery that will work with the handler.
1047-
func (h *ConnectionHandler) convertQuery(query string) (ConvertedQuery, error) {
1047+
func (h *ConnectionHandler) convertQuery(query string, modifiers ...QueryModifier) (ConvertedQuery, error) {
1048+
for _, modifier := range modifiers {
1049+
query = modifier(query)
1050+
}
1051+
10481052
parsable := true
10491053
stmts, err := parser.Parse(query)
10501054
if err != nil {

pgserver/query_modifier.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pgserver
2+
3+
import "regexp"
4+
5+
type QueryModifier func(string) string
6+
7+
func NewQueryReplacer(regex string, replacement string) QueryModifier {
8+
r := regexp.MustCompile(regex)
9+
return func(query string) string {
10+
return r.ReplaceAllString(query, replacement)
11+
}
12+
13+
}
14+
15+
func NewQueryRemover(regex string) QueryModifier {
16+
return NewQueryReplacer(regex, "")
17+
}
18+
19+
var (
20+
removeLocaleProvider = NewQueryRemover(`(?i)LOCALE_PROVIDER = [^ ;]*`)
21+
removeLocale = NewQueryRemover(`(?i)LOCALE = [^ ;]*`)
22+
)

0 commit comments

Comments
 (0)