### Install Package Examples Source: https://docs.vertica.com/25.3.x/en/admin/using-admin-tools/admin-tools-reference/writing-admin-tools-scripts Examples demonstrating how to use the admintools -t install_package command to install or reinstall packages. ```bash admintools -t install_package --package PACKAGE -d DB -p PASSWORD Examples: admintools -t install_package -d mydb -p 'mypasswd' --package default # (above) install all default packages that aren't currently installed admintools -t install_package -d mydb -p 'mypasswd' --package default --force-reinstall # (above) upgrade (re-install) all default packages to the current version admintools -t install_package -d mydb -p 'mypasswd' --package hcat # (above) install package hcat See also: admintools -t list_packages ``` -------------------------------- ### Start Single-Node Database Example Source: https://docs.vertica.com/25.3.x/en/admin/operating-db/starting-db This example demonstrates starting a single-node database named VMart using the `start_db` command. It shows the typical output indicating the node status and successful startup. ```bash $ /opt/vertica/bin/admintools -t start_db -d VMart Info: no password specified, using none Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (DOWN) Node Status: v_vmart_node0001: (UP) Database VMart started successfully ``` -------------------------------- ### Example Request to Start Database Process Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/post-dbsdb-namehostshost-idprocess This example demonstrates how to make a POST request to start the database process. Ensure you replace `` with your actual node address and use the correct database name and host ID. ```http POST https://:5444/databases/testDB/hosts/192.168.232.181/process ``` -------------------------------- ### Create a User and Grant Usage Source: https://docs.vertica.com/25.3.x/en/sql-reference/statements/create-statements/create-user This example demonstrates how to create a new user named Fred with a password and then grant them USAGE privilege on the PUBLIC schema. This is a common starting point for new user setup. ```sql CREATE USER Fred IDENTIFIED BY 'Mxyzptlk'; GRANT USAGE ON SCHEMA PUBLIC to Fred; ``` -------------------------------- ### Example GET Request for Database Licenses Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/_print This example demonstrates how to make a GET request to retrieve license details for a specific database. Ensure you replace placeholders with actual values and include the necessary authentication headers. ```http GET https://:5444/VMart/licenses?user_id=username&passwd=username_password ``` -------------------------------- ### cURL Example for Starting a Database Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/post-dbsdb-nameprocess An example using cURL to send a POST request to start a database. It includes parameters for epoch and included hosts, and requires an API key for authentication. ```curl curl -d "epoch=epoch_number&include=host1,host2" -X POST -H "VerticaApiKey: ValidAPIKey" https://:5444/:testDB/process ``` -------------------------------- ### Change Directory to Examples Source: https://docs.vertica.com/25.3.x/en/getting-started/restoring-status-of-your-host Navigate to the /examples directory on the host machine. ```bash $ cd /opt/vertica/examples ``` -------------------------------- ### Get Today's Date Source: https://docs.vertica.com/25.3.x/en/sql-reference/data-types/data-type-coercion A simple example to retrieve the current date. This can be used as a starting point for date-related operations. ```sql => SELECT DATE 'now'; ``` -------------------------------- ### Start Subcluster Example Source: https://docs.vertica.com/25.3.x/en/eon/managing-subclusters/starting-and-stopping-subclusters This example demonstrates starting the 'analytics_cluster' subcluster for the 'verticadb' database with a specified password. ```bash $ adminTools -t restart_subcluster -c analytics_cluster \ -d verticadb -p password *** Restarting subcluster for database verticadb *** Restarting host [10.11.12.192] with catalog [v_verticadb_node0006_catalog] Restarting host [10.11.12.181] with catalog [v_verticadb_node0004_catalog] Restarting host [10.11.12.205] with catalog [v_verticadb_node0005_catalog] Issuing multi-node restart Starting nodes: v_verticadb_node0004 (10.11.12.181) v_verticadb_node0005 (10.11.12.205) v_verticadb_node0006 (10.11.12.192) Starting Vertica on all nodes. Please wait, databases with a large catalog may take a while to initialize. Node Status: v_verticadb_node0002: (UP) v_verticadb_node0004: (DOWN) v_verticadb_node0005: (DOWN) v_verticadb_node0006: (DOWN) Node Status: v_verticadb_node0002: (UP) v_verticadb_node0004: (DOWN) v_verticadb_node0005: (DOWN) v_verticadb_node0006: (DOWN) Node Status: v_verticadb_node0002: (UP) v_verticadb_node0004: (DOWN) v_verticadb_node0005: (DOWN) v_verticadb_node0006: (DOWN) Node Status: v_verticadb_node0002: (UP) v_verticadb_node0004: (DOWN) v_verticadb_node0005: (DOWN) v_verticadb_node0006: (DOWN) Node Status: v_verticadb_node0002: (UP) v_verticadb_node0004: (UP) v_verticadb_node0005: (UP) v_verticadb_node0006: (UP) Communal storage detected: syncing catalog Restart Subcluster result: 1 ``` -------------------------------- ### C++ ODBC Example: Setting up Environment and Connecting Source: https://docs.vertica.com/25.3.x/en/connecting-to/client-libraries/accessing/ccpp/_print This C++ code snippet shows the initial setup for an ODBC connection, including allocating an environment handle, setting the ODBC version, allocating a database handle, and establishing a connection to the database. ```cpp // Some standard headers #include #include // Only needed for Windows clients // #include // Standard ODBC headers #include #include #include int main() { // Set up the ODBC environment SQLRETURN ret; SQLHENV hdlEnv; ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Tell ODBC that the application uses ODBC 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC3.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); if(!SQL_SUCCEEDED(ret)) { printf("Could not aalocate a database handle.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Connect to the database printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "dbadmin"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); // Create table to hold the data SQLExecDirect(hdlStmt, (SQLCHAR*)"DROP TABLE IF EXISTS customers", SQL_NTS); SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers" "(Last_Name char(50) NOT NULL, First_Name char(50),Email char(50), " "Phone_Number char(15));", SQL_NTS); ``` -------------------------------- ### Run VMart Installation Script Source: https://docs.vertica.com/25.3.x/en/getting-started/vmart-install-connect/quick-installation-using-script Execute the `install_example` script to create the VMart database. The script takes the database name as an argument. ```bash $ /opt/vertica/sbin/install_example VMart ``` -------------------------------- ### Example Request for GET databases/:database_name/hosts Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/get-dbsdb-namehosts An example of how to make a GET request to the API endpoint, specifying the database name. ```http GET https://:5444/databases/VMart/hosts ``` -------------------------------- ### Example Single-Node Install with Config File Source: https://docs.vertica.com/25.3.x/en/setup/set-up-on-premises/install-using-command-line/install-silently This is an example command for performing a single-node Vertica installation using a specified properties file. ```bash # /opt/vertica/sbin/install_vertica --config-file /tmp/vertica-inst.prp ``` -------------------------------- ### Change to Examples Directory Source: https://docs.vertica.com/25.3.x/en/getting-started/vmart-install-connect/quick-installation-using-script Navigate to the directory containing the example scripts. ```bash $ cd /opt/vertica/examples ``` -------------------------------- ### Example GET Request for Database Licenses Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/get-dbsdb-namelicenses An example of how to make a GET request to retrieve license information for the 'VMart' database, including user credentials. ```http GET https://:5444/VMart/licenses?user_id=username&passwd=username_password ``` -------------------------------- ### Example Request for GET databases/:database_name/nodes Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/get-dbsdb-namenodes This example shows a GET request to retrieve node IDs for the 'VMart' database. Ensure you include the VerticaAPIKey in the request header for authentication. ```http GET https://:5444/VMart/nodes ``` -------------------------------- ### ODBC Initialization and Connection Setup (C) Source: https://docs.vertica.com/25.3.x/en/connecting-to/client-libraries/accessing/ccpp/loading-data/_print This C code snippet demonstrates the initial steps for setting up an ODBC environment, allocating handles, setting the ODBC version, and connecting to a database. It also shows how to disable autocommit and prepare a statement handle. ```c // Some standard headers #include #include // Only needed for Windows clients // #include // Standard ODBC headers #include #include #include // Some constants for the size of the data to be inserted. #define CUST_NAME_LEN 50 #define PHONE_NUM_LEN 15 #define NUM_ENTRIES 4 int main() { // Set up the ODBC environment SQLRETURN ret; SQLHENV hdlEnv; ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Tell ODBC that the application uses ODBC 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC3.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); // Connect to the database printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "dbadmin"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Disable AUTOCOMMIT printf("Disabling autocommit.\n"); ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not disable autocommit.\n"); exit(EXIT_FAILURE); } // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); SQLExecDirect(hdlStmt, (SQLCHAR*)"DROP TABLE IF EXISTS customers", SQL_NTS); SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers " "(CustID int, CustName varchar(100), Phone_Number char(15));", SQL_NTS); ``` -------------------------------- ### Create Table and Load Data (Simple Partitioning) Source: https://docs.vertica.com/25.3.x/en/admin/partitioning-tables/_print This example demonstrates creating a table partitioned by date and then loading data into it. It highlights how simple date partitioning can lead to a large number of ROS containers. ```sql => DROP TABLE IF EXISTS public.store_orders CASCADE; => CREATE TABLE public.store_orders( order_no int, order_date timestamp NOT NULL, shipper varchar(20), ship_date date ) UNSEGMENTED ALL NODES PARTITION BY order_date::DATE; => COPY store_orders FROM '/home/dbadmin/export_store_orders_data.txt'; ``` -------------------------------- ### vbr Show Configuration Example Source: https://docs.vertica.com/25.3.x/en/admin/backup-and-restore/_print Demonstrates how to display the configuration values used for a specific task or a given configuration file before vbr starts execution. ```bash vbr -t task -c configfile --showconfig ``` ```bash vbr -c configfile --showconfig ``` -------------------------------- ### Example: Selecting rows starting with 'a' Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/match-and-search-functions/regular-expression-functions/_print Demonstrates how to select rows where the 'v' column starts with the letter 'a'. ```APIDOC ## Example: Select rows starting with 'a' ### Query ```sql SELECT v FROM t WHERE REGEXP_LIKE(v,'^a'); ``` ### Result ``` v ------ aaa abc abc1 (3 rows) ``` ``` -------------------------------- ### C++ ODBC Example: Connecting and Setting Up Environment Source: https://docs.vertica.com/25.3.x/en/connecting-to/client-libraries/accessing/_print This C++ code initializes the ODBC environment, sets the ODBC version to 3, allocates a database handle, and connects to a specified DSN with user credentials. It includes error checking for each allocation and connection step. ```cpp // Some standard headers #include #include // Only needed for Windows clients // #include // Standard ODBC headers #include #include #include int main() { // Set up the ODBC environment SQLRETURN ret; SQLHENV hdlEnv; ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Tell ODBC that the application uses ODBC 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC3.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); if(!SQL_SUCCEEDED(ret)) { printf("Could not aalocate a database handle.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Connect to the database printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "dbadmin"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); // Create table to hold the data SQLExecDirect(hdlStmt, (SQLCHAR*)"DROP TABLE IF EXISTS customers", SQL_NTS); SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers" "(Last_Name char(50) NOT NULL, First_Name char(50),Email char(50), " "Phone_Number char(15));", SQL_NTS); ``` -------------------------------- ### Example Request for GET Backups Config Script Base Archive ID Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/backup-and-restore/get-backupsconfig-script-basearchive-id An example of a GET request to retrieve details for a specific backup, including the node, configuration script base, and archive ID. ```http GET https://:5444/backups/fullbk/v_vdb_bk_snapshot_20190304_204814 ``` -------------------------------- ### ODBC Connection Setup Source: https://docs.vertica.com/25.3.x/en/connecting-to/_print This C code demonstrates the initial steps for setting up an ODBC environment and connecting to a database. It includes allocating handles, setting the ODBC version, and establishing a connection. ```c #include #include // Only needed for Windows clients // #include // SQL data types and ODBC API functions #include #include #include int main() { SQLRETURN ret; // Stores return value from ODBC API calls SQLHENV hdlEnv; // Handle for the SQL environment object // Allocate an a SQL environment object ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Set the ODBC version we are going to use to 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC 3.\n"); exit(EXIT_FAILURE); } else { printf("Application version set to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); assert(SQL_SUCCEEDED(ret)); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate database handle.\n"); exit(EXIT_FAILURE); } else { printf("Database handle allocated.\n"); } // Connect to the database using // SQL Connect printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "ExampleUser"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Query the v_monitor.current_session table to find the name of the node we've connected to. // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); assert(SQL_SUCCEEDED(ret)); ``` -------------------------------- ### Full CREATE LOCATION Syntax Example Source: https://docs.vertica.com/25.3.x/en/sql-reference/statements/create-statements/create-location Demonstrates the complete syntax for creating a storage location, including all optional parameters for node, sharing, communal access, usage, label, and size limit. ```sql CREATE LOCATION 'path' [NODE 'node' | ALL NODES] [ SHARED ] [ COMMUNAL ] [ USAGE 'usage'] [LABEL 'label'] [LIMIT 'size'] ``` -------------------------------- ### Create and Configure Resource Pools with CASCADE TO Source: https://docs.vertica.com/25.3.x/en/admin/managing-db/managing-workloads/resource-pool-architecture/_print Demonstrates creating two resource pools, setting their RUNTIMECAP, and configuring one to cascade to the other. It also shows how to assign a user to the primary resource pool. ```sql => CREATE RESOURCE POOL shortUserQueries RUNTIMECAP '1 minutes' => CREATE RESOURCE POOL userOverflow RUNTIMECAP '5 minutes'; => ALTER RESOURCE POOL shortUserQueries CASCADE TO userOverflow; => CREATE USER molly RESOURCE POOL shortUserQueries; ``` -------------------------------- ### Example: Getting and Setting Transaction Isolation Levels Source: https://docs.vertica.com/25.3.x/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/_print This example demonstrates getting the connection's transaction isolation level, setting it using the connection property, and setting the transaction isolation level for a new transaction. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; Vertica.Data.VerticaClient; namespace ConsoleApplication { class Program { static void Main(string[] args) { VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder(); builder.Host = "192.168.1.10"; builder.Database = "VMart"; builder.User = "dbadmin"; VerticaConnection _conn1 = new VerticaConnection(builder.ToString()); _conn1.Open(); VerticaTransaction txn1 = _conn1.BeginTransaction(); Console.WriteLine("\n Transaction 1 Transaction Isolation Level: " + txn1.IsolationLevel.ToString()); txn1.Rollback(); VerticaTransaction txn2 = _conn1.BeginTransaction(IsolationLevel.Serializable); Console.WriteLine("\n Transaction 2 Transaction Isolation Level: " + txn2.IsolationLevel.ToString()); txn2.Rollback(); VerticaTransaction txn3 = _conn1.BeginTransaction(IsolationLevel.ReadCommitted); Console.WriteLine("\n Transaction 3 Transaction Isolation Level: " + txn3.IsolationLevel.ToString()); _conn1.Close(); } } } ``` -------------------------------- ### Example: Create and Make HDFS Directory Snapshottable Source: https://docs.vertica.com/25.3.x/en/hadoop-integration/using-hdfs-storage-locations/hadoop-config-backup-and-restore This example demonstrates the combined steps of creating an HDFS directory and then enabling snapshotting for it. It also shows the expected success message. ```bash $ hdfs dfs -mkdir /tmp/snaptest $ hdfs dfsadmin -allowSnapshot /tmp/snaptest Allowing snaphot on /tmp/snaptest succeeded ``` -------------------------------- ### DATEDIFF Example with INTERVAL Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/data-type-specific-functions/datetime-functions/datediff Example demonstrating the use of DATEDIFF with INTERVAL data types for start and end dates. ```APIDOC ## Example: INTERVAL Data Types ```sql SELECT DATEDIFF(day, INTERVAL '26 days', INTERVAL '1 month '); ``` ### Result ``` datediff ---------- 4 (1 row) ``` ``` -------------------------------- ### Setup Schema and Data Source: https://docs.vertica.com/25.3.x/en/sql-reference/language-elements/predicates/interpolate/_print Defines the tables and inserts sample data for demonstrating join operations. ```sql CREATE TABLE t(x TIME); CREATE TABLE t1(y TIME); INSERT INTO t VALUES('12:40:23'); INSERT INTO t VALUES('13:40:25'); INSERT INTO t VALUES('13:45:00'); INSERT INTO t VALUES('14:49:55'); INSERT INTO t1 VALUES('12:40:23'); INSERT INTO t1 VALUES('14:00:00'); COMMIT; ``` -------------------------------- ### Example Request for Node Details Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/get-dbsdb-namenodesnode-id An example of a GET request to retrieve details for a specific node in the 'VMart' database. ```http GET https://:5444/databases/VMart/nodes/v_vmart_node0001 ``` -------------------------------- ### Examples of Adding Hosts Source: https://docs.vertica.com/25.3.x/en/admin/managing-db/managing-nodes/adding-nodes/_print These examples demonstrate various ways to specify hosts when adding them to the cluster, including single hostnames, IP addresses, and comma-separated lists of multiple hosts. ```bash --add-hosts host01 --rpm ``` ```bash --add-hosts 192.168.233.101 ``` ```bash --add-hosts host02,host03 ``` -------------------------------- ### Vertica Installation Properties File Example Source: https://docs.vertica.com/25.3.x/en/setup/set-up-on-premises/install-using-command-line/install-silently This is an example of the contents of a configuration properties file used for silent Vertica installations. It includes settings for EULA acceptance, license file path, recording options, and database administrator credentials. ```properties accept_eula = True license_file = /tmp/license.txt record_to = file_name root_password = password vertica_dba_group = verticadba vertica_dba_user = dbadmin vertica_dba_user_password = password ``` -------------------------------- ### Compile All Examples Source: https://docs.vertica.com/25.3.x/en/extending/developing-udxs/developing-with-sdk/java-sdk/_print Issue this command in the `Java-and-C++` directory under the examples directory to compile all examples, including Java examples. Ensure JAVA_HOME is set to your JDK directory. ```bash $ make ``` -------------------------------- ### Start Database Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/post-dbsdb-nameprocess Creates a job to start the database identified by :database_name. The :database_name is the value of the _name_ field that the GET databases command returns. Returns a job ID that can be used to determine the status of the job. See GET jobs. ```APIDOC ## POST /databases/:database_name/process ### Description Creates a job to start the database identified by :database_name. The :database_name is the value of the _name_ field that the GET databases command returns. Returns a job ID that can be used to determine the status of the job. See GET jobs. ### Method POST ### Endpoint https://:5444/databases/:database_name/process ### Parameters #### Query Parameters - **epoch** (string) - Optional - Start the database from this epoch. - **include** (string) - Optional - Include only these hosts when starting the database. Use a comma-separated list of hostnames. ### Request Body This endpoint does not explicitly define a request body schema, but query parameters are used. ### Request Example **POST** `https://:5444/databases/:testDB/process` An example of the full request using cURL: ``` curl -d "epoch=epoch_number&include=host1,host2" -X POST -H "VerticaApiKey: ValidAPIKey" https://:5444/:testDB/process ``` ### Response #### Success Response (200) - **id** (string) - The ID of the job created. - **url** (string) - The URL to track the job status. #### Response Example ```json { "id": "StartDatabase-testDB-2014-07-20 12:41:46.061408", "url": "/jobs/StartDatabase-testDB-2014-07-20 12:41:46.061408" } ``` ``` -------------------------------- ### Complete Cluster Setup Commands Source: https://docs.vertica.com/25.3.x/en/mc/getting-started-with-mc/creating-cluster-using-mc/_print A comprehensive example demonstrating the creation of an SSH key pair and enabling password-less access to three cluster hosts (docg01-docg03) from the docg01 host. ```bash ssh docg01 cd ~/.ssh ssh-keygen -q -t rsa -f ~/.ssh/vid_rsa -N '' cat vid_rsa.pub > vauthorized_keys2 cat vid_rsa.pub >> authorized_keys chmod 600 ~/.ssh/* scp -r /root/.ssh/vauthorized_keys2 docg02:/root/.ssh/. scp -r /root/.ssh/vauthorized_keys2 docg03:/root/.ssh/. ssh docg02 "cd /root/.ssh/;cat vauthorized_keys2 >> authorized_keys; chmod 600 /root/.ssh/authorized_keys" ssh docg03 "cd /root/.ssh/;cat vauthorized_keys2 >> authorized_keys; chmod 600 /root/.ssh/authorized_keys" ssh -i /root/.ssh/vid_rsa docg02 "rm /root/.ssh/vauthorized_keys2" ssh -i /root/.ssh/vid_rsa docg03 "rm /root/.ssh/vauthorized_keys2" rm ~/.ssh/vauthorized_keys2 ``` -------------------------------- ### Find Pattern Starting from Specific Position Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/match-and-search-functions/_print Finds the first occurrence of a pattern starting the search from a specified character position. This example starts searching from the second character. ```sql => SELECT REGEXP_INSTR('easy come, easy go','e\w*y',2); REGEXP_INSTR -------------- 12 (1 row) ``` -------------------------------- ### Create Sample Views Schema Source: https://docs.vertica.com/25.3.x/en/admin/profiling-db-performance/sample-views-counter-information Run this script to create the `v_demo` schema and populate it with sample profiling views. ```bash /opt/vertica/scripts/demo_eeprof_view.sql ``` -------------------------------- ### Find Occurrence Starting from Specific Position with REGEXP_INSTR Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/match-and-search-functions/regular-expression-functions/_print Specify a starting position to search for the pattern. This example finds the first match for 'e\w*y' starting from the second character. ```sql SELECT REGEXP_INSTR('easy come, easy go','e\w*y',2); ``` -------------------------------- ### Complete Cluster Setup Commands Source: https://docs.vertica.com/25.3.x/en/mc/getting-started-with-mc/creating-cluster-using-mc/create-private-key-file A comprehensive example demonstrating the creation of an SSH key pair and the distribution of the public key to three cluster hosts (docg01-docg03) for password-less SSH access. ```bash ssh docg01 cd ~/.ssh ssh-keygen -q -t rsa -f ~/.ssh/vid_rsa -N '' cat vid_rsa.pub > vauthorized_keys2 cat vid_rsa.pub >> authorized_keys chmod 600 ~/.ssh/* scp -r /root/.ssh/vauthorized_keys2 docg02:/root/.ssh/. scp -r /root/.ssh/vauthorized_keys2 docg03:/root/.ssh/. ssh docg02 "cd /root/.ssh/;cat vauthorized_keys2 >> authorized_keys; chmod 600 /root/.ssh/authorized_keys" ssh docg03 "cd /root/.ssh/;cat vauthorized_keys2 >> authorized_keys; chmod 600 /root/.ssh/authorized_keys" ssh -i /root/.ssh/vid_rsa docg02 "rm /root/.ssh/vauthorized_keys2" ssh -i /root/.ssh/vid_rsa docg03 "rm /root/.ssh/vauthorized_keys2" rm ~/.ssh/vauthorized_keys2 ``` -------------------------------- ### Get Default Start Time of a Time Slice Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice Returns the default start time of a 3-second time slice. The default unit is 'SECOND' and the default boundary is 'START'. ```sql SELECT TIME_SLICE('2009-09-19 00:00:01', 3); ``` -------------------------------- ### ODBC Connection and Setup Source: https://docs.vertica.com/25.3.x/en/connecting-to/_print This C code snippet demonstrates the essential steps for setting up an ODBC environment, allocating handles, connecting to a database, and disabling autocommit. ```c // Some standard headers #include #include // Only needed for Windows clients // #include // Standard ODBC headers #include #include #include // Some constants for the size of the data to be inserted. #define CUST_NAME_LEN 50 #define PHONE_NUM_LEN 15 #define NUM_ENTRIES 4 int main() { // Set up the ODBC environment SQLRETURN ret; SQLHENV hdlEnv; ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Tell ODBC that the application uses ODBC 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC3.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); // Connect to the database printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "dbadmin"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Disable AUTOCOMMIT printf("Disabling autocommit.\n"); ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not disable autocommit.\n"); exit(EXIT_FAILURE); } // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); SQLExecDirect(hdlStmt, (SQLCHAR*)"DROP TABLE IF EXISTS customers", SQL_NTS); SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers " "(CustID int, CustName varchar(100), Phone_Number char(15));", SQL_NTS); // Set up a bunch of variables to be bound to the statement // parameters. ``` -------------------------------- ### Example Usage of KafkaTopicDetails Source: https://docs.vertica.com/25.3.x/en/kafka-integration/kafka-function-reference/kafkatopicdetails An example demonstrating how to call the KafkaTopicDetails function to get partition and broker information for a Kafka topic. ```APIDOC ## Example ```sql => SELECT KafkaTopicDetails(USING PARAMETERS brokers='kafka1-01.example.com:9092',topic='iot_data') OVER(); partition_id | lead_broker | replica_brokers | in_sync_replica_brokers --------------+-------------+-----------------+------------------------- 0 | 0 | 0 | 0 1 | 1 | 1 | 1 2 | 0 | 0 | 0 3 | 1 | 1 | 1 4 | 0 | 0 | 0 (5 rows) ``` ``` -------------------------------- ### ODBC Initialization and Connection Source: https://docs.vertica.com/25.3.x/en/connecting-to/client-libraries/accessing/ccpp/_print Sets up the ODBC environment, allocates handles, and connects to a database. Includes error checking for each step. ```c // Some standard headers #include #include // Only needed for Windows clients // #include // Standard ODBC headers #include #include #include int main() { // Set up the ODBC environment SQLRETURN ret; SQLHENV hdlEnv; ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate a handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated an environment handle.\n"); } // Tell ODBC that the application uses ODBC 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if(!SQL_SUCCEEDED(ret)) { printf("Could not set application version to ODBC3.\n"); exit(EXIT_FAILURE); } else { printf("Set application to ODBC 3.\n"); } // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); if(!SQL_SUCCEEDED(ret)) { printf("Could not allocate database handle.\n"); exit(EXIT_FAILURE); } else { printf("Allocated Database handle.\n"); } // Connect to the database printf("Connecting to database.\n"); const char *dsnName = "ExampleDB"; const char* userID = "dbadmin"; const char* passwd = "password123"; ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not connect to database.\n"); exit(EXIT_FAILURE); } else { printf("Connected to database.\n"); } // Get the AUTOCOMMIT state SQLINTEGER autoCommitState; SQLGetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, &autoCommitState, 0, NULL); printf("Autocommit is set to: %d\n", autoCommitState); // Disable AUTOCOMMIT printf("Disabling autocommit.\n"); ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_NTS); if(!SQL_SUCCEEDED(ret)) { printf("Could not disable autocommit.\n"); exit(EXIT_FAILURE); } // Get the AUTOCOMMIT state again SQLGetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, &autoCommitState, 0, NULL); printf("Autocommit is set to: %d\n", autoCommitState); ``` -------------------------------- ### Example: Restarting a Node with a New IP Address Source: https://docs.vertica.com/25.3.x/en/admin/managing-db/managing-nodes/reconfiguring-node-messaging/restarting-node-with-new-host-ips This example demonstrates how to first list all nodes to identify the target node and its current state, then restart a specific node (`v_k8s_node0003`) with a new IP address (`172.28.1.7`) for the database `K8s`, and finally verify the update by listing nodes again. ```bash $ admintools -t list_allnodes Node | Host | State | Version | DB ----------------+------------+----------+----------------+----- v_k8s_node0001 | 172.28.1.4 | UP | vertica-10.1.1 | K8s v_k8s_node0002 | 172.28.1.5 | UP | vertica-10.1.1 | K8s v_k8s_node0003 | 172.28.1.6 | DOWN | vertica-10.1.1 | K8s $ admintools -t restart_node -s v_k8s_node0003 --new-host-ips 172.28.1.7 -d K8s Info: no password specified, using none *** Updating IP addresses for nodes of database K8s *** Start update IP addresses for nodes Updating node IP addresses Generating new configuration information and reloading spread *** Restarting nodes for database K8s *** Restarting host [172.28.1.7] with catalog [v_k8s_node0003_catalog] Issuing multi-node restart Starting nodes: v_k8s_node0003 (172.28.1.7) Starting Vertica on all nodes. Please wait, databases with a large catalog may take a while to initialize. Node Status: v_k8s_node0003: (DOWN) Node Status: v_k8s_node0003: (DOWN) Node Status: v_k8s_node0003: (DOWN) Node Status: v_k8s_node0003: (DOWN) Node Status: v_k8s_node0003: (RECOVERING) Node Status: v_k8s_node0003: (UP) $ admintools -t list_allnodes Node | Host | State | Version | DB ----------------+------------+-------+----------------+----- v_k8s_node0001 | 172.28.1.4 | UP | vertica-10.1.1 | K8s v_k8s_node0002 | 172.28.1.5 | UP | vertica-10.1.1 | K8s v_k8s_node0003 | 172.28.1.7 | UP | vertica-10.1.1 | K8s ``` -------------------------------- ### Find start position of a captured subexpression Source: https://docs.vertica.com/25.3.x/en/sql-reference/functions/match-and-search-functions/regular-expression-functions/regexp-instr This example shows how to find the starting position of a specific captured subexpression within a larger pattern, such as finding the start of the third word. ```APIDOC ## REGEXP_INSTR('one two three','(\w+)\s+(\w+)\s+(\w+)', 1, 1, 0, '', 3) ### Description Finds the starting position of the third captured subexpression (the third word) in the string. ### Parameters - **string** (string) - The string to search within. - **pattern** (string) - The regular expression pattern with capturing groups. - **start_position** (integer) - The position in the string to start the search from. - **occurrence** (integer) - The specific occurrence of the overall pattern to find. - **return_option** (integer) - Specifies whether to return the starting position (0) or the ending position (1) of the match. - **group_delimiter** (string) - A delimiter for capturing groups (often empty). - **subexpression_index** (integer) - The index of the subexpression whose start position should be returned (e.g., 3 for the third captured group). ### Example ```sql SELECT REGEXP_INSTR('one two three','(\w+)\s+(\w+)\s+(\w+)', 1,1,0,'',3); ``` ### Response - **position** (integer) - The starting position of the specified captured subexpression. ``` -------------------------------- ### Compile All Examples Source: https://docs.vertica.com/25.3.x/en/extending/developing-udxs/developing-with-sdk/cpp-sdk/setting-up-cpp-sdk Issue this command in the `Java-and-C++` directory under the examples directory to compile all examples, including Java. A g++ development environment is required. ```bash $ make ``` -------------------------------- ### GET databases/:database_name/configuration Example Request Source: https://docs.vertica.com/25.3.x/en/connecting-to/management-api/rest-apis-agent/dbs/_print This example demonstrates how to make a GET request to retrieve the configuration parameters for a specific database. Ensure you include your user ID and password as query parameters. Authentication is handled via a VerticaAPIKey in the request header. ```http GET https://:5444/databases/testDB/configuration?user_id=username&passwd=username_password ``` -------------------------------- ### Automate Vertica Installation on SELinux Source: https://docs.vertica.com/25.3.x/en/setup/set-up-on-premises/before-you-install/_print This script automates the installation of Vertica on multiple hosts within a SELinux environment. It handles package installation, security context setup, and database creation. ```bash /opt/vertica/selinux/gen_httpstls_json.sh DBADMIN=$(id -un) DBADMIN_GROUP=$(id -gn) ROOT_DIR=/vertica hosts=(192.168.0.50 192.168.0.51 192.168.0.52) hostlist= for h in $hosts; do if [ -z "$hostlist" ]; then hostlist=$h else hostlist="$hostlist,$h" fi scp vertica-latest.rhel.x86_64.rpm $h:/tmp scp httpstls.json *.pem $h:/tmp ssh $h sudo rpm -Uvh /tmp/vertica-latest.rhel.x86_64.rpm ssh $h sudo DBADMIN=$DBADMIN DBADMIN_GROUP=$DBADMIN_GROUP ROOT_DIR=$ROOT_DIR /opt/vertica/selinux/seinstall_root.sh ssh $DBADMIN@$h ROOT_DIR=$ROOT_DIR /opt/vertica/selinux/seinstall.sh done ssh ${hosts[1]} vcluster create_db --db-name selinux_vdb --hosts $hostlist --catalog-path $ROOT_DIR --data-path $ROOT_DIR --depot-path $ROOT_DIR/depot --password pw --depot-size 80% --communal-storage-location s3://vertica-fleeting/selinux_vdb --shard-count 8 for h in $hosts; do ssh $h ps xfZ | grep unconfined && echo "warning: dbadmin processes are running unconfined" done ``` -------------------------------- ### Start Database Command Line Syntax Source: https://docs.vertica.com/25.3.x/en/admin/operating-db/starting-db Use the `start_db` command with various options to start a database. Specify the database name, and optionally password, hosts, timeout, and other flags. ```bash $ /opt/vertica/bin/admintools -t start_db -d db-name [-p password] [-s host1[,...] | --hosts=host1[,...]] [--timeout seconds] [-i | --noprompts] [--fast] [-F | --force] ```