我已经在同一实例上的 2 个不同数据库上恢复了 2 个数据库,调用它geo
并且restore1
架构是相同的,唯一的区别是geo
数据库仅包含 <= 之前2023-11-23
和 >= 之后的记录2023-12-01
,而restore1
包含 <= 2023-11-30
,我如何复制这些每个表容易缺失值(2023-11-23
直到数据库) 2023-11-30
?restore1
geo
我能想到的一种方法是,为每个表创建一个程序,从之前选择最新的 id 2023-11-24
(geo
称为X
),然后选择 id 大于的所有记录X
,然后手动将其插入geo
数据库。
有没有更简单的方法?
有数百张表,但大多数都是这样的:
restore1=# \d station_logs_599
Table "public.station_logs_599"
Column | Type | Collation | Nullable | Default
------------------------+--------------------------------+-----------+----------+------------------------------------------
id | integer | | not null | nextval('station_logs_id_seq'::regclass)
created_at | timestamp(6) without time zone | | |
updated_at | timestamp(6) without time zone | | |
deleted_at | timestamp(6) without time zone | | |
submitted_at | timestamp(6) without time zone | | not null |
sequence | integer | | |
level_sensor | double precision | | |
accel_x | double precision | | |
accel_y | double precision | | |
accel_z | double precision | | |
power_current | double precision | | |
ip_address | character varying(50) | | |
log_type | integer | | |
station_id | integer | | not null |
power_voltage | double precision | | |
data | jsonb | | |
is_deleted | boolean | | not null | false
temperature | double precision | | |
wind_speed | double precision | | |
soil_moisture | double precision | | |
wind_direction | double precision | | |
raindrop | double precision | | |
humidity | integer | | |
barometric_pressure | double precision | | |
wind_speed_average | double precision | | |
wind_gust | double precision | | |
wind_direction_average | double precision | | |
rain_rate | double precision | | |
Indexes:
"station_logs_599_epoch" btree (date_part('epoch'::text, submitted_at))
"station_logs_599_submitted_at" btree (submitted_at)
"uniq_sid_sat_599" UNIQUE CONSTRAINT, btree (submitted_at)
Foreign-key constraints:
"station_logs_599_station_fk" FOREIGN KEY (station_id) REFERENCES stations(id)
我使用golang来解决这个问题:
tl;dw
:DATE(submitted_at), COUNT(1)
)