Oracle Checkpoint
Sunday 8 September 2024
Unveiling DBMS_SEARCH in Oracle 23 AI: The New Era of Database Search
In the world of database management, efficiently locating data is paramount. With the advent of Oracle 23 AI, Oracle has introduced a game-changing feature: `DBMS_SEARCH`. This new feature, designed to simplify and accelerate search operations within Oracle databases, is making waves in the industry. In this blog post, we will dive deep into what `DBMS_SEARCH` is, how it works, and its benefits through a real-world example.
Imagine a global e-commerce company, "ShopEasy," with millions of users, transactions, products, and reviews stored in its Oracle 23ai database. As the business grows, so does the need to quickly retrieve data that powers search functionality on their platform. Users may want to find products based on specific keywords, filter by categories, or even search through product reviews to see what others are saying. The traditional approach would involve writing complex SQL queries and potentially creating multiple indexes. However, with Oracle 23ai's `DBMS_SEARCH` package, things have become much more streamlined.
### What is `DBMS_SEARCH`?
`DBMS_SEARCH` is a new built-in package in Oracle 23 AI that allows you to perform powerful and flexible full-text searches directly within the database. It provides a simplified, high-performance method for searching across multiple tables and columns, offering a unified search interface similar to popular search engines like Elasticsearch but directly integrated within Oracle.
### How Does `DBMS_SEARCH` Work?
Under the hood, `DBMS_SEARCH` leverages AI-powered indexing and advanced algorithms to understand the context of data better. It automatically indexes the specified columns, understands the relationships between tables, and optimizes search queries to provide near-instantaneous results. The package comes with several built-in functions, such as `DBMS_SEARCH.CREATE_INDEX`, `DBMS_SEARCH.SEARCH`, and `DBMS_SEARCH.DROP_INDEX`, allowing developers to define search contexts, execute searches, and manage indexes effortlessly.
For example, to set up a search index across the `PRODUCTS` and `REVIEWS` tables, you can use:
```sql
BEGIN
DBMS_SEARCH.CREATE_INDEX(
index_name => 'product_review_index',
tables => 'PRODUCTS, REVIEWS',
columns => 'product_name, review_text'
);
END;
/
```
With this setup, the `DBMS_SEARCH.SEARCH` function can be used to search for "wireless headphones" across both tables, returning relevant product names and reviews in a single, optimized query:
```sql
SELECT * FROM TABLE(DBMS_SEARCH.SEARCH('product_review_index', 'wireless headphones'));
```
### Benefits of `DBMS_SEARCH`
The benefits of `DBMS_SEARCH` are manifold:
1. **Unified Search Across Multiple Tables**: Unlike traditional methods where each table would require separate indexing and querying, `DBMS_SEARCH` allows for a single, cohesive search across multiple tables and columns.
2. **AI-Powered Optimization**: By leveraging AI, Oracle 23ai intelligently optimizes search queries, reducing latency and boosting performance. This is especially useful for real-time applications like e-commerce, where quick search results are crucial.
3. **Simplified Development and Maintenance**: Developers can set up and manage search contexts with just a few lines of code. There's no need for external search engines or additional infrastructure.
4. **Enhanced User Experience**: For "ShopEasy," `DBMS_SEARCH` directly translates to a better user experience. Users can search for products, filter by reviews, or find popular items effortlessly, driving more engagement and sales.
### A Real-World Impact
For "ShopEasy," implementing `DBMS_SEARCH` led to a 50% reduction in search query latency and simplified their search infrastructure. The customers could instantly find products matching their queries, read reviews, and make purchases, boosting customer satisfaction and revenue.
### Conclusion
`DBMS_SEARCH` in Oracle 23 AI represents a significant leap forward in database search capabilities, bringing the power of AI-driven search directly into the hands of developers. Whether you’re running an e-commerce platform, a financial service, or a healthcare application, `DBMS_SEARCH` offers an efficient, high-performance, and unified way to handle search operations. With its ease of use, powerful performance, and integration with Oracle's robust database ecosystem, `DBMS_SEARCH` is set to become a must-have tool for modern database management.
Saturday 25 May 2024
Vector index creation in Oracle 23ai
As you are aware there is AI embedded in Oracle 23ai powered by Vector Search, you can create vector indexes in Oracle 23ai, To allow vector index creation, you must enable a new memory area stored in the SGA called the Vector Pool. The Vector Pool is a memory allocated in SGA to store Hierarchical Navigable Small World (HNSW) vector indexes and all associated metadata. It is also used to speed up Inverted Flat File (IVF) index creation as well as DML operations on base tables with IVF indexes.
To size the Vector Pool, use the VECTOR_MEMORY_SIZE initialization parameter. You can dynamically modify this parameter at the following levels:
1) At the CDB level VECTOR_MEMORY_SIZE specifies the current size of the Vector Pool. Reducing the parameter value will fail if there is current vector usage.
2) At the PDB level VECTOR_MEMORY_SIZE specifies the maximum Vector Pool usage allowed by a PDB. Reducing the parameter value will be allowed even if current vector usage exceeds the new quota.
3) You can change the value of a parameter in a parameter file in the following ways:
3a) By editing an initialization parameter file. In most cases, the new value takes effect the next time you start an instance of the database.
3b) By issuing an ALTER SYSTEM SET ... SCOPE=SPFILE statement to update a server parameter file.
3c) By issuing an ALTER SYSTEM RESET statement to clear an initialization parameter value and set it back to its default value.
Lets see a demo how you can do it :
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.4.0.24.05
SQL> show con_name
CON_NAME
------------------------------
FREEPDB1
SQL> show user
USER is "SYS"
SQL> show parameter vector_memory_size
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
vector_memory_size big integer 0
SQL> SELECT ISPDB_MODIFIABLE FROM V$SYSTEM_PARAMETER WHERE NAME='vector_memory_size';
ISPDB
-----
TRUE
SQL> ALTER SYSTEM SET vector_memory_size=1G SCOPE=BOTH;
System altered.
SQL> show parameter vector_memory_size
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
vector_memory_size big integer 1G
V$VECTOR_MEMORY_POOL, is the view you can query to monitor the Vector Pool.
Reference : https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/size-vector-pool.html
New Ping command in Oracle 23ai database
Oracle 23ai offers a very useful command Ping. Lets go deep and understand what it is :
Firstly to make the confusion clear it is just like tnsping, so if you want to test connectivity and see the network reachability for listener, database and so on this is very helpful. As per Oracle officially ping utility : Pings the database or database network listener to check availability. The PING
command will fail with an error if either the database or the network listener are unavailable. It indicates that either the network listener or the database needs to be restarted, or that the database connection is not usable and needs to be recreated.
PING
command is executed without a connect identifier, then a round-trip message is sent through the network listener to the currently connected database. When it is executed with a connect identifier, then a round-trip message is sent to the specified network listener to verify if it is able to handle the database connections.Oracle 23ai helpful feature of error details for Oracle users
I was testing the new 23ai free VM shared by Oracle, and i observed very helpful feature of 23ai which shares us the url of the error to read more about it for knowledge. Here is how it works :
So here the table t does not exists, and we get Help page to see about the error and its details and action page
SQL> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view "SYS"."T" does not exist
Help: https://docs.oracle.com/error-help/db/ora-00942/
SQL> show errordetails
errordetails ON
SQL> set errordetails off
SQL> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view "SYS"."T" does not exist
SQL> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view "SYS"."T" does not exist
# Further the verbose page shows more details like Cause: as well.
SQL> set errordetails verbose
SQL> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view "SYS"."T" does not exist
Help: https://docs.oracle.com/error-help/db/ora-00942/
Cause: The specified table or view did not exist, or a synonym
pointed to a table or view that did not exist.
To find existing user tables and views, query the
ALL_TABLES and ALL_VIEWS data dictionary views. Certain
privileges may be required to access the table. If an
application returned this message, then the table that the
application tried to access did not exist in the database, or
the application did not have access to it.
Action: Check each of the following:
- The spelling of the table or view name is correct.
- The referenced table or view name does exist.
- The synonym points to an existing table or view.
If the table or view does exist, ensure that the correct access
privileges are granted to the database user requiring access
to the table. Otherwise, create the table.
Also, if you are attempting to access a table or view in another
schema, make sure that the correct schema is referenced and that
access to the object is granted.
Params: 1) object_name: The table or view name specified as
SCHEMA.OBJECT_NAME, if one is provided.
Otherwise, it is blank.
How to fix ORA-01017 in 23ai Oracle
As you know Oracle has announced 23ai as a big announcement with so many features more than 300 for developers and Oracle users, here is the post on How to fix ORA-01017 in 23ai Oracle for the VM which Oracle provides to developer for free .
[oracle@localhost ~]$ ps -ef | grep smon
oracle 1738 1 0 17:27 ? 00:00:00 db_smon_FREE
oracle 4398 4334 0 17:37 pts/3 00:00:00 grep --color=auto smon
[oracle@localhost ~]$ . oraenv
ORACLE_SID = [FREE] ? FREE
The Oracle base remains unchanged with value /opt/oracle
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Sat May 25 17:37:30 2024
Version 23.4.0.24.05
Copyright (c) 1982, 2024, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid credential or not authorized; logon denied
Help: https://docs.oracle.com/error-help/db/ora-01017/
[oracle@localhost ~]$ sqlplus sys@localhost:1521/FREEPDB1 as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Sat May 25 17:38:24 2024
Version 23.4.0.24.05
Copyright (c) 1982, 2024, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.4.0.24.05
Saturday 27 May 2023
Startup Modes in Oracle Database
In this blog post we will learn Startup Modes in Oracle Database
There are 3 states in which Oracle instance can be started i.e nomount, mount and open. Remember you can go directory to open from scratch i.e when database is shutdown and you can also go directly to mount and as always you can go to mount from nomount or you can go to open from mount as well. Its like climbing stairs in order.
1) First mode is nomount, in this mode only spfile/parameter is read and Oracle instance SGA memory is allocated :- Lets see :
Verify database instance is down :
[oracle@node2 ~]$ ps -ef | grep smon
oracle 3597 2134 0 11:49 pts/0 00:00:00 grep --color=auto smon
[oracle@node2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 21.0.0.0.0 - Production on Sun May 28 11:49:10 2023
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1073740680 bytes
Fixed Size 9694088 bytes
Variable Size 469762048 bytes
Database Buffers 591396864 bytes
Redo Buffers 2887680 bytes
Starting Oracle processes via shell script
In this post we will learn how to start Oracle processes via shell script
Lets write a script to start listener and then the database :
[oracle@node2 ~]$ cat start.sh
ORACLE_SID=orcl
ORAENV_ASK=NO
. oraenv
lsnrctl stop
lsnrctl start
sqlplus -s /nolog <<EOF
connect / as sysdba
startup
exit;
EOF