tursopg --server reused DatabaseOpts::turso_cli(), which turns on SQL
load_extension. The listener has no password (NoopHandler). A client
could SELECT load_extension and run native code in the server process.
Interactive CLI still enables the flag. The wire path uses the library
default (off), matching sqlite3_enable_load_extension and #3250.
Tests: tursopg wire_load_extension_is_disabled,
repl_load_extension_still_attempts_to_open_the_file
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Part 2 of 22 in the pg_dump feature series, stacked on
https://github.com/tursodatabase/turso/pull/9716 (`postgres-pgdump-
catalog-tableoid`). Review this diff against its immediate parent.
Declare existing catalog boolean fields as BOOLEAN instead of INTEGER,
so PostgreSQL clients receive the expected column types. Stored row
values remain unchanged. tableoid comes from the preceding layer.
This is one of ten smaller layers extracted from the former combined PR
#9701. Catalog system columns and boolean types now come before session
setup. The combined source and existing regression tests are unchanged;
early layers do not claim complete pg_dump support.
Reorganized with Amp under Pedro's direction, preserving the published
combined source and running before/after regressions plus cumulative
checks at every new layer.
Closes#9717
pg_dump sets search_path to an empty string before reading catalogs. Store
search_path in the injected connection state so native set_config calls
and SET statements update the same session setting during execution.
Keep an explicitly empty path distinct from the default and preserve
access to qualified public tables and implicit PostgreSQL catalogs.
Support session-scoped search_path only. Reject transaction-local settings
and unsupported parameters; transaction rollback restoration and separate
wire-client sessions are not implemented in this change.
Tests: eight new WAL/MVCC regression cases fail before and pass afterward;
424 PostgreSQL integration, 22 frontend, 181 parser, and four wire-protocol
search-path tests pass. CLI build and formatting checks pass.
Amp-Thread-ID: https://ampcode.com/threads/T-01a11786-6662-751d-925e-4ec4fecf16b3
Co-authored-by: pedro muniz <pedro.muniz.carlo@gmail.com>
Database had five public ways to open a connection: connect,
connect_with_encryption, connect_with_page_codec, connect_async and
connect_with_encryption_async. Every new connection setting needs more
variants, and the async path doubles them again.
Database::connect and Database::connect_async now take a ConnectOpts
that holds the encryption key and the page codec, and the other three
variants are removed. ConnectOpts has no Default, so every caller goes
through ConnectOpts::new() and a required argument added there later
makes the compiler find every call site.
Query terminal background colors on Windows and fall back to the native console color table when ANSI responses are unavailable. Share color parsing across platforms, bound terminal reads, and restore console modes after detection. Cache the detected theme for the process so repeated lookups do not re-query the terminal.
Tests: cargo test --locked -p turso_cli config::terminal::tests -j1; cargo check --locked -p tursopg --tests
Tokenize dot commands without treating path separators as shell escapes, and share the same parser between execution and completion. Keep quoted paths and embedded quotes intact across the Turso and PostgreSQL CLIs.
Tests: cargo test --locked -p turso_cli; cargo check --locked -p tursopg --tests
Adds PostgreSQL frontend support for `SET search_path` when resolving
unqualified table names.
The change stores `search_path` as PostgreSQL session state, passes it
into statement preparation, and makes table resolution honor the
configured schema order. Explicitly qualified names keep their existing
behavior. The resolver also preserves temp-schema priority and maps
`public` to the main database.
This also updates the PostgreSQL SET parser helper to support multi-
value `search_path` assignments and adds regression coverage for the new
behavior.
`SET search_path` was already accepted by the PostgreSQL parser, but it
did not affect name resolution. As a result, queries like `SELECT * FROM
demo` could resolve to whichever attached schema happened to be
found first instead of following PostgreSQL search path semantics.
This makes the PostgreSQL frontend behave closer to Postgres for schema-
qualified and unqualified table lookup, especially when multiple schemas
contain tables with the same name.
Related to the PostgreSQL frontend TODO for `SET search_path`.
I used AI for codebase navigation, debugging guidance, and review of the
implementation approach and tests. The implementation itself was written
and reviewed by me
Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>
Closes#8062
Auto-attaches persisted PostgreSQL schema sidecar databases during
tursopg startup.
`CREATE SCHEMA` stores non-public schemas as sidecar database files.
This change runs the existing schema auto-attach step before dispatching
to server, one-shot SQL, stdin, or interactive CLI modes, so schema-
qualified queries continue to work after reopening the main database.
Adds a CLI regression test that creates a schema/table in one tursopg
process and reads it back from a second process using the same file-
backed database.
Before this change, sidecar schema files persisted on disk, but the
regular CLI startup path did not reattach them. Reopening the main
database and querying `schema.table` failed with `no such database`
until `CREATE SCHEMA` was run again.
This makes persisted schema behavior consistent across tursopg startup
modes.
I used AI for codebase navigation, debugging guidance, and review of the
implementation approach and tests. The implementation itself was written
and reviewed by me
Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Closes#8084
The version() string and the server_version startup parameter are
hardcoded independently (SERVER_VERSION in the frontend, pgwire's
DefaultServerParameterProvider default), so a pgwire upgrade could
silently drift the two apart. Compare their numeric prefixes over one
connection: the harness now keeps the startup response and can extract
ParameterStatus and DataRow values.
Adds version(), current_database(), current_schema(), pg_backend_pid(),
quote_ident(), quote_literal(), and NULL stubs for
obj_description()/col_description() to the frontend dialect. The bare
current_schema and current_catalog keywords translate to the same
functions. Zero-argument session functions in FROM position desugar
into a one-row subselect (cast to TEXT because bare subselect columns
wire as bytea) since core's TableCall path resolves only table-valued
functions.
Result columns without an explicit alias are now named after the
function or keyword as PostgreSQL derives them (FigureColname). This
also fixes count(*) reporting as "count (*)" instead of "count".
quote_ident classifies keywords with pg_query's scanner, so reserved
keywords quote and unreserved ones stay bare. version() reports the
same major version as the server_version startup parameter pgwire
advertises.
Tests: postgres/tests/integration/postgres/functions.rs;
pg-sqltests/functions.sqltest validated case-by-case against stock
PostgreSQL 16.
The git pin (rev 64644ffe, added in June 2025 for the onig/GCC 15 build
fix) forces cargo to clone syntect with its testdata/Packages submodule,
so CI randomly fails whenever fetching sublimehq/Packages flakes.
syntect 5.3.0 on crates.io contains the pinned rev (v5.3.0 is 36 commits
ahead of it, 0 behind) and ships as a self-contained tarball, so the git
clone and submodule fetch disappear entirely. Applies to both tursodb
and tursopg, dependencies and build-dependencies alike.
Tests: cargo build -p turso_cli -p tursopg; tursodb answers queries.
Translate PostgreSQL CREATE TABLE AS and its legacy SELECT ... INTO
spelling into Turso's CREATE TABLE ... AS SELECT so the pg frontend can
create tables from query results. WITH NO DATA creates the table from
the SELECT's shape without copying rows, IF NOT EXISTS is honored, and
INTO in nested or compound positions is rejected rather than silently
dropped. The server reports completion as `SELECT n` like PostgreSQL,
except WITH NO DATA which keeps the plain CREATE TABLE AS tag.
Explicit column lists on CTAS are rejected because the engine derives
column names from the SELECT and cannot override them.
Tests: postgres/conformance/pg-sqltests/table.sqltest covers CTAS and
SELECT INTO behavior; postgres/cli/tests/tursopg.rs covers the wire
command tags; postgres/tests/integration covers the rejection paths
where Turso intentionally diverges from PostgreSQL.
Co-authored-by: theFestest <theFestest@users.noreply.github.com>
Allow PostgreSQL clients and migrations to issue COMMENT ON statements without persisting comment metadata. Return the COMMENT wire completion tag so clients do not observe the internal no-op statement.
Tests: cargo fmt --all -- --check; git diff --check
The wire-protocol tests derived their server port from a fixed per-test
seed plus the test process id. nextest runs each test in its own process
with roughly sequential pids, so two concurrently started tests can
compute the same port. The loser of the bind race has its server exit,
but its readiness poll still succeeds by connecting to the winner's
server — and the test then fails mid-run when the winner tears that
server down. This broke main's macOS build-native job with
wire_cast_reports_target_type returning no RowDescription.
Ask the kernel for a free ephemeral port instead, and treat the child
exiting during the readiness poll as a lost bind race, retrying on a
fresh port rather than connecting to another test's server.
Tests: cargo test -p tursopg --test tursopg
Name the PostgreSQL-compatible CLI after the product, consistent with
tursodb and the turso_pg* crate naming. The prompt, history file, crate
and binary names, tests, and documentation all follow.
Interactive PostgreSQL-flavored shell (psql-style commands, multi-line
editing via a read state machine) that embeds the PG frontend and can
serve the pgwire protocol via turso_postgres_server.
Tests: postgres/cli/tests/pgmicro.rs
Co-authored-by: Pekka Enberg <penberg@iki.fi>