How to check last checkpoints in the datafile headers

SQL> column file# format a10
SQL> column TO_CHAR format a60
SQL> column FILE_NAME format a30
SQL> set linesize 150
SQL> SELECT TO_CHAR(SYSDATE,'DD/MM/YYYY HH24:MI:SS') FROM dual;
TO_CHAR(SYSDATE,'DD
-------------------
05/02/2016 09:22:48

SQL> SELECT FILE# file_nr, TO_CHAR(CHECKPOINT_TIME,'DD/MM/YYYY HH24:MI:SS') checkpoint_time, NAME file_name
 FROM v$datafile_header;

   FILE_NR CHECKPOINT_TIME     FILE_NAME
---------- ------------------- ------------------------------------------------------------
         1 05/02/2016 09:22:19 /u01/app/oracle/oradata/prim/system01.dbf
         2 05/02/2016 09:22:19 /u01/app/oracle/oradata/prim/sysaux01.dbf
         3 05/02/2016 09:22:19 /u01/app/oracle/oradata/prim/undotbs01.dbf
         4 05/02/2016 09:22:19 /u01/app/oracle/oradata/prim/users01.dbf
         5 05/02/2016 09:22:19 /u01/app/oracle/oradata/prim/example01.dbf


How to enable autotrace on

Description:-
SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

solution:-
For execution AUTOTRACE the users needs to have the PLUSTRACE role, which does not
exist by default. PLUSTRACE role can be created using SYS user by executing
/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/plustrce.sql
[oracle@server1]$ sqlplus /  as sysdba
SQL> @/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/plustrce.sql
SQL>
SQL> drop role plustrace;
drop role plustrace
          *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


SQL> create role plustrace;

Role created.

SQL>
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>
SQL> set echo off
SQL> grant plustrace to appuser;

Grant succeeded.
SQL>conn appuser/appuser

SQL> create table abc (id number);

Table created.

SQL> insert into abc values (1);

1 row created.


Execution Plan
----------------------------------------------------------

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

| Id  | Operation                | Name | Rows  | Bytes | Cost (%CPU)| Time
|

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

|   0 | INSERT STATEMENT         |      |     1 |   100 |     1   (0)| 00:00:01
|

|   1 |  LOAD TABLE CONVENTIONAL | ABC  |       |       |            |
|

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



Statistics
----------------------------------------------------------
        136  recursive calls
         58  db block gets
         32  consistent gets
          0  physical reads
       6400  redo size
        843  bytes sent via SQL*Net to client
        782  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          1  rows processed



How to set username and instance name at SQL prompt

[oracle@server1 ~]$ sqlplus /  as sysdba
SQL> SET SQLPROMPT "_USER @ _CONNECT_IDENTIFIER> "
SYS @ prim> select instance_name from v$instance;
INSTANCE_NAME
----------------
prim

MongoDB backup using shell script for all databases

vi /backups/mongodb_backup.sh

#!/bin/bash
date1=`date +%d%m%Y_%H%M%S`
export path1=/backups/mongodb_backup
OUTPUTDIR="$path1/$date1"
/usr/bin/find /backups/mongodb_backup/* -type d -mtime +30 -exec rm -r {} \; 2> /dev/null
mongodump -o $path1/$date1
/bin/tar -zcvf  /backups/mongodb_backup/backup_$date1.tar.gz $path1/$date1
rm -rf $path1/$date1
exit

#Schedule in crontab:-
 crontab -e

0 0 * * * /backups/mongodb_backup.sh > /dev/null

How to start/stop oracle database from linux command prompt

How to start/stop oracle database from linux command prompt:-
[oracle@configsrv1 ~]$vi /etc/oratab
#

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
prim:/u01/app/oracle/product/11.2.0/db_1:N

change the entry to this

prim:/u01/app/oracle/product/11.2.0/db_1:Y

and save the file.

For starting db
[oracle@configsrv1 ~] dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOME
Processing Database instance "prim": log file /u01/app/oracle/product/11.2.0/db_1/startup.log

To fix the above error;

[oracle@configsrv1 ~]export ORACLE_HOME_LISTNER=$ORACLE_HOME
[oracle@configsrv1 ~]dbstart $ORACLE_HOME
Then start the db again
[oracle@configsrv1 bin]$ dbstart $ORACLE_HOME
Processing Database instance "prim": log file /u01/app/oracle/product/11.2.0/db_1/startup.log

For stopping db
[oracle@configsrv1 ~] dbshut


How to enable/disable case-sensitive password in oracle 11g


From oracle 11g password can be case sensitive by setting
SEC_CASE_SENSITIVE_LOGON = true in  initialization parameter file.

SQL> show parameter SEC_CASE_SENSITIVE_LOGON

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sec_case_sensitive_logon             boolean     TRUE

Lets check the feature,
[oracle@configsrv1 ~]$ sqlplus /  as sysdba
SQL> create user soumya identified by das;

User created.

SQL> grant connect to soumya;

Grant succeeded.

[oracle@configsrv1 ~]$ sqlplus /  as sysdba
SQL> conn soumya/das
Connected.

Now we will check by providing the password in caps letter.
SQL> conn soumya/DAS
ERROR:
ORA-01017: invalid username/password; logon denied


Warning: You are no longer connected to ORACLE.

We can disable this feature by setting the parameter value to false.
SQL> alter system set SEC_CASE_SENSITIVE_LOGON= false scope=both;

System altered.

SQL> conn soumya/DAS
Connected.

Postgresql backup shell script for all databases in linux

vi /backups/postgre_backup.sh

#!/bin/bash
date1=`date +%d%m%Y_%H%M%S`
export path1=/backups/postgre_backup
OUTPUTDIR="$path1/$date1"
/usr/bin/find /backups/postgre_backup/* -type d -mtime +32 -exec rm -r {} \; 2> /dev/null
su postgres -c 'pg_dumpall' > "$OUTPUTDIR.sql"
/bin/tar -zcvf /backups/postgre_backup/backup_$date1.tar.gz $OUTPUTDIR.sql
rm $OUTPUTDIR.sql
exit

:wq

Schedule in crontab:-
# crontab -e

0 0 * * * /backups/postgre_backup.sh > /dev/null
Related Posts Plugin for WordPress, Blogger...