Documentation
¶
Overview ¶
Package dbs runs managed databases (Phase 12): dedicated data members pinned to nodes with node-local volumes, internal and public endpoints, an access list per database, and metrics. Valkey is the first engine: Sentinel failover, online memory and read-replica autoscaling, and the explorer.
Index ¶
- Constants
- Variables
- func EtcdHost(ord int) string
- func Host(d store.Database) string
- func NormalizeNetwork(n *Network, exists func(p secgroup.Peer) bool) error
- func PgDatabase(d store.Database) string
- func PgObjectPrivileges() map[string][]string
- func PortEntrypoint(port int) string
- func PublicHost(d store.Database, base string) string
- func PublicReadHost(d store.Database, base string) string
- func ReadHost(d store.Database) string
- func Volume(d store.Database, kind string, ordinal int) string
- type AutoscaleStatus
- type Autoscaling
- type BackupRun
- type CreateRequest
- type Credentials
- type EngineInfo
- type ErrInvalid
- type EtcdView
- type Info
- type KeyInfo
- type KeyPage
- type Live
- type Manager
- func (m *Manager) AlterPgDatabase(ctx context.Context, d store.Database, name string, in PgDatabaseInput) error
- func (m *Manager) AlterPgRole(ctx context.Context, d store.Database, name string, in PgRoleInput) (string, error)
- func (m *Manager) ApplyPgPreset(ctx context.Context, d store.Database, db string, p PgAccessPreset) ([]string, error)
- func (m *Manager) ApplyPgPrivileges(ctx context.Context, d store.Database, db string, changes []PgPrivilegeChange) ([]string, error)
- func (m *Manager) Autoscale(id string) AutoscaleStatus
- func (m *Manager) Backups(ctx context.Context, d store.Database) (PgBackups, error)
- func (m *Manager) ChangePgExtension(ctx context.Context, d store.Database, db string, ch PgExtensionChange) error
- func (m *Manager) Command(ctx context.Context, d store.Database, args []string) (any, error)
- func (m *Manager) Create(ctx context.Context, req CreateRequest) (View, error)
- func (m *Manager) CreatePgDatabase(ctx context.Context, d store.Database, in PgDatabaseInput) error
- func (m *Manager) CreatePgRole(ctx context.Context, d store.Database, in PgRoleInput) (string, error)
- func (m *Manager) Credentials(ctx context.Context, d store.Database) (Credentials, error)
- func (m *Manager) Delete(ctx context.Context, id string) error
- func (m *Manager) DeleteKeys(ctx context.Context, d store.Database, keys ...string) (int64, error)
- func (m *Manager) Directory(ctx context.Context, vip func(index int) string, pool store.IndexPool, ...) ([]*agentv1.VirtualService, []*agentv1.DNSRecord)
- func (m *Manager) DropPgDatabase(ctx context.Context, d store.Database, name string) error
- func (m *Manager) DropPgRole(ctx context.Context, d store.Database, name, reassignTo string) error
- func (m *Manager) Enqueue(id string)
- func (m *Manager) Etcd(ctx context.Context) []EtcdView
- func (m *Manager) EtcdHosts(ctx context.Context) []string
- func (m *Manager) Events(ctx context.Context, id string, limit int, before string) ([]store.DatabaseEvent, error)
- func (m *Manager) Expire(ctx context.Context, d store.Database, key string, seconds int64) error
- func (m *Manager) Failover(ctx context.Context, id string) error
- func (m *Manager) Get(ctx context.Context, d store.Database, key string) (Value, error)
- func (m *Manager) Hooks() agentgw.Hooks
- func (m *Manager) InfoSections(ctx context.Context, d store.Database) (Sections, error)
- func (m *Manager) List(ctx context.Context) ([]View, error)
- func (m *Manager) PgDatabases(ctx context.Context, d store.Database) ([]PgDatabaseInfo, error)
- func (m *Manager) PgExtensions(ctx context.Context, d store.Database, db string) ([]PgExtension, error)
- func (m *Manager) PgObjectByName(ctx context.Context, d store.Database, db, schema, name string, oid uint32) (PgObjectDetail, error)
- func (m *Manager) PgObjectGrants(ctx context.Context, d store.Database, db string, ref PgObjectRef, role string) (PgPrivileges, error)
- func (m *Manager) PgReplicationStatus(ctx context.Context, d store.Database) (PgReplication, error)
- func (m *Manager) PgRoleByName(ctx context.Context, d store.Database, name string) (PgRole, error)
- func (m *Manager) PgRoles(ctx context.Context, d store.Database) ([]PgRole, error)
- func (m *Manager) PgSchemaTree(ctx context.Context, d store.Database, db string, system bool) ([]PgSchema, error)
- func (m *Manager) PgSessions(ctx context.Context, d store.Database, all bool) ([]PgSession, error)
- func (m *Manager) PgSettings(ctx context.Context, d store.Database) ([]PgSetting, error)
- func (m *Manager) PgTableRows(ctx context.Context, d store.Database, db string, q PgRowsQuery) (PgRows, error)
- func (m *Manager) PublicEngines(ctx context.Context) []string
- func (m *Manager) PublicHosts(ctx context.Context, base string) []string
- func (m *Manager) PublicPorts(ctx context.Context) []PublicPort
- func (m *Manager) PublicRoutes(ctx context.Context, base string) []PublicRoute
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) RunPgQuery(ctx context.Context, d store.Database, q PgQuery, write bool) (PgQueryResult, error)
- func (m *Manager) Scan(ctx context.Context, d store.Database, pattern, typ string, cursor uint64, ...) (KeyPage, error)
- func (m *Manager) Set(ctx context.Context, d store.Database, key string, w Write) error
- func (m *Manager) SetNetwork(ctx context.Context, id string, n Network, exists func(p secgroup.Peer) bool, ...) (View, error)
- func (m *Manager) SignalPgSession(ctx context.Context, d store.Database, pid int, terminate bool) error
- func (m *Manager) SlowLog(ctx context.Context, d store.Database) ([]SlowEntry, error)
- func (m *Manager) StartBackup(ctx context.Context, d store.Database) (store.DatabaseBackup, error)
- func (m *Manager) Update(ctx context.Context, id string, spec Spec, actor string) (View, error)
- func (m *Manager) Usage(ctx context.Context) map[string]workload.Usage
- func (m *Manager) View(ctx context.Context, d store.Database) View
- type Member
- type Network
- type PgAccessPreset
- type PgAddon
- type PgArchiver
- type PgBackupSpec
- type PgBackups
- type PgBaseBackup
- type PgClusterMember
- type PgColumn
- type PgColumnMeta
- type PgConstraint
- type PgDatabaseInfo
- type PgDatabaseInput
- type PgDefaultGrant
- type PgExtension
- type PgExtensionChange
- type PgGrant
- type PgIndex
- type PgMembership
- type PgObject
- type PgObjectDetail
- type PgObjectRef
- type PgParam
- type PgPrivilegeChange
- type PgPrivileges
- type PgQuery
- type PgQueryError
- type PgQueryResult
- type PgReplica
- type PgReplication
- type PgReplicationSpec
- type PgRestore
- type PgRole
- type PgRoleInput
- type PgRowFilter
- type PgRows
- type PgRowsQuery
- type PgSchema
- type PgSession
- type PgSetting
- type PgSlot
- type PgStatementResult
- type PgTrigger
- type PostgresSpec
- type PublicEndpoint
- type PublicPort
- type PublicRoute
- type Range
- type Recorder
- type RestoreState
- type RestoreWindow
- type S3Access
- type Secrets
- type Sections
- type SlowEntry
- type Spec
- type State
- type StreamEntry
- type Usage
- type Value
- type View
- type Write
- type ZMember
Constants ¶
const ( EngineValkey = "valkey" EnginePostgres = "postgres" )
Engine names.
const ( EtcdPrefix = "dbe_" // EtcdServiceID labels etcd containers for security groups. EtcdServiceID = "etcd" )
const ( ReplAsync = "async" ReplSync = "sync" ReplStrict = "strict" )
const ( // DefaultVersion of Valkey. DefaultVersion = "8.1" // Port of data members; sentinels listen on SentinelPort. Port = 6379 SentinelPort = 26379 // Sentinels run when a database can have replicas (quorum 2 of 3). Sentinels = 3 )
const ( MemberPrefix = "dbm_" SentinelPrefix = "dbs_" // Zone is the internal DNS zone (as discovery's). Zone = "syncloud.internal" )
Task ID prefixes of database containers.
const ( KindData = "data" KindSentinel = "sentinel" )
Kinds of members.
const BackupPrefix = "dbk_"
BackupPrefix is the task ID prefix of base backup runs.
const (
PostgresPort = 5432
)
const (
// TopicDatabase carries a View when a database changes ({id, deleted} on delete).
TopicDatabase = "database.updated"
)
Variables ¶
var DefaultPublicPorts = [2]int{21000, 21999}
DefaultPublicPorts is where dedicated public database ports come from.
var Engines = []EngineInfo{ { Name: EngineValkey, Title: "Valkey", Available: true, Description: "Redis-compatible in-memory store (BSD). Sentinel failover, read replicas, online memory autoscaling.", Versions: versions(), DefaultVersion: DefaultVersion, Port: Port, Scheme: "redis", TLSScheme: "rediss", Entrypoint: "valkey", Features: []string{"explorer", "console", "failover", "memoryAutoscaling", "replicaAutoscaling"}, }, { Name: EnginePostgres, Title: "PostgreSQL", Available: true, Description: "PostgreSQL 18 or 17 with Patroni failover, streaming replicas and WAL-G backups; optional pgvector, TimescaleDB (Apache), pg_duckdb, PostGIS, pg_partman and pg_cron.", Versions: pgVersions, DefaultVersion: pgDefaultVersion, Port: PostgresPort, Scheme: "postgresql", TLSScheme: "postgresql", Entrypoint: "postgres", Features: []string{"failover"}, Addons: PgAddons, Parameters: PgParams, }, }
Engines lists the engines, available ones first.
var ErrNoKey = errors.New("no such key")
ErrNoKey means the key does not exist.
ErrUnavailable means no member can answer right now.
var EvictionPolicies = []string{"noeviction", "allkeys-lru", "allkeys-lfu", "allkeys-random", "volatile-lru", "volatile-lfu", "volatile-random", "volatile-ttl"}
EvictionPolicies are the maxmemory-policy values offered.
var Images = map[string]string{"8.1": "valkey/valkey:8.1-alpine", "8.0": "valkey/valkey:8.0-alpine"}
Images by version.
var PgAddons = []PgAddon{ {Name: "timescaledb", Title: "TimescaleDB", Description: "Time-series hypertables, compression and continuous aggregates (Apache edition).", Preload: "timescaledb", Extensions: []string{"timescaledb"}}, {Name: "pg_duckdb", Title: "pg_duckdb", Description: "DuckDB's columnar engine for analytics queries, Parquet and S3.", Preload: "pg_duckdb", Extensions: []string{"pg_duckdb"}}, {Name: "pg_cron", Title: "pg_cron", Description: "Cron-style jobs scheduled inside the database.", Preload: "pg_cron", Extensions: []string{"pg_cron"}}, {Name: "vector", Title: "pgvector", Description: "Vector similarity search (embeddings) with HNSW and IVFFlat indexes.", Extensions: []string{"vector"}}, {Name: "postgis", Title: "PostGIS", Description: "Geographic objects, spatial indexes and functions.", Extensions: []string{"postgis", "postgis_topology", "postgis_raster", "postgis_tiger_geocoder"}}, {Name: "pg_partman", Title: "pg_partman", Description: "Time- and serial-based partition management.", Extensions: []string{"pg_partman"}}, {Name: "hypopg", Title: "HypoPG", Description: "Hypothetical indexes for EXPLAIN.", Extensions: []string{"hypopg"}}, }
PgAddons are the add-ons a cluster can enable.
var PgParams = []PgParam{ {Name: "shared_buffers", Group: "Memory", Type: "memory", Min: 128, Max: 1 << 30, Restart: true, Description: "Shared page cache (default: a quarter of the memory)."}, {Name: "effective_cache_size", Group: "Memory", Type: "memory", Min: 8, Max: 1 << 31, Description: "Planner's estimate of the OS and Postgres caches (default: three quarters of the memory)."}, {Name: "work_mem", Group: "Memory", Type: "memory", Min: 64, Max: 1 << 31, Description: "Memory per sort or hash step before spilling to disk."}, {Name: "maintenance_work_mem", Group: "Memory", Type: "memory", Min: 1024, Max: 1 << 31, Description: "Memory for VACUUM, CREATE INDEX and ALTER TABLE."}, {Name: "temp_buffers", Group: "Memory", Type: "memory", Min: 800, Max: 1 << 30, Description: "Per-session buffers for temporary tables."}, {Name: "huge_pages", Group: "Memory", Type: "enum", Enum: []string{"try", "on", "off"}, Restart: true, Description: "Use huge pages for shared memory."}, {Name: "max_worker_processes", Group: "Parallelism", Type: "int", Min: 8, Max: 256, Restart: true, Description: "Background worker processes (parallel queries, add-ons)."}, {Name: "max_parallel_workers", Group: "Parallelism", Type: "int", Min: 0, Max: 256, Description: "Workers available to parallel queries."}, {Name: "max_parallel_workers_per_gather", Group: "Parallelism", Type: "int", Min: 0, Max: 64, Description: "Workers one query step may use."}, {Name: "max_parallel_maintenance_workers", Group: "Parallelism", Type: "int", Min: 0, Max: 64, Description: "Workers one CREATE INDEX or VACUUM may use."}, {Name: "random_page_cost", Group: "Planner", Type: "real", Min: 0, Max: 100, Description: "Cost of a random page read (1.1 suits SSDs)."}, {Name: "seq_page_cost", Group: "Planner", Type: "real", Min: 0, Max: 100, Description: "Cost of a sequential page read."}, {Name: "effective_io_concurrency", Group: "Planner", Type: "int", Min: 0, Max: 1000, Description: "Concurrent disk reads the storage handles well."}, {Name: "default_statistics_target", Group: "Planner", Type: "int", Min: 1, Max: 10000, Description: "Detail of ANALYZE statistics."}, {Name: "jit", Group: "Planner", Type: "bool", Description: "Compile expensive queries with LLVM."}, {Name: "checkpoint_timeout", Group: "WAL", Type: "time", Min: 30_000, Max: 86_400_000, Description: "Longest time between checkpoints."}, {Name: "checkpoint_completion_target", Group: "WAL", Type: "real", Min: 0, Max: 1, Description: "Fraction of the interval a checkpoint spreads its writes over."}, {Name: "max_wal_size", Group: "WAL", Type: "memory", Min: 2048, Max: 1 << 31, Description: "WAL that triggers a checkpoint."}, {Name: "min_wal_size", Group: "WAL", Type: "memory", Min: 2048, Max: 1 << 31, Description: "WAL kept for reuse."}, {Name: "wal_compression", Group: "WAL", Type: "enum", Enum: []string{"off", "on", "pglz", "lz4", "zstd"}, Description: "Compress full-page images in the WAL."}, {Name: "wal_buffers", Group: "WAL", Type: "memory", Min: 64, Max: 1 << 21, Restart: true, Description: "WAL in shared memory not yet written."}, {Name: "synchronous_commit", Group: "WAL", Type: "enum", Enum: []string{"on", "remote_apply", "remote_write", "local", "off"}, Description: "How far a commit waits (with synchronous replication: for the replicas)."}, {Name: "statement_timeout", Group: "Sessions", Type: "time", Min: 0, Max: 2_147_483_647, Description: "Cancel statements running longer (0 = never)."}, {Name: "lock_timeout", Group: "Sessions", Type: "time", Min: 0, Max: 2_147_483_647, Description: "Give up waiting for a lock after this (0 = never)."}, {Name: "idle_in_transaction_session_timeout", Group: "Sessions", Type: "time", Min: 0, Max: 2_147_483_647, Description: "End sessions idle inside a transaction (0 = never)."}, {Name: "idle_session_timeout", Group: "Sessions", Type: "time", Min: 0, Max: 2_147_483_647, Description: "End idle sessions (0 = never)."}, {Name: "default_transaction_isolation", Group: "Sessions", Type: "enum", Enum: []string{"read committed", "repeatable read", "serializable"}, Description: "Isolation level of new transactions."}, {Name: "timezone", Group: "Sessions", Type: "string", Description: "Time zone for displaying timestamps (e.g. UTC, Europe/Berlin)."}, {Name: "max_locks_per_transaction", Group: "Sessions", Type: "int", Min: 10, Max: 10000, Restart: true, Description: "Lock table size per transaction (many partitions need more)."}, {Name: "max_prepared_transactions", Group: "Sessions", Type: "int", Min: 0, Max: 10000, Restart: true, Description: "Two-phase commit transactions (0 = off)."}, {Name: "autovacuum", Group: "Autovacuum", Type: "bool", Description: "Run the autovacuum daemon."}, {Name: "autovacuum_max_workers", Group: "Autovacuum", Type: "int", Min: 1, Max: 64, Restart: true, Description: "Concurrent autovacuum workers."}, {Name: "autovacuum_naptime", Group: "Autovacuum", Type: "time", Min: 1000, Max: 86_400_000, Description: "Pause between autovacuum rounds."}, {Name: "autovacuum_vacuum_scale_factor", Group: "Autovacuum", Type: "real", Min: 0, Max: 100, Description: "Fraction of a table changed before it is vacuumed."}, {Name: "autovacuum_analyze_scale_factor", Group: "Autovacuum", Type: "real", Min: 0, Max: 100, Description: "Fraction of a table changed before it is analyzed."}, {Name: "autovacuum_vacuum_cost_limit", Group: "Autovacuum", Type: "int", Min: -1, Max: 10000, Description: "Work per autovacuum round before it pauses (-1 = vacuum_cost_limit)."}, {Name: "log_min_duration_statement", Group: "Logging", Type: "time", Min: -1, Max: 2_147_483_647, Description: "Log statements slower than this (-1 = off)."}, {Name: "log_statement", Group: "Logging", Type: "enum", Enum: []string{"none", "ddl", "mod", "all"}, Description: "Which statements to log."}, {Name: "log_connections", Group: "Logging", Type: "bool", Description: "Log each connection."}, {Name: "log_disconnections", Group: "Logging", Type: "bool", Description: "Log each session's end and duration."}, {Name: "log_lock_waits", Group: "Logging", Type: "bool", Description: "Log waits longer than the deadlock timeout."}, {Name: "log_temp_files", Group: "Logging", Type: "memory", Min: -1, Max: 1 << 31, Description: "Log temporary files at least this large (-1 = off)."}, {Name: "log_autovacuum_min_duration", Group: "Logging", Type: "time", Min: -1, Max: 2_147_483_647, Description: "Log autovacuum runs longer than this (-1 = off)."}, {Name: "track_io_timing", Group: "Statistics", Type: "bool", Description: "Time disk reads and writes (EXPLAIN, pg_stat_statements)."}, {Name: "track_functions", Group: "Statistics", Type: "enum", Enum: []string{"none", "pl", "all"}, Description: "Track function calls."}, {Name: "pg_stat_statements.max", Group: "Statistics", Type: "int", Min: 100, Max: 1_000_000, Restart: true, Description: "Statements pg_stat_statements tracks."}, {Name: "pg_stat_statements.track", Group: "Statistics", Type: "enum", Enum: []string{"top", "all", "none"}, Description: "Track top-level statements, nested ones too, or none."}, {Name: "max_standby_streaming_delay", Group: "Replicas", Type: "time", Min: -1, Max: 2_147_483_647, Description: "How long replica queries may hold back replay (-1 = forever)."}, {Name: "max_standby_archive_delay", Group: "Replicas", Type: "time", Min: -1, Max: 2_147_483_647, Description: "The same while replaying archived WAL."}, {Name: "cron.max_running_jobs", Group: "Add-ons", Type: "int", Min: 1, Max: 1000, Restart: true, Addon: "pg_cron", Description: "pg_cron jobs running at once."}, {Name: "timescaledb.max_background_workers", Group: "Add-ons", Type: "int", Min: 1, Max: 1000, Restart: true, Addon: "timescaledb", Description: "TimescaleDB background workers (compression, aggregates)."}, {Name: "duckdb.max_memory", Group: "Add-ons", Type: "memory", Min: 1024, Max: 1 << 31, Addon: "pg_duckdb", Description: "Memory DuckDB may use per query."}, {Name: "duckdb.threads", Group: "Add-ons", Type: "int", Min: -1, Max: 256, Addon: "pg_duckdb", Description: "Threads DuckDB uses per query (-1 = one per core)."}, }
Memory limits are in kB, durations in ms; -1 is "off" where PostgreSQL allows it.
Functions ¶
func Host ¶
Host is the database's internal read-write name: in its environment's zone for a project database, under db.syncloud.internal when standalone.
func NormalizeNetwork ¶
NormalizeNetwork validates n and canonicalizes its peers and CIDRs. exists reports whether a referenced project, environment, service or group exists.
func PgDatabase ¶
PgDatabase is the app database's name: the cluster name as an identifier, or the source's for a restored cluster.
func PgObjectPrivileges ¶
PgObjectPrivileges lists the privilege kinds an object type supports.
func PortEntrypoint ¶ added in v0.1.2
PortEntrypoint is the Traefik entrypoint of a dedicated port.
func PublicHost ¶
PublicHost is the public read-write name under the base domain.
func PublicReadHost ¶
PublicReadHost is the public read-only name.
Types ¶
type AutoscaleStatus ¶
type AutoscaleStatus struct {
MemoryPercent float64 `json:"memoryPercent"` // used / maxmemory on the primary
ReadCPU float64 `json:"readCpu"` // avg CPU % of the members serving reads
Blocked string `json:"blocked,omitempty"`
}
AutoscaleStatus is the autoscaler's view of a database.
type Autoscaling ¶
type Autoscaling struct {
// CPUTarget is the replicas' average CPU (% of one core) to hold.
CPUTarget float64 `json:"cpuTarget"`
// MemoryHigh is used/maxmemory (%) above which memory grows.
MemoryHigh float64 `json:"memoryHigh"`
}
Autoscaling tunes the autoscaler; a dimension scales only when its min < max.
type BackupRun ¶
type BackupRun struct {
ID string `json:"id"`
Member string `json:"member"`
Trigger string `json:"trigger"`
State string `json:"state"`
Error string `json:"error,omitempty"`
StartedAt time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt,omitempty"`
}
BackupRun is a base backup task as the API shows it.
type CreateRequest ¶
type CreateRequest struct {
Name, Engine, Version string
// Env is the project environment; nil for a standalone database.
Env *store.Environment
Spec Spec
Network Network
// Exists checks access-list references (nil: not checked).
Exists func(p secgroup.Peer) bool
Actor string
// Restore creates a PostgreSQL cluster from another one's archive.
Restore *PgRestore
}
CreateRequest is a new database.
type Credentials ¶
type Credentials struct {
Host string `json:"host"`
ReadHost string `json:"readHost"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database,omitempty"` // PostgreSQL
URL string `json:"url"` // redis://default:…@host:6379
ReadURL string `json:"readUrl"` // read-only endpoint
// PublicURL and PublicReadURL reach the database from outside the
// cluster over TLS (only while the public endpoint is on); the plain
// ones without TLS (absent when the database requires TLS).
PublicURL string `json:"publicUrl,omitempty"`
PublicReadURL string `json:"publicReadUrl,omitempty"`
PublicPlainURL string `json:"publicPlainUrl,omitempty"`
PublicPlainReadURL string `json:"publicPlainReadUrl,omitempty"`
// HAURL (PostgreSQL) lists every member: libpq-compatible clients find
// the primary themselves, so they follow a failover even while the
// controller (which moves the endpoints) is down.
HAURL string `json:"haUrl,omitempty"`
}
Credentials are what clients need to connect.
type EngineInfo ¶
type EngineInfo struct {
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
Available bool `json:"available"` // false: planned
Versions []string `json:"versions"`
DefaultVersion string `json:"defaultVersion,omitempty"`
Port int `json:"port"`
// Scheme and TLSScheme build connection URLs (internal and public).
Scheme string `json:"scheme"`
TLSScheme string `json:"tlsScheme"`
// Entrypoint is the Traefik entrypoint of its public endpoints.
Entrypoint string `json:"-"`
// Features the dashboard and CLI offer: explorer, console, failover,
// memoryAutoscaling, replicaAutoscaling.
Features []string `json:"features"`
// PostgreSQL: the optional add-ons and the parameters users may set
// (§13c2), for the wizard.
Addons []PgAddon `json:"addons,omitempty"`
Parameters []PgParam `json:"parameters,omitempty"`
}
EngineInfo describes a database engine for the API and the wizard. The operator core (members, placement, network, public endpoints, events) is shared; each engine brings its task specs, probe, autoscaling signals and tools.
func EngineByName ¶
func EngineByName(name string) (EngineInfo, bool)
EngineByName returns an engine (ok false for unknown ones).
type ErrInvalid ¶
type ErrInvalid struct{ Err error }
ErrInvalid wraps validation errors.
func (ErrInvalid) Error ¶
func (e ErrInvalid) Error() string
type EtcdView ¶
type EtcdView struct {
Name string `json:"name"`
Node string `json:"node"`
State string `json:"state"`
IP string `json:"ip"`
Error string `json:"error,omitempty"`
}
EtcdView is the platform etcd as the API shows it.
type KeyInfo ¶
type KeyInfo struct {
Key string `json:"key"`
Type string `json:"type"`
TTL int64 `json:"ttlMs"` // -1 = no expiry
Bytes int64 `json:"bytes"` // MEMORY USAGE (approximate)
}
KeyInfo is one key in a listing.
type KeyPage ¶
type KeyPage struct {
Cursor uint64 `json:"cursor"` // 0 = done
Keys []KeyInfo `json:"keys"`
Total int64 `json:"total"` // keys in the database (DBSIZE)
}
KeyPage is a page of a SCAN.
type Live ¶
type Live struct {
At time.Time `json:"at"`
Role string `json:"role"` // master | slave | sentinel
Info Info `json:"-"`
Error string `json:"error,omitempty"`
LinkUp bool `json:"linkUp"`
LagBytes int64 `json:"lagBytes"`
// Sentinels: the replicas and other sentinels it knows (failover needs
// every replica known and a majority of sentinels).
KnownReplicas, KnownPeers int
}
Live is what the last probe saw of a member.
type Manager ¶
type Manager struct {
// DNS returns a node's discovery resolver and search domains for a
// member of the environment (nil without the private network).
DNS func(nodeID, project, env string) (servers, search []string)
// OnChange runs when endpoints or members change (service directory).
OnChange func()
// OnNetworkChange runs when the set of public endpoints or access lists
// changes (certificates, host firewall, security policy).
OnNetworkChange func()
// PostgresImages maps each PostgreSQL major version to the image of its
// members and backups; the default version's image also runs the
// platform etcd.
PostgresImages map[string]string
// ImageReady reports whether an image can be pulled yet (images the
// release carries are loaded into the registry on first use): nil, or
// why members must wait. Nil means always ready.
ImageReady func(ctx context.Context, image string) error
// ResolveImage turns "@registry/…" into a pullable reference with node
// credentials; RegistryCA is a certificate nodes must trust for it.
ResolveImage func(image string) (ref, registryAuth string)
RegistryCA func(ref string) string
// BaseDomain returns the platform's base domain ("" = none, so no
// public endpoints).
BaseDomain func() string
// PublicPortRange is where dedicated public ports come from (zero:
// DefaultPublicPorts).
PublicPortRange [2]int
// Metrics stores member samples (nil = none).
Metrics Recorder
// S3 resolves a registered S3 endpoint (by name or ID) for WAL-G.
S3 func(ctx context.Context, endpoint string) (S3Access, error)
// contains filtered or unexported fields
}
Manager is the database operator.
func (*Manager) AlterPgDatabase ¶
func (m *Manager) AlterPgDatabase(ctx context.Context, d store.Database, name string, in PgDatabaseInput) error
AlterPgDatabase renames a database, or changes its owner, limit or comment.
func (*Manager) AlterPgRole ¶
func (m *Manager) AlterPgRole(ctx context.Context, d store.Database, name string, in PgRoleInput) (string, error)
AlterPgRole changes a role and returns the password it set ("" when unchanged).
func (*Manager) ApplyPgPreset ¶
func (m *Manager) ApplyPgPreset(ctx context.Context, d store.Database, db string, p PgAccessPreset) ([]string, error)
ApplyPgPreset grants (or revokes) read-only or read-write access to a whole database: CONNECT, USAGE on its schemas, rights on every existing table and sequence, and default privileges for objects the schema owners and the database owner create later.
func (*Manager) ApplyPgPrivileges ¶
func (m *Manager) ApplyPgPrivileges(ctx context.Context, d store.Database, db string, changes []PgPrivilegeChange) ([]string, error)
ApplyPgPrivileges runs the changes in one transaction on db and returns the statements it ran.
func (*Manager) Autoscale ¶
func (m *Manager) Autoscale(id string) AutoscaleStatus
Autoscale returns the latest autoscaler measurements.
func (*Manager) ChangePgExtension ¶
func (m *Manager) ChangePgExtension(ctx context.Context, d store.Database, db string, ch PgExtensionChange) error
ChangePgExtension applies an extension change in db.
func (*Manager) CreatePgDatabase ¶
CreatePgDatabase creates a database (owner defaults to app).
func (*Manager) CreatePgRole ¶
func (m *Manager) CreatePgRole(ctx context.Context, d store.Database, in PgRoleInput) (string, error)
CreatePgRole creates a role and returns the password it set ("" when none).
func (*Manager) Credentials ¶
Credentials returns the app user's connection details.
func (*Manager) DeleteKeys ¶
Delete removes keys.
func (*Manager) Directory ¶
func (m *Manager) Directory(ctx context.Context, vip func(index int) string, pool store.IndexPool, cooldown time.Duration) ([]*agentv1.VirtualService, []*agentv1.DNSRecord)
Directory is what discovery publishes for databases: the read-write and read-only VIPs, and DNS names for the endpoints and every member.
func (*Manager) DropPgDatabase ¶
DropPgDatabase drops a database, disconnecting its sessions.
func (*Manager) DropPgRole ¶
DropPgRole hands the role's objects in every database to reassignTo (app by default), drops its privileges, then drops it.
func (*Manager) Events ¶
func (m *Manager) Events(ctx context.Context, id string, limit int, before string) ([]store.DatabaseEvent, error)
Events lists a database's scaling and failover events, newest first, older than the event before names when set.
func (*Manager) InfoSections ¶
InfoSections returns the primary's INFO, by section.
func (*Manager) PgDatabases ¶
PgDatabases lists the cluster's databases.
func (*Manager) PgExtensions ¶
func (m *Manager) PgExtensions(ctx context.Context, d store.Database, db string) ([]PgExtension, error)
PgExtensions lists the offered extensions and which are installed in db.
func (*Manager) PgObjectByName ¶
func (m *Manager) PgObjectByName(ctx context.Context, d store.Database, db, schema, name string, oid uint32) (PgObjectDetail, error)
PgObjectByName describes a relation or type in schema by name, or a routine by its OID (oid > 0).
func (*Manager) PgObjectGrants ¶
func (m *Manager) PgObjectGrants(ctx context.Context, d store.Database, db string, ref PgObjectRef, role string) (PgPrivileges, error)
PgObjectGrants reads an object's grants (and the effective rights of role).
func (*Manager) PgReplicationStatus ¶
PgReplicationStatus reads pg_stat_replication, the slots and Patroni's view of the members.
func (*Manager) PgRoleByName ¶
PgRoleByName returns one role.
func (*Manager) PgSchemaTree ¶
func (m *Manager) PgSchemaTree(ctx context.Context, d store.Database, db string, system bool) ([]PgSchema, error)
PgSchemaTree lists a database's schemas and their objects.
func (*Manager) PgSessions ¶
PgSessions lists client sessions (platform ones only when all is set).
func (*Manager) PgSettings ¶
PgSettings lists the catalog with the leader's values.
func (*Manager) PgTableRows ¶
func (m *Manager) PgTableRows(ctx context.Context, d store.Database, db string, q PgRowsQuery) (PgRows, error)
PgTableRows reads a page of a table, view or materialized view.
func (*Manager) PublicEngines ¶
PublicEngines are the engines with at least one public database (their entrypoint ports are opened on the controller and edge nodes).
func (*Manager) PublicHosts ¶
PublicHosts are the names that need certificates.
func (*Manager) PublicPorts ¶ added in v0.1.2
func (m *Manager) PublicPorts(ctx context.Context) []PublicPort
PublicPorts are the dedicated ports of every public database, for the Traefik entrypoints and the firewall. They need no base domain: plain connections work without one.
func (*Manager) PublicRoutes ¶
func (m *Manager) PublicRoutes(ctx context.Context, base string) []PublicRoute
PublicRoutes are the TCP routes of every public database. The SNI routes need a base domain; the dedicated ports work without one. The read-write routes target the current primary.
func (*Manager) RunPgQuery ¶
func (m *Manager) RunPgQuery(ctx context.Context, d store.Database, q PgQuery, write bool) (PgQueryResult, error)
RunPgQuery runs SQL in the console.
func (*Manager) Scan ¶
func (m *Manager) Scan(ctx context.Context, d store.Database, pattern, typ string, cursor uint64, count int) (KeyPage, error)
Scan lists keys matching pattern (and type), one SCAN step at a time.
func (*Manager) SetNetwork ¶
func (m *Manager) SetNetwork(ctx context.Context, id string, n Network, exists func(p secgroup.Peer) bool, actor string) (View, error)
SetNetwork changes a database's access list and public endpoint.
func (*Manager) SignalPgSession ¶
func (m *Manager) SignalPgSession(ctx context.Context, d store.Database, pid int, terminate bool) error
SignalPgSession cancels a session's query, or terminates the session.
func (*Manager) StartBackup ¶
StartBackup takes a base backup now.
func (*Manager) Update ¶
Update changes a database's spec. Memory and replicas apply online; persistence, eviction policy and a higher memory maximum restart the members one at a time (replicas first).
type Member ¶
type Member struct {
ID string `json:"id"`
Name string `json:"name"` // m0, s1…
Kind string `json:"kind"`
Node string `json:"node"`
NodeID string `json:"nodeId"`
State string `json:"state"`
IP string `json:"ip"`
Role string `json:"role"` // primary | replica | sentinel | ""
LinkUp bool `json:"linkUp"`
LagBytes int64 `json:"lagBytes"`
Memory int64 `json:"usedMemoryBytes"`
Ops float64 `json:"opsPerSec"`
Clients int64 `json:"clients"`
CPU float64 `json:"cpuPercent"`
Error string `json:"error,omitempty"`
Since time.Time `json:"createdAt"`
}
Member is one container of a database.
type Network ¶
type Network = store.DatabaseNetwork
Network is a database's access list and public endpoint (Phase 12e).
type PgAccessPreset ¶
type PgAccessPreset struct {
Role string `json:"role"`
Access string `json:"access"` // read, write or none
Schemas []string `json:"schemas,omitempty"` // default: every non-system schema
}
PgAccessPreset gives a role a common level of access to a database.
type PgAddon ¶
type PgAddon struct {
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
Preload string `json:"preload,omitempty"` // shared_preload_libraries entry
Extensions []string `json:"extensions,omitempty"` // CREATE EXTENSION names it unlocks
}
PgAddon is an optional extension shipped in the image. Enabled add-ons can be installed in databases; those with a library are preloaded.
type PgArchiver ¶
type PgArchiver struct {
ArchivedCount int64 `json:"archivedCount"`
LastArchived string `json:"lastArchived"`
LastAt *time.Time `json:"lastArchivedAt"`
FailedCount int64 `json:"failedCount"`
LastFailed string `json:"lastFailed"`
LastFailedAt *time.Time `json:"lastFailedAt"`
}
PgArchiver is the primary's pg_stat_archiver.
type PgBackupSpec ¶
type PgBackupSpec struct {
// Endpoint is a registered S3 endpoint (by name or ID); its
// credentials stay sealed there.
Endpoint string `json:"endpoint"`
Bucket string `json:"bucket"`
// Prefix inside the bucket; default syncloud-pg/<database ID>.
Prefix string `json:"prefix,omitempty"`
// EveryHours between base backups (1–168, default 24).
EveryHours int `json:"everyHours"`
// RetainFull base backups are kept (1–100, default 7)...
RetainFull int `json:"retainFull"`
// ...and every backup of the last RetainDays days (0–365, default 7),
// which is how far back a restore can go.
RetainDays int `json:"retainDays"`
}
PgBackupSpec turns on continuous archiving and scheduled base backups.
type PgBackups ¶
type PgBackups struct {
Configured bool `json:"configured"`
Config *PgBackupSpec `json:"config,omitempty"`
Location string `json:"location,omitempty"` // s3://bucket/prefix
Backups []PgBaseBackup `json:"backups"`
Runs []BackupRun `json:"runs"`
Archiver *PgArchiver `json:"archiver,omitempty"`
Window *RestoreWindow `json:"window,omitempty"`
Error string `json:"error,omitempty"` // the archive could not be read
Restore *RestoreState `json:"restoredFrom,omitempty"`
NextRun *time.Time `json:"nextRun,omitempty"`
}
PgBackups is the backup status of a cluster.
type PgBaseBackup ¶
type PgBaseBackup struct {
Name string `json:"name"`
StartTime time.Time `json:"startTime"`
FinishTime time.Time `json:"finishTime"`
StartLSN string `json:"startLsn"`
FinishLSN string `json:"finishLsn"`
CompressedSize int64 `json:"compressedSize"`
UncompressedSize int64 `json:"uncompressedSize"`
Permanent bool `json:"permanent"`
}
PgBaseBackup is one base backup in the archive.
type PgClusterMember ¶
type PgClusterMember struct {
Name string `json:"name"`
Role string `json:"role"`
State string `json:"state"`
Timeline int `json:"timeline"`
LagBytes any `json:"lag,omitempty"` // bytes, or "unknown"
PendingRestart bool `json:"pendingRestart"`
}
PgClusterMember is a member as Patroni reports it.
type PgColumn ¶
type PgColumn struct {
Name string `json:"name"`
Type string `json:"type"`
NotNull bool `json:"notNull"`
Default string `json:"default,omitempty"`
Identity string `json:"identity,omitempty"` // "always" or "by default"
Generated string `json:"generated,omitempty"` // the expression of a stored generated column
Comment string `json:"comment,omitempty"`
}
PgColumn is a table column.
type PgColumnMeta ¶
PgColumnMeta names a result column.
type PgConstraint ¶
type PgConstraint struct {
Name string `json:"name"`
Kind string `json:"kind"` // primary key, foreign key, unique, check, exclusion, not null
Definition string `json:"definition"`
References string `json:"references,omitempty"` // foreign keys: the referenced table
}
PgConstraint is a table constraint.
type PgDatabaseInfo ¶
type PgDatabaseInfo struct {
Name string `json:"name"`
Owner string `json:"owner"`
Encoding string `json:"encoding"`
Collation string `json:"collation"`
SizeBytes int64 `json:"sizeBytes"`
Connections int `json:"connections"`
ConnLimit int `json:"connLimit"`
AllowConn bool `json:"allowConnections"`
Comment string `json:"comment"`
Primary bool `json:"primary"` // the cluster's own database (credentials point here)
Protected bool `json:"protected"` // a platform database
}
PgDatabaseInfo is one database in a cluster.
type PgDatabaseInput ¶
type PgDatabaseInput struct {
Name string `json:"name,omitempty"` // create; or the new name when renaming
Owner string `json:"owner,omitempty"`
ConnLimit *int `json:"connLimit,omitempty"`
Comment *string `json:"comment,omitempty"`
}
PgDatabaseInput creates or changes a database.
type PgDefaultGrant ¶
type PgDefaultGrant struct {
ForRole string `json:"forRole"`
ObjectType string `json:"objectType"` // table, sequence, function, type, schema
Grantee string `json:"grantee"`
Privileges map[string]bool `json:"privileges"`
}
PgDefaultGrant is a default privilege: what objects a role creates in a schema will grant.
type PgExtension ¶
type PgExtension struct {
Name string `json:"name"`
DefaultVersion string `json:"defaultVersion"`
InstalledVersion string `json:"installedVersion,omitempty"`
Schema string `json:"schema,omitempty"`
Comment string `json:"comment"`
Preloaded bool `json:"preloaded"` // its library is loaded (add-ons that need one)
Addon string `json:"addon,omitempty"` // the add-on that offers it ("" = PostgreSQL's own)
Enabled bool `json:"enabled"` // installable: PostgreSQL's own, or an enabled add-on
}
PgExtension is an extension available in the image.
type PgExtensionChange ¶
type PgExtensionChange struct {
Name string `json:"name"`
Action string `json:"action"` // install, update, drop
Schema string `json:"schema,omitempty"` // install
Cascade bool `json:"cascade,omitempty"`
}
PgExtensionChange installs, updates or drops an extension.
type PgGrant ¶
type PgGrant struct {
Grantee string `json:"grantee"` // a role, or PUBLIC
Privileges map[string]bool `json:"privileges"`
Grantors map[string]string `json:"grantors,omitempty"` // privilege -> grantor
}
PgGrant is one grantee's privileges on an object.
type PgIndex ¶
type PgIndex struct {
Name string `json:"name"`
Definition string `json:"definition"`
Primary bool `json:"primary"`
Unique bool `json:"unique"`
Valid bool `json:"valid"`
SizeBytes int64 `json:"sizeBytes"`
Scans int64 `json:"scans"`
}
PgIndex is an index on a table.
type PgMembership ¶
type PgMembership struct {
Role string `json:"role"`
Admin bool `json:"admin"`
Inherit bool `json:"inherit"`
}
PgMembership is membership in another role.
type PgObject ¶
type PgObject struct {
Name string `json:"name"`
Kind string `json:"kind"` // table, partitioned, view, matview, foreign, sequence, function, procedure, aggregate, type
OID uint32 `json:"oid"`
Owner string `json:"owner"`
RowEstimate int64 `json:"rowEstimate,omitempty"`
SizeBytes int64 `json:"sizeBytes,omitempty"`
Partitions int `json:"partitions,omitempty"`
Comment string `json:"comment,omitempty"`
}
PgObject is one object in a schema.
type PgObjectDetail ¶
type PgObjectDetail struct {
PgObject
Schema string `json:"schema"`
TableBytes int64 `json:"tableBytes,omitempty"`
IndexBytes int64 `json:"indexBytes,omitempty"`
ToastBytes int64 `json:"toastBytes,omitempty"`
LiveRows int64 `json:"liveRows,omitempty"`
DeadRows int64 `json:"deadRows,omitempty"`
SeqScans int64 `json:"seqScans,omitempty"`
IndexScans int64 `json:"indexScans,omitempty"`
LastVacuum *time.Time `json:"lastVacuum,omitempty"`
LastAutovacuum *time.Time `json:"lastAutovacuum,omitempty"`
LastAnalyze *time.Time `json:"lastAnalyze,omitempty"`
Columns []PgColumn `json:"columns"`
Constraints []PgConstraint `json:"constraints"`
Indexes []PgIndex `json:"indexes"`
Triggers []PgTrigger `json:"triggers"`
PartitionOf string `json:"partitionOf,omitempty"`
PartitionKey string `json:"partitionKey,omitempty"`
PartitionList []string `json:"partitionList,omitempty"`
DDL string `json:"ddl"`
}
PgObjectDetail describes one object: a relation's structure and statistics, or a routine's or type's definition.
type PgObjectRef ¶
type PgObjectRef struct {
Kind string `json:"kind"` // database, schema, table (also views), sequence, function
Schema string `json:"schema,omitempty"`
Name string `json:"name,omitempty"` // database or schema name, or the relation
OID uint32 `json:"oid,omitempty"` // functions
}
PgObjectRef names a privilege target.
type PgParam ¶
type PgParam struct {
Name string `json:"name"`
Group string `json:"group"`
Type string `json:"type"` // int, real, bool, enum, memory, time, string
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
Enum []string `json:"enum,omitempty"`
Restart bool `json:"restart,omitempty"` // takes a restart (otherwise a reload)
Addon string `json:"addon,omitempty"` // only with this add-on enabled
Description string `json:"description"`
}
PgParam is a setting users may change. Values are what PostgreSQL accepts: memory with kB/MB/GB/TB, durations with ms/s/min/h/d.
type PgPrivilegeChange ¶
type PgPrivilegeChange struct {
Revoke bool `json:"revoke,omitempty"`
Privileges []string `json:"privileges"` // or ["ALL"]
Grantee string `json:"grantee"` // a role, or PUBLIC
GrantOption bool `json:"grantOption,omitempty"`
// Target: one object; "all-tables", "all-sequences" or "all-functions"
// in Schema; or "default-tables", "default-sequences", "default-functions"
// (ALTER DEFAULT PRIVILEGES FOR ROLE ForRole IN SCHEMA Schema).
Target string `json:"target"` // "object" (default) or the above
Object PgObjectRef `json:"object"`
ForRole string `json:"forRole,omitempty"`
}
PgPrivilegeChange is one GRANT or REVOKE.
type PgPrivileges ¶
type PgPrivileges struct {
Kind string `json:"kind"`
Object string `json:"object"`
Owner string `json:"owner"`
Available []string `json:"available"`
Grants []PgGrant `json:"grants"`
Defaults []PgDefaultGrant `json:"defaults,omitempty"` // schemas only
// Effective is what Role can do through every membership, when asked.
Role string `json:"role,omitempty"`
Effective map[string]bool `json:"effective,omitempty"`
}
PgPrivileges are the grants on one object.
type PgQuery ¶
type PgQuery struct {
Database string `json:"database"` // "" = the cluster's own
SQL string `json:"sql"`
Role string `json:"role"` // "" = app
MaxRows int `json:"maxRows"`
}
PgQuery is a console run.
type PgQueryError ¶
type PgQueryError struct {
Statement int `json:"statement"` // index into the statements
Message string `json:"message"`
Code string `json:"code,omitempty"`
Detail string `json:"detail,omitempty"`
Hint string `json:"hint,omitempty"`
Position int `json:"position,omitempty"` // 1-based, in the whole text
}
PgQueryError is where and why a run stopped.
type PgQueryResult ¶
type PgQueryResult struct {
Results []PgStatementResult `json:"results"`
Error *PgQueryError `json:"error,omitempty"`
RolledBack bool `json:"rolledBack,omitempty"` // a transaction left open was rolled back
ReadOnly bool `json:"readOnly"`
Role string `json:"role"`
Database string `json:"database"`
}
PgQueryResult is a console run's results.
type PgReplica ¶
type PgReplica struct {
Name string `json:"name"`
ClientAddr string `json:"clientAddr"`
State string `json:"state"`
SyncState string `json:"syncState"`
SentLSN string `json:"sentLsn"`
ReplayLSN string `json:"replayLsn"`
LagBytes int64 `json:"lagBytes"`
WriteLagMs float64 `json:"writeLagMs"`
FlushLagMs float64 `json:"flushLagMs"`
ReplayLagMs float64 `json:"replayLagMs"`
}
PgReplica is a replica as the primary sees it (pg_stat_replication).
type PgReplication ¶
type PgReplication struct {
Settings PgReplicationSpec `json:"settings"`
Replicas []PgReplica `json:"replicas"`
Slots []PgSlot `json:"slots"`
Members []PgClusterMember `json:"members"`
CurrentLSN string `json:"currentLsn"`
Timeline int `json:"timeline"`
}
PgReplication is a cluster's replication status.
type PgReplicationSpec ¶
type PgReplicationSpec struct {
// Mode: async; sync (commits wait for a replica, async while none is
// left); strict (writes stop rather than run without one).
Mode string `json:"mode"`
// SyncReplicas is how many replicas confirm each commit (sync modes).
SyncReplicas int `json:"syncReplicas"`
// MaxLagOnFailover (MiB): a replica further behind is not promoted.
MaxLagOnFailover int `json:"maxLagOnFailover"`
// FailoverTTL (s) is the leader lease: a leader silent this long is
// replaced.
FailoverTTL int `json:"failoverTtl"`
// Slots keep the WAL a replica still needs.
Slots bool `json:"slots"`
// HotStandbyFeedback stops the primary from vacuuming rows that
// replica queries still read.
HotStandbyFeedback bool `json:"hotStandbyFeedback"`
// WalKeepSize (MiB) of WAL kept for replicas without slots.
WalKeepSize int `json:"walKeepSize"`
// MaxSlotWalKeepSize (MiB) caps the WAL a slot holds (0 = unlimited).
MaxSlotWalKeepSize int `json:"maxSlotWalKeepSize"`
}
PgReplicationSpec is how members replicate and fail over.
type PgRestore ¶
type PgRestore struct {
// From is the source database (name). It is never changed.
From string `json:"from"`
// Backup is a base backup name; default the newest one that finished
// before TargetTime (or the newest).
Backup string `json:"backup,omitempty"`
// TargetTime is the moment to recover to; nil replays the whole
// archive (a clone of the latest state).
TargetTime *time.Time `json:"targetTime,omitempty"`
}
PgRestore asks for a new cluster restored from another one's archive.
type PgRole ¶
type PgRole struct {
Name string `json:"name"`
Login bool `json:"login"`
CreateDB bool `json:"createDb"`
CreateRole bool `json:"createRole"`
Inherit bool `json:"inherit"`
Superuser bool `json:"superuser"`
Replication bool `json:"replication"`
BypassRLS bool `json:"bypassRls"`
ConnLimit int `json:"connLimit"`
ValidUntil *time.Time `json:"validUntil"`
HasPassword bool `json:"hasPassword"`
MemberOf []PgMembership `json:"memberOf"`
Members []string `json:"members"`
Owns []string `json:"owns"` // databases
Connections int `json:"connections"`
Comment string `json:"comment"`
Protected bool `json:"protected"` // a platform role
Predefined bool `json:"predefined"` // pg_* built-in roles
App bool `json:"app"` // the credentials' role
}
PgRole is a role with its attributes.
type PgRoleInput ¶
type PgRoleInput struct {
Name string `json:"name,omitempty"` // create; or the new name when renaming
Password *string `json:"password,omitempty"`
GeneratePassword bool `json:"generatePassword,omitempty"`
Login *bool `json:"login,omitempty"`
CreateDB *bool `json:"createDb,omitempty"`
CreateRole *bool `json:"createRole,omitempty"`
Inherit *bool `json:"inherit,omitempty"`
ConnLimit *int `json:"connLimit,omitempty"`
ValidUntil *string `json:"validUntil,omitempty"` // RFC 3339; "" = never expires
MemberOf *[]PgMembership `json:"memberOf,omitempty"` // the full set wanted
Comment *string `json:"comment,omitempty"`
}
PgRoleInput creates or changes a role. Nil fields stay as they are.
type PgRowFilter ¶
type PgRowFilter struct {
Column string `json:"column"`
Op string `json:"op"` // = <> < <= > >= like ilike null notnull
Value string `json:"value"`
}
PgRowFilter narrows a data page.
type PgRows ¶
type PgRows struct {
Columns []PgColumnMeta `json:"columns"`
Rows [][]*string `json:"rows"`
More bool `json:"more"`
Total *int64 `json:"total,omitempty"`
}
PgRows is a page of rows, every value in PostgreSQL's text form.
type PgRowsQuery ¶
type PgRowsQuery struct {
Schema string `json:"schema"`
Table string `json:"table"`
Limit int `json:"limit"`
Offset int `json:"offset"`
OrderBy string `json:"orderBy"`
Desc bool `json:"desc"`
Filters []PgRowFilter `json:"filters"`
Count bool `json:"count"` // also count the matching rows
}
PgRowsQuery asks for a page of a relation's rows.
type PgSchema ¶
type PgSchema struct {
Name string `json:"name"`
Owner string `json:"owner"`
System bool `json:"system"` // catalogs and extension-internal schemas
Comment string `json:"comment,omitempty"`
Objects []PgObject `json:"objects"`
}
PgSchema is a schema and its objects.
type PgSession ¶
type PgSession struct {
PID int `json:"pid"`
User string `json:"user"`
Database string `json:"database"`
Client string `json:"client"`
Application string `json:"application"`
State string `json:"state"`
WaitEvent string `json:"waitEvent"`
Query string `json:"query"`
BackendStart *time.Time `json:"backendStart"`
XactStart *time.Time `json:"xactStart"`
QueryStart *time.Time `json:"queryStart"`
BlockedBy []int `json:"blockedBy"`
Platform bool `json:"platform"` // Patroni, replication and the explorer
}
PgSession is a client connection.
type PgSetting ¶
type PgSetting struct {
PgParam
Value string `json:"value"` // as the server reports it, with its unit
Source string `json:"source"` // default, configuration file, …
Configured string `json:"configured"` // the spec's value ("" = the default)
Pending bool `json:"pendingRestart"` // changed, waiting for a restart
Available bool `json:"available"` // its add-on is enabled
Default string `json:"platformDefault"` // the platform's value, if it sets one
}
PgSetting is a parameter's catalog entry and its live value.
type PgSlot ¶
type PgSlot struct {
Name string `json:"name"`
Type string `json:"type"`
Active bool `json:"active"`
WalStatus string `json:"walStatus"`
HeldBytes int64 `json:"heldBytes"`
}
PgSlot is a replication slot.
type PgStatementResult ¶
type PgStatementResult struct {
Statement string `json:"statement"`
Columns []PgColumnMeta `json:"columns"`
Rows [][]*string `json:"rows"`
Truncated bool `json:"truncated"`
Tag string `json:"tag"`
RowsAffected int64 `json:"rowsAffected"`
DurationMs float64 `json:"durationMs"`
}
PgStatementResult is one statement's outcome.
type PgTrigger ¶
type PgTrigger struct {
Name string `json:"name"`
Definition string `json:"definition"`
Enabled bool `json:"enabled"`
}
PgTrigger is a trigger on a table.
type PostgresSpec ¶
type PostgresSpec struct {
// Synchronous mirrors replication.mode != async (older clients set it).
Synchronous bool `json:"synchronous"`
// MaxConnections defaults from memory.
MaxConnections int `json:"maxConnections"`
// Extensions are the enabled add-ons (§13c2); nil on clusters from
// before them means all.
Extensions store.NullList[string] `json:"extensions"`
// Parameters override PostgreSQL settings from the curated catalog.
Parameters map[string]string `json:"parameters,omitempty"`
// Replication is how members replicate and fail over.
Replication *PgReplicationSpec `json:"replication,omitempty"`
// Backup turns on WAL archiving and base backups to S3 (Phase 13c).
Backup *PgBackupSpec `json:"backup,omitempty"`
}
PostgresSpec holds the PostgreSQL-only settings.
type PublicEndpoint ¶
type PublicEndpoint struct {
Enabled bool `json:"enabled"`
// Available is false when the endpoint cannot work (Reason says why).
Available bool `json:"available"`
Reason string `json:"reason,omitempty"`
Host string `json:"host,omitempty"`
ReadHost string `json:"readHost,omitempty"`
// Port and ReadPort take TLS and, unless RequireTLS, plain connections
// (zero until assigned). SNIPort is the engine's shared TLS port, where
// the host name picks the database.
Port int `json:"port"`
ReadPort int `json:"readPort"`
SNIPort int `json:"sniPort"`
TLS bool `json:"tls"`
RequireTLS bool `json:"requireTls"`
}
PublicEndpoint is the database as reached from outside the cluster.
type PublicPort ¶ added in v0.1.2
PublicPort is a dedicated port to open, with its allowed sources.
type PublicRoute ¶
type PublicRoute struct {
Name string // router/service name
Entrypoint string
Host string
Port int
Plain bool // the plain (non-TLS) router of a dedicated port
Servers []string // host:port of members
Allow []string
}
PublicRoute is one endpoint Traefik serves for a database: TLS by SNI on the engine's shared entrypoint (Host set), or any TLS or plain connection on a dedicated port (Port set, Host empty).
type RestoreState ¶
type RestoreState struct {
Source string `json:"source"` // the source's ID
SourceName string `json:"sourceName"` // and name, as it was
Endpoint string `json:"endpoint"`
Bucket string `json:"bucket"`
Prefix string `json:"prefix"`
Backup string `json:"backup"`
TargetTime *time.Time `json:"targetTime,omitempty"`
}
RestoreState records how a cluster was created from an archive.
type RestoreWindow ¶
RestoreWindow is the span a restore can target: from the oldest base backup's end to the newest archived WAL.
type Secrets ¶
type Secrets struct {
Password string `json:"password"` // the app user ("default")
AdminPassword string `json:"adminPassword"` // "syncloud": replication, Sentinel, the controller (Postgres: the superuser)
// PostgreSQL: the replication user, Patroni's REST API and its etcd user.
ReplicationPassword string `json:"replicationPassword,omitempty"`
RestPassword string `json:"restPassword,omitempty"`
EtcdPassword string `json:"etcdPassword,omitempty"`
// WalgKey encrypts the cluster's archive (hex, 32 bytes);
// RestoreWalgKey reads the source's archive of a restored cluster.
WalgKey string `json:"walgKey,omitempty"`
RestoreWalgKey string `json:"restoreWalgKey,omitempty"`
}
Secrets are sealed in the database row.
type SlowEntry ¶
type SlowEntry struct {
ID int64 `json:"id"`
At time.Time `json:"at"`
Duration int64 `json:"durationMicros"`
Args []string `json:"args"`
Client string `json:"client"`
}
SlowEntry is one slow log entry.
type Spec ¶
type Spec struct {
// Memory is maxmemory in MiB; autoscaled between Min and Max.
Memory Range `json:"memory"`
// Replicas is the read-replica count; autoscaled between Min and Max.
Replicas Range `json:"replicas"`
// CPU reserved per data member, in cores.
CPU float64 `json:"cpu"`
// Persistence: aof (AOF everysec + RDB snapshots, default), rdb or none.
Persistence string `json:"persistence"`
// EvictionPolicy is maxmemory-policy (default noeviction).
EvictionPolicy string `json:"evictionPolicy"`
// Nodes limits members to these nodes, within the project's allowed nodes.
Nodes []string `json:"nodes,omitempty"`
// Autoscaling settings.
Autoscaling Autoscaling `json:"autoscaling"`
// Postgres is set for PostgreSQL databases (and only for them).
Postgres *PostgresSpec `json:"postgres,omitempty"`
}
Spec is what the user asks for.
func (*Spec) ForEngine ¶
ForEngine prepares a spec for an engine: PostgreSQL specs carry their own section, Valkey specs never do.
func (Spec) HasSentinels ¶
HasSentinels reports whether the database runs Sentinel: a Valkey database that can have replicas.
type State ¶
type State struct {
// MemoryMiB is the current maxmemory.
MemoryMiB int `json:"memoryMiB"`
// Replicas is the current read-replica count.
Replicas int `json:"replicas"`
// Primary is the ordinal of the data member that is primary.
Primary int `json:"primary"`
// LimitMiB is the container memory limit the members were created with.
LimitMiB int `json:"limitMiB"`
// Bootstrapped: the PostgreSQL app user and database exist.
Bootstrapped bool `json:"bootstrapped,omitempty"`
// Restore: a PostgreSQL cluster created from another one's archive.
Restore *RestoreState `json:"restore,omitempty"`
// Database overrides the app database's name (a restored cluster
// keeps its source's).
Database string `json:"database,omitempty"`
// BootstrapDCS is PostgreSQL's first dynamic configuration, frozen at
// creation; DCSHash is the last one applied through Patroni (§13c2).
BootstrapDCS string `json:"bootstrapDcs,omitempty"`
DCSHash string `json:"dcsHash,omitempty"`
}
State is what the operator decided and observed.
type StreamEntry ¶
type Usage ¶
type Usage struct {
UsedMemoryBytes int64 `json:"usedMemoryBytes"`
MaxMemoryBytes int64 `json:"maxMemoryBytes"`
Keys int64 `json:"keys"`
OpsPerSec float64 `json:"opsPerSec"`
Clients int64 `json:"clients"`
HitRate float64 `json:"hitRate"` // %; -1 before any lookup
UptimeSeconds int64 `json:"uptimeSeconds"`
}
Usage is the primary's latest figures.
type Value ¶
type Value struct {
Key string `json:"key"`
Type string `json:"type"`
TTL int64 `json:"ttlMs"`
Bytes int64 `json:"bytes"`
Length int64 `json:"length"` // items, fields or bytes
Truncated bool `json:"truncated"` // only the first items are shown
String *string `json:"string,omitempty"`
Hash map[string]string `json:"hash,omitempty"`
List []string `json:"list,omitempty"`
Set []string `json:"set,omitempty"`
ZSet []ZMember `json:"zset,omitempty"`
Stream []StreamEntry `json:"stream,omitempty"`
}
Value is one key with its value, shaped by type.
type View ¶
type View struct {
ID string `json:"id"`
Project string `json:"project"`
Environment string `json:"environment"`
Name string `json:"name"`
Engine string `json:"engine"`
Version string `json:"version"`
Spec Spec `json:"spec"`
State State `json:"state"`
Status string `json:"status"` // why the operator is stuck ("" = fine)
Health string `json:"health"` // healthy | degraded | starting | down | deleting
Deleting bool `json:"deleting"`
Host string `json:"host"` // read-write
ReadHost string `json:"readHost"` // read-only
Port int `json:"port"`
Standalone bool `json:"standalone"`
Network Network `json:"network"`
Public PublicEndpoint `json:"public"`
Members []Member `json:"members"`
Usage Usage `json:"usage"`
Autoscale AutoscaleStatus `json:"autoscale"`
// FailoverReady: every sentinel knows every replica and its peers, so a
// failed primary is replaced (false without replicas).
FailoverReady bool `json:"failoverReady"`
// SameNode: the primary and its replicas run on one node (a one-server
// cluster), so they don't survive losing that node.
SameNode bool `json:"sameNode"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
View is a database as the API shows it.
type Write ¶
type Write struct {
Type string `json:"type"` // string | hash | list | set | zset
String string `json:"string"`
Hash map[string]string `json:"hash"`
List []string `json:"list"`
Set []string `json:"set"`
ZSet []ZMember `json:"zset"`
TTL int64 `json:"ttlSeconds"` // 0 = keep / none
Replace bool `json:"replace"`
}
Write sets a key. Replace deletes it first; otherwise fields, items and members are added to what is there.