Thursday, 14 August 2025

Changing the hostname in Linux

(adsbygoogle = window.adsbygoogle || []).push({});
Changing the hostname in Linux depends on your distribution and whether you're using **systemd** (most modern distros do).

1. Check Current Hostname

[root@test ~]# hostnamectl status
   Static hostname: test.localdomain
         Icon name: computer-vm
           Chassis: vm
[root@test ~]# date
Thu Aug 14 15:53:54 +04 2025
[root@test ~]# uptime
 15:53:56 up 1 min,  1 user,  load average: 2.46, 0.70, 0.24
 
2. Change Hostname (Permanent)

Using `hostnamectl` (Recommended for systemd-based systems like Ubuntu, CentOS 7+, RHEL 7+, Debian 9+)

sudo hostnamectl set-hostname new-hostname
[root@test ~]# hostnamectl set-hostname muthu.org


> Replace `new-hostname` with your desired name.

3. Update `/etc/hosts`

Edit the file:

sudo nano /etc/hosts

[root@test ~] vi /etc/hosts

Find the line like:

127.0.1.1    old-hostname

And change it to:

127.0.1.1    new-hostname

This ensures local name resolution works properly.

4. Reboot or Re-login

Although the change is immediate, some services may require a reboot:
sudo reboot

[root@test ~]# reboot

Wednesday, 13 August 2025

##Viewing Alert Logs in Oracle Cloud Infrastructure (OCI) for Oracle Autonomous Databases

### Limited OS Access
For Oracle Autonomous Databases, direct access to the underlying operating system is restricted. Therefore, alert log monitoring must be done through SQL views and the OCI Console.


### SQL-Based Alert Log Access

#### Deprecated View
- **`V$DIAG_ALERT_EXT`**: Previously used to query alert logs directly via SQL.
- **Status**: **Removed** in recent Oracle ADB updates.

#### Replacement View
- **`V$CLIENT_ERRORS`**: Introduced as the new method to access alert log-related error data.
- **Purpose**: Displays XML-based error logs, including client connection issues and user errors like `ORA-4021`.

### Current Limitations of `V$CLIENT_ERRORS`

- **Session Dependency**: The view only shows error data **while the session is active**.
- **Post-Session Visibility**: If a session is terminated (e.g., killed due to resource limits), its error data **is no longer visible** in the view.
- **User Experience**: This behavior is understandably frustrating, as it limits post-mortem diagnostics.

### Enhancement in Progress

Oracle is actively working on enhancing `V$CLIENT_ERRORS` to improve its usability and persistence of error data beyond session lifetime. No official release date has been announced yet, but updates are expected soon.

we will keep posted about any recent update

 Goldengate cdc replication from Oracle to Postgres (DAA)

ADD EXTRACT PROCESS

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 10> dblogin USERID c##oggadmin@node1.muthu.org:1526/oradb, PASSWORD ******* , ENCRYPTKEY DEFAULT

Successfully logged into database CDB$ROOT.

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 11> register extract EXT_E1_2 database container(PDB)

2025-08-12 20:22:02  INFO    OGG-02003  Extract group EXT_E1_2 successfully registered with database at SCN 11849257800002.

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 12> add extract EXT_E1_2 integrated tranlog begin now

Integrated Extract added.


GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 13> add exttrail ./dirdat/ex  extract EXT_E1_2 megabytes 500

EXTTRAIL added.

ADD PUMP PROCESS

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 14> add extract PXT_P2 exttrailsource ./dirdat/ex

Extract added.

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 15> add rmttrail ./dirdat/er extract PXT_P2 megabytes 500

RMTTRAIL added.

EXTRACT  PARAMETERS:

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 9> view params EXT_E1_2

EXTRACT EXT_E1_2
SETENV (ORACLE_SID='oradb')
USERID c##oggadmin@node1.muthu.org:1526/oradb, PASSWORD *******, ENCRYPTKEY DEFAULT
EXTTRAIL ./dirdat/ex
SOURCECATALOG PDB
DDL &
INCLUDE MAPPED
DDLOPTIONS REPORT
reportcount every 1 minutes, rate
REPORTROLLOVER AT 01:30 ON Sunday
LOGALLSUPCOLS
UPDATERECORDFORMAT FULL
TABLE PDB.EMP.SALARY;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 10>

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 10> info EXT_E1_2

Extract    EXT_E1_2  Initialized  2024-08-12 00:34   Status STOPPED
Checkpoint Lag       00:00:00 (updated 00:02:45 ago)
Log Read Checkpoint  Oracle Integrated Redo Logs
                     2024-08-12 00:34:17
                     SCN 0.0 (0)

PUMP  PARAMETERS;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 27> view params PXT_P2


EXTRACT PXT_P2
SETENV (ORACLE_SID='oradb')
USERID c##oggadmin@node1.muthu.org:1526/oradb, PASSWORD ******* , ENCRYPTKEY DEFAULT
rmthost 27-45-2-299, mgrport 7809
rmttrail ./dirdat/er
PASSTHRU
SOURCECATALOG PDB
TABLE PDB.EMP.SALARY;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 16> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
EXTRACT     STOPPED     EXT_E1_2    00:00:00      00:00:37
EXTRACT     STOPPED     PXT_P2    00:00:00      00:00:10

START EXTRACT CDC;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 17> start EXT_E1_2

Sending START request to Manager ...

Extract group EXT_E1_2 starting.

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 18> info EXT_E1_2

Extract    EXT_E1_2  Initialized  2025-08-12 20:22   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:49 ago)
Process ID           1135560
Log Read Checkpoint  Oracle Integrated Redo Logs
                     2025-08-12 20:22:10
                     SCN 0.0 (0)

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 26> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT_E1_2    00:00:03      00:00:08
EXTRACT     STOPPED     PXT_P2    00:00:00      00:08:35

CDC PUMP PROCESS TO START;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 28>  info PXT_P2,detail
Extract    PXT_P2  Initialized  2025-08-12 20:22   Status STOPPED
Checkpoint Lag       00:00:00 (updated 00:10:16 ago)
Log Read Checkpoint  File ./dirdat/ex000000000
First Record  RBA 0
  Target Extract Trails:
  Trail Name                                       Seqno        RBA     Max MB Trail Type
  ./dirdat/er                                          0          0        500 RMTTRAIL

START CDC PUMP PROCESS;

GGSCI (node1.muthu.org as c##oggadmin@oradb/CDB$ROOT) 29> start PXT_P2

Sending START request to Manager ...

Extract group PXT_P2 starting.


GGSCI (node1.muthu.org) 3> info PXT_P2,detail

Extract    PXT_P2  Last Started 2025-08-12 22:01   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:09 ago)
Process ID           1316914
Log Read Checkpoint  File ./dirdat/ex000000000
                     2025-08-12 21:17:05.000000  RBA 5298768
  Target Extract Trails:
  Trail Name                                       Seqno        RBA     Max MB Trail Type
  ./dirdat/er                                          0    5298846        500 RMTTRAIL

INITIAL LOAD:

INITIAL LOAD EXTRACT:

GGSCI (node1.muthu.org) 1> info all tasks


Program     Status      Group       Lag at Chkpt  Time Since Chkpt
EXTRACT     STOPPED     ILT_03

SCN - Used here is from the REAL TIME EXTRACT PROCESS Registered SCN.

“ Extract group EXT_E1_2 successfully registered with database at SCN 11849257800002.”


GGSCI (node1.muthu.org) 24> view params ILT_03


EXTRACT ILT_03
USERID c##oggadmin@node1.muthu.org:1526/oradb, PASSWORD ******* , ENCRYPTKEY DEFAULT
RMTHOST 27-45-2-299,mgrport 7809, Compress
rmtfile /gg01/app/oracle/product/21.3.0/postgres/dirdat/m11/ta
SOURCECATALOG PDB
TABLE PDB.EMP.COUNTRY SQLPREDICATE 'AS OF SCN 11849257800002';

GGSCI (node1.muthu.org) > delete extract ILT_03

GGSCI (node1.muthu.org) 6> add extract ILT_03,sourceistable

Extract added.

GGSCI (node1.muthu.org) 7> info ILT_03
Extract    ILT_03   Initialized  2025-08-12 23:00   Status STOPPED
Checkpoint Lag       Not Available
Log Read Checkpoint  Not Available
First Record         Record 0
Task                 SOURCEISTABLE

GGSCI (node1.muthu.org) 28> start ILT_03

Sending START request to Manager ...

Extract group ILT_03 starting.


GGSCI (node1.muthu.org) 29> info ILT_03

Extract    ILT_03   Initialized  2025-08-12 23:07   Status RUNNING
Checkpoint Lag       Not Available
Process ID           1437844
Log Read Checkpoint  Not Available
                     First Record         Record 0
Task                 SOURCEISTABLE

GGSCI (node1.muthu.org) 34> info ILT_03

Extract    ILT_03   Last Started 2025-08-12 23:08   Status RUNNING
Checkpoint Lag       Not Available
Process ID           1437844
Log Read Checkpoint  Table PDB.EMP.COUNTRY
                     2025-08-12 23:10:09  Record 12715001
Task                 SOURCEISTABLE


INITIAL LOAD REPLICAT

GGSCI (ip-27-45-2-299.us-east) 3> view params ILT_03

replicat ILT_03
SETENV (ODBCINI="/u01/app/oracle/product/21.3.0/postgres/odbc.ini" )
targetdb pgdbs, userid oggadmin PASSWORD *******
DISCARDFILE /gg01/app/oracle/product/21.3.0/postgres/dirprm/dsc_max.dsc, APPEND, MEGABYTES 200
BATCHSQL 
MAP PDB.EMP.COUNTRY,TARGET EMP.COUNTRY;

GGSCI (ip-27-45-2-299.us-east) 7> add replicat ILT_03,exttrail /u01/app/oracle/product/21.3.0/postgres/dirdat/m11/ta , NODBCHECKPOINT

Replicat added.

GGSCI (ip-27-45-2-299.us-east) 9> start ILT_03

Sending START request to Manager ...

Replicat group ILT_03 starting.


GGSCI (ip-27-45-2-299.us-east) 10> info ILT_03

Replicat   ILT_03   Last Started 2025-08-12 00:16   Status RUNNING
Checkpoint Lag       01:08:00 (updated 00:00:00 ago)
Process ID           1797
Log Read Checkpoint  File /u01/app/oracle/product/21.3.0/postgres/dirdat/m11/ta000000
                     2025-08-12 23:08:11.626226  RBA 901433

Once the initial load is completed then start cdc replication process.


GGSCI (ip-27-45-2-299.us-east) 2> add replicat REP_R3,exttrail  ./dirdat/er, NODBCHECKPOINT

Replicat added.


GGSCI (ip-27-45-2-299.us-east) 3> info REP_R3

Replicat   REP_R3  Initialized  2025-08-12 05:51   Status STOPPED
Checkpoint Lag       00:00:00 (updated 00:00:05 ago)
Log Read Checkpoint  File ./dirdat/er000000000
                     First Record  RBA 0


GGSCI (ip-27-45-2-299.us-east) 7> START REPLICAT REP_R3 AFTERCSN 11849257800002

Sending START request to Manager ...

Replicat group REP_R3 starting.


GGSCI (ip-27-45-2-299.us-east) 16> view params REP_R3


REPLICAT REP_R3
SETENV (ODBCINI="/u01/app/oracle/product/21.3.0/postgres/odbc.ini" )
targetdb pgdbs, userid oggadmin PASSWORD ******* 
DISCARDFILE /gg01/app/oracle/product/21.3.0/postgres/dirrpt/REP_R3.dsc
MAP PDB.EMP.SALARY,TARGET EMP.SALARY;

GGSCI (ip-27-45-2-299.us-east) 15> info REP_R3

Replicat   REP_R3  Last Started 2025-08-12 05:59   Status RUNNING
Checkpoint Lag       04:37:25 (updated 00:00:03 ago)
Process ID           8836
Log Read Checkpoint  File ./dirdat/er000000000
                     2025-08-12 01:25:40.013362  RBA 16962583

SCRIPTS USED TO DROP OBJECTS

Note : Login to respective user then execute this script

SELECT
'DROP TABLE ' || table_schema || '.' || table_name || ' CASCADE;'
FROM
information_schema.tables
WHERE
table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema');


COUNTS;

SELECT
'SELECT COUNT(*) FROM ' || table_schema || '.' || table_name || ';'
FROM
information_schema.tables
WHERE
table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema');



SCRIPT FOR TRIGGERS;

CREATE OR REPLACE FUNCTION set_replica_identity_on_create()
RETURNS event_trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN
        SELECT
            objid::regclass AS full_table_name,
            n.nspname AS schema_name,
            c.relname AS table_name
        FROM pg_event_trigger_ddl_commands() AS e
        JOIN pg_class c ON c.oid = e.objid
        JOIN pg_namespace n ON n.oid = c.relnamespace
        WHERE e.command_tag = 'CREATE TABLE'
          AND n.nspname = 'entitystore'
          AND c.relkind IN ('r', 'p') -- regular and partitioned tables
    LOOP
        EXECUTE 'ALTER TABLE ' || quote_ident(r.schema_name) || '.' || quote_ident(r.table_name) || ' REPLICA IDENTITY FULL';
        RAISE NOTICE 'Set REPLICA IDENTITY FULL for table: %.%', r.schema_name, r.table_name;
    END LOOP;
END;
$$;



CREATE EVENT TRIGGER set_replica_identity_on_create

ON ddl_command_end

WHEN TAG IN ('CREATE TABLE')

EXECUTE FUNCTION set_replica_identity_on_create();


CREATE OR REPLACE FUNCTION set_replica_identity_on_alter()
RETURNS event_trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN
        SELECT
            n.nspname AS schema_name,
            c.relname AS table_name,
            c.relreplident
        FROM pg_event_trigger_ddl_commands() e
        JOIN pg_class c ON c.oid = e.objid
        JOIN pg_namespace n ON n.oid = c.relnamespace
        WHERE e.command_tag = 'ALTER TABLE'
          AND c.relkind IN ('r', 'p')
          AND n.nspname = 'entitystore'
          AND c.relreplident != 'f'  -- Skip if already FULL
    LOOP
        EXECUTE 'ALTER TABLE ' || quote_ident(r.schema_name) || '.' || quote_ident(r.table_name) || ' REPLICA IDENTITY FULL';
        RAISE NOTICE 'Set REPLICA IDENTITY FULL for table: %.%', r.schema_name, r.table_name;
    END LOOP;
END;
$$;



CREATE EVENT TRIGGER set_replica_identity_on_alter
    ON ddl_command_end
    WHEN TAG IN ('ALTER TABLE')
    EXECUTE FUNCTION set_replica_identity_on_alter();


SELECT
    evtname AS trigger_name,
    evtevent AS event,
    evtowner AS owner_id,
    evtfoid::regprocedure AS function_name,
    evtenabled AS enabled_status
FROM pg_event_trigger;

Tuesday, 12 August 2025

Ads

Convert oracle standalone database to oracle ASM

Here is the sequence of operations to migrate an Oracle database from a file system to ASM (Automatic Storage Management) and register it with Oracle Clusterware.

1. Initial State & Failed Backup Attempt

First, the database instance is started in MOUNT mode. An initial attempt to back up the database using RMAN fails because the database is running in NOARCHIVELOG mode. An online backup cannot be performed on active datafiles in this state.

# Connect to the idle instance
[oracle@node1 dbs]$ sqlplus / as sysdba
Connected to an idle instance.

SQL> startup mount
Database mounted.

# Attempt backup using RMAN
[oracle@node1 dbs]$ rman target /
connected to target database: ORADB (DBID=2803372975, not open)

RMAN> BACKUP AS COPY DATABASE FORMAT '+DATA';
...
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/12/2025 14:20:46
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
...

2. Enabling ARCHIVELOG Mode

To resolve the backup failure, ARCHIVELOG mode must be enabled. An initial attempt fails with error ORA-00265, indicating that instance recovery is required due to the previous unclean state. A clean shutdown and restart in MOUNT mode resolve this, allowing ARCHIVELOG and FORCE LOGGING to be successfully enabled.

# Attempt to enable archivelog mode fails
SQL> alter database archivelog;
*
ERROR at line 1:
ORA-00265: instance recovery required, cannot set ARCHIVELOG mode

# Perform a clean shutdown and restart
SQL> shutdown immediate;
ORACLE instance shut down.

SQL> startup mount;
Database mounted.

# Successfully enable archivelog and force logging
SQL> alter database archivelog;
Database altered.

SQL> alter database force logging;
Database altered.

3. Successful Backup and Switch to ASM

With the database in ARCHIVELOG mode, the RMAN backup to the +DATA ASM disk group now succeeds. The BACKUP AS COPY command creates an image copy of the datafiles directly in ASM. Afterward, the SWITCH DATABASE TO COPY command updates the control file to point to these new datafile locations on ASM, effectively migrating the datafiles.

# RMAN backup to ASM
[oracle@node1 trace]$ rman target /
RMAN> BACKUP AS COPY DATABASE FORMAT '+DATA';
Starting backup at 12-AUG-2025 14:27:48
...
output file name=+DATA/ORADB/DATAFILE/system.261.1208960879
...
Finished backup at 12-AUG-2025 14:29:15

# Switch database to use the new datafile copies in ASM
RMAN> SWITCH DATABASE TO COPY;
datafile 1 switched to datafile copy "+DATA/ORADB/DATAFILE/system.261.1208960879"
...

# Open the database
RMAN> ALTER DATABASE OPEN;
Statement processed

4. Relocating Redo Log Files to ASM

The final migration step is moving the online redo log files from the local file system to ASM. This is done by adding new log groups in ASM, switching log files until the old ones are no longer active, and then dropping the old log files.

-- Verify datafiles are now in ASM
SQL> SELECT name FROM V$DATAFILE;
NAME
--------------------------------------------------
+DATA/ORADB/DATAFILE/system.261.1208960879
+DATA/ORADB/DATAFILE/sysaux.262.1208960903
...

-- Add new redo log groups in the '+FRA' disk group
SQL> alter database add logfile group 4 ('+FRA/redo1.log') size 500M;
SQL> alter database add logfile group 5 ('+FRA/redo2.log') size 500M;
SQL> alter database add logfile group 6 ('+FRA/redo3.log') size 500M;

-- Switch logfiles to make old groups inactive
SQL> alter system switch logfile;

-- Drop old file system-based redo log groups
SQL> alter database drop logfile group 2;
SQL> alter database drop logfile group 3;

-- The current log group cannot be dropped immediately
SQL> alter database drop logfile group 1;
*
ERROR at line 1:
ORA-01623: log 1 is current log for instance oradb (thread 1) - cannot drop

-- Switch again to make group 1 inactive, then drop it
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> alter database drop logfile group 1; 

5. Registering and Managing with Oracle Clusterware

Finally, the database is registered with Oracle Clusterware using the srvctl utility. This allows the cluster to manage the database startup, shutdown, and monitoring.

# Add the database and instance to the Clusterware configuration
[oracle@node1 ~]$ srvctl add database -d oradb -o /u01/app/oracle/product/19.0.0/db_1
[oracle@node1 ~]$ srvctl add instance -d oradb -i oradb1 -n node1

# Start the database using srvctl
[oracle@node1 dbs]$ srvctl start database -d oradb

# Verify the status
[oracle@node1 dbs]$ srvctl status database -d oradb
Instance oradb1 is running on node node1

# Final check of the running processes
[oracle@node1 ~]$ ps -ef|grep pmon
oracle   21502     1 0 15:57 ?        00:00:00 ora_pmon_oradb

Sample Text

Sample text