1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 10:33:53 +03:00
fq/format/postgres/pg_heap.go

72 lines
1.4 KiB
Go
Raw Normal View History

package postgres
import (
2022-09-23 13:50:54 +03:00
"embed"
2022-10-07 14:17:04 +03:00
2022-10-07 14:12:36 +03:00
"github.com/wader/fq/format/postgres/common/pg_heap/pgproee"
"github.com/wader/fq/format/postgres/common/pg_heap/postgres"
2022-10-05 19:37:42 +03:00
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
// TO DO
// oom kill on 1 GB file
2022-09-23 13:50:54 +03:00
//go:embed pg_heap.md
var pgHeapFS embed.FS
func init() {
2023-05-04 08:45:42 +03:00
interp.RegisterFormat(format.Pg_Heap, &decode.Format{
Description: "PostgreSQL heap file",
DecodeFn: decodePgheap,
2023-05-04 08:45:42 +03:00
DefaultInArg: format.Pg_Heap_In{
Flavour: PG_FLAVOUR_POSTGRES14,
Page: 0,
Segment: 0,
},
2022-09-02 11:53:35 +03:00
RootArray: true,
RootName: "pages",
})
2022-09-23 13:50:54 +03:00
interp.RegisterFS(pgHeapFS)
}
2023-05-03 09:45:25 +03:00
func decodePgheap(d *decode.D) any {
d.Endian = decode.LittleEndian
2023-05-04 08:45:42 +03:00
var pgIn format.Pg_Heap_In
2023-05-03 09:45:25 +03:00
if !d.ArgAs(&pgIn) {
d.Fatalf("no flavour specified")
2022-09-06 12:55:15 +03:00
}
switch pgIn.Flavour {
2022-10-07 14:12:36 +03:00
case PG_FLAVOUR_POSTGRES10,
PG_FLAVOUR_POSTGRES11,
PG_FLAVOUR_POSTGRES12,
PG_FLAVOUR_POSTGRES13,
PG_FLAVOUR_POSTGRES14,
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_POSTGRES15,
2022-10-07 14:12:36 +03:00
PG_FLAVOUR_PGPRO10,
PG_FLAVOUR_PGPRO11,
PG_FLAVOUR_PGPRO12,
PG_FLAVOUR_PGPRO13,
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_PGPRO14,
PG_FLAVOUR_PGPRO15:
2022-10-07 14:12:36 +03:00
return postgres.DecodeHeap(d, pgIn)
case PG_FLAVOUR_PGPROEE10,
PG_FLAVOUR_PGPROEE11,
PG_FLAVOUR_PGPROEE12,
PG_FLAVOUR_PGPROEE13,
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_PGPROEE14,
PG_FLAVOUR_PGPROEE15:
2022-10-07 14:12:36 +03:00
return pgproee.DecodeHeap(d, pgIn)
2022-08-26 12:12:22 +03:00
default:
break
}
2022-10-07 14:12:36 +03:00
return postgres.DecodeHeap(d, pgIn)
}