Skip to content

Commit

Permalink
add pgpro12 postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Safonov committed Aug 26, 2022
1 parent 7bf6b11 commit 9570d4d
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 2 deletions.
220 changes: 220 additions & 0 deletions format/postgres/flavours/pgpro12/pg_control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package pgpro12

import (
"github.com/wader/fq/format/postgres/common"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)

// type = struct ControlFileData {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;
/* 16 | 4 */ // DBState state;
/* XXX 4-byte hole */
/* 24 | 8 */ // pg_time_t time;
/* 32 | 8 */ // XLogRecPtr checkPoint;
/* 40 | 88 */ // CheckPoint checkPointCopy;
/* 128 | 8 */ // XLogRecPtr unloggedLSN;
/* 136 | 8 */ // XLogRecPtr minRecoveryPoint;
/* 144 | 4 */ // TimeLineID minRecoveryPointTLI;
/* XXX 4-byte hole */
/* 152 | 8 */ // XLogRecPtr backupStartPoint;
/* 160 | 8 */ // XLogRecPtr backupEndPoint;
/* 168 | 1 */ // _Bool backupEndRequired;
/* XXX 3-byte hole */
/* 172 | 4 */ // int wal_level;
/* 176 | 1 */ // _Bool wal_log_hints;
/* XXX 3-byte hole */
/* 180 | 4 */ // int MaxConnections;
/* 184 | 4 */ // int max_worker_processes;
/* 188 | 4 */ // int max_wal_senders;
/* 192 | 4 */ // int max_prepared_xacts;
/* 196 | 4 */ // int max_locks_per_xact;
/* 200 | 1 */ // _Bool track_commit_timestamp;
/* XXX 3-byte hole */
/* 204 | 4 */ // uint32 maxAlign;
/* 208 | 8 */ // double floatFormat;
/* 216 | 4 */ // uint32 blcksz;
/* 220 | 4 */ // uint32 relseg_size;
/* 224 | 4 */ // uint32 xlog_blcksz;
/* 228 | 4 */ // uint32 xlog_seg_size;
/* 232 | 4 */ // uint32 nameDataLen;
/* 236 | 4 */ // uint32 indexMaxKeys;
/* 240 | 4 */ // uint32 toast_max_chunk_size;
/* 244 | 4 */ // uint32 loblksize;
/* 248 | 1 */ // _Bool float4ByVal;
/* 249 | 1 */ // _Bool float8ByVal;
/* XXX 2-byte hole */
/* 252 | 4 */ // uint32 data_checksum_version;
/* 256 | 32 */ // char mock_authentication_nonce[32];
/* 288 | 4 */ // pg_icu_version icu_version;
/* 292 | 4 */ // pg_crc32c crc;
//
/* total size (bytes): 296 */

// type = struct CheckPoint {
/* 0 | 8 */ // XLogRecPtr redo;
/* 8 | 4 */ // TimeLineID ThisTimeLineID;
/* 12 | 4 */ // TimeLineID PrevTimeLineID;
/* 16 | 1 */ // _Bool fullPageWrites;
/* XXX 7-byte hole */
/* 24 | 8 */ // FullTransactionId nextFullXid;
/* 32 | 4 */ // Oid nextOid;
/* 36 | 4 */ // MultiXactId nextMulti;
/* 40 | 4 */ // MultiXactOffset nextMultiOffset;
/* 44 | 4 */ // TransactionId oldestXid;
/* 48 | 4 */ // Oid oldestXidDB;
/* 52 | 4 */ // MultiXactId oldestMulti;
/* 56 | 4 */ // Oid oldestMultiDB;
/* XXX 4-byte hole */
/* 64 | 8 */ // pg_time_t time;
/* 72 | 4 */ // TransactionId oldestCommitTsXid;
/* 76 | 4 */ // TransactionId newestCommitTsXid;
/* 80 | 4 */ // TransactionId oldestActiveXid;
/* XXX 4-byte padding */
//
/* total size (bytes): 88 */

func DecodePgControl(d *decode.D, in any) any {
d.SeekAbs(0)
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;
/* 16 | 4 */ // DBState state;
/* XXX 4-byte hole */
d.FieldU64("system_identifier")
d.FieldU32("pg_control_version", common.VersionMapper)
d.FieldU32("catalog_version_no")
d.FieldU32("state", common.DBState)
d.U32()

/* 24 | 8 */ // pg_time_t time;
/* 32 | 8 */ // XLogRecPtr checkPoint;
/* 40 | 88 */ // CheckPoint checkPointCopy;
d.FieldS64("time", common.TimeMapper)
d.FieldU64("checkPoint", common.XLogRecPtrMapper)
d.FieldStruct("checkPointCopy", func(d *decode.D) {
/* 0 | 8 */ // XLogRecPtr redo;
/* 8 | 4 */ // TimeLineID ThisTimeLineID;
/* 12 | 4 */ // TimeLineID PrevTimeLineID;
/* 16 | 1 */ // _Bool fullPageWrites;
/* XXX 7-byte hole */
d.FieldU64("redo", common.XLogRecPtrMapper)
d.FieldU32("ThisTimeLineID")
d.FieldU32("PrevTimeLineID")
d.FieldU8("fullPageWrites")
d.U56()

/* 24 | 8 */ // FullTransactionId nextFullXid;
/* 32 | 4 */ // Oid nextOid;
/* 36 | 4 */ // MultiXactId nextMulti;
/* 40 | 4 */ // MultiXactOffset nextMultiOffset;
/* 44 | 4 */ // TransactionId oldestXid;
/* 48 | 4 */ // Oid oldestXidDB;
/* 52 | 4 */ // MultiXactId oldestMulti;
/* 56 | 4 */ // Oid oldestMultiDB;
/* XXX 4-byte hole */
d.FieldU64("nextFullXid")
d.FieldU32("nextOid")
d.FieldU32("nextMulti")
d.FieldU32("nextMultiOffset")
d.FieldU32("oldestXid")
d.FieldU32("oldestXidDB")
d.FieldU32("oldestMulti")
d.FieldU32("oldestMultiDB")
d.U32()

/* 64 | 8 */ // pg_time_t time;
/* 72 | 4 */ // TransactionId oldestCommitTsXid;
/* 76 | 4 */ // TransactionId newestCommitTsXid;
/* 80 | 4 */ // TransactionId oldestActiveXid;
/* XXX 4-byte padding */
d.FieldS64("time", common.TimeMapper)
d.FieldU32("oldestCommitTsXid")
d.FieldU32("newestCommitTsXid")
d.FieldU32("oldestActiveXid")
d.U32()
})

/* 128 | 8 */ // XLogRecPtr unloggedLSN;
/* 136 | 8 */ // XLogRecPtr minRecoveryPoint;
/* 144 | 4 */ // TimeLineID minRecoveryPointTLI;
/* XXX 4-byte hole */
d.FieldU64("unloggedLSN", common.LocPtrMapper)
d.FieldU64("minRecoveryPoint", common.LocPtrMapper)
d.FieldU32("minRecoveryPointTLI")
d.U32()

/* 152 | 8 */ // XLogRecPtr backupStartPoint;
/* 160 | 8 */ // XLogRecPtr backupEndPoint;
/* 168 | 1 */ // _Bool backupEndRequired;
/* XXX 3-byte hole */
d.FieldU64("backupStartPoint", common.LocPtrMapper)
d.FieldU64("backupEndPoint", common.LocPtrMapper)
d.FieldU8("backupEndRequired")
d.U24()

/* 172 | 4 */ // int wal_level;
/* 176 | 1 */ // _Bool wal_log_hints;
/* XXX 3-byte hole */
d.FieldS32("wal_level", common.WalLevel)
d.FieldU8("wal_log_hints")
d.U24()

/* 180 | 4 */ // int MaxConnections;
/* 184 | 4 */ // int max_worker_processes;
/* 188 | 4 */ // int max_wal_senders;
/* 192 | 4 */ // int max_prepared_xacts;
/* 196 | 4 */ // int max_locks_per_xact;
/* 200 | 1 */ // _Bool track_commit_timestamp;
/* XXX 3-byte hole */
d.FieldS32("MaxConnections")
d.FieldS32("max_worker_processes")
d.FieldS32("max_wal_senders")
d.FieldS32("max_prepared_xacts")
d.FieldS32("max_locks_per_xact")
d.FieldU8("track_commit_timestamp")
d.U24()

/* 204 | 4 */ // uint32 maxAlign;
/* 208 | 8 */ // double floatFormat;
/* 216 | 4 */ // uint32 blcksz;
/* 220 | 4 */ // uint32 relseg_size;
/* 224 | 4 */ // uint32 xlog_blcksz;
/* 228 | 4 */ // uint32 xlog_seg_size;
/* 232 | 4 */ // uint32 nameDataLen;
/* 236 | 4 */ // uint32 indexMaxKeys;
/* 240 | 4 */ // uint32 toast_max_chunk_size;
/* 244 | 4 */ // uint32 loblksize;
/* 248 | 1 */ // _Bool float4ByVal;
/* 249 | 1 */ // _Bool float8ByVal;
/* XXX 2-byte hole */
d.FieldU32("maxAlign")
d.FieldF64("floatFormat")
d.FieldU32("blcksz")
d.FieldU32("relseg_size")
d.FieldU32("xlog_blcksz")
d.FieldU32("xlog_seg_size")
d.FieldU32("nameDataLen")
d.FieldU32("indexMaxKeys")
d.FieldU32("toast_max_chunk_size")
d.FieldU32("loblksize")
d.FieldU8("float4ByVal")
d.FieldU8("float8ByVal")
d.U16()

/* 252 | 4 */ // uint32 data_checksum_version;
/* 256 | 32 */ // char mock_authentication_nonce[32];
/* 288 | 4 */ // pg_icu_version icu_version;
/* 292 | 4 */ // pg_crc32c crc;
d.FieldU32("data_checksum_version")
d.FieldRawLen("mock_authentication_nonce", 32*8, scalar.RawHex)
d.FieldU32("icu_version", common.IcuVersionMapper)
d.FieldU32("crc")
/* total size (bytes): 296 */

d.AssertPosBytes(296)

return nil
}
62 changes: 62 additions & 0 deletions format/postgres/flavours/pgpro12/pg_heap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pgpro12

import (
"github.com/wader/fq/format/postgres/common"
"github.com/wader/fq/format/postgres/flavours/postgres14/common14"
"github.com/wader/fq/pkg/decode"
)

// type = struct PageHeaderData {
/* 0 | 8 */ // PageXLogRecPtr pd_lsn;
/* 8 | 2 */ // uint16 pd_checksum;
/* 10 | 2 */ // uint16 pd_flags;
/* 12 | 2 */ // LocationIndex pd_lower;
/* 14 | 2 */ // LocationIndex pd_upper;
/* 16 | 2 */ // LocationIndex pd_special;
/* 18 | 2 */ // uint16 pd_pagesize_version;
/* 20 | 4 */ // TransactionId pd_prune_xid;
/* 24 | 0 */ // ItemIdData pd_linp[];
//
/* total size (bytes): 24 */

// type = struct HeapTupleHeaderData {
/* 0 | 12 */ // union {
/* 12 */ // HeapTupleFields t_heap;
/* 12 */ // DatumTupleFields t_datum;
// } t_choice;
// /* total size (bytes): 12 */
//
/* 12 | 6 */ // ItemPointerData t_ctid;
/* 18 | 2 */ // uint16 t_infomask2;
/* 20 | 2 */ // uint16 t_infomask;
/* 22 | 1 */ // uint8 t_hoff;
/* 23 | 0 */ // bits8 t_bits[];
/* XXX 1-byte padding */
//
/* total size (bytes): 24 */

// type = struct HeapTupleFields {
/* 0 | 4 */ // TransactionId t_xmin;
/* 4 | 4 */ // TransactionId t_xmax;
/* 8 | 4 */ // union {
/* 4 */ // CommandId t_cid;
/* 4 */ // TransactionId t_xvac;
// } t_field3;
/* total size (bytes): 4 */
//
/* total size (bytes): 12 */

// type = struct DatumTupleFields {
/* 0 | 4 */ // int32 datum_len_;
/* 4 | 4 */ // int32 datum_typmod;
/* 8 | 4 */ // Oid datum_typeid;
//
/* total size (bytes): 12 */

func DecodeHeap(d *decode.D) any {
heap := &common14.HeapD{
PageSize: common.HeapPageSize,
DecodePageHeaderDataFn: common14.DecodePageHeaderData,
}
return common14.DecodeHeap(d, heap)
}
4 changes: 4 additions & 0 deletions format/postgres/pg_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postgres

import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/postgres/flavours/pgpro12"
"github.com/wader/fq/format/postgres/flavours/pgpro13"
"github.com/wader/fq/format/postgres/flavours/pgpro14"
"github.com/wader/fq/format/postgres/flavours/pgproee10"
Expand Down Expand Up @@ -41,6 +42,7 @@ const (
PG_FLAVOUR_POSTGRES12 = "postgres12"
PG_FLAVOUR_POSTGRES13 = "postgres13"
PG_FLAVOUR_POSTGRES14 = "postgres14"
PG_FLAVOUR_PGPRO12 = "pgpro12"
PG_FLAVOUR_PGPRO13 = "pgpro13"
PG_FLAVOUR_PGPRO14 = "pgpro14"
PG_FLAVOUR_PGPROEE10 = "pgproee10"
Expand All @@ -63,6 +65,8 @@ func decodePgControl(d *decode.D, in any) any {
return postgres13.DecodePgControl(d, in)
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES:
return postgres14.DecodePgControl(d, in)
case PG_FLAVOUR_PGPRO12:
return pgpro12.DecodePgControl(d, in)
case PG_FLAVOUR_PGPRO13:
return pgpro13.DecodePgControl(d, in)
case PG_FLAVOUR_PGPRO14:
Expand Down
8 changes: 6 additions & 2 deletions format/postgres/pgheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postgres

import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/postgres/flavours/pgpro12"
"github.com/wader/fq/format/postgres/flavours/pgpro13"
"github.com/wader/fq/format/postgres/flavours/pgpro14"
"github.com/wader/fq/format/postgres/flavours/pgproee10"
Expand Down Expand Up @@ -49,12 +50,15 @@ func decodePgheap(d *decode.D, in any) any {
return pgproee12.DecodeHeap(d)
case PG_FLAVOUR_PGPROEE13:
return pgproee13.DecodeHeap(d)
case PG_FLAVOUR_PGPROEE14:
return pgproee14.DecodeHeap(d)
case PG_FLAVOUR_PGPRO12:
return pgpro12.DecodeHeap(d)
case PG_FLAVOUR_PGPRO13:
return pgpro13.DecodeHeap(d)
case PG_FLAVOUR_PGPRO14:
return pgpro14.DecodeHeap(d)
case PG_FLAVOUR_PGPROEE14:
return pgproee14.DecodeHeap(d)

default:
break
}
Expand Down

0 comments on commit 9570d4d

Please sign in to comment.