Connecting from the command line
You can connect to a database using vsql from the command line on multiple client platforms.
If the connection cannot be made for any reason—for example, you have insufficient privileges, or the server is not running on the targeted host—vsql returns an error and terminates.
Syntax
/opt/vertica/bin/vsql [-h host] [ option...] [ dbname [ username ] ]
Parameters
host
- Optional if you connect to a local server. You can provide an IPv4 or IPv6 IP address or a host name.
For Vertica servers that have both IPv4 and IPv6 addressed and you have provided a host name instead of an IP address, you can prefer to use an IPv4 address with the
-4
option and to use the IPv6 adddress with the-6
option if the DNS is configured to provide both IPv4 and IPv6 addresses. If you are using IPv6 and provide an IP address, you must append the address with an%
interface name
. option
- One or more vsql command-line options.
If the database is password protected, you must specify the -w or
--password
command line option. *
dbname*
- The name of the target database, by default your Linux user name.
*
username*
- A database username, by default your Linux user name.
Exit codes
vsql returns 0 to the shell when it terminates normally. Otherwise, it returns one of the following:
-
1: A fatal error occurred—for example, out of memory or file not found.
-
2: The connection to the server went bad and the session was not interactive
-
3: An error occurred in a script and the variable
ON_ERROR_STOP
was set. -
Unrecognized words in the command line might be interpreted as database or user names.
Examples
The following example shows how to capture error messages by redirecting vsql output to the output file retail_queries.out
:
$ vsql --echo-all < retail_queries.sql > retail_queries.out 2>&1