user:kluong:migrating_time_received_to_utc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
user:kluong:migrating_time_received_to_utc [2022/02/12 03:00]
kluong
user:kluong:migrating_time_received_to_utc [2022/02/17 01:28] (current)
kluong
Line 3: Line 3:
 ===== Background ===== ===== Background =====
  
 +Reference from chat:
  
 <​code>​ <​code>​
Line 15: Line 16:
 In the production database we need to modify the "​time_received"​ column for multiple table. ​ In the production database we need to modify the "​time_received"​ column for multiple table. ​
  
-Something like this would work:+If we had migrations for the service setup, it would be a bit easier to make this modification,​ but running manal commands shouldn'​t be too bad. Something like this would work:
  
 <​code>​ <​code>​
-ALTER TABLE apple ALTER COLUMN time_received TYPE timestamp WITH TIME ZONE+ALTER TABLE apple ALTER COLUMN time_received TYPE timestamp WITH TIME ZONE;
 </​code>​ </​code>​
 +
 +Here's what it would look like in the postgres terminal, making sure to check the table before and after:
 +
 +<​code>​
 +postgres-# \d apple;
 +                               Table "​public.apple"​
 +       ​Column ​      ​| ​           Type             | Collation | Nullable | Default
 +--------------------+-----------------------------+-----------+----------+---------
 + ​time_received ​     | timestamp without time zone |           | not null |
 + ​schema ​            | integer ​                    ​| ​          ​| ​         |
 + ​node_addr ​         | integer ​                    ​| ​          ​| ​         |
 + ​uptime_ms ​         | bigint ​                     |           ​| ​         |
 + ​batt_mv ​           | integer ​                    ​| ​          ​| ​         |
 + ​panel_mv ​          | integer ​                    ​| ​          ​| ​         |
 + ​press_pa ​          | integer ​                    ​| ​          ​| ​         |
 + ​temp_c ​            | integer ​                    ​| ​          ​| ​         |
 + ​humidity_centi_pct | integer ​                    ​| ​          ​| ​         |
 + ​apogee_w_m2 ​       | double precision ​           |           ​| ​         |
 +
 +postgres=# ALTER TABLE apple ALTER COLUMN time_received TYPE timestamp WITH TIME ZONE;
 +ALTER TABLE
 +postgres=# \d apple;
 +                              Table "​public.apple"​
 +       ​Column ​      ​| ​          ​Type ​          | Collation | Nullable | Default
 +--------------------+--------------------------+-----------+----------+---------
 + ​time_received ​     | timestamp with time zone |           | not null |
 + ​schema ​            | integer ​                 |           ​| ​         |
 + ​node_addr ​         | integer ​                 |           ​| ​         |
 + ​uptime_ms ​         | bigint ​                  ​| ​          ​| ​         |
 + ​batt_mv ​           | integer ​                 |           ​| ​         |
 + ​panel_mv ​          | integer ​                 |           ​| ​         |
 + ​press_pa ​          | integer ​                 |           ​| ​         |
 + ​temp_c ​            | integer ​                 |           ​| ​         |
 + ​humidity_centi_pct | integer ​                 |           ​| ​         |
 + ​apogee_w_m2 ​       | double precision ​        ​| ​          ​| ​         |
 +
 +</​code>​
 +
  
 It would need to be repeated for all other tables. Looking at the tables that should be available: It would need to be repeated for all other tables. Looking at the tables that should be available:
Line 44: Line 83:
   - Then, the production gateway should be updated so that it writes using UTC (pull from master)   - Then, the production gateway should be updated so that it writes using UTC (pull from master)
   - Then, the production gateway should be started again   - Then, the production gateway should be started again
 +
 +
 +It might also be good to get into the routine of running a backup of the database prior to doing large commands: this might be a good way to do this: https://​www.tecmint.com/​backup-and-restore-postgresql-database/​
  • user/kluong/migrating_time_received_to_utc.1644634845.txt.gz
  • Last modified: 2022/02/12 03:00
  • by kluong