TheRobotLearns Platform · ProxySQL: from first install to production

DuckDB SQL Endpoints and SQLite-Backed RAG Indexing

  • about 20 min read

Learning objectives

  • Serve DuckDB through MySQL and PostgreSQL endpoints using `mysql_users` or `pgsql_users` for one database.
  • Explain why DuckDB endpoint auth lacks per-user roles and schema permissions, requiring trusted access.
  • Harden DuckDB SQL endpoints via local binding, TLS, user SSL rows, and frontend credentials; they alone do not isolate listeners.
  • Operate RAG indexing with SQLite FTS5 for keywords and DuckDB endpoints for analytics separately.
  • Tune DuckDB endpoint behavior through database path, read-only, external-access, and resource limit settings.
  • Write simple DuckDB text queries with one statement, DuckDB SQL, no prepared statements or concatenation.

DuckDB listeners use frontend users

You point a MySQL client at the DuckDB endpoint, but authentication fails. The endpoint needs a frontend credential in the table for that protocol. A frontend credential is a user row in mysql_users or pgsql_users.

The MySQL protocol uses mysql_users. The PostgreSQL protocol uses pgsql_users. A user needs a matching entry in each table to authenticate through both endpoints. The user must be active, enabled for frontend use, and loaded to Runtime, the running configuration. After editing either table, run LOAD MYSQL USERS TO RUNTIME or LOAD PGSQL USERS TO RUNTIME. If the credential must survive a restart, save users to Disk, the persistent configuration.

Common DuckDB listener ports are 6031 for DuckDB MySQL and 6034 for DuckDB PostgreSQL. ProxySQL Admin uses 6032, and the normal ProxySQL MySQL listener uses 6033. Check whether the configured address exists locally, whether another process or ProxySQL listener uses the port, and whether each listener has a dedicated port. An empty listener value disables that protocol. After changing the DuckDB listener address values in duckdb-mysql_ifaces or duckdb-pgsql_ifaces, save to Disk and restart ProxySQL. If a socket is closed before protocol setup, check duckdb-max_connections and your client pool size. Lowering that cap preserves existing connections, but it does not stop sessions or queries already running.

Takeaway: mysql_users and pgsql_users govern DuckDB endpoint logins, and LOAD ... TO RUNTIME makes them live.

Tune DuckDB paths and limits

You change duckdb-database_path or duckdb-threads, but the running endpoint still behaves as before. The edit sits in Main, the editable configuration stored in global_variables; runtime_global_variables is the layer in effect.

This returns editable and running values:

SELECT variable_name, variable_value
FROM global_variables
WHERE variable_name LIKE 'duckdb-%'
ORDER BY variable_name;

SELECT variable_name, variable_value
FROM runtime_global_variables
WHERE variable_name LIKE 'duckdb-%'
ORDER BY variable_name;

Compare Main and Runtime by reading global_variables and runtime_global_variables for rows where variable_name LIKE 'duckdb-%'. For a live change, run LOAD DUCKDB VARIABLES TO RUNTIME. If Main holds an invalid value or a pending restart change, that load can fail, including other valid live edits. Correct those rows before retrying.

The database path should be absolute. A writable database needs write access to its containing directory as well as the file. duckdb-read_only=true cannot use :memory: or an empty database path; use an existing file-backed database or disable read-only mode, save the corrected configuration, and restart ProxySQL. External file access is disabled by default. To enable it deliberately, edit duckdb-enable_external_access in Main, save to Disk, and restart ProxySQL. LOAD cannot enable it while the database is open.

Resource controls include duckdb-memory_limit, duckdb-threads, and duckdb-max_connections. These apply live after LOAD. The plugin has no per-query execution timeout. The memory limit is not a cap on total process memory, and reducing the connection limit does not stop existing sessions or queries.

Takeaway: LOAD DUCKDB VARIABLES TO RUNTIME applies live settings; database path, read-only mode, and external access need SAVE ... TO DISK plus restart.

Send simple DuckDB text queries

Your client sends SET NAMES utf8; SELECT 1 and receives an error. The DuckDB endpoint does not execute MySQL or PostgreSQL dialect. The protocol you connect with does not select the SQL dialect; you write DuckDB SQL.

Start with this tiny text query:

SELECT 42;

Only a small set of discovery and session commands is handled for compatibility. If a query fails, reduce it to find unsupported syntax, missing objects, permissions, or driver protocol mode.

Send one statement per request. SET NAMES utf8 and SELECT 1 must arrive as separate requests. The listeners do not support client-visible prepared statements. MySQL clients receive Command not supported with error 1045 after successful authentication, and PostgreSQL extended-query requests return SQLSTATE 0A000. Configure the driver for simple-query mode or use a non-prepared text-query API. Do not concatenate untrusted input into SQL.

Both protocols advertise text columns, so values may arrive as strings. Parse results according to your expected query schema. Some special types, such as UUIDs and nested values, need conversion to text. Statements like DML with RETURNING may not use that automatic conversion, so cast the returned expression explicitly.

Takeaway: Use one DuckDB text statement per request, simple-query mode, and explicit casts for special returned values.

Index RAG in SQLite

An AI agent asks for context from documents, articles, or posts. ProxySQL RAG indexes database content and returns relevant chunks. It stores the index in SQLite3 Server, which is reached through the MySQL protocol on port 6030.

RAG has keyword and semantic paths. Full-text search uses SQLite FTS5, the fast keyword index, and BM25 ranking to find exact terms, identifiers, or error messages. Vector search compares embeddings for meaning. Hybrid search combines both through Reciprocal Rank Fusion. Model Context Protocol tools, called MCP tools, expose rag.search_fts, rag.search_vector, and rag.search_hybrid.

rag_ingest connects to a MySQL/MariaDB source, applies JSON mappings, chunks documents, and stores results in rag_documents, rag_chunks, and rag_fts_chunks. Incremental ingestion tracks watermarks in rag_sync_state, so reprocessing a source requires deleting rows for that source_id. This initializes and runs the index build:

rag_ingest init -h 127.0.0.1 -P 6030 -u myuser -p mypass -D main
rag_ingest ingest -h 127.0.0.1 -P 6030 -u myuser -p mypass -D main

SQLite3 Server functions as the persistent storage backend for RAG. The DuckDB MySQL and PostgreSQL protocol listeners handle DuckDB SQL queries. RAG requires ProxySQL v4.0+ with RAG features enabled. Set mcp-use_ssl=true; false is only for local development.

Takeaway: RAG indexes into SQLite FTS5 for keyword search, while DuckDB endpoints serve DuckDB SQL separately.

Inspect and apply DuckDB settings and users

This checks editable and running duckdb-* values, applies the live load, persists Main, and activates frontend user rows.

SELECT variable_name, variable_value FROM global_variables WHERE variable_name LIKE 'duckdb-%' ORDER BY variable_name;
SELECT variable_name, variable_value FROM runtime_global_variables WHERE variable_name LIKE 'duckdb-%' ORDER BY variable_name;
LOAD DUCKDB VARIABLES TO RUNTIME;
SAVE DUCKDB VARIABLES TO DISK;
LOAD MYSQL USERS TO RUNTIME;
LOAD PGSQL USERS TO RUNTIME;

The first SELECT returns editable duckdb-* rows from Main. The second SELECT returns running duckdb-* rows from Runtime. LOAD DUCKDB VARIABLES TO RUNTIME applies live values from Main. SAVE DUCKDB VARIABLES TO DISK writes the corrected Main configuration so it can survive restart. LOAD MYSQL USERS TO RUNTIME activates frontend user rows for the MySQL endpoint. LOAD PGSQL USERS TO RUNTIME activates frontend user rows for the PostgreSQL endpoint.

Try it: config_layer_sim

Connect to ProxySQL Admin. Run the two duckdb-% SELECT statements from the worked example. Compare whether Main and Runtime differ. Run LOAD DUCKDB VARIABLES TO RUNTIME and inspect any error. If the load fails, look for an invalid value or pending restart change in Main, correct those rows, and retry. Run SAVE DUCKDB VARIABLES TO DISK if the settings must survive restart. Restart ProxySQL when a database path, read-only mode, external access, or listener address change is required.

Sources

Do more with an account

DuckDB SQL Endpoints and SQLite-Backed RAG Indexing — ProxySQL: from first install to production