int zbx_dbconn_lock_ids(zbx_dbconn_t *db, const char *table_name, const char *field_name, zbx_vector_uint64_t *ids)
#if defined(HAVE_POSTGRESQL)
# include "zbx_dbversion_constants.h"
#define ZBX_MAX_SQL_SIZE 262144
#ifndef ZBX_MAX_OVERFLOW_SQL_SIZE
# define ZBX_MAX_OVERFLOW_SQL_SIZE ZBX_MAX_SQL_SIZE
#elif 0 != ZBX_MAX_OVERFLOW_SQL_SIZE && \
(1024 > ZBX_MAX_OVERFLOW_SQL_SIZE || ZBX_MAX_OVERFLOW_SQL_SIZE > ZBX_MAX_SQL_SIZE)
#error ZBX_MAX_OVERFLOW_SQL_SIZE is out of range
ZBX_CONST_PTR_VECTOR_IMPL(const_db_field_ptr, const zbx_db_field_t *)
ZBX_PTR_VECTOR_IMPL(db_value_ptr, zbx_db_value_t *)
const char *idcache_tables[] = {"events", "event_tag", "problem_tag", "dservices", "dhosts", "alerts",
"escalations", "autoreg_host", "event_suppress", "trigger_queue",
"proxy_history", "proxy_dhistory", "proxy_autoreg_host", "host_proxy"};
#define ZBX_IDS_SIZE ARRSIZE(idcache_tables)
static int compare_table_names(const void *d1, const void *d2)
const char *n1 = *(const char * const *)d1;
const char *n2 = *(const char * const *)d2;
zbx_uint64_t lastids[ZBX_IDS_SIZE];
static zbx_mutex_t idcache_mutex = ZBX_MUTEX_NULL;
zbx_shmem_info_t *idcache_mem;
static zbx_db_idcache_t *idcache = NULL;
int zbx_db_init(char **error)
qsort(idcache_tables, ZBX_IDS_SIZE, sizeof(idcache_tables[0]), compare_table_names);
if (SUCCEED != dbconn_init(error))
if (SUCCEED != zbx_mutex_create(&idcache_mutex, ZBX_MUTEX_CACHE_IDS, error))
if (SUCCEED != zbx_shmem_create_min(&idcache_mem, sizeof(zbx_db_idcache_t), "table ids cache", NULL, 0, error))
idcache = idcache_mem->base;
memset(idcache, 0, sizeof(zbx_db_idcache_t));
zbx_shmem_destroy(idcache_mem);