You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Boot up Docker. There may be zero containers running. (`docker ps`)
23
+
-`docker ps -a` (check if db01 and db02 are running)
23
24
- Docker containers are in `docker` directory. Read README: <https://github.com/andyatkinson/rideshare/blob/main/docker/README.md>
24
-
- Create a docker network (`rideshare-net`) the containers can use
25
-
- Run the script to start the `db01` container
26
-
- Run the script to start the `db02` container
27
-
- Verify they're running with `docker ps`
28
-
29
-
```sh
30
-
# Clean-up from past runs:
31
-
cd docker
32
-
rm postgresql.conf
33
-
rm -rf postgres-docker/
34
-
35
-
# Starting point:
36
-
docker network create rideshare-net
37
-
sh run_db_db01_primary.sh
38
-
sh run_db_db02_replica.sh
39
-
```
40
-
41
-
Let's configure them.
25
+
- (created by script) Create a docker network (`rideshare-net`) the containers can use
26
+
- (created by script) Run the script to start the `db01` container
27
+
- (created by script) Run the script to start the `db02` container
42
28
43
29
## Part 2: Enabling Physical Replication
44
30
Prep: Remove annoying Docker messages:
@@ -57,28 +43,16 @@ docker ps -a
57
43
Go to the `docker` directory and run `sh reset_docker_instances.sh`.
58
44
59
45
If you're missing `postgresql.conf`, you'll be prompted to create it.
60
-
61
-
62
46
```sh
63
47
cd rideshare
64
48
cd docker
65
49
sh reset_docker_instances.sh
66
50
```
67
51
68
-
Follow the commands to copy down `postgresql.conf`.
69
-
70
-
Edit the settings `wal_level = logical` and save the changes. The script copies postgresql.conf to db01.
71
-
72
-
Run the command again to do that:
73
-
74
-
```sh
75
-
sh reset_docker_instances.sh
76
-
```
77
-
78
52
Let's walk through the highlights:
79
53
- Replaced `postgresql.conf` config file on db01
80
54
- Created replication slot on primary db01
81
-
- Created `replication_user` user on db01 with a unique password and permissions
55
+
- Created `replication_user` user on db01 with a unique password (scram encryption) and permissions
82
56
- Created `pg_hba.conf` on db01 to allow access
83
57
- Placed password in `.pgpass` and copied to db01 and db02 for `replication_user`
84
58
- Restarted db01
@@ -208,10 +182,19 @@ And on db02, something like this:
208
182
2024-05-01 02:07:18.648 UTC [31] LOG: started streaming WAL from primary at 0/7000000 on timeline 1
209
183
```
210
184
185
+
Now the system identifiers will be the same. db02 is a byte-for-byte-copy of db01.
186
+
```sh
187
+
docker exec --user postgres -it db01 \
188
+
psql -c "SELECT system_identifier FROM pg_control_system();"
189
+
190
+
docker exec --user postgres -it db02 \
191
+
psql -c "SELECT system_identifier FROM pg_control_system();"
192
+
```
193
+
211
194
## Conclusion
212
-
That concludes the basics of setting up a replica instance.
195
+
That concludes the basics of setting up a replica instance. You're now working with two instances, one as a primary, and the other in "ready only" "recovery" mode replaying changes from the primary.
213
196
214
-
In the next section we'll continue with adding content, then layer on application-level configuration.
197
+
In the next section we'll continue with using more instances, adding application-level configuration.
0 commit comments