Move logs from array to dedicated table
All checks were successful
/ release (push) Successful in 1m23s
All checks were successful
/ release (push) Successful in 1m23s
This avoids the append problem which bloats the database to 200+ gb in a month and shrinks again to 5g with a full vacuum
This commit is contained in:
parent
15a960da19
commit
f52f517dc1
9 changed files with 99 additions and 11 deletions
1
migrations/000022_create_logs_table.down.sql
Normal file
1
migrations/000022_create_logs_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS logs;
|
5
migrations/000022_create_logs_table.up.sql
Normal file
5
migrations/000022_create_logs_table.up.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE IF NOT EXISTS logs(
|
||||
id bigserial PRIMARY KEY,
|
||||
task_id bigint REFERENCES tasks(id) NOT NULL,
|
||||
message text
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
DROP INDEX logs_task_id;
|
1
migrations/000023_create_index_logs_table_task_id.up.sql
Normal file
1
migrations/000023_create_index_logs_table_task_id.up.sql
Normal file
|
@ -0,0 +1 @@
|
|||
CREATE INDEX logs_task_id on logs(task_id);
|
1
migrations/000024_migrate_logs.down.sql
Normal file
1
migrations/000024_migrate_logs.down.sql
Normal file
|
@ -0,0 +1 @@
|
|||
/* migration is irreversable */
|
3
migrations/000024_migrate_logs.up.sql
Normal file
3
migrations/000024_migrate_logs.up.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO logs (task_id, message)
|
||||
SELECT id as task_id, l as message
|
||||
FROM tasks, unnest(log) l ORDER BY task_id ASC;
|
Loading…
Add table
Add a link
Reference in a new issue