smax-postgres v0.9
PostgreSQL / TimescaleDB logger for SMA-X
Loading...
Searching...
No Matches
postgres-backend.c File Reference

Macros

#define _GNU_SOURCE
 C source code standard.
 
#define COL_NAME_STEM   "c"
 prefix for array data columns
 
#define DEFAULT_STRING_LEN   16
 (bytes) default initial size for variable-length strings
 
#define FIX_SCALAR_DIMS   0
 Whether singled-element 1D data should be stored as scalars.
 
#define MASTER_TABLE   "titles"
 table name in which to store variable name -> id pairings
 
#define META_NAME_PATTERN   TABLE_NAME_PATTERN "_meta"
 pattern for metadata table names
 
#define META_SERIAL_ID   "serial"
 column name/id for metadata serial numbers
 
#define META_SHAPE_LEN   X_MAX_STRING_DIMS
 Maximum number of dimensions to store.
 
#define META_UNIT_LEN   32
 Maximum size for sotring physical units.
 
#define MIN_CMD_SIZE   16384
 (bytes) Initial size of the command buffer
 
#define POSTGRES   1
 Use PostgreSQL data types from sql-types.h.
 
#define SQL_COL_NAME_LEN   32
 (bytes) Maximum length for column names
 
#define SQL_SEP   ", "
 List separator.
 
#define SQL_TABLE_NAME_LEN   32
 (bytes) Maximum length for table names
 
#define SQL_TYPE_LEN   64
 (bytes) Maximum length of SQL data type names
 
#define TABLE_NAME_PATTERN   "var_%06d"
 pattern for tables names that store data for variables
 
#define VARNAME_ID   "name"
 column name/id for variable names
 

Functions

int deleteVars (const char *pattern)
 
int insertQueue (Variable *u)
 
int setupDB (const char *owner, const char *passwd)
 
void * SQLThread ()
 

Detailed Description

Date
Created on Nov 5, 2023
Author
Attila Kovacs

SQL backend module for smaxLogger. It supports most common SQL flavors. The specific SQL flavor to use can be selected via an appropriate compiler constant.

Function Documentation

◆ deleteVars()

int deleteVars ( const char *  pattern)

Deletes variables and metadata from the SQL DB, and removes them from the master table also.

Parameters
patternGlob variable name pattern
Returns
The number of variables deleted from the SQL DB, or -1 if there was an error (errno will indicate the type of error).

References MASTER_TABLE.

◆ insertQueue()

int insertQueue ( Variable u)

Add the variable to the queue for database insertion.

Parameters
uPointer to the variable data structure
Returns
SUCCESS_RETURN (0) if successful, or else ERROR_RETURN (-1; errno will indicate the type of error).

References ERROR_RETURN, Variable::next, and SUCCESS_RETURN.

◆ setupDB()

int setupDB ( const char *  owner,
const char *  passwd 
)

Sets up (bootstraps) a clean new database

Parameters
ownerUser that will own the database (it must have privileges for creating the database)
passwdPassword for oqner
Returns
SUUCCESS_RETURN if successful, or else ERROR_RETURN.

References IDLE_STATE.

◆ SQLThread()

void * SQLThread ( )

The main processing thread, which pulls values from the queue and inserts them into the database asynchronously. It is started up by initialize();

Returns
NULL

References CONNECT_RETRY_ATTEMPTS, destroyVariable(), ERROR_EXIT, IDLE_STATE, META_NAME_PATTERN, Variable::next, SQL_TABLE_NAME_LEN, SUCCESS_RETURN, and TRUE.