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
Rename the partition and create a new normal table with the same name as the partitioned table, then
115
116
convert to a hypertable:
@@ -127,6 +128,44 @@ EOF
127
128
</Procedure>
128
129
129
130
131
+
## Specify the tables to synchronize
132
+
133
+
After the schema is migrated, you [`CREATE PUBLICATION`][create-publication] on the source database that
134
+
specifies the tables to synchronize.
135
+
136
+
<Procedure>
137
+
138
+
1.**Create a publication that specifies the table to synchronize**
139
+
140
+
A `PUBLICATION` enables you to synchronize some or all the tables in the schema or database.
141
+
142
+
```sql
143
+
CREATE PUBLICATION <publication_name> FOR TABLE <table_name>, <table_name>;
144
+
```
145
+
146
+
To add tables after to an existing publication, use [ALTER PUBLICATION][alter-publication]**
147
+
148
+
```sql
149
+
ALTER PUBLICATION <publication_name> ADD TABLE <table_name>;
150
+
```
151
+
152
+
1.**Publish the $PG declarative partitioned table**
153
+
154
+
```sql
155
+
ALTER PUBLICATION <publication_name>SET(publish_via_partition_root=true);
156
+
```
157
+
158
+
To convert partitioned table to hypertable, follow [Convert partitions and tables with time-series data into hypertables](#convert-partitions-and-tables-with-time-series-data-into-hypertables).
159
+
160
+
1.**Stop syncing a table in the `PUBLICATION`, use `DROP TABLE`**
161
+
162
+
```sql
163
+
ALTER PUBLICATION <publication_name> DROP TABLE <table_name>;
164
+
```
165
+
166
+
</Procedure>
167
+
168
+
130
169
## Synchronize data to your $SERVICE_LONG
131
170
132
171
You use the $LIVESYNC docker image to synchronize changes in real-time from a $PG database
@@ -136,42 +175,85 @@ instance to a $SERVICE_LONG:
136
175
137
176
1.**Start $LIVESYNC**
138
177
139
-
As you run $LIVESYNC continuously, best practice is to run it as a background process.
178
+
As you run $LIVESYNC continuously, best practice is to run it as a Docker daemon.
140
179
141
180
```shell
142
-
docker run -d --rm --name livesync timescale/live-sync:v0.1.16 run --publication analytics --subscription livesync --source $SOURCE --target $TARGET
181
+
docker run -d --rm --name livesync timescale/live-sync:v0.1.17 run \
The `state` column indicates the current state of the table synchronization.
161
216
Possible values for `state` are:
162
217
163
-
- d: initial table data sync
218
+
| state | description |
219
+
|-------|-------------|
220
+
| d | initial table data sync |
221
+
| f | initial table data sync completed |
222
+
| s | catching up with the latest changes |
223
+
| r | table is ready, synching live changes |
224
+
225
+
To see the replication lag, run the following against the SOURCE database:
164
226
165
-
- f: initial table data sync completed
227
+
```bash
228
+
psql $SOURCE -f - <<'EOF'
229
+
SELECT
230
+
slot_name,
231
+
pg_size_pretty(pg_current_wal_flush_lsn() - confirmed_flush_lsn) AS lag
232
+
FROM pg_replication_slots
233
+
WHERE slot_name LIKE 'live_sync_%' AND slot_type = 'logical'
234
+
EOF
235
+
```
236
+
237
+
1.**Add or remove tables from the publication**
238
+
239
+
To add tables, use [ALTER PUBLICATION .. ADD TABLE][alter-publication]**
166
240
167
-
- s: catching up with the latest change
241
+
```sql
242
+
ALTER PUBLICATION <publication_name> ADD TABLE <table_name>;
243
+
```
244
+
245
+
To remove tables, use [ALTER PUBLICATION .. DROP TABLE][alter-publication]**
246
+
247
+
```sql
248
+
ALTER PUBLICATION <publication_name> DROP TABLE <table_name>;
249
+
```
168
250
169
-
- r: table is ready, synching live changes
251
+
1.**Update table statistics**
170
252
171
-
1.**(Optional) Update table statistics**
253
+
If you have a large table, you can run `ANALYZE` on the target $SERVICE_LONG
254
+
to update the table statistics after the initial sync is complete.
172
255
173
-
If you have a large table, you can run `ANALYZE` on the target $SERVICE_LONG to update the table statistics
174
-
after the initial sync is complete. This helps the query planner make better decisions for query execution plans.
256
+
This helps the query planner make better decisions for query execution plans.
175
257
176
258
```bash
177
259
vacuumdb --analyze --verbose --dbname=$TARGET
@@ -185,7 +267,11 @@ instance to a $SERVICE_LONG:
185
267
186
268
1.**(Optional) Reset sequence nextval on the target $SERVICE_LONG**
187
269
188
-
$LIVESYNC does not automatically reset the sequence nextval on the target $SERVICE_LONG. Run the following script to reset the sequence for all tables that have a serial or identity column in the target $SERVICE_LONG:
270
+
$LIVESYNC does not automatically reset the sequence nextval on the target
271
+
$SERVICE_LONG.
272
+
273
+
Run the following script to reset the sequence for all tables that have a
274
+
serial or identity column in the target $SERVICE_LONG:
189
275
190
276
```bash
191
277
psql $TARGET -f - <<'EOF'
@@ -226,53 +312,13 @@ EOF
226
312
227
313
1.**Cleanup**
228
314
229
-
Removes replication slots created by $LIVESYNC on the source database.
315
+
Use the `--drop` flag to remove the replication slots created by $LIVESYNC on the source database.
230
316
231
317
```shell
232
-
docker run -it --rm --name livesync timescale/live-sync:v0.1.16 run --publication analytics --subscription livesync --source $SOURCE --target $TARGET --drop
233
-
```
234
-
235
-
</Procedure>
236
-
237
-
238
-
## Specify the tables to synchronize
239
-
240
-
After the $LIVESYNC docker is up and running, you [`CREATE PUBLICATION`][create-publication] on the SOURCE database to
241
-
specify the list of tables which you intend to synchronize. Once you create a PUBLICATION, it is
242
-
automatically picked by $LIVESYNC, which starts syncing the tables expressed as part of it.
243
-
244
-
For example:
245
-
246
-
<Procedure>
247
-
248
-
1.**Create a publication named `analytics` which publishes `metrics` and `tags` tables**
249
-
250
-
`PUBLICATION` enables you to add all the tables in the schema or even all the tables in the database. However, it
251
-
requires superuser privileges on most of the managed $PG offerings.
252
-
253
-
```sql
254
-
CREATE PUBLICATION analytics FOR TABLE metrics, tags;
255
-
```
256
-
257
-
1.**Add tables after to an existing publication with a call to [ALTER PUBLICATION][alter-publication]**
258
-
259
-
```sql
260
-
ALTER PUBLICATION analytics ADD TABLE events;
261
-
```
262
-
263
-
1.**Publish $PG declarative partitioned table**
264
-
265
-
To publish declaratively partitioned table changes to your $SERVICE_LONG, set the `publish_via_partition_root`
266
-
special `PUBLICATION` config to `true`:
267
-
268
-
```sql
269
-
ALTER PUBLICATION analytics SET(publish_via_partition_root=true);
270
-
```
271
-
272
-
1.**Stop syncing a table in the `PUBLICATION` with a call to `DROP TABLE`**
273
-
274
-
```sql
275
-
ALTER PUBLICATION analytics DROPTABLEtags;
318
+
docker run -it --rm --name livesync timescale/live-sync:v0.1.17 run \
0 commit comments