Tuesday 27 September 2016

Setup Docker and then Postgres on the Docker Centos6.

Follow the steps one to six under heading Install with yum given in below link to setup and start docker.


Install with yum

  1. Log into your machine as a user with sudo or root privileges.
  2. Make sure your existing yum packages are up-to-date.
    $ sudo yum update
    
  3. Add the yum repo.
    $ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/6/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
    
  4. Install the Docker package.
    $ sudo yum install docker-engine
    
  5. Start the Docker daemon.
    $ sudo service docker start
    
  6. Verify docker is installed correctly by running a test image in a container.
    $ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
        latest: Pulling from hello-world
        a8219747be10: Pull complete
        91c95931e552: Already exists
        hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
        Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
        Status: Downloaded newer image for hello-world:latest
        Hello from Docker.
        This message shows that your installation appears to be working correctly.
    
        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
                (Assuming it was not already locally available.)
         3. The Docker daemon created a new container from that image which runs the
                executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent it
                to your terminal.
    
        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash
    
        For more examples and ideas, visit:
         http://docs.docker.com/userguide/
  7. If you are behind proxy then follow the below link and restart the docker as given below.
  8. https://crondev.com/running-docker-behind-proxy/
For RedHat/CentOS version 6:



Now you are ready to setup PostgreSQL.


Execute following command and it will pull latest version of PostgreSQL and follow link below to start and connect PostgreSQL with docker.

Link is given below.



docker pull postgres




start a postgres instance


$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres


docker run --name postgres9.5 -e POSTGRES_PASSWORD=postgres -d postgres




Start psql


$ docker run -it --rm --link some-postgres:postgres postgres psql -h postgres -U postgres
psql (9.5.0)
Type "help" for help.

postgres=# SELECT 1;
 ?column? 
----------
        1
(1 row)





docker run -it --rm --link postgres9.5:postgres postgres psql -h postgres -U postgres



Password for user postgres:
psql (9.5.4)
Type "help" for help.

postgres=# select 1;
 ?column?
----------
        1
(1 row)


postgres=# \q





First execute following command to list running docker.

[root@centos6_pri lib]# docker ps -a

It will show you the name of the all docker images avaliable and their status in my case is  "postgres9.5"


To login to Docker

 docker exec -i -t postgres9.5 /bin/bash

Tuesday 6 September 2016

How to check if Oracle Database instance is up and running?


I. Log into infrastructure instance  & login as sysdba;


\$ sqlplus /nolog
SQL> conn / as sysdba;
SQL> select status from v$instance;

STATUS
------------------------------------
OPEN

II. Log into database server & issue the following command

\$ ps -ef | grep pmon
ocsinfra 11021     1   0 09:15:15 ?           0:09 ora_pmon_orcl
ocsinfra 17960 17592   0 10:47:15 pts/2       0:00 grep pmon

If DB instance is running, then the above command returns the pmon process running as above.

Monitoring Multiple Oracle database tablespaces on multiple machines.

This post help you to monitor your multiple database's tablespaces on multiple servers by collecting information into a table from each database using a job and then use that table to report the tablespace status.


CREATE TABLE scripts.VERIFY_TABLESPACE
(
  TABLESPACE_NAME  VARCHAR2(30 BYTE),
  MEGS_ALLOC       NUMBER,
  MEGS_FREE        NUMBER,
  MEGS_USED        NUMBER,
  PCT_FREE         NUMBER,
  PCT_USED         NUMBER,
  MAX              NUMBER,
  USED_PCT_OF_MAX  NUMBER
)
TABLESPACE USERS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING
/

create or replace public synonym VERIFY_TABLESPACE for scripts.VERIFY_TABLESPACE
/
GRANT INSERT, SELECT ON scripts.VERIFY_TABLESPACE TO PUBLIC
/

CREATE PUBLIC DATABASE LINK monitor_db
CONNECT TO smbackup
IDENTIFIED BY smbackup
USING 'backuprep';
/

grant select any dictionary to scripts
/
create or replace force view scripts.v_verify_tablespace
as
select  a.tablespace_name,
       round(a.bytes_alloc / 1024 / 1024) megs_alloc,
       round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
       round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
       round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free,
       100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used,
       round(maxbytes/1048576) Max,
       round(round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) / round(maxbytes/1048576)*100) used_pct_of_max
from  ( select  f.tablespace_name,
               sum(f.bytes) bytes_alloc,
               sum(decode(f.autoextensible, 'YES',f.maxbytes,'NO', f.bytes)) maxbytes
        from dba_data_files f
        group by tablespace_name) a,
      ( select  f.tablespace_name,
               sum(f.bytes)  bytes_free
        from dba_free_space f
        group by tablespace_name) b
where a.tablespace_name = b.tablespace_name (+)
union all
select h.tablespace_name,
       round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
       round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576) megs_free,
       round(sum(nvl(p.bytes_used, 0))/ 1048576) megs_used,
       round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) Pct_Free,
       100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) pct_used,
       round(sum(f.maxbytes) / 1048576) max,
       round( round(sum(nvl(p.bytes_used, 0))/ 1048576)  / round(sum(f.maxbytes) / 1048576) *100) used_pct_of_max
from   sys.v_$TEMP_SPACE_HEADER h, sys.v_$Temp_extent_pool p, dba_temp_files f
where  p.file_id(+) = h.file_id
and    p.tablespace_name(+) = h.tablespace_name
and    f.file_id = h.file_id
and    f.tablespace_name = h.tablespace_name
group by h.tablespace_name
/

create or replace public synonym v_verify_tablespace for scripts.v_verify_tablespace
/


create or replace procedure scripts.p_log_tablespace
as
begin
insert into verify_tablespace(
TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
)
select
TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
from v_verify_tablespace;
delete from smbackup.verify_tablespace@monitor_db where client = 'ASPEN';
commit;
insert into smbackup.verify_tablespace@monitor_db(
CLIENT, TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
)
select
'ASPEN', TABLESPACE_NAME, MEGS_ALLOC, MEGS_FREE, MEGS_USED, PCT_FREE, PCT_USED, MAX, USED_PCT_OF_MAX
from verify_tablespace;
commit;
exception
when others then null;
end;
/
create or replace public synonym  p_log_tablespace for scripts.p_log_tablespace
/


DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
  ( job       => X
   ,what      => 'scripts.p_log_tablespace;'
   ,next_date => to_date('19/07/2011 7:00:00','dd/mm/yyyy hh24:mi:ss')
   ,interval  => 'trunc(SYSDATE+1)+6/24'
   ,no_parse  => FALSE
  );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
/

Reporting_server Tns

BACKUPREP =
 (DESCRIPTION = 
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.20.23)(PORT = 1521))
   )
 (CONNECT_DATA =
   (SERVICE_NAME = ORA12)
 ) 
) 

 Step – 1:

add your reporting server tns entry on client machine in                        tnsnames.ora to create db link.
 Step – 2:

Replace client name in last procedure in attached script file 
 Step – 3:

Execute scripts in attached file one-by-one carefully on client                database. And also create database job at suitable time as in my                case is 6:45 AM 
 Step – 4:

Test result data on BACKUPREP {tns given above}