2018-04-29 11:20:51 -04:00
|
|
|
/***********************************************************************************************************************************
|
2018-09-25 10:24:42 +01:00
|
|
|
PostgreSQL Interface
|
2018-04-29 11:20:51 -04:00
|
|
|
***********************************************************************************************************************************/
|
2018-09-25 10:24:42 +01:00
|
|
|
#ifndef POSTGRES_INTERFACE_H
|
|
|
|
#define POSTGRES_INTERFACE_H
|
2018-04-29 11:20:51 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2018-09-25 10:24:42 +01:00
|
|
|
#include "common/type/string.h"
|
2019-08-21 11:29:30 -04:00
|
|
|
#include "storage/storage.h"
|
2018-09-25 10:24:42 +01:00
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Defines for various Postgres paths and files
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_FILE_PGCONTROL "pg_control"
|
2019-09-26 07:52:02 -04:00
|
|
|
#define PG_FILE_PGVERSION "PG_VERSION"
|
|
|
|
STRING_DECLARE(PG_FILE_PGVERSION_STR);
|
2019-08-21 16:26:28 -04:00
|
|
|
#define PG_FILE_POSTMASTERPID "postmaster.pid"
|
2019-09-26 07:52:02 -04:00
|
|
|
STRING_DECLARE(PG_FILE_POSTMASTERPID_STR);
|
|
|
|
#define PG_FILE_RECOVERYCONF "recovery.conf"
|
|
|
|
STRING_DECLARE(PG_FILE_RECOVERYCONF_STR);
|
|
|
|
#define PG_FILE_TABLESPACEMAP "tablespace_map"
|
2018-09-25 10:24:42 +01:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
#define PG_PATH_ARCHIVE_STATUS "archive_status"
|
2019-09-26 07:52:02 -04:00
|
|
|
#define PG_PATH_BASE "base"
|
2018-09-25 10:24:42 +01:00
|
|
|
#define PG_PATH_GLOBAL "global"
|
2019-09-26 07:52:02 -04:00
|
|
|
STRING_DECLARE(PG_PATH_GLOBAL_STR);
|
2018-09-25 10:24:42 +01:00
|
|
|
|
2019-08-01 15:38:27 -04:00
|
|
|
#define PG_NAME_WAL "wal"
|
|
|
|
STRING_DECLARE(PG_NAME_WAL_STR);
|
|
|
|
#define PG_NAME_XLOG "xlog"
|
|
|
|
STRING_DECLARE(PG_NAME_XLOG_STR);
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Name of default PostgreSQL database used for running all queries and commands
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_DB_POSTGRES "postgres"
|
|
|
|
STRING_DECLARE(PG_DB_POSTGRES_STR);
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Define default page size
|
|
|
|
|
|
|
|
Page size can only be changed at compile time and is not known to be well-tested, so only the default page size is supported.
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_PAGE_SIZE_DEFAULT ((unsigned int)(8 * 1024))
|
|
|
|
|
2019-09-26 07:52:02 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Define the minimum oid that can be used for a user object
|
|
|
|
|
|
|
|
Everything below this number should have been created at initdb time.
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_USER_OBJECT_MIN_ID 16384
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Define default segment size and pages per segment
|
|
|
|
|
|
|
|
Segment size can only be changed at compile time and is not known to be well-tested, so only the default segment size is supported.
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_SEGMENT_SIZE_DEFAULT ((unsigned int)(1 * 1024 * 1024 * 1024))
|
|
|
|
#define PG_SEGMENT_PAGE_DEFAULT (PG_SEGMENT_SIZE_DEFAULT / PG_PAGE_SIZE_DEFAULT)
|
|
|
|
|
2018-04-29 11:20:51 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
PostgreSQL Control File Info
|
|
|
|
***********************************************************************************************************************************/
|
2018-09-25 10:24:42 +01:00
|
|
|
typedef struct PgControl
|
2018-04-29 11:20:51 -04:00
|
|
|
{
|
2018-09-25 10:24:42 +01:00
|
|
|
unsigned int version;
|
2018-04-29 11:20:51 -04:00
|
|
|
uint64_t systemId;
|
2018-09-25 10:24:42 +01:00
|
|
|
|
|
|
|
unsigned int pageSize;
|
|
|
|
unsigned int walSegmentSize;
|
|
|
|
|
|
|
|
bool pageChecksum;
|
|
|
|
} PgControl;
|
2018-04-29 11:20:51 -04:00
|
|
|
|
2019-03-19 19:44:06 +04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
PostgreSQL WAL Info
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
typedef struct PgWal
|
|
|
|
{
|
|
|
|
unsigned int version;
|
|
|
|
uint64_t systemId;
|
|
|
|
} PgWal;
|
|
|
|
|
2018-04-29 11:20:51 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Functions
|
|
|
|
***********************************************************************************************************************************/
|
2019-09-07 18:04:39 -04:00
|
|
|
uint32_t pgCatalogVersion(unsigned int pgVersion);
|
2019-08-21 11:29:30 -04:00
|
|
|
PgControl pgControlFromFile(const Storage *storage, const String *pgPath);
|
2018-09-25 10:24:42 +01:00
|
|
|
PgControl pgControlFromBuffer(const Buffer *controlFile);
|
2019-09-07 18:04:39 -04:00
|
|
|
uint32_t pgControlVersion(unsigned int pgVersion);
|
2018-09-06 10:12:14 -07:00
|
|
|
unsigned int pgVersionFromStr(const String *version);
|
|
|
|
String *pgVersionToStr(unsigned int version);
|
2018-04-29 11:20:51 -04:00
|
|
|
|
2019-03-19 19:44:06 +04:00
|
|
|
PgWal pgWalFromFile(const String *walFile);
|
|
|
|
PgWal pgWalFromBuffer(const Buffer *walBuffer);
|
|
|
|
|
2019-09-09 07:37:57 -04:00
|
|
|
// Get the tablespace identifier used to distinguish versions in a tablespace directory, e.g. PG_9.0_201008051
|
2019-09-08 06:53:23 -04:00
|
|
|
String *pgTablespaceId(unsigned int pgVersion);
|
|
|
|
|
2019-08-01 15:38:27 -04:00
|
|
|
const String *pgWalName(unsigned int pgVersion);
|
|
|
|
|
2018-09-25 10:24:42 +01:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Functions
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#ifdef DEBUG
|
|
|
|
Buffer *pgControlTestToBuffer(PgControl pgControl);
|
2019-03-19 19:44:06 +04:00
|
|
|
void pgWalTestToBuffer(PgWal pgWal, Buffer *walBuffer);
|
2018-09-25 10:24:42 +01:00
|
|
|
#endif
|
|
|
|
|
2018-05-18 11:57:32 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Macros for function logging
|
|
|
|
***********************************************************************************************************************************/
|
2018-09-25 10:24:42 +01:00
|
|
|
String *pgControlToLog(const PgControl *pgControl);
|
2019-03-19 19:44:06 +04:00
|
|
|
String *pgWalToLog(const PgWal *pgWal);
|
2018-09-25 10:24:42 +01:00
|
|
|
|
2019-01-21 17:41:59 +02:00
|
|
|
#define FUNCTION_LOG_PG_CONTROL_TYPE \
|
2018-09-25 10:24:42 +01:00
|
|
|
PgControl
|
2019-01-21 17:41:59 +02:00
|
|
|
#define FUNCTION_LOG_PG_CONTROL_FORMAT(value, buffer, bufferSize) \
|
|
|
|
FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgControlToLog, buffer, bufferSize)
|
2018-05-18 11:57:32 -04:00
|
|
|
|
2019-03-19 19:44:06 +04:00
|
|
|
#define FUNCTION_LOG_PG_WAL_TYPE \
|
|
|
|
PgWal
|
|
|
|
#define FUNCTION_LOG_PG_WAL_FORMAT(value, buffer, bufferSize) \
|
|
|
|
FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgWalToLog, buffer, bufferSize)
|
|
|
|
|
2018-04-29 11:20:51 -04:00
|
|
|
#endif
|