1
1
mirror of https://github.com/wader/fq.git synced 2024-12-03 13:46:37 +03:00
fq/format/postgres/pg_wal.go

68 lines
1.4 KiB
Go
Raw Normal View History

2022-07-12 11:18:16 +03:00
package postgres
import (
"github.com/wader/fq/format"
2022-07-28 12:32:35 +03:00
"github.com/wader/fq/format/postgres/flavours/postgres14"
2022-07-12 11:18:16 +03:00
"github.com/wader/fq/pkg/decode"
2022-07-19 08:58:31 +03:00
"github.com/wader/fq/pkg/interp"
2022-07-12 11:18:16 +03:00
)
// TO DO
// not ready yet
2022-07-12 11:18:16 +03:00
func init() {
2022-07-19 08:58:31 +03:00
interp.RegisterFormat(decode.Format{
Name: format.PG_WAL,
2022-07-12 11:18:16 +03:00
Description: "PostgreSQL write-ahead log file",
2022-07-28 12:32:35 +03:00
DecodeFn: decodePgwal,
DecodeInArg: format.PostgresIn{
Flavour: "default",
},
2022-07-12 11:18:16 +03:00
})
}
2022-07-28 12:32:35 +03:00
// https://pgpedia.info/x/XLOG_PAGE_MAGIC.html
2022-07-12 11:18:16 +03:00
const (
2022-07-28 12:32:35 +03:00
XLOG_PAGE_MAGIC_15 = uint16(0xD10F)
XLOG_PAGE_MAGIC_14 = uint16(0xD10D)
XLOG_PAGE_MAGIC_13 = uint16(0xD106)
XLOG_PAGE_MAGIC_12 = uint16(0xD101)
XLOG_PAGE_MAGIC_11 = uint16(0xD098)
XLOG_PAGE_MAGIC_10 = uint16(0xD097)
XLOG_PAGE_MAGIC_96 = uint16(0xD093)
2022-07-12 11:18:16 +03:00
)
2022-07-28 12:32:35 +03:00
func decodePgwal(d *decode.D, in any) any {
2022-07-12 11:18:16 +03:00
d.Endian = decode.LittleEndian
2022-07-28 12:32:35 +03:00
flavour := in.(format.PostgresIn).Flavour
switch flavour {
//case PG_FLAVOUR_POSTGRES11:
// return postgres11.DecodePgControl(d, in)
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES:
return postgres14.DecodePgwal(d, in)
//case PG_FLAVOUR_PGPROEE14:
// return pgproee14.DecodePgControl(d, in)
default:
break
}
2022-07-12 11:18:16 +03:00
2022-07-28 12:32:35 +03:00
return probePgwal(d, in)
}
2022-07-12 11:18:16 +03:00
2022-07-28 12:32:35 +03:00
func probePgwal(d *decode.D, in any) any {
// read version
xlp_magic := uint16(d.U16())
2022-07-12 11:18:16 +03:00
2022-07-28 12:32:35 +03:00
// restore position
d.SeekAbs(0)
2022-07-12 11:18:16 +03:00
2022-07-28 12:32:35 +03:00
switch xlp_magic {
case XLOG_PAGE_MAGIC_14:
return postgres14.DecodePgwal(d, in)
default:
d.Fatalf("unsupported xlp_magic = %X\n", xlp_magic)
}
2022-07-12 11:18:16 +03:00
return nil
}