Skip to main content

serened psql

serened psql is a PostgreSQL-compatible command-line client built into the serened binary — no separate installation required. It connects to a running SereneDB server over the PostgreSQL wire protocol and behaves like the standard psql client: on startup it attaches to the server and switches to the requested database, so you can run queries interactively or in batch.

To work with a local database file directly, without a running server, use serened shell instead.

Connect

serened psql -h localhost -p 7890 -d postgres
note

serened psql follows the PostgreSQL convention and defaults to port 5432, while a SereneDB server listens on 7890 by default. Pass -p 7890 (or set PGPORT) so the client reaches the server.

When an option is omitted, the client falls back to the corresponding environment variable, then a built-in default:

SettingFlagDefault
Host-h$PGHOST, otherwise localhost
Port-p$PGPORT, otherwise 5432
User-U$PGUSER, $USER, otherwise postgres
Database-d$PGDATABASE, otherwise the user name

The first two positional arguments are taken as DBNAME and USERNAME when the matching flags are not given:

serened psql -h localhost -p 7890 postgres alice

Authentication is not required yet, so the -w / -W / --password / --no-password options are accepted but ignored.

Running a single command

Use -c to run one statement and exit:

serened psql -h localhost -p 7890 -d postgres -c "SELECT 1 + 1 AS sum;"
┌───────┐
│ sum │
│ int32 │
├───────┤
│ 2 │
└───────┘

Connection options

OptionDescription
-h, --host=HOSTNAMEServer host (default: $PGHOST or localhost)
-p, --port=PORTServer port (default: $PGPORT or 5432)
-d, --dbname=DBNAMEDatabase name (default: $PGDATABASE or the user name)
-U, --username=NAMEUser name (default: $PGUSER, $USER, or postgres)
-w, --no-passwordAccepted, ignored (no authentication yet)
-W, --passwordAccepted, ignored (no authentication yet)

General options

OptionDescription
-c, --command=COMMANDRun a single command (SQL or dot-command) and exit
-f, --file=FILENAMEExecute commands from a file, then exit
-l, --listList the available databases, then exit
-1, --single-transactionRun the -c / -f batch inside a single transaction
-X, --no-psqlrcDo not read the startup file (~/.duckdbrc)
-q, --quietSuppress startup and informational messages
-V, --versionPrint the SereneDB version and exit
-?, --helpShow the help message and exit

Output format options

The default output is the aligned duckbox table. These options change how results are rendered:

OptionDescription
-A, --no-alignUnaligned output
--csvCSV output
-H, --htmlHTML output
-t, --tuples-onlyPrint rows only, without column headers
-x, --expandedExpanded output (one value per line)
-F, --field-separator=STRField separator for unaligned output (default |)
-R, --record-separator=STRRecord separator for unaligned output (default newline)
-o, --output=FILENAMESend query results to a file
-P, --pset=VAR[=ARG]Set a printing option (format, expanded, null, tuples_only, pager)
--MODESet the output mode directly (box, csv, json, markdown, line, …)

Examples

List the databases on the server:

serened psql -h localhost -p 7890 -l

Run a SQL script and exit:

serened psql -h localhost -p 7890 -d postgres -f schema.sql

Export a query result as CSV:

serened psql -h localhost -p 7890 -d postgres --csv -c "SELECT 'a' AS x, 1 AS y;"
x,y
a,1

Run a script as a single transaction, writing the output to a file:

serened psql -h localhost -p 7890 -d postgres -1 -f migrate.sql -o result.txt