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.

When the 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.

When i fired just ping it did this to me :

SQL> ping
Ok (1.398 msec)

So it tests the current connection reachability.

Now when i give a wrong name which means i dont have an entry in respective tnsnames.ora it hangs for a moment for obvious reasons and returns this info :

SQL> ping a
>> Hangs here for a while (few seconds)

SP2-1679: Connect identifier (a) was not found.
Help: https://docs.oracle.com/error-help/db/sp2-1679/
Cause:  Connect identifier passed was not found in tnsnames.ora.
Action: Check the connect identifier used in the PING command.

Now lets try to actually ping something whose entry exists in the tnsnames.ora i.e :

SQL> ping FREEPDB1
Local Net Naming configuration file: /opt/oracle/product/23ai/dbhomeFree/network/admin/tnsnames.ora
Attempting to contact: (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = FREEPDB1)))
Ok (20.312 msec)


SQL> !cat /opt/oracle/product/23ai/dbhomeFree/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/product/23ai/dbhomeFree/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

FREE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FREE)
    )
  )

LISTENER_FREE =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


FREEPDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FREEPDB1)
    )
  )

#Happy learning, thanks



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


So the solution is, the credentials must be used for FREEPDB1 as mentioned in the Oracle portal . Here is the link for more info to get started with 23ai https://www.oracle.com/database/free/get-started/