psql
Interactive command-line interface for Apache Cloudberry
Synopsis
psql [<option> ...] [<dbname> [<username>]]
Description
psql
is a terminal-based front-end to Apache Cloudberry. It enables you to type in queries interactively, issue them to Apache Cloudberry, and see the query results. Alternatively, input can be from a file. In addition, it provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks.
Options
-a | --echo-all
Print all nonempty input lines to standard output as they are read. (This does not apply to lines read interactively.) This is equivalent to setting the variable ECHO to all
.
-A | --no-align
Switches to unaligned output mode. (The default output mode is aligned.)
-c 'command' | --command='command'
Specifies that psql
is to run the specified command string, and then exit. This is useful in shell scripts. command must be either a command string that is completely parseable by the server, or a single backslash command. Thus you cannot mix SQL and psql
meta-commands with this option. To achieve that, you could pipe the string into psql
, like this:
echo '\x \\ SELECT * FROM foo;' | psql
(\
is the separator meta-command.)
If the command string contains multiple SQL commands, they are processed in a single transaction, unless there are explicit BEGIN/COMMIT
commands included in the string to divide it into multiple transactions. This is different from the behavior when the same string is fed to psql
's standard input. Also, only the result of the last SQL command is returned.
-d dbname | --dbname=dbname
Specifies the name of the database to connect to. This is equivalent to specifying dbname as the first non-option argument on the command line.
If this parameter contains an =
sign or starts with a valid URI prefix (postgresql://
or postgres://
), it is treated as a conninfo
string. See Connection Strings in the PostgreSQL documentation for more information.
-e | --echo-queries
Copy all SQL commands sent to the server to standard output as well.
-E | --echo-hidden
Echo the actual queries generated by \d
and other backslash commands. You can use this to study psql
's internal operations. This is equivalent to setting the variable ECHO_HIDDEN to on
.
-f filename | --file=filename
Use the file filename as the source of commands instead of reading commands interactively. After the file is processed, psql
terminates. This is in many ways equivalent to the meta-command \i
.
If filename is -
(hyphen), then standard input is read until an EOF indication or \q
meta-command. Note however that Readline is not used in this case (much as if -n
had been specified).
Using this option is subtly different from writing psql < <filename>
. In general, both will do what you expect, but using -f
enables some nice features such as error messages with line numbers. There is also a slight chance that using this option will reduce the start-up overhead. On the other hand, the variant using the shell's input redirection is (in theory) guaranteed to yield exactly the same output you would have received had you entered everything by hand.
-F separator | --field-separator=separator
Use the specified separator as the field separator for unaligned output.
-H | --html
Turn on HTML tabular output.
-l | --list
List all available databases, then exit. Other non-connection options are ignored.
-L filename | --log-file=filename
Write all query output into the specified log file, in addition to the normal output destination.
-n | --no-readline
Do not use Readline for line editing and do not use the command history. This can be useful to turn off tab expansion when cutting and pasting.
-o filename | --output=filename
Put all query output into the specified file.
-P assignment | --pset=assignment
Allows you to specify printing options in the style of \pset
on the command line. Note that here you have to separate name and value with an equal sign instead of a space. Thus to set the output format to LaTeX
, you could write -P format=latex
.
-q | --quiet
Specifies that psql
should do its work quietly. By default, it prints welcome messages and various informational output. If this option is used, none of this happens. This is useful with the -c
option. This is equivalent to setting the variable QUIET to on
.
-R separator | --record-separator=separator
Use separator as the record separator for unaligned output.
-s | --single-step
Run in single-step mode. That means the user is prompted before each command is sent to the server, with the option to cancel execution as well. Use this to debug scripts.
-S | --single-line
Runs in single-line mode where a new line terminates an SQL command, as a semicolon does.
-t | --tuples-only
Turn off printing of column names and result row count footers, etc. This command is equivalent to \pset tuples_only
and is provided for convenience.
-T table_options | --table-attr= table_options
Allows you to specify options to be placed within the HTML table tag. See \pset
for details.
-v assignment | --set=assignment | --variable= assignment
Perform a variable assignment, like the \set
meta command. Note that you must separate name and value, if any, by an equal sign on the command line. To unset a variable, leave off the equal sign. To set a variable with an empty value, use the equal sign but leave off the value. These assignments are done during a very early stage of start-up, so variables reserved for internal purposes might get overwritten later.
-V | --version
Print the psql
version and exit.
-x | --expanded
Turn on the expanded table formatting mode.
-X | --no-psqlrc
Do not read the start-up file (neither the system-wide psqlrc
file nor the user's ~/.psqlrc
file).
-z | --field-separator-zero
Set the field separator for unaligned output to a zero byte.
-0 | --record-separator-zero
Set the record separator for unaligned output to a zero byte. This is useful for interfacing, for example, with xargs -0
.
-1 | --single-transaction
When psql
runs a script, adding this option wraps BEGIN
/COMMIT
around the script to run it as a single transaction. This ensures that either all the commands complete successfully, or no changes are applied.
If the script itself uses BEGIN
, COMMIT
, or ROLLBACK
, this option will not have the desired effects. Also, if the script contains any command that cannot be run inside a transaction block, specifying this option will cause that command (and hence the whole transaction) to fail.
-? | --help
Show help about psql
command line arguments, and exit.
Connection options
-h host | --host=host
The host name of the machine on which the Cloudberry coordinator database server is running. If not specified, reads from the environment variable PGHOST
or defaults to localhost.
When starting psql
on the coordinator host, if the host value begins with a slash, it is used as the directory for the UNIX-domain socket.
-p port | --port=port
The TCP port on which the Cloudberry coordinator database server is listening for connections. If not specified, reads from the environment variable PGPORT
or defaults to 5432
.
-U username | --username=username
The database role name to connect as. If not specified, reads from the environment variable PGUSER
or defaults to the current system role name.
-W | --password
Force a password prompt. psql
should automatically prompt for a password whenever the server requests password authentication. However, currently password request detection is not totally reliable, hence this option to force a prompt. If no password prompt is issued and the server requires password authentication, the connection attempt will fail.
-w --no-password
Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.
Note This option remains set for the entire session, and so it affects uses of the meta-command
\connect
as well as the initial connection attempt.