Пример #1
0
/* commit if needed */
bool
pgut_commit(PGconn *conn)
{
	if (conn && PQtransactionStatus(conn) != PQTRANS_IDLE)
		return pgut_command(conn, "COMMIT", 0, NULL) == PGRES_COMMAND_OK;

	return true;	/* nothing to do */
}
Пример #2
0
/*
 * command - Execute a SQL and discard the result.
 */
ExecStatusType
command(const char *query, int nParams, const char **params)
{
	return pgut_command(connection, query, nParams, params);
}
Пример #3
0
static bool
Checkpoint_exec(CheckpointLog *ckpt, PGconn *conn, const char *instid)
{
	const char	   *params[10];
	char			write_duration[32];	/* for "%ld.%03d" */
	char			sync_duration[32];
	char			total_duration[32];

	elog(DEBUG2, "write (checkpoint)");

	params[0] = instid;						/* instid */
	params[1] = ckpt->start;				/* start */
	params[2] = ckpt->flags;				/* flags */
	params[3] = list_nth(ckpt->params, 0);	/* num_buffers */

#if PG_VERSION_NUM >= 90100
	params[4] = list_nth(ckpt->params, 2);	/* xlog_added */
	params[5] = list_nth(ckpt->params, 3);	/* xlog_removed */
	params[6] = list_nth(ckpt->params, 4);	/* xlog_recycled */

	snprintf(write_duration, lengthof(write_duration), "%s.%s",
		(const char *) list_nth(ckpt->params, 5),
		(const char *) list_nth(ckpt->params, 6));
	snprintf(sync_duration, lengthof(sync_duration), "%s.%s",
		(const char *) list_nth(ckpt->params, 7),
		(const char *) list_nth(ckpt->params, 8));
	snprintf(total_duration, lengthof(total_duration), "%s.%s",
		(const char *) list_nth(ckpt->params, 9),
		(const char *) list_nth(ckpt->params, 10));
#else
	if (ckpt->type == CKPT_TYPE_RESTARTPOINT)
	{
		params[4] = NULL;	/* xlog_added */
		params[5] = NULL;	/* xlog_removed */
		params[6] = NULL;	/* xlog_recycled */

		snprintf(write_duration, lengthof(write_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 2),
			(const char *) list_nth(ckpt->params, 3));
		snprintf(sync_duration, lengthof(sync_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 4),
			(const char *) list_nth(ckpt->params, 5));
		snprintf(total_duration, lengthof(total_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 6),
			(const char *) list_nth(ckpt->params, 7));
	}
	else
	{
		params[4] = list_nth(ckpt->params, 2);	/* xlog_added */
		params[5] = list_nth(ckpt->params, 3);	/* xlog_removed */
		params[6] = list_nth(ckpt->params, 4);	/* xlog_recycled */

		snprintf(write_duration, lengthof(write_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 5),
			(const char *) list_nth(ckpt->params, 6));
		snprintf(sync_duration, lengthof(sync_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 7),
			(const char *) list_nth(ckpt->params, 8));
		snprintf(total_duration, lengthof(total_duration), "%s.%s",
			(const char *) list_nth(ckpt->params, 9),
			(const char *) list_nth(ckpt->params, 10));
	}
#endif

	params[7] = write_duration;	/* write_duration */
	params[8] = sync_duration;	/* sync_duration */
	params[9] = total_duration;	/* total_duration */

	return pgut_command(conn,
				SQL_INSERT_CHECKPOINT, 10, params) == PGRES_COMMAND_OK;
}
Пример #4
0
/* rollback if needed */
void
pgut_rollback(PGconn *conn)
{
	if (conn && PQtransactionStatus(conn) != PQTRANS_IDLE)
		pgut_command(conn, "ROLLBACK", 0, NULL);
}