Wednesday, January 12, 2022

ORA-02291: integrity constraint (RMAN.RLH_F1) violated - parent key not found

 issue:

when I tried to register the oracle DB with catalog DB during registration process got the below error.

RMAN> REGISTER DATABASE;


database registered in recovery catalog

starting full resync of recovery catalog

got ORA-02291: integrity constraint (RMAN.RLH_F1) violated - parent key not found

ORA-06512: at "RMAN.DBMS_RCVCAT", line 7261 during resync

retrying with snapshot controlfile

Creating and using snapshot control file for resync

starting full resync of recovery catalog

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03008: error while performing automatic resync of recovery catalog

ORA-02291: integrity constraint (RMAN.RLH_F1) violated - parent key not found


Cause:

could be the same Db already registered and not properly unregistred ,so that we  got the above error.

Solution:

connect to RMAN catalog DB using Catalog user and  execute the below package.

Connected to:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.11.0.0.0


SQL> select name,open_mode from v$database;


NAME      OPEN_MODE

--------- --------------------

4RMANCAT  READ WRITE


SQL> select 'EXEC DBMS_RCVCAT.UNREGISTERDATABASE('||DB_KEY||','||DBID||');'

  command, resetlogs_time

 from rc_database

 where name = '&db_name';  2    3    4

Enter value for db_name: TESTDB

old   4:  where name = '&db_name'

new   4:  where name = 'TESTDB'

 from rc_database

      *

ERROR at line 3:

ORA-00942: table or view does not exist



SQL> conn rman

Enter password:

Connected.

SQL> select 'EXEC DBMS_RCVCAT.UNREGISTERDATABASE('||DB_KEY||','||DBID||');'

  command, resetlogs_time

 from rc_database

 where name = '&db_name';  

Enter value for db_name: TESTDB

old   4:  where name = '&db_name'

new   4:  where name = 'TESTDB'


COMMAND

--------------------------------------------------------------------------------

RESETLOGS

---------

EXEC DBMS_RCVCAT.UNREGISTERDATABASE(85399,987618234);

28-JAN-21



SQL> EXEC DBMS_RCVCAT.UNREGISTERDATABASE(85399,987618234);


PL/SQL procedure successfully completed.


SQL> commit;


Commit complete.


SQL>


> rman target / catalog rman@RCATDB


Recovery Manager: Release 19.0.0.0.0 - Production on Wed Jan 12 06:11:50 2022

Version 19.6.0.0.0


Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.


connected to target database: TESTDB (DBID=987618234)

recovery catalog database Password:

connected to recovery catalog database

recovery catalog schema version 19.11.00.00. is newer than RMAN version


RMAN> REGISTER DATABASE ;


database registered in recovery catalog

starting full resync of recovery catalog

full resync complete



RMAN> list db_unique_name all;



List of Databases

DB Key  DB Name  DB ID            Database Role    Db_unique_name

------- ------- ----------------- ---------------  ------------------

86302   TESTDB    987618234        PRIMARY          TESTDB





Monday, December 27, 2021

script to check mysql db user locked status

 SELECT 

    user, host, account_locked

FROM

    mysql.user

WHERE

    user = 'mysqluser' ;


mysql> CREATE USER mysqluser

    -> IDENTIFIED BY '5password67'

    -> ACCOUNT LOCK;

Query OK, 0 rows affected (2.10 sec)


mysql> SELECT

    ->     user, host, account_locked

    -> FROM

    ->     mysql.user

    -> WHERE

    ->     user = 'mysqluser' AND

    ->     host='localhost';

Empty set (0.00 sec)


mysql> SELECT

    ->     user, host, account_locked

    -> FROM

    ->     mysql.user

    -> WHERE

    ->     user = 'mysqluser' ;

+-----------+------+----------------+

| user      | host | account_locked |

+-----------+------+----------------+

| mysqluser | %    | Y              |

+-----------+------+----------------+

1 row in set (0.00 sec)

If the mysql server is performing slow than how to find out the process which is causing problem.

 If the mysql server is performing slow than how to find out the process which is causing problem.


Answer: Best way is to check with: ‘SHOW PROCESSLIST / SHOW ENGINE INNODB STATUS

script to check the uptime of a mysql database server?


SELECT
  VARIABLE_VALUE AS Uptime_seconds,
  NOW() AS "Now",
  NOW() - INTERVAL VARIABLE_VALUE SECOND AS "Up since",
  DATEDIFF(NOW(), NOW() - INTERVAL VARIABLE_VALUE SECOND) AS "Uptime_days"
FROM performance_schema.session_status
WHERE VARIABLE_NAME = 'Uptime';


 mysql> SELECT

    ->   VARIABLE_VALUE AS Uptime_seconds,

    ->   NOW() AS "Now",

    ->   NOW() - INTERVAL VARIABLE_VALUE SECOND AS "Up since",

    ->   DATEDIFF(NOW(), NOW() - INTERVAL VARIABLE_VALUE SECOND) AS "Uptime_days"

    -> FROM performance_schema.session_status

    -> WHERE VARIABLE_NAME = 'Uptime';

+----------------+---------------------+----------------------------+-------------+

| Uptime_seconds | Now                 | Up since                   | Uptime_days |

+----------------+---------------------+----------------------------+-------------+

| 100752         | 2021-12-27 10:02:34 | 2021-12-26 06:03:22.000000 |           1 |

+----------------+---------------------+----------------------------+-------------+

1 row in set (0.01 sec)


mysql> SHOW GLOBAL STATUS LIKE '%UPTIME%';

+---------------------------+--------+

| Variable_name             | Value  |

+---------------------------+--------+

| Uptime                    | 100776 |

| Uptime_since_flush_status | 100776 |

+---------------------------+--------+

2 rows in set (0.00 sec)

What are the different database engine present in MySQL?

different database engine present in MySQL

MyISAM

Heap

Merge

INNO DB

ISAM


 What are the advantages of MyISAM over InnoDB?

MyISAM follows a conservative approach to disk space management and stores each MyISAM table in a separate file, which can be further compressed if required. On the other hand, InnoDB stores the tables in the tablespace. Its further optimization is difficult.


What is InnoDB?

InnoDB is a storage database for SQL. The ACID-transactions are also provided in InnoDB and also includes support for the foreign key. Initially owned by InnobaseOY now belongs to Oracle Corporation after it acquired the latter since 2005.

****************************************


What is ISAM?

It is a system for file management developed by IBM, which allows records to access sequentially or even randomly.

How to grant super user privilege to user in MySQL?

 Grant All Privilege's On All Databases

GRANT ALL PRIVILEGES ON * . * TO 'someuser'@'localhost';

FLUSH PRIVILEGES;

Show Grants

SHOW GRANTS FOR 'someuser'@'localhost';

How to list the tables in MySQL ?

SELECT table_name 
FROM information_schema.tables
WHERE table_schema = 'your_db_name';


mysql> use mysql;

Database changed

mysql> show tables;

+----------------------------------------------+

| Tables_in_mysql                              |

+----------------------------------------------+

| columns_priv                                 |

| component                                    |

| db                                           |

| default_roles                                |

| engine_cost                                  |

command to spool query output to another log file in MySQL

 Spooling  SQL query Output in a File in MySQL & MariaDB


mysql> use testdb;

Database changed

mysql> tee testspool.txt;

Logging to file 'testspool.txt;'

mysql> select name from emp;

mysql> notee

Outfile disabled.


commands in MySQL to get the current user and date

 mysql> SELECT CURRENT_DATE();

+----------------+

| CURRENT_DATE() |

+----------------+

| 2021-12-24     |

+----------------+

1 row in set (0.00 sec)


mysql> select current_user();

+----------------+

| current_user() |

+----------------+

| aaadbadmin@%   |

+----------------+

1 row in set (0.00 sec)


mysql> select @@datadir;

--------------

select @@datadir

--------------


+----------------------------------------+

| @@datadir                              |

+----------------------------------------+

| E:\MySQL8\MySQL\MySQL Server 8.0\Data\ |

+----------------------------------------+

1 row in set (0.00 sec)

to know the current database

mysql> SELECT DATABASE()

    -> ;

+--------------------+

| DATABASE()         |

+--------------------+

| information_schema |

+--------------------+

1 row in set (0.00 sec)





How to start/stop MySQL services in windows and Linux servers

 On Windows


If you are using Windows Open the Command Prompt and type


To Stop MySQL Service:


net stop MySQL80 

To Start MySQL Service:


net start MySQL80

On Linux


# /etc/init.d/mysqld start

# /etc/init.d/mysqld stop

# /etc/init.d/mysqld restart