Connecting from the command line

You can connect to a database using vsql from the command line on multiple client platforms.

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.


/opt/vertica/bin/vsql [-h host] [ -p port ] [ option...] [ dbname [ username ] ]


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.

The database server port.

Default: 5433

One or more vsql command-line options.

If the database is password protected, you must specify the -w or --password command line option.

The name of the target database. If unspecified, vsql automatically connects to the database on the specified host and port.
A database username, by default your system username.

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.


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