### Example Setup Universe Replication Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/additional-features/colocation.md An example demonstrating how to set up universe replication using yb-admin with specific master addresses and a parent colocation table UUID. ```Shell ./yb-admin --master_addresses 127.0.0.2 setup_universe_replication A1-B2 127.0.0.1 00004000000030008000000000004004.colocation.parent.uuid ``` -------------------------------- ### Install Dependencies and Setup Database Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/ruby/activerecord.md Navigate to the Rails application directory, install project dependencies, create the database, and perform migrations to set up tables. ```shell $ cd ./orm-examples/ruby/ror/ ``` ```shell $ ./bin/bundle install ``` ```shell $ bin/rails db:create ``` ```shell $ bin/rails db:migrate ``` -------------------------------- ### Install Golang Driver using Go Get Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/mage/drivers/golang/README.md Command to install the Golang driver using the go get command. ```bash go get github.com/apache/age/drivers/golang ``` -------------------------------- ### Setup Tables for Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/releases/techadvisories/ta-28222.md SQL statements to create and populate sample tables 't1' and 't2' for demonstrating query plan changes. ```sql drop table if exists t1, t2; create table t1 (a int, b int); insert into t1 select i, i from generate_series(1, 100) i; create table t2 (k1 int, k2 int, k3 int, k4 int, v int, primary key (k1 asc)); create unique index i_t2_k2 on t2 (k2); create index i_t2_k3 on t2 (k3); insert into t2 select i, i, (i / 10) * 10, i % 10, i from generate_series(1, 1000000) i; ``` -------------------------------- ### Install Dependencies and Start Jupyter Notebook Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/postgresql_anonymizer/docs/how-to/README.md Installs project dependencies and launches the Jupyter Notebook server. Ensure you have Python and pip installed. ```bash pip install -r requirements.txt jupyter notebook ``` -------------------------------- ### Table Setup for Mode Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/exprs/aggregate_functions/function-syntax-semantics/mode-percentile-disc-percentile-cont.md Sets up a sample table 't' with integer and text columns for demonstrating aggregate functions. ```plpgsql drop table if exists t cascade; create table t( k int primary key, v1 text, v2 text); insert into t(k, v1, v2) values (1, 'dog', 'food'), (2, 'cat', 'flap'), (3, null, null), (4, 'zebra', 'stripe'), (5, 'frog', 'man'), (6, 'fish', 'soup'), (7, 'ZEB', 'RASTRIPE'); ``` -------------------------------- ### Setup for PL/pgSQL Exception Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/user-defined-subprograms-and-anon-blocks/language-plpgsql-subprograms/plpgsql-syntax-and-semantics/exception-section.md Sets up the necessary schema, type, and initial function for demonstrating PL/pgSQL exception handling. ```plpgsql \c :db :u drop schema if exists s cascade; create schema s; create type s.rec as(outcome text, a numeric, b text); ``` -------------------------------- ### YB-Master Configuration File Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/deploy/manual-deployment/start-masters.md This is an example of a `master.conf` file used to configure YB-Master servers. The flags specified here can be loaded using the `--flagfile` option when starting the `yb-master` binary. ```bash --master_addresses=172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 --rpc_bind_addresses=172.151.17.130:7100 --fs_data_dirs=/home/centos/disk1,/home/centos/disk2 --placement_cloud=aws --placement_region=us-west --placement_zone=us-west-2a ``` -------------------------------- ### Setup Test Table Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/architecture/transactions/read-committed.md Creates a test table and inserts initial data. This is a prerequisite for the transaction examples. ```sql CREATE TABLE test (k int primary key, v int); INSERT INTO test VALUES (2, 5); ``` -------------------------------- ### Install and Start Realtime Poll App Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/integrations/hasura/hasura-sample-app.md Install dependencies and start the Realtime Poll application locally. The application will be accessible at http://localhost:3000. ```sh $ npm install $ npm start ``` -------------------------------- ### Example Node Agent Installation with Certificate Verification Skip Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yugabyte-platform/prepare/server-nodes-software/software-on-prem-manual.md Example of running the node agent installer script, including the option to skip certificate verification for the YBA instance. ```sh # To ignore verification of YBA certificate, add --skip_verify_cert. ./installer.sh -c install -u https://10.98.0.42 -t 301fc382-cf06-4a1b-b5ef-0c8c45273aef ``` -------------------------------- ### Create sample tables and indexes Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/exprs/func_yb_index_check.md Sets up sample tables and indexes for demonstrating index consistency checks. ```sql CREATE TABLE abcd(a int primary key, b int, c int, d int); CREATE INDEX abcd_b_c_d_idx ON abcd (b ASC) INCLUDE (c, d); CREATE INDEX abcd_b_c_idx ON abcd(b) INCLUDE (c) WHERE d > 50; CREATE INDEX abcd_expr_expr1_d_idx ON abcd ((2*c) ASC, (2*b) ASC) INCLUDE (d); INSERT INTO abcd SELECT i, i, i, i FROM generate_series(1, 10) i; ``` -------------------------------- ### ysqlsh Output Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysqlsh.md Example of the initial output when starting ysqlsh, indicating the version and prompt. ```output ysqlsh (15.2-YB-{{}}-b0) Type "help" for help. yugabyte=# ``` -------------------------------- ### Example: Create Accounts Table and Insert Data Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/explore/ysql-language-features/advanced-features/stored-procedures.md Sets up an 'accounts' table and populates it with initial user data. This is a prerequisite for the stored procedure example. ```sql drop table if exists accounts; create table accounts ( id int generated by default as identity, name varchar(100) not null, balance dec(15,2) not null, primary key(id) ); insert into accounts(name,balance) values('User1',10000); insert into accounts(name,balance) values('User2',10000); ``` -------------------------------- ### Manage Postgres Installations with Cargo PGRX Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/pgrx/cargo-pgrx/README.md Commands to check the status, start, and stop all managed Postgres installations. `cargo pgrx run` will automatically start its target Postgres instance if it's not already running. ```console cargo pgrx status all ``` ```text Postgres v12 is stopped Postgres v13 is stopped Postgres v14 is stopped Postgres v15 is stopped Postgres v16 is stopped ``` ```console cargo pgrx start all ``` ```text Starting Postgres v12 on port 28812 Starting Postgres v13 on port 28813 Starting Postgres v14 on port 28814 Starting Postgres v15 on port 28815 Starting Postgres v16 on port 28816 ``` ```console cargo pgrx status all ``` ```text Postgres v12 is running Postgres v13 is running Postgres v14 is running Postgres v15 is running Postgres v16 is running ``` ```console cargo pgrx stop all ``` ```text Stopping Postgres v12 Stopping Postgres v13 Stopping Postgres v14 Stopping Postgres v15 Stopping Postgres v16 ``` -------------------------------- ### CREATE TABLE Example with Partition and Clustering Keys Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ycql/ddl_create_table.md Demonstrates creating a table with a composite primary key, defining both partition and clustering columns. ```sql CREATE TABLE users ( user_id UUID, username TEXT, email TEXT, created_at TIMESTAMP, PRIMARY KEY (user_id, username) ); ``` -------------------------------- ### Setup Table and Indexes for EXPLAIN Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ycql/explain.md Defines the keyspace, tables, and indexes required for demonstrating the EXPLAIN statement. Ensure these are created before running EXPLAIN queries. ```cql cqlsh> CREATE KEYSPACE IF NOT EXISTS imdb; cqlsh> CREATE TABLE IF NOT EXISTS imdb.movie_stats ( movie_name text, movie_genre text, user_name text, user_rank int, last_watched timestamp, PRIMARY KEY (movie_genre, movie_name, user_name) ) WITH transactions = { 'enabled' : true }; cqlsh> CREATE INDEX IF NOT EXISTS most_watched_by_year ON imdb.movie_stats((movie_genre, last_watched), movie_name, user_name) INCLUDE(user_rank); cqlsh> CREATE INDEX IF NOT EXISTS best_rated ON imdb.movie_stats((user_rank, movie_genre), movie_name, user_name) INCLUDE(last_watched); ``` -------------------------------- ### Start YugabyteDB Cluster Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/tutorials/azure/azure-event-hubs.md Starts a single-node YugabyteDB cluster. Ensure the path to the binary is correct for your installation. ```sh ./path/to/bin/yugabyted start ``` -------------------------------- ### Get All Employees using cURL Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/java/ebean.md Example cURL command to send a GET request to retrieve all employees. ```sh curl -v -X GET http://localhost:8080/employees ``` -------------------------------- ### Create Sample Table and Data Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/additional-features/pg-extensions/extension-hypopg.md Set up a sample table with data to demonstrate index performance. This table is used for subsequent EXPLAIN queries. ```sql CREATE TABLE up_and_down (up int primary key, down int); INSERT INTO up_and_down SELECT a AS up, 10001-a AS down FROM generate_series(1,10000) a; ``` -------------------------------- ### Install YugabyteDB Anywhere Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yugabyte-platform/install-yugabyte-platform/install-software/installer.md Perform a full installation of YugabyteDB Anywhere. This command first runs all preflight checks, then proceeds with the installation, and waits for YBA to start. ```sh sudo ./yba-ctl install ``` ```output YBA Url | Install Root | yba-ctl config | yba-ctl Logs | https://10.150.0.218 | /opt/yugabyte | /opt/yba-ctl/yba-ctl.yml | /opt/yba-ctl/yba-ctl.log | Services: Systemd service | Version | Port | Log File Locations | Running Status | postgres | 10.23 | 5432 | /opt/yugabyte/data/logs/postgres.log | Running | prometheus | 2.42.0 | 9090 | /opt/yugabyte/data/prometheus/prometheus.log | Running | yb-platform | {{}} | 443 | /opt/yugabyte/data/logs/application.log | Running | INFO[2023-04-24T23:19:59Z] Successfully installed YugabyteDB Anywhere! ``` -------------------------------- ### Initialize Go Module and Install Dependencies Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/orms/go/ysql-gorm.md Navigate to the Go GORM application directory, initialize the Go module, and download project dependencies. ```shell cd golang/gorm go mod init gorm-example ``` ```shell go mod tidy ``` -------------------------------- ### Get Range from Start Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yedis/api/getrange.md Retrieve a substring from the beginning of the string value using positive start and end offsets. ```sh $ GETRANGE yugakey 0 3 ``` -------------------------------- ### Set up and run Laravel database migrations Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/orms/php/ysql-laravel.md Install migration support and then run migrations to set up the database schema. 'migrate:fresh' will drop all existing tables and re-create them. ```sh php artisan migrate:install php artisan migrate:fresh ``` -------------------------------- ### Install Diesel CLI Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/rust/diesel.md Install the Diesel command-line interface with PostgreSQL support to manage database migrations and setup. ```shell cargo install diesel_cli --no-default-features --features postgres ``` -------------------------------- ### Build and install libpqxx Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/cpp/ysql.md Build and install the libpqxx driver from source. ```shell $ cd libpqxx $ ./configure $ make $ make install ``` -------------------------------- ### Install and Configure Node Agent Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yugabyte-platform/prepare/server-nodes-software/software-on-prem-manual.md Run the downloaded installer script to install and start the interactive configuration for the node agent. Provide YBA address and API token. ```sh ./installer.sh -c install -u https:// -t ``` -------------------------------- ### Create Sample Table and Insert Initial Row Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/the-sql-language/statements/savepoint_rollback.md Sets up a table for demonstrating savepoint functionality. ```plpgsql CREATE TABLE sample(k int PRIMARY KEY, v int); INSERT INTO sample(k, v) VALUES (1, 2); ``` -------------------------------- ### Example Usage Source: https://github.com/yugabyte/yugabyte-db/blob/master/managed/yba-cli/docs/yba_ha_describe.md A basic example demonstrating how to invoke the command to get HA configuration. This command is a subcommand of 'yba ha'. ```bash yba ha get ``` -------------------------------- ### Create and Populate Original Table Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/pg_partman/doc/pg_partman_howto_native.md Creates and populates an example table before partitioning. This serves as the source data for the partitioning process. ```sql CREATE TABLE public.original_table ( col1 bigint not null , col2 text not null , col3 timestamptz DEFAULT now() , col4 text); CREATE INDEX ON public.original_table (col1); INSERT INTO public.original_table (col1, col2, col3, col4) VALUES (generate_series(1,100000), 'stuff'||generate_series(1,100000), now(), 'stuff'); ``` -------------------------------- ### Start YugabyteDB Cluster Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/integrations/prisma.md Starts a YugabyteDB 1-node cluster with the transaction isolation level set to serializable. Ensure YugabyteDB is installed before running. ```bash ./bin/yugabyted start --tserver_flags ysql_pg_conf="default_transaction_isolation=serializable" ``` -------------------------------- ### Create Parent Table and Partition Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/pg_partman/doc/pg_partman_howto_triggerbased.md Demonstrates creating a parent table and then using the create_parent function to set up initial partitions based on an integer column. ```sql keith=# \d partman_test.id_taptest_table Table "partman_test.id_taptest_table" ( Column | Type | Modifiers --------+--------------------------+-------------------------------- col1 | integer | not null col2 | text | not null default 'stuff'::text col3 | timestamp with time zone | default now() Indexes: "id_taptest_table_pkey" PRIMARY KEY, btree (col1) keith=# SELECT create_parent('partman_test.id_taptest_table', 'col1', 'partman', '10'); create_parent --------------- t (1 row) keith=# \d+ partman_test.id_taptest_table Table "partman_test.id_taptest_table" ( Column | Type | Modifiers | Storage | Stats target | Description --------+--------------------------+--------------------------------+----------+--------------+------------- col1 | integer | not null | plain | | col2 | text | not null default 'stuff'::text | extended | | col3 | timestamp with time zone | default now() | plain | | Indexes: "id_taptest_table_pkey" PRIMARY KEY, btree (col1) Triggers: id_taptest_table_part_trig BEFORE INSERT ON partman_test.id_taptest_table FOR EACH ROW EXECUTE PROCEDURE partman_test.id_taptest_table_part_trig_func() Child tables: partman_test.id_taptest_table_p0, partman_test.id_taptest_table_p10, partman_test.id_taptest_table_p20, partman_test.id_taptest_table_p30, partman_test.id_taptest_table_p40 ``` -------------------------------- ### Install All Test Tables Script Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/exprs/window_functions/function-syntax-semantics/data-sets/_index.md This script installs all necessary test tables for window function examples. It can be run repeatedly without issue. ```plpgsql -- You can run this script time and again. It will always finish silently. \i t1.sql \echo 't1 done' \i t2.sql \echo 't2 done' \i t3.sql \echo 't3 done' \i t4_1.sql \i t4_2.sql \echo 't4 done' ``` -------------------------------- ### Get string length Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yedis/api/strlen.md Use the STRLEN command to retrieve the length of the string value associated with a key. This example gets the length of 'yugakey'. ```sh STRLEN yugakey ``` -------------------------------- ### Create demo table Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/explore/ysql-language-features/indexes-constraints/covering-index-ysql.md Creates a table named 'demo' with 'id' and 'username' columns. Use this to set up the environment for index examples. ```sql CREATE TABLE IF NOT EXISTS demo (id bigint, username text); ``` -------------------------------- ### Get First Value from Zero-Starting Sequence Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/the-sql-language/statements/ddl_create_sequence.md Retrieve the first value from a sequence that has been configured to start at 0. The output confirms the starting value. ```sql SELECT nextval('s3'); ``` ```output nextval --------- 0 (1 row) ``` -------------------------------- ### Get Data Type and Start of Epoch Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/datatypes/type_datetime/timezones/timezone-sensitive-operations/timestamptz-interval-day-arithmetic.md Sets the timezone to UTC and selects the data type and value for the start of the epoch using the to_timestamp function. ```plpgsql set timezone = 'UTC'; select pg_typeof(to_timestamp(0)) as "data type", to_timestamp(0) as "start of epoch"; ``` -------------------------------- ### Install Node.js and Go Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/contribute/core-database/build-from-src-ubuntu.md Installs npm for Node.js and Go 1.20. Also configures the Go binary path in your shell's startup file. ```shell sudo apt install -y npm golang-1.20 # Also add the following line to your .bashrc or equivalent. export PATH="/usr/lib/go-1.20/bin:$PATH" ``` -------------------------------- ### Create Node.js Project and Install Dependencies Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/integrations/camunda.md Set up a new Node.js project and install the necessary Camunda External Task Client library and the 'open' package. ```bash mkdir charge-card-worker cd ./charge-card-worker npm init -y ``` ```bash npm install camunda-external-task-client-js npm install -D open ``` -------------------------------- ### Clone Repository Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/AI/ai-langchain-openai.md Clone the sample application repository to get started. ```sh git clone https://github.com/YugabyteDB-Samples/yugabytedb-langchain-openai-shoe-store-search.git ``` -------------------------------- ### Initialize NPM Project and Install Prisma Client Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/integrations/prisma.md Set up a new Node.js project using npm and install the necessary Prisma client library. This is the initial step for using Prisma ORM in a JavaScript project. ```sh npm init -y npm install --save prisma-client-lib ``` -------------------------------- ### Start React Frontend Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/AI/google-vertex-ai.md Navigates to the frontend directory and starts the React development server. ```shell cd {project_dir}/frontend npm run dev ``` -------------------------------- ### Clone the Repository Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/AI/ai-llamaindex-openai.md Clone the sample application repository to get started. ```sh git clone https://github.com/YugabyteDB-Samples/yugabytedb-llamaindex-sp500-search.git cd yugabytedb-llamaindex-sp500-search ``` -------------------------------- ### Basic pg_hint_plan Usage Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/pg_hint_plan/docs/description.md Demonstrates how to apply hints for join methods and scan types using special comment syntax. Ensure hints are correctly formatted within /*+ ... */. ```sql =# /*+ HashJoin(a b) SeqScan(a) */ EXPLAIN SELECT * FROM pgbench_branches b JOIN pgbench_accounts a ON b.bid = a.bid ORDER BY a.aid; ``` -------------------------------- ### Install Yugabyte Go Driver for YCQL Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/go/ycql.md Install the Yugabyte Go Driver for YCQL locally using the go get command. This driver is based on gocql. ```sh $ go get github.com/yugabyte/gocql ``` -------------------------------- ### Setup function for DATE examples Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/datatypes/type_datetime/typecasting-between-date-time-values.md This PL/pgSQL function creates a DATE value for use in subsequent examples. It is used to generate a specific date for testing typecasts. ```plpgsql drop function if exists date_value() cascade; create function date_value() returns date language sql as $body$ select make_date(2021, 6, 1); $body$; ``` -------------------------------- ### Install Golang Driver from Source Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/mage/drivers/golang/README.md Instructions for installing the Golang driver from source on Linux and macOS. ```bash cd age/drivers/golang ./install.sh ``` -------------------------------- ### CREATE TABLE Example with Column Primary Key Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ycql/ddl_create_table.md Shows how to define a primary key using a single column constraint, making it the partition key. ```sql CREATE TABLE products ( product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL ); ``` -------------------------------- ### Example Listen Configuration Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/odyssey/documentation/configuration.md A complete example of a 'listen' block, demonstrating host, port, backlog, and commented-out TLS-related settings. ```ini listen { host "*" port 6432 backlog 128 # ls "disable" # ls_cert_file "" # ls_key_file "" # ls_ca_file "" # ls_protocols "" } ``` -------------------------------- ### Get Key Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yedis/api/flushdb.md Demonstrates retrieving the value associated with a key in YEDIS. ```sh $ GET yuga1 ``` ```sh "America" ``` ```sh $ GET yuga2 ``` ```sh "Africa" ``` -------------------------------- ### Run yb-tserver with configuration flags Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/reference/configuration/yb-tserver.md This example demonstrates how to run the yb-tserver binary with essential configuration flags for master addresses, bind addresses, YSQL enablement, and data directories. Ensure the paths and addresses are adjusted for your environment. ```sh ./bin/yb-tserver \ --tserver_master_addrs 172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 \ --rpc_bind_addresses 172.151.17.130 \ --enable_ysql \ --fs_data_dirs "/home/centos/disk1,/home/centos/disk2" & ``` -------------------------------- ### Complete pg_dist_rag Example Workflow Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/yb-extensions/pg_dist_rag/README.md A step-by-step example demonstrating the installation of the extension, creation of document sources, initialization of a vector index, building the index, and monitoring its progress. ```sql -- Step 1: Install the extension CREATE EXTENSION IF NOT EXISTS pg_dist_rag; -- Step 2: Create document sources SELECT dist_rag.create_source( r_source_uri := 'https://docs.example.com/api-reference/' ) AS api_source_id; -- returns: e.g. 'a1b2c3d4-...' SELECT dist_rag.create_source( r_source_uri := 's3://company-docs/engineering/', r_metadata := '{"team": "engineering", "access": "internal"}'::jsonb, r_secrets_provider := 'AWS', r_secrets_provider_params := '{"region": "us-east-1"}'::jsonb ) AS eng_source_id; -- returns: e.g. 'e5f6g7h8-...' -- Step 3: Initialize a vector index with both sources SELECT dist_rag.init_vector_index( r_index_name := 'engineering_kb', r_sources := ARRAY['a1b2c3d4-...', 'e5f6g7h8-...']::UUID[], r_ai_provider := 'OPENAI', r_embedding_model_params := '{"dimensions": 1536, "model": "text-embedding-ada-002"}'::jsonb ); -- Step 4: Build the index (queues all documents for preprocessing) SELECT dist_rag.build_index(r_index_name := 'engineering_kb'); -- Step 5: Monitor progress SELECT index_name, document_name, pipeline_status, chunks_processed, current_step FROM dist_rag.vector_index_pipeline_details WHERE index_name = 'engineering_kb'; -- Step 6: Check overall stats SELECT document_name, calls, total_chunks_processed, completion_rate_percent FROM dist_rag.pipeline_stats WHERE index_name = 'engineering_kb'; ``` -------------------------------- ### Install sysbench from Source Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/benchmark/sysbench-ysql.md Install sysbench by cloning the repository, configuring with PostgreSQL support, and compiling. This method is suitable for building from source. ```bash $ cd $HOME $ git clone https://github.com/yugabyte/sysbench.git $ cd sysbench $ ./autogen.sh && ./configure --with-pgsql && make -j && sudo make install ``` -------------------------------- ### Frame Clause Error Example Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ysql/exprs/window_functions/invocation-syntax-semantics.md This example demonstrates an invalid frame clause where the frame starting from the current row attempts to include preceding rows, resulting in an error. ```sql 42P20: frame starting from current row cannot have preceding rows ``` -------------------------------- ### Install Oracle Instant Client Repositories Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yugabyte-voyager/rhel.md Install the Oracle instant client repositories required for certain dependencies. ```bash sudo yum install oracle-instant-clients-repo ``` -------------------------------- ### Migrate Oracle Hierarchical Query with START WITH to PostgreSQL Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/orafce/doc/sql_migration/sql_migration04.md This example shows how to migrate an Oracle hierarchical query that includes a START WITH clause to a PostgreSQL recursive query. The START WITH condition is moved to the WHERE clause of the initial SELECT statement within the WITH clause. ```sql SELECT staff_id, name, manager_id FROM staff_table START WITH staff_id = '1001' CONNECT BY PRIOR staff_id = manager_id; ``` ```sql WITH RECURSIVE staff_table_w( staff_id, name, manager_id ) AS ( SELECT staff_id, name, manager_id FROM staff_table WHERE staff_id = '1001' UNION ALL SELECT n.staff_id, n.name, n.manager_id FROM staff_table n, staff_table_w w WHERE w.staff_id = n.manager_id ) SELECT staff_id, name, manager_id FROM staff_table_w; ``` -------------------------------- ### Install YugabyteDB Single Node on Linux Source: https://github.com/yugabyte/yugabyte-db/wiki/YugabyteDB-Fundamentals-Training-Preparation-and-FAQ Installs a single node YugabyteDB instance on Linux. Requires wget and tar. The post_install.sh script must be run before starting the database. ```bash $ wget https://downloads.yugabyte.com/yugabyte-2.3.0.0-linux.tar.gz $ tar xvfz yugabyte-2.3.0.0-linux.tar.gz && cd yugabyte-2.3.0.0/ $ ./bin/post_install.sh $ ./bin/yugabyted start ``` -------------------------------- ### Start Prisma Studio Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/drivers-orms/nodejs/prisma.md Launch Prisma Studio to visually explore and manage your database data. Access it via the provided localhost URL. ```bash npx prisma studio ``` -------------------------------- ### Get Names of Brothers and Their Residences Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/integrations/janusgraph.md Retrieve the names of brothers and the names of the places they live. This query extends the previous example by using '.by('name')' to get property values. ```gremlin gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select('god', 'place').by('name') ``` ```text ==>[god:neptune,place:sea] ==>[god:jupiter,place:sky] ``` -------------------------------- ### Start UI Development Server Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/AI/ai-ollama.md Navigates to the UI directory and starts the development server using npm. This makes the UI accessible at http://localhost:5173. ```shell cd news-app-ui npm run dev ``` -------------------------------- ### Get YugabyteDB PostgreSQL version Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/additional-features/pg-extensions/install-extensions.md Check the version of PostgreSQL used by your YugabyteDB installation. ```sql ./bin/ysqlsh --version ``` -------------------------------- ### Install Python 3.8 and SELinux Package Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/yugabyte-platform/prepare/server-nodes-software/_index.md This example demonstrates installing Python 3.8 using yum, installing the corresponding SELinux Python package using pip, and creating symbolic links to make python3.8 the default Python 3 interpreter. ```sh sudo yum install python38 sudo pip3.8 install selinux sudo ln -s /usr/bin/python3.8 /usr/bin/python sudo rm /usr/bin/python3 sudo ln -s /usr/bin/python3.8 /usr/bin/python3 python3 -c "import selinux; import sys; print(sys.version)" ``` -------------------------------- ### CREATE TABLE Example with Table Properties and Aliases Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/api/ycql/ddl_create_table.md Illustrates creating a table with specific table properties and using aliases for column names. ```sql CREATE TABLE "MyTable" ( "MyColumn1" INT, "MyColumn2" TEXT, PRIMARY KEY ("MyColumn1") ) WITH "my_property" = 'my_value'; ``` -------------------------------- ### Start YugabyteDB Cluster in Docker Source: https://github.com/yugabyte/yugabyte-db/blob/master/docs/content/stable/develop/AI/google-vertex-ai.md Starts a 3-node YugabyteDB cluster using Docker. Ensure Docker is installed and running. The command creates a network and mounts volumes for data persistence. ```sh rm -rf ~/yb_docker_data mkdir ~/yb_docker_data docker network create yb-network docker run -d --name ybnode1 --hostname ybnode1 --net yb-network \ -p 15433:15433 -p 7001:7000 -p 9001:9000 -p 5433:5433 \ -v ~/yb_docker_data/node1:/home/yugabyte/yb_data --restart unless-stopped \ yugabytedb/yugabyte:{{< yb-version version="stable" format="build">}} \ bin/yugabyted start \ --base_dir=/home/yugabyte/yb_data --background=false docker run -d --name ybnode2 --hostname ybnode2 --net yb-network \ -p 15434:15433 -p 7002:7000 -p 9002:9000 -p 5434:5433 \ -v ~/yb_docker_data/node2:/home/yugabyte/yb_data --restart unless-stopped \ yugabytedb/yugabyte:{{< yb-version version="stable" format="build">}} \ bin/yugabyted start --join=ybnode1 \ --base_dir=/home/yugabyte/yb_data --background=false docker run -d --name ybnode3 --hostname ybnode3 --net yb-network \ -p 15435:15433 -p 7003:7000 -p 9003:9000 -p 5435:5433 \ -v ~/yb_docker_data/node3:/home/yugabyte/yb_data --restart unless-stopped \ yugabytedb/yugabyte:{{< yb-version version="stable" format="build">}} \ bin/yugabyted start --join=ybnode1 \ --base_dir=/home/yugabyte/yb_data --background=false ``` -------------------------------- ### Create Sample Table and Data Source: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/third-party-extensions/hypopg/docs/usage.md Sets up a sample table with a large amount of data for testing index performance. ```sql CREATE TABLE hypo (id integer, val text) ; INSERT INTO hypo SELECT i, 'line ' || i FROM generate_series(1, 100000) i ; VACUUM ANALYZE hypo ; ```