2022-07-29 09:10:00 +03:00
|
|
|
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
|
|
|
|
2022-07-29 09:10:00 +03:00
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
|
|
|
"github.com/wader/fq/pkg/interp"
|
|
|
|
)
|
|
|
|
|
2022-09-02 16:14:24 +03:00
|
|
|
// 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
|
|
|
|
|
2022-07-29 09:10:00 +03:00
|
|
|
func init() {
|
|
|
|
interp.RegisterFormat(decode.Format{
|
2022-09-02 16:14:24 +03:00
|
|
|
Name: format.PG_HEAP,
|
2022-07-29 09:10:00 +03:00
|
|
|
Description: "PostgreSQL heap file",
|
|
|
|
DecodeFn: decodePgheap,
|
2022-10-07 12:58:36 +03:00
|
|
|
DecodeInArg: format.PostgresHeapIn{
|
|
|
|
Flavour: PG_FLAVOUR_POSTGRES14,
|
|
|
|
PageNumber: 0,
|
|
|
|
SegmentNumber: 0,
|
2022-07-29 09:10:00 +03:00
|
|
|
},
|
2022-09-02 11:53:35 +03:00
|
|
|
RootArray: true,
|
2022-09-23 14:05:19 +03:00
|
|
|
RootName: "pages",
|
2022-07-29 09:10:00 +03:00
|
|
|
})
|
2022-09-23 13:50:54 +03:00
|
|
|
interp.RegisterFS(pgHeapFS)
|
2022-07-29 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func decodePgheap(d *decode.D, in any) any {
|
|
|
|
d.Endian = decode.LittleEndian
|
|
|
|
|
2022-10-07 12:58:36 +03:00
|
|
|
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
|
|
|
|
2022-07-29 09:10:00 +03:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-10-07 14:12:36 +03:00
|
|
|
return postgres.DecodeHeap(d, pgIn)
|
2022-07-29 09:10:00 +03:00
|
|
|
}
|