You are on page 1of 3

VERTICA VSQL COMMAND LINE EXAMPLES

In this tutorial we will se how we can write administration scripts useing the Vsql command line
options.
Connect to the database :

1
2
3
4
5
6
7

[dbadmin@Vertica_Master1 /]$ vsql -Uusername -wpassword


Welcome to vsql, the Vertica Analytic Database interactive terminal.
Type: \h for help with SQL commands
\? for help with vsql commands
\g or terminate with semicolon to execute query
\q to quit
dbadmin:

How to Connect to a specific node/host form the command line


Where -h option will be followd by host name or ip address.

1
2
[dbadmin@Vertica_Master1 /]$ vsql -hVertica_Master2 -Udbadmin -wdbadmin
3
Welcome to vsql, the Vertica Analytic Database interactive terminal.
4
Type: \h for help with SQL commands
5
\? for help with vsql commands
6
\g or terminate with semicolon to execute query
7
\q to quit
8
dbadmin: select node_name,user_name from sessions;
9
node_name | user_name
1
0 -1
v_cluster_node0002 | dbadmin
1
(1 row)
1 dbadmin:
2

Now change the node/host

Where -h option will be followd by host name or ip address.

1
2
[dbadmin@Vertica_Master1 /]$ vsql -hVertica_Master1 -Udbadmin -wdbadmin
3
Welcome to vsql, the Vertica Analytic Database interactive terminal.
4
Type: \h for help with SQL commands
5
\? for help with vsql commands
6
\g or terminate with semicolon to execute query
7
\q to quit
8
dbadmin= select node_name,user_name from sessions;
9
node_name | user_name
1
0 -1
v_cluster_node0001 | dbadmin
1
(1 row)
1
dbadmin=
2

Connect to specific database:


Where -d option will be followd by database name.

[dbadmin@Vertica_Master1 /]$ vsql ?dbaname -Udbadmin ?dbadmin

Run a single command from the vsql line:


Where -c option will be followd by the command you want to be executed.
-command will execute and exit

1 [dbadmin@Vertica_Master1 /]$ vsql -Udbadmin -wdbadmin -c 'select database_name from


2 databases';
3 database_name
4
5 cluster
6 (1 row)

[dbadmin@Vertica_Master1 /]$

Redirect output to a file

vsql -Udbadmin -wdbadmin -c 'select database_name from databases' file location/file name ;

Execute commands from file, then exit

1
2
3
4
5

[dbadmin@Vertica_Master1 tmp]$ vsql -U dbadmin -w dbadmin -f test


database_name
cluster
(1 row)

How to List all available databases from vsql.


PgSQL

1
2
3
4
5
6
7

[dbadmin@Vertica_Master1 tmp]$ vsql -U dbadmin -w dbadmin -l


List of databases
name | user_name
cluster | dbadmin
(1 row)

This are just few of the many examples of how Vsql command line can be used.