1
1
mirror of https://github.com/wader/fq.git synced 2024-12-02 12:45:53 +03:00
fq/format/postgres/pg_heap.go

70 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() {
interp.RegisterFormat(decode.Format{
Name: format.PG_HEAP,
Description: "PostgreSQL heap file",
DecodeFn: decodePgheap,
DecodeInArg: format.PostgresHeapIn{
Flavour: PG_FLAVOUR_POSTGRES14,
PageNumber: 0,
SegmentNumber: 0,
},
2022-09-02 11:53:35 +03:00
RootArray: true,
RootName: "pages",
})
2022-09-23 13:50:54 +03:00
interp.RegisterFS(pgHeapFS)
}
func decodePgheap(d *decode.D, in any) any {
d.Endian = decode.LittleEndian
pgIn, ok := in.(format.PostgresHeapIn)
2022-09-06 12:55:15 +03:00
if !ok {
d.Fatalf("DecodeInArg must be PostgresIn!\n")
}
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,
PG_FLAVOUR_PGPRO10,
PG_FLAVOUR_PGPRO11,
PG_FLAVOUR_PGPRO12,
PG_FLAVOUR_PGPRO13,
PG_FLAVOUR_PGPRO14:
return postgres.DecodeHeap(d, pgIn)
case PG_FLAVOUR_PGPROEE10,
PG_FLAVOUR_PGPROEE11,
PG_FLAVOUR_PGPROEE12,
PG_FLAVOUR_PGPROEE13,
PG_FLAVOUR_PGPROEE14:
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)
}