static void xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec) { int i; appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time)); if (xlrec->nrels > 0) { appendStringInfoString(buf, "; rels:"); for (i = 0; i < xlrec->nrels; i++) { char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM); appendStringInfo(buf, " %s", path); pfree(path); } } if (xlrec->nsubxacts > 0) { TransactionId *xacts = (TransactionId *) &xlrec->xnodes[xlrec->nrels]; appendStringInfoString(buf, "; subxacts:"); for (i = 0; i < xlrec->nsubxacts; i++) appendStringInfo(buf, " %u", xacts[i]); } }
static void xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec) { int i; TransactionId *subxacts; subxacts = (TransactionId *) &xlrec->xnodes[xlrec->nrels]; appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time)); if (xlrec->nrels > 0) { appendStringInfo(buf, "; rels:"); for (i = 0; i < xlrec->nrels; i++) { char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM); appendStringInfo(buf, " %s", path); pfree(path); } } if (xlrec->nsubxacts > 0) { appendStringInfo(buf, "; subxacts:"); for (i = 0; i < xlrec->nsubxacts; i++) appendStringInfo(buf, " %u", subxacts[i]); } if (xlrec->nmsgs > 0) { SharedInvalidationMessage *msgs; msgs = (SharedInvalidationMessage *) &subxacts[xlrec->nsubxacts]; if (XactCompletionRelcacheInitFileInval(xlrec->xinfo)) appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u", xlrec->dbId, xlrec->tsId); appendStringInfo(buf, "; inval msgs:"); for (i = 0; i < xlrec->nmsgs; i++) { SharedInvalidationMessage *msg = &msgs[i]; if (msg->id >= 0) appendStringInfo(buf, " catcache %d", msg->id); else if (msg->id == SHAREDINVALCATALOG_ID) appendStringInfo(buf, " catalog %u", msg->cat.catId); else if (msg->id == SHAREDINVALRELCACHE_ID) appendStringInfo(buf, " relcache %u", msg->rc.relId); /* remaining cases not expected, but print something anyway */ else if (msg->id == SHAREDINVALSMGR_ID) appendStringInfo(buf, " smgr"); else if (msg->id == SHAREDINVALRELMAP_ID) appendStringInfo(buf, " relmap"); else appendStringInfo(buf, " unknown id %d", msg->id); } } }
static void pg_decode_commit_txn(LogicalDecodingContext* ctx, ReorderBufferTXN* txn, XLogRecPtr commit_lsn) { OutputPluginPrepareWrite(ctx, true); appendStringInfo( ctx->out, "{\"type\":\"transaction.commit\",\"xid\":\"%u\",\"committed\":\"%s\"}", txn->xid, timestamptz_to_str(txn->commit_time) ); OutputPluginWrite(ctx, true); }
static void pg_output_begin(LogicalDecodingContext* ctx, DecodingJsonData* data, ReorderBufferTXN* txn, bool last_write) { OutputPluginPrepareWrite(ctx, last_write); appendStringInfo( ctx->out, "{\"type\":\"transaction.begin\",\"xid\":\"%u\",\"committed\":\"%s\"}", txn->xid, timestamptz_to_str(txn->commit_time) ); OutputPluginWrite(ctx, last_write); }
/* * Keep track of important messages from primary. */ static void ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime) { /* use volatile pointer to prevent code rearrangement */ volatile WalRcvData *walrcv = WalRcv; TimestampTz lastMsgReceiptTime = GetCurrentTimestamp(); /* Update shared-memory status */ SpinLockAcquire(&walrcv->mutex); walrcv->lastMsgSendTime = sendTime; walrcv->lastMsgReceiptTime = lastMsgReceiptTime; SpinLockRelease(&walrcv->mutex); elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d transfer latency %d", timestamptz_to_str(sendTime), timestamptz_to_str(lastMsgReceiptTime), GetReplicationApplyDelay(), GetReplicationTransferLatency()); }
static void xact_desc_commit_compact(StringInfo buf, xl_xact_commit_compact *xlrec) { int i; appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time)); if (xlrec->nsubxacts > 0) { appendStringInfoString(buf, "; subxacts:"); for (i = 0; i < xlrec->nsubxacts; i++) appendStringInfo(buf, " %u", xlrec->subxacts[i]); } }
void commit_ts_desc(StringInfo buf, XLogReaderState *record) { char *rec = XLogRecGetData(record); uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; if (info == COMMIT_TS_ZEROPAGE) { int pageno; memcpy(&pageno, rec, sizeof(int)); appendStringInfo(buf, "%d", pageno); } else if (info == COMMIT_TS_TRUNCATE) { int pageno; memcpy(&pageno, rec, sizeof(int)); appendStringInfo(buf, "%d", pageno); } else if (info == COMMIT_TS_SETTS) { xl_commit_ts_set *xlrec = (xl_commit_ts_set *) rec; int nsubxids; appendStringInfo(buf, "set %s/%d for: %u", timestamptz_to_str(xlrec->timestamp), xlrec->nodeid, xlrec->mainxid); nsubxids = ((XLogRecGetDataLen(record) - SizeOfCommitTsSet) / sizeof(TransactionId)); if (nsubxids > 0) { int i; TransactionId *subxids; subxids = palloc(sizeof(TransactionId) * nsubxids); memcpy(subxids, XLogRecGetData(record) + SizeOfCommitTsSet, sizeof(TransactionId) * nsubxids); for (i = 0; i < nsubxids; i++) appendStringInfo(buf, ", %u", subxids[i]); pfree(subxids); } } }
static void xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId origin_id) { xl_xact_parsed_commit parsed; int i; ParseCommitRecord(info, xlrec, &parsed); /* If this is a prepared xact, show the xid of the original xact */ if (TransactionIdIsValid(parsed.twophase_xid)) appendStringInfo(buf, "%u: ", parsed.twophase_xid); appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time)); if (parsed.nrels > 0) { appendStringInfoString(buf, "; rels:"); for (i = 0; i < parsed.nrels; i++) { char *path = relpathperm(parsed.xnodes[i], MAIN_FORKNUM); appendStringInfo(buf, " %s", path); pfree(path); } } if (parsed.nsubxacts > 0) { appendStringInfoString(buf, "; subxacts:"); for (i = 0; i < parsed.nsubxacts; i++) appendStringInfo(buf, " %u", parsed.subxacts[i]); } if (parsed.nmsgs > 0) { if (XactCompletionRelcacheInitFileInval(parsed.xinfo)) appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u", parsed.dbId, parsed.tsId); appendStringInfoString(buf, "; inval msgs:"); for (i = 0; i < parsed.nmsgs; i++) { SharedInvalidationMessage *msg = &parsed.msgs[i]; if (msg->id >= 0) appendStringInfo(buf, " catcache %d", msg->id); else if (msg->id == SHAREDINVALCATALOG_ID) appendStringInfo(buf, " catalog %u", msg->cat.catId); else if (msg->id == SHAREDINVALRELCACHE_ID) appendStringInfo(buf, " relcache %u", msg->rc.relId); /* not expected, but print something anyway */ else if (msg->id == SHAREDINVALSMGR_ID) appendStringInfoString(buf, " smgr"); /* not expected, but print something anyway */ else if (msg->id == SHAREDINVALRELMAP_ID) appendStringInfoString(buf, " relmap"); else if (msg->id == SHAREDINVALSNAPSHOT_ID) appendStringInfo(buf, " snapshot %u", msg->sn.relId); else appendStringInfo(buf, " unknown id %d", msg->id); } } if (XactCompletionForceSyncCommit(parsed.xinfo)) appendStringInfo(buf, "; sync"); if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) { appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s", origin_id, (uint32)(parsed.origin_lsn >> 32), (uint32)parsed.origin_lsn, timestamptz_to_str(parsed.origin_timestamp)); }
char* fs_info(void) { char* result; FILE *fp; struct mntent *fs; struct statvfs vfs; StringInfoData resultbuf; char strbuf[30]; TimestampTz now; initStringInfo(&resultbuf); appendStringInfo(&resultbuf, "FSINFO;"); fp = setmntent("/etc/mtab", "r"); /* read only */ if (fp == NULL) { elog(LOG, "%s: could not open: %s\n", "/etc/mtab", strerror(errno)); result = palloc(2); strcpy(result, ""); return result; } while ((fs = getmntent(fp)) != NULL) { if (fs->mnt_fsname[0] == '/') { if (statvfs(fs->mnt_dir, & vfs) != 0) { //elog(LOG, "SKIPPING %s: statvfs failed: %s\n", fs->mnt_dir, strerror(errno)); } else { /* Filesystem Info */ appendStringInfoString(&resultbuf, fs->mnt_fsname); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, fs->mnt_dir); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, fs->mnt_type); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, fs->mnt_opts); appendStringInfo(&resultbuf, FIELD_DELIMIT); /* Filesystem Stats */ sprintf(strbuf, "%ld", (unsigned long) vfs.f_bsize); appendStringInfoString(&resultbuf, strbuf); appendStringInfo(&resultbuf, FIELD_DELIMIT); sprintf(strbuf, "%ld", (unsigned long) vfs.f_frsize); appendStringInfoString(&resultbuf, strbuf); appendStringInfo(&resultbuf, FIELD_DELIMIT); sprintf(strbuf, "%ld", (unsigned long) vfs.f_blocks); appendStringInfoString(&resultbuf, strbuf); appendStringInfo(&resultbuf, FIELD_DELIMIT); sprintf(strbuf, "%ld", (unsigned long) vfs.f_bfree); appendStringInfoString(&resultbuf, strbuf); appendStringInfo(&resultbuf, FIELD_DELIMIT); sprintf(strbuf, "%ld", (unsigned long) vfs.f_bavail); appendStringInfoString(&resultbuf, strbuf); appendStringInfo(&resultbuf, FIELD_DELIMIT); /* add current_timestamp */ now = GetCurrentTimestamp(); appendStringInfoString(&resultbuf, (char *)timestamptz_to_str(now)); appendStringInfo(&resultbuf,REC_DELIMIT); } } } endmntent(fp); // elog(LOG, "FSINFO: %s", resultbuf.data); //print the command to send, debugging appendStringInfoString(&resultbuf, CDELIMIT); result = pstrdup(resultbuf.data); return result; }