Wednesday 31 July 2019

How to upgrade oracle golden gate from 12.2.0.1 to 12.2.0.2


Note: before start below step copy you new software version to respective database server. So activity won’t take more time.

1] First stop all traffic of your primary database, then stop extract process.

GGSCI (source.example.com) 15> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DATAPMP0 00:00:00 00:00:01
EXTRACT RUNNING DATAPMP1 00:00:00 00:00:02
EXTRACT STOPPED EXTRACT0 00:00:07 00:00:35
EXTRACT STOPPED EXTRACT1 00:00:00 00:00:34

2] Check lag of extract and pump on primary (source) database.

=> Check lag of extract process

GGSCI (source.example.com as ggadmin@DB11G) 8> lag extract EXTRACT0

Sending GETLAG request to EXTRACT EXTRACT0 ...
No records yet processed.

=> Check lag of PUMP process.

GGSCI (source.example.com as ggadmin@DB11G) 9> lag extract DATAPMP0

Sending GETLAG request to EXTRACT DATAPMP0 ...
No records yet processed.
At EOF, no more records to process.

3] Stop extract, pump and mgr process on source database.

GGSCI (source.example.com) 1> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DATAPMP0 00:00:00 00:00:06
EXTRACT RUNNING EXTRACT0 00:00:10 00:00:04

GGSCI (source.example.com) 2> stop *

Sending STOP request to EXTRACT DATAPMP0 ...
Request processed.
Sending STOP request to EXTRACT EXTRACT0 ...
Request processed.

GGSCI (source.example.com) 3> stop mgr

Manager process is required by other GGS processes.
Are you sure you want to stop it (y/n)?y
Sending STOP request to MANAGER ...
Request processed.
Manager stopped.

GGSCI (source.example.com) 4> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
EXTRACT STOPPED DATAPMP0 00:00:00 00:00:10
EXTRACT STOPPED EXTRACT0 00:00:02 00:00:10
GGSCI (source.example.com) 5>

3] start installation of 12.2.0.2 Golden gate software Source Database .

4] Take copy of dir* directories from new gg home.

mv dirwww dirwww_bkp
mv dirout dirout_bkp
mv dirsql dirsql_bkp
mv dirdef dirdef_bkp
mv dirbdb dirbdb_bkp
mv dirwlt dirwlt_bkp
mv dircrd dircrd_bkp
mv dirprm dirprm_bkp
mv dirchk dirchk_bkp
mv dirdmp dirdmp_bkp
mv dirrpt dirrpt_bkp
mv dirtmp dirtmp_bkp
mv dirdat dirdat_bkp
mv dirpcs dirpcs_bkp

5] Create soft link of above directories from old GG_HOME new GG_HOME.

[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirout dirout
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirsql dirsql
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdef dirdef
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirbdb dirbdb
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirwlt dirwlt
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dircrd dircrd
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirprm dirprm
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirchk dirchk
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdmp dirdmp
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirrpt dirrpt
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirtmp dirtmp
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdat dirdat
[oracle@source ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirpcs dirpcs

vaidation:

[oracle@source ggs.12.2.0.2]$ ls -dltr dir*

lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:34 dirwww -> /u02/ggs.12.2.0.1/dirwww
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirout -> /u02/ggs.12.2.0.1/dirout
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirsql -> /u02/ggs.12.2.0.1/dirsql
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirdef -> /u02/ggs.12.2.0.1/dirdef
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirbdb -> /u02/ggs.12.2.0.1/dirbdb
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirwlt -> /u02/ggs.12.2.0.1/dirwlt
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dircrd -> /u02/ggs.12.2.0.1/dircrd
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirprm -> /u02/ggs.12.2.0.1/dirprm
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirchk -> /u02/ggs.12.2.0.1/dirchk
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirdmp -> /u02/ggs.12.2.0.1/dirdmp
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirrpt -> /u02/ggs.12.2.0.1/dirrpt
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirtmp -> /u02/ggs.12.2.0.1/dirtmp
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirdat -> /u02/ggs.12.2.0.1/dirdat
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:35 dirpcs -> /u02/ggs.12.2.0.1/dirpcs

6] Check lag of replicat process on target database server.

GGSCI (target.example.com as ggadmin@DB11G) 7> lag REPLCAT0

Sending GETLAG request to REPLICAT REPLCAT0 ...
Last record lag 20,698 seconds.
Low watermark lag: 1.
High watermark lag: 1.
Low watermark position: 1031955.
High watermark position: 1036542.
At EOF, no more records to process.

GGSCI (target.example.com as ggadmin@DB11G) 8> stop REPLCAT0

Sending STOP request to REPLICAT REPLCAT0 ...
Request processed.

GGSCI (target.example.com as ggadmin@DB11G) 9> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
REPLICAT STOPPED REPLCAT0 00:00:00 00:00:40
GGSCI (target.example.com as ggadmin@DB11G) 10>

7] start installation of 12.2.0.2 Golden gate software target Database .

8] Take back of dir* drectories from new GG_HOME.

[oracle@target ggs.12.2.0.2]$ mv dirwww dirwww_bkp
[oracle@target ggs.12.2.0.2]$ mv dirout dirout_bkp
[oracle@target ggs.12.2.0.2]$ mv dirsql dirsql_bkp
[oracle@target ggs.12.2.0.2]$ mv dirdef dirdef_bkp
[oracle@target ggs.12.2.0.2]$ mv dirbdb dirbdb_bkp
[oracle@target ggs.12.2.0.2]$ mv dirwlt dirwlt_bkp
[oracle@target ggs.12.2.0.2]$ mv dircrd dircrd_bkp
[oracle@target ggs.12.2.0.2]$ mv dirprm dirprm_bkp
[oracle@target ggs.12.2.0.2]$ mv dirchk dirchk_bkp
[oracle@target ggs.12.2.0.2]$ mv dirdmp dirdmp_bkp
[oracle@target ggs.12.2.0.2]$ mv dirrpt dirrpt_bkp
[oracle@target ggs.12.2.0.2]$ mv dirtmp dirtmp_bkp
[oracle@target ggs.12.2.0.2]$ mv dirdat dirdat_bkp
[oracle@target ggs.12.2.0.2]$ mv dirpcs dirpcs_bkp

9] Create softlink of above directories from old GG_HOME new GG_HOME.

[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirwww dirwww
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirout dirout
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirsql dirsql
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdef dirdef
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirbdb dirbdb
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirwlt dirwlt
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dircrd dircrd
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirprm dirprm
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirchk dirchk
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdmp dirdmp
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirrpt dirrpt
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirtmp dirtmp
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirdat dirdat
[oracle@target ggs.12.2.0.2]$ ln -ds /u02/ggs.12.2.0.1/dirpcs dirpcs

[oracle@target ggs.12.2.0.2]$ ls -dltr dir*

lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirwww -> /u02/ggs.12.2.0.1/dirwww
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirout -> /u02/ggs.12.2.0.1/dirout
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirsql -> /u02/ggs.12.2.0.1/dirsql
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirdef -> /u02/ggs.12.2.0.1/dirdef
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirbdb -> /u02/ggs.12.2.0.1/dirbdb
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirwlt -> /u02/ggs.12.2.0.1/dirwlt
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dircrd -> /u02/ggs.12.2.0.1/dircrd
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirprm -> /u02/ggs.12.2.0.1/dirprm
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirchk -> /u02/ggs.12.2.0.1/dirchk
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirdmp -> /u02/ggs.12.2.0.1/dirdmp
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirrpt -> /u02/ggs.12.2.0.1/dirrpt
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirtmp -> /u02/ggs.12.2.0.1/dirtmp
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirdat -> /u02/ggs.12.2.0.1/dirdat
lrwxrwxrwx. 1 oracle oinstall 24 Jul 31 10:54 dirpcs -> /u02/ggs.12.2.0.1/dirpcs

[oracle@target ggs.12.2.0.2]$

10] Start manager process on both source and target database server.

Source database Server :

GGSCI (source.example.com) 3> start mgr
Manager started.

GGSCI (source.example.com) 4> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED DATAPMP0 00:00:00 00:46:49
EXTRACT STOPPED EXTRACT0 00:00:02 00:46:49

Target database Server :

GGSCI (target.example.com) 2> start mgr
Manager started.

GGSCI (target.example.com) 3> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT STOPPED REPLCAT0 00:00:00 00:20:32

11] Start extract and dump process on source database server.

GGSCI (source.example.com) 5> start extract EXTRACT0

Sending START request to MANAGER ...
EXTRACT EXTRACT0 starting

GGSCI (source.example.com) 6> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED DATAPMP0 00:00:00 00:49:33
EXTRACT RUNNING EXTRACT0 00:49:32 00:00:03

GGSCI (source.example.com) 7> start extract DATAPMP0

Sending START request to MANAGER...
EXTRACT DATAPMP0 starting

GGSCI (source.example.com) 11> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DATAPMP0 00:00:00 00:00:00
EXTRACT RUNNING EXTRACT0 00:00:03 00:00:04
12] Start replicat process on target database server.

GGSCI (target.example.com) 4> start REPLCAT0

Sending START request to MANAGER ...
REPLICAT REPLCAT0 starting

GGSCI (target.example.com) 5> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPLCAT0 00:00:00 00:00:01

Validation:

A] Insert one row in source database table

SQL> insert into departments values(280,'sales',205,1700);
1 row created.
SQL> commit;
Commit complete.

B] Check stats of extract, pump and replicat process.

GGSCI (source.example.com) 12> stats DATAPMP0

Sending STATS request to EXTRACT DATAPMP0 ...
Start of Statistics at 2019-07-31 11:10:44.
Output to /u02/ggs.12.2.0.1/dirdat/tx:
Extracting from HR.DEPARTMENTS to HR.DEPARTMENTS:
*** Total statistics since 2019-07-31 11:10:35 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Daily statistics since 2019-07-31 11:10:35 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Hourly statistics since 2019-07-31 11:10:35 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Latest statistics since 2019-07-31 11:10:35 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
End of Statistics.

GGSCI (target.example.com) 8> stats REPLCAT

Sending STATS request to REPLICAT REPLCAT0 ...
Start of Statistics at 2019-07-31 11:11:27.
Integrated Replicat Statistics:
Total transactions 1.00
Redirected 0.00
DDL operations 0.00
Stored procedures 0.00
Datatype functionality 0.00
Event actions 0.00
Direct transactions ratio 0.00%
Replicating from HR.DEPARTMENTS to HR.DEPARTMENTS:
*** Total statistics since 2019-07-31 11:10:39 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Daily statistics since 2019-07-31 11:10:39 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Hourly statistics since 2019-07-31 11:10:39 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
*** Latest statistics since 2019-07-31 11:10:39 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 1.00
End of Statistics.
GGSCI (target.example.com) 9>

OGG-14054 Lag from heartbeat table requires DBLOGIN.


Error Details: OGG-14054   Lag from heartbeat table requires DBLOGIN.

GGSCI (source.example.com) 5> lag EXTRACT0
2019-07-31 09:53:34 INFO    OGG-14054  Lag from heartbeat table requires DBLOGIN.
Sending GETLAG request to EXTRACT EXTRACT0...
No records yet processed.

Solution login with DBlogin :
GGSCI (source.example.com) 6> dblogin userid ggadmin@srcdb password Admin12345
Successfully logged into database.
GGSCI (source.example.com as ggadmin@DB11G) 7> lag EXTRACT0
Sending GETLAG request to EXTRACT EXTRACT0...
No records yet processed.
GGSCI (source.example.com as ggadmin@DB11G) 8>

Tuesday 30 July 2019

How to Install Golden gate 12c R2 using Silent option




1] Set below parameter first if not set on OS level :

$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
$ export ORACLE_BASE=/u01/app/oracle

2] Got to golden gate software stage folder:

$ cd /u01/fbo_ggs_Linux_x64_shiphome

3] Find response file and edit below parameter in responce file.

[oracle@source fbo_ggs_Linux_x64_shiphome]$ find . -name oggcore.rsp
./Disk1/response/oggcore.rsp
SOFTWARE_LOCATION=/u02/ggs.12.2.0.1    ---GG_HOME location
START_MANAGER=true       --if you want to start manager after installation use "true"
MANAGER_PORT=7810        --GG manager port number
DATABASE_LOCATION=/u01/app/oracle/product/11.2.0.4/db_1   --ORACLE_HOME
INVENTORY_LOCATION=/u02/ggs.12.2.0.1/oraInventory    
UNIX_GROUP_NAME=oinstall                    ---linux group for gg installation

==> Sample response file:

####################################################################
## Copyright(c) Oracle Corporation 2014. All rights reserved.     ##
##                                                                ##
## Specify values for the variables listed below to customize     ##
## your installation.                                             ##
##                                                                ##
## Each variable is associated with a comment. The comment        ##
## can help to populate the variables with the appropriate        ##
## values.                                                        ##
##                                                                ##
## IMPORTANT NOTE: This file should be secured to have read       ##
## permission only by the oracle user or an administrator who     ##
## own this installation to protect any sensitive input values.   ##
##                                                                ##
####################################################################

#-------------------------------------------------------------------------------
# Do not change the following system generated value.
#-------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v12_1_2

################################################################################
##                                                                            ##
## Oracle GoldenGate installation option and details                          ##
##                                                                            ##
################################################################################
#-------------------------------------------------------------------------------
# Specify the installation option.
# Specify ORA12c for installing Oracle GoldenGate for Oracle Database 12c and
#         ORA11g for installing Oracle GoldenGate for Oracle Database 11g
#-------------------------------------------------------------------------------
INSTALL_OPTION=ORA11g

#-------------------------------------------------------------------------------
# Specify a location to install Oracle GoldenGate
#-------------------------------------------------------------------------------
SOFTWARE_LOCATION=/u02/ggs.12.2.0.1

#-------------------------------------------------------------------------------
# Specify true to start the manager after installation.
#-------------------------------------------------------------------------------
START_MANAGER=true

#-------------------------------------------------------------------------------
# Specify a free port within the valid range for the manager process.
# Required only if START_MANAGER is true.
#-------------------------------------------------------------------------------
MANAGER_PORT=7810

#-------------------------------------------------------------------------------
# Specify the location of the Oracle Database.
# Required only if START_MANAGER is true.
#-------------------------------------------------------------------------------
DATABASE_LOCATION=/u01/app/oracle/product/11.2.0.4/db_1


################################################################################
##                                                                            ##
## Specify details to Create inventory for Oracle installs                    ##
## Required only for the first Oracle product install on a system.            ##
##                                                                            ##
################################################################################

#-------------------------------------------------------------------------------
# Specify the location which holds the install inventory files.
# This is an optional parameter if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
INVENTORY_LOCATION=/u02/ggs.12.2.0.1/oraInventory
#-------------------------------------------------------------------------------
# Unix group to be set for the inventory directory.
# This parameter is not applicable if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
UNIX_GROUP_NAME=oinstall

4] Execute run-Installer with silent option.

[oracle@source Disk1]$ ./runInstaller -silent -responseFile /u01/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB.   Actual 28888 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3998 MB    Passed
How to install oracle Golden Gate 12c r2 through silent mode
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-07-30_09-25-30AM. Please wait ...[oracle@source Disk1]$ You can find the log of this install session at:
 /u01/app/oraInventory/logs/installActions2019-07-30_09-25-30AM.log
The installation of Oracle GoldenGate Core was successful.
Please check '/u01/app/oraInventory/logs/silentInstall2019-07-30_09-25-30AM.log' for more details.
Successfully Setup Software.

5] Go to GG home directory and check manager process is running or not.

[oracle@source Disk1]$ cd /u02/ggs.12.2.0.1/
[oracle@source ggs.12.2.0.1]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (source.example.com) 1> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING
GGSCI (source.example.com) 2>

Thursday 25 July 2019

how to install Mongo DB on linux..

->how to install Mongo DB on linux?

OS details:

[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
[root@localhost ~]#

mongo db version Details.

mongodb-org-3.0

installation steps

1) check network connections

[root@MongoDB ~]# ping mongodb.com
PING mongodb.com (52.21.89.200) 56(84) bytes of data.
64 bytes from ec2-52-21-89-200.compute-1.amazonaws.com (52.21.89.200): icmp_seq=1 ttl=45 time=224 ms
64 bytes from ec2-52-21-89-200.compute-1.amazonaws.com (52.21.89.200): icmp_seq=2 ttl=45 time=227 ms

--- mongodb.com ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2001ms
rtt min/avg/max/mdev = 224.843/226.084/227.325/1.241 ms

2) create and add below paramters in vi /etc/yum.repos.d/mongodb-org-3.0.repo file 

[root@MongoDB ~]# cat /etc/yum.repos.d/mongodb-org-3.0.repo
[mongodb-org-3.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1

3) Run yum command to install mongoDB RPM

[root@MongoDB ~]# yum install -y mongodb-org
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:3.0.12-1.el5 set to be updated
--> Processing Dependency: mongodb-org-tools = 3.0.12 for package: mongodb-org
--> Processing Dependency: mongodb-org-shell = 3.0.12 for package: mongodb-org
--> Processing Dependency: mongodb-org-server = 3.0.12 for package: mongodb-org
--> Processing Dependency: mongodb-org-mongos = 3.0.12 for package: mongodb-org
--> Running transaction check
---> Package mongodb-org-mongos.x86_64 0:3.0.12-1.el5 set to be updated
---> Package mongodb-org-server.x86_64 0:3.0.12-1.el5 set to be updated
---> Package mongodb-org-shell.x86_64 0:3.0.12-1.el5 set to be updated
---> Package mongodb-org-tools.x86_64 0:3.0.12-1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                                Arch                       Version                           Repository                           Size
===============================================================================================================================================
Installing:
 mongodb-org                            x86_64                     3.0.12-1.el5                      mongodb-org-3.0                     5.7 k
Installing for dependencies:
 mongodb-org-mongos                     x86_64                     3.0.12-1.el5                      mongodb-org-3.0                     4.7 M
 mongodb-org-server                     x86_64                     3.0.12-1.el5                      mongodb-org-3.0                     9.8 M
 mongodb-org-shell                      x86_64                     3.0.12-1.el5                      mongodb-org-3.0                     5.0 M
 mongodb-org-tools                      x86_64                     3.0.12-1.el5                      mongodb-org-3.0                      28 M

Transaction Summary
===============================================================================================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total size: 48 M
Total download size: 28 M
Downloading Packages:
mongodb-org-tools-3.0.12-1.el5.x86_64.rpm                                                                               |  28 MB     03:29
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : mongodb-org-server                                                                                                      1/5
  Installing     : mongodb-org-shell                                                                                                       2/5
  Installing     : mongodb-org-tools                                                                                                       3/5
  Installing     : mongodb-org-mongos                                                                                                      4/5
  Installing     : mongodb-org                                                                                                             5/5

Installed:
  mongodb-org.x86_64 0:3.0.12-1.el5

Dependency Installed:
  mongodb-org-mongos.x86_64 0:3.0.12-1.el5       mongodb-org-server.x86_64 0:3.0.12-1.el5       mongodb-org-shell.x86_64 0:3.0.12-1.el5
  mongodb-org-tools.x86_64 0:3.0.12-1.el5

Complete!
[root@MongoDB ~]#

4) MongoDB details 

[root@MongoDB ~]# service mongod status
mongod is stopped
[root@MongoDB ~]# service mongod start
Starting mongod:                                           [  OK  ]
[root@MongoDB ~]# service mongod status
mongod (pid 3672) is running...
[root@MongoDB ~]#

=> mongoDB logs 

[root@MongoDB ~]# cat /var/log/mongodb/mongod.log
2016-07-30T17:55:37.721+0530 I CONTROL  ***** SERVER RESTARTED *****
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] MongoDB starting : pid=3672 port=27017 dbpath=/var/lib/mongo 64-bit host=MongoDB.example.com
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] db version v3.0.12
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] git version: 33934938e0e95d534cebbaff656cde916b9c3573
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] build info: Linux build13.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2016-07-30T17:55:37.725+0530 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-07-30T17:55:37.751+0530 I JOURNAL  [initandlisten] journal dir=/var/lib/mongo/journal
2016-07-30T17:55:37.751+0530 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2016-07-30T17:55:37.898+0530 I JOURNAL  [durability] Durability thread started
2016-07-30T17:55:37.898+0530 I JOURNAL  [journal writer] Journal writer thread started
2016-07-30T17:55:37.901+0530 I INDEX    [initandlisten] allocating new ns file /var/lib/mongo/local.ns, filling with zeroes...
2016-07-30T17:55:37.944+0530 I STORAGE  [FileAllocator] allocating new datafile /var/lib/mongo/local.0, filling with zeroes...
2016-07-30T17:55:37.944+0530 I STORAGE  [FileAllocator] creating directory /var/lib/mongo/_tmp
2016-07-30T17:55:38.286+0530 I STORAGE  [FileAllocator] done allocating datafile /var/lib/mongo/local.0, size: 64MB,  took 0.298 secs
2016-07-30T17:55:38.292+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-07-30T17:58:05.287+0530 I CONTROL  [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2016-07-30T17:58:05.287+0530 I CONTROL  [signalProcessingThread] now exiting
2016-07-30T17:58:05.287+0530 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2016-07-30T17:58:05.287+0530 I NETWORK  [signalProcessingThread] closing listening socket: 6
2016-07-30T17:58:05.287+0530 I NETWORK  [signalProcessingThread] closing listening socket: 7
2016-07-30T17:58:05.288+0530 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2016-07-30T17:58:05.288+0530 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2016-07-30T17:58:05.288+0530 I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2016-07-30T17:58:05.288+0530 I STORAGE  [signalProcessingThread] shutdown: waiting for fs preallocator...
2016-07-30T17:58:05.288+0530 I STORAGE  [signalProcessingThread] shutdown: final commit...
2016-07-30T17:58:05.288+0530 I JOURNAL  [signalProcessingThread] journalCleanup...
2016-07-30T17:58:05.288+0530 I JOURNAL  [signalProcessingThread] removeJournalFiles
2016-07-30T17:58:05.311+0530 I JOURNAL  [signalProcessingThread] Terminating durability thread ...
2016-07-30T17:58:05.394+0530 I JOURNAL  [journal writer] Journal writer thread stopped
2016-07-30T17:58:05.394+0530 I JOURNAL  [durability] Durability thread stopped
2016-07-30T17:58:05.394+0530 I STORAGE  [signalProcessingThread] shutdown: closing all files...
2016-07-30T17:58:05.395+0530 I STORAGE  [signalProcessingThread] closeAllFiles() finished
2016-07-30T17:58:05.395+0530 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2016-07-30T17:58:05.395+0530 I CONTROL  [signalProcessingThread] dbexit:  rc: 0


[root@MongoDB ~]# mongod --version
db version v3.0.12
git version: 33934938e0e95d534cebbaff656cde916b9c3573

[root@MongoDB ~]# mongo -version
MongoDB shell version: 3.0.12


:- Uninstall MongoDB

[root@MongoDB ~]# service mongod stop
Stopping mongod:                                           [  OK  ]
[root@MongoDB ~]# service mongod status
mongod is stopped
[root@MongoDB ~]#

[root@MongoDB ~]# yum erase $(rpm -qa | grep mongodb-org)

Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:3.0.12-1.el5 set to be erased
---> Package mongodb-org-mongos.x86_64 0:3.0.12-1.el5 set to be erased
---> Package mongodb-org-server.x86_64 0:3.0.12-1.el5 set to be erased
---> Package mongodb-org-shell.x86_64 0:3.0.12-1.el5 set to be erased
---> Package mongodb-org-tools.x86_64 0:3.0.12-1.el5 set to be erased
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                                 Arch                        Version                              Repository                      Size
===============================================================================================================================================
Removing:
 mongodb-org                             x86_64                      3.0.12-1.el5                         installed                       0.0
 mongodb-org-mongos                      x86_64                      3.0.12-1.el5                         installed                       13 M
 mongodb-org-server                      x86_64                      3.0.12-1.el5                         installed                       26 M
 mongodb-org-shell                       x86_64                      3.0.12-1.el5                         installed                       14 M
 mongodb-org-tools                       x86_64                      3.0.12-1.el5                         installed                       92 M

Transaction Summary
===============================================================================================================================================
Install      0 Package(s)
Update       0 Package(s)
Remove       5 Package(s)

Is this ok [y/N]:y

[root@MongoDB ~]# rm -r /var/log/mongodb
[root@MongoDB ~]# rm -r /var/lib/mongo

CRUD operations in MongoDB


create,read,update and delete operation in mongoDB

I have below collections in my db, I will perform all operation on products collections.

> show collections
products
products_bak
system.indexes
>

1) insert records in collections.

> db.products.find().count()
12

> db.products.insert({ "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 })
WriteResult({ "nInserted" : 1 })

> db.products.find().count()
13

>  db.products.find()

{ "_id" : "ac3", "name" : "AC3 Phone", "brand" : "ACME", "type" : "phone", "price" : 200, "warranty_years" : 1, "available" : true }
{ "_id" : "ac7", "name" : "AC7 Phone", "brand" : "ACME", "type" : "phone", "price" : 320, "warranty_years" : 1, "available" : false }
{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "name" : "AC3 Series Charger", "type" : [ "accessory", "charger" ], "price" : 19, "warranty_years" : 0.25, "for" : [ "ac3", "ac7", "ac9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfa"), "name" : "AC3 Case Green", "type" : [ "accessory", "case" ], "color" : "green", "price" : 12, "warranty_years" : 0 }
{ "_id" : ObjectId("507d95d5719dbef170f15bfb"), "name" : "Phone Extended Warranty", "type" : "warranty", "price" : 38, "warranty_years" : 2, "for" : [ "ac3", "ac7", "ac9", "qp7", "qp8", "qp9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfc"), "name" : "AC3 Case Black", "type" : [ "accessory", "case" ], "color" : "black", "price" : 12.5, "warranty_years" : 0.25, "available" : false, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfd"), "name" : "AC3 Case Red", "type" : [ "accessory", "case" ], "color" : "red", "price" : 12, "warranty_years" : 0.25, "available" : true, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "name" : "Phone Service Basic Plan", "type" : "service", "monthly_price" : 40, "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } }, "term_years" : 2 }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "name" : "Phone Service Core Plan", "type" : "service", "monthly_price" : 60, "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } }, "term_years" : 1 }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "name" : "Phone Service Family Plan", "type" : "service", "monthly_price" : 90, "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } }, "sales_tax" : true, "term_years" : 3 }
{ "_id" : ObjectId("507d95d5719dbef170f15c01"), "name" : "Cable TV Basic Service Package", "type" : "tv", "monthly_price" : 50, "term_years" : 2, "cancel_penalty" : 25, "sales_tax" : true, "additional_tarriffs" : [ { "kind" : "federal tarriff", "amount" : { "percent_of_service" : 0.06 } }, { "kind" : "misc tarriff", "amount" : 2.25 } ] }
{ "_id" : "ac9", "name" : "AC9 Phone", "brand" : "ACME", "type" : "phone", "price" : 333, "warranty_years" : 0.25, "available" : true }
{ "_id" : ObjectId("57af8659f78428671f128162"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 }


note:- mongoDB collection usually created implicitly.


2) read data from collections.

- db.collection.find() command use for read data from collections
> db.products.find()
{ "_id" : "ac3", "name" : "AC3 Phone", "brand" : "ACME", "type" : "phone", "price" : 200, "warranty_years" : 1, "available" : true }
{ "_id" : "ac7", "name" : "AC7 Phone", "brand" : "ACME", "type" : "phone", "price" : 320, "warranty_years" : 1, "available" : false }
{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "name" : "AC3 Series Charger", "type" : [ "accessory", "charger" ], "price" : 19, "warranty_years" : 0.25, "for" : [ "ac3", "ac7", "ac9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfa"), "name" : "AC3 Case Green", "type" : [ "accessory", "case" ], "color" : "green", "price" : 12, "warranty_years" : 0 }
{ "_id" : ObjectId("507d95d5719dbef170f15bfb"), "name" : "Phone Extended Warranty", "type" : "warranty", "price" : 38, "warranty_years" : 2, "for" : [ "ac3", "ac7", "ac9", "qp7", "qp8", "qp9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfc"), "name" : "AC3 Case Black", "type" : [ "accessory", "case" ], "color" : "black", "price" : 12.5, "warranty_years" : 0.25, "available" : false, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfd"), "name" : "AC3 Case Red", "type" : [ "accessory", "case" ], "color" : "red", "price" : 12, "warranty_years" : 0.25, "available" : true, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "name" : "Phone Service Basic Plan", "type" : "service", "monthly_price" : 40, "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } }, "term_years" : 2 }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "name" : "Phone Service Core Plan", "type" : "service", "monthly_price" : 60, "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } }, "term_years" : 1 }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "name" : "Phone Service Family Plan", "type" : "service", "monthly_price" : 90, "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } }, "sales_tax" : true, "term_years" : 3 }
{ "_id" : ObjectId("507d95d5719dbef170f15c01"), "name" : "Cable TV Basic Service Package", "type" : "tv", "monthly_price" : 50, "term_years" : 2, "cancel_penalty" : 25, "sales_tax" : true, "additional_tarriffs" : [ { "kind" : "federal tarriff", "amount" : { "percent_of_service" : 0.06 } }, { "kind" : "misc tarriff", "amount" : 2.25 } ] }
{ "_id" : "ac9", "name" : "AC9 Phone", "brand" : "ACME", "type" : "phone", "price" : 333, "warranty_years" : 0.25, "available" : true }
{ "_id" : ObjectId("57af87dbf78428671f128163"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 5000 }

- lets check count of document in collection

> db.products.find().count()
12                    ----there are 12 documment in collection

- find perticuler document from collection..

> db.products.find({},{"limits"=1})
2016-08-14T01:49:00.937+0530 SyntaxError: Unexpected token =
> db.products.find({},{"limits":1})
{ "_id" : "ac3" }
{ "_id" : "ac7" }
{ "_id" : ObjectId("507d95d5719dbef170f15bf9") }
{ "_id" : ObjectId("507d95d5719dbef170f15bfa") }
{ "_id" : ObjectId("507d95d5719dbef170f15bfb") }
{ "_id" : ObjectId("507d95d5719dbef170f15bfc") }
{ "_id" : ObjectId("507d95d5719dbef170f15bfd") }
{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } } }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } } }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } } }
{ "_id" : ObjectId("507d95d5719dbef170f15c01") }
{ "_id" : "ac9" }

note:- all document where name exists limits..

- only deplay records where limits have the values

>db.products.find({limits:{$exists:true}},{"limits" :1})

{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } } }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } } }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } } }

-deplay the records without _id

> db.products.find({limits:{$exists:true}},{"limits" :1 , _id:0})

{ "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } } }
{ "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } } }
{ "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } } }

3) update the recods in collections.

> db.products.update( {"emp_name" : "shiv"},{$set:{"salary" : 5000}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.products.find()
{ "_id" : "ac3", "name" : "AC3 Phone", "brand" : "ACME", "type" : "phone", "price" : 200, "warranty_years" : 1, "available" : true }
{ "_id" : "ac7", "name" : "AC7 Phone", "brand" : "ACME", "type" : "phone", "price" : 320, "warranty_years" : 1, "available" : false }
{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "name" : "AC3 Series Charger", "type" : [ "accessory", "charger" ], "price" : 19, "warranty_years" : 0.25, "for" : [ "ac3", "ac7", "ac9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfa"), "name" : "AC3 Case Green", "type" : [ "accessory", "case" ], "color" : "green", "price" : 12, "warranty_years" : 0 }
{ "_id" : ObjectId("507d95d5719dbef170f15bfb"), "name" : "Phone Extended Warranty", "type" : "warranty", "price" : 38, "warranty_years" : 2, "for" : [ "ac3", "ac7", "ac9", "qp7", "qp8", "qp9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfc"), "name" : "AC3 Case Black", "type" : [ "accessory", "case" ], "color" : "black", "price" : 12.5, "warranty_years" : 0.25, "available" : false, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfd"), "name" : "AC3 Case Red", "type" : [ "accessory", "case" ], "color" : "red", "price" : 12, "warranty_years" : 0.25, "available" : true, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "name" : "Phone Service Basic Plan", "type" : "service", "monthly_price" : 40, "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } }, "term_years" : 2 }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "name" : "Phone Service Core Plan", "type" : "service", "monthly_price" : 60, "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } }, "term_years" : 1 }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "name" : "Phone Service Family Plan", "type" : "service", "monthly_price" : 90, "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } }, "sales_tax" : true, "term_years" : 3 }
{ "_id" : ObjectId("507d95d5719dbef170f15c01"), "name" : "Cable TV Basic Service Package", "type" : "tv", "monthly_price" : 50, "term_years" : 2, "cancel_penalty" : 25, "sales_tax" : true, "additional_tarriffs" : [ { "kind" : "federal tarriff", "amount" : { "percent_of_service" : 0.06 } }, { "kind" : "misc tarriff", "amount" : 2.25 } ] }
{ "_id" : "ac9", "name" : "AC9 Phone", "brand" : "ACME", "type" : "phone", "price" : 333, "warranty_years" : 0.25, "available" : true }
{ "_id" : ObjectId("57af87dbf78428671f128163"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 5000 }

4) remove document(record) from collection.

> db.products.remove({"salary" : 5000 })
WriteResult({ "nRemoved" : 1 })

> db.products.find()
{ "_id" : "ac3", "name" : "AC3 Phone", "brand" : "ACME", "type" : "phone", "price" : 200, "warranty_years" : 1, "available" : true }
{ "_id" : "ac7", "name" : "AC7 Phone", "brand" : "ACME", "type" : "phone", "price" : 320, "warranty_years" : 1, "available" : false }
{ "_id" : ObjectId("507d95d5719dbef170f15bf9"), "name" : "AC3 Series Charger", "type" : [ "accessory", "charger" ], "price" : 19, "warranty_years" : 0.25, "for" : [ "ac3", "ac7", "ac9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfa"), "name" : "AC3 Case Green", "type" : [ "accessory", "case" ], "color" : "green", "price" : 12, "warranty_years" : 0 }
{ "_id" : ObjectId("507d95d5719dbef170f15bfb"), "name" : "Phone Extended Warranty", "type" : "warranty", "price" : 38, "warranty_years" : 2, "for" : [ "ac3", "ac7", "ac9", "qp7", "qp8", "qp9" ] }
{ "_id" : ObjectId("507d95d5719dbef170f15bfc"), "name" : "AC3 Case Black", "type" : [ "accessory", "case" ], "color" : "black", "price" : 12.5, "warranty_years" : 0.25, "available" : false, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfd"), "name" : "AC3 Case Red", "type" : [ "accessory", "case" ], "color" : "red", "price" : 12, "warranty_years" : 0.25, "available" : true, "for" : "ac3" }
{ "_id" : ObjectId("507d95d5719dbef170f15bfe"), "name" : "Phone Service Basic Plan", "type" : "service", "monthly_price" : 40, "limits" : { "voice" : { "units" : "minutes", "n" : 400, "over_rate" : 0.05 }, "data" : { "units" : "gigabytes", "n" : 20, "over_rate" : 1 }, "sms" : { "units" : "texts sent", "n" : 100, "over_rate" : 0.001 } }, "term_years" : 2 }
{ "_id" : ObjectId("507d95d5719dbef170f15bff"), "name" : "Phone Service Core Plan", "type" : "service", "monthly_price" : 60, "limits" : { "voice" : { "units" : "minutes", "n" : 1000, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0 } }, "term_years" : 1 }
{ "_id" : ObjectId("507d95d5719dbef170f15c00"), "name" : "Phone Service Family Plan", "type" : "service", "monthly_price" : 90, "limits" : { "voice" : { "units" : "minutes", "n" : 1200, "over_rate" : 0.05 }, "data" : { "n" : "unlimited", "over_rate" : 0 }, "sms" : { "n" : "unlimited", "over_rate" : 0.01 } }, "sales_tax" : true, "term_years" : 3 }
{ "_id" : ObjectId("507d95d5719dbef170f15c01"), "name" : "Cable TV Basic Service Package", "type" : "tv", "monthly_price" : 50, "term_years" : 2, "cancel_penalty" : 25, "sales_tax" : true, "additional_tarriffs" : [ { "kind" : "federal tarriff", "amount" : { "percent_of_service" : 0.06 } }, { "kind" : "misc tarriff", "amount" : 2.25 } ] }
{ "_id" : "ac9", "name" : "AC9 Phone", "brand" : "ACME", "type" : "phone", "price" : 333, "warranty_years" : 0.25, "available" : true }


reference:-https://docs.mongodb.com/manual/reference/command/ 

Replication in mongoDB step by step.



                                               Replication in mongoDB step by step.

Operating system details:-

Red Hat Enterprise Linux Server release 5.4 (Tikanga)

mongoDB version details:-

MongoDB shell version: 2.6.12

Node details(servers)

node1: mongodb1.example.com

node2: mongodb2.example.com

node3: mongodb3.example.com

note:- i configured DNS server

1) create directory for dbpath (location of files)

Node1:

-bash-3.2$ pwd
/var/lib/mongo

-bash-3.2$ mkdir 1

-bash-3.2$ ls -ltr
total 82020
-rw------- 1 mongod mongod 16777216 Aug 11 05:34 local.ns
-rw------- 1 mongod mongod 67108864 Aug 11 05:34 local.0
-rwxr-xr-x 1 mongod mongod        5 Aug 29 03:29 mongod.lock
drwxr-xr-x 2 mongod mongod     4096 Aug 29 03:29 journal
drwxr-xr-x 2 mongod mongod     4096 Aug 29 04:04 1

Node2:

-bash-3.2$ pwd
/var/lib/mongo
-bash-3.2$ mkdir 2
-bash-3.2$ ls -ltr
total 82020
-rw------- 1 mongod mongod 16777216 Aug 11 05:34 local.ns
-rw------- 1 mongod mongod 67108864 Aug 11 05:34 local.0
-rwxr-xr-x 1 mongod mongod        5 Aug 29 03:29 mongod.lock
drwxr-xr-x 2 mongod mongod     4096 Aug 29 03:29 journal
drwxr-xr-x 2 mongod mongod     4096 Aug 29 04:05 2

Node3:

-bash-3.2$ mkdir 3
-bash-3.2$ pwd
/var/lib/mongo
-bash-3.2$ ls -ltr
total 82020
-rw------- 1 mongod mongod 16777216 Aug 11 05:34 local.ns
-rw------- 1 mongod mongod 67108864 Aug 11 05:34 local.0
-rwxr-xr-x 1 mongod mongod        5 Aug 29 03:28 mongod.lock
drwxr-xr-x 2 mongod mongod     4096 Aug 29 03:28 journal
drwxr-xr-x 2 mongod mongod     4096 Aug 29 04:06 3
-bash-3.2$

2)  Create replication set and start mongod process in each server

Node1:

-bash-3.2$ mongod --port 27001 --replSet abc --dbpath /var/lib/mongo/1 --logpath /var/lib/mongo/log.1 --logappend --oplogSize 50 -smallfiles --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4146
child process started successfully, parent exiting

Node2:

-bash-3.2$ mongod --port 27002 --replSet abc --dbpath /var/lib/mongo/2 --logpath /var/lib/mongo/log.2 --logappend --oplogSize 50 -smallfiles --fork
about to fork child process, waiting until server is ready for connections.
forked process: 8573
child process started successfully, parent exiting

Node3:

-bash-3.2$ mongod --port 27003 --replSet abc --dbpath /var/lib/mongo/3 --logpath /var/lib/mongo/log.3 --logappend --oplogSize 50 -smallfiles --fork
about to fork child process, waiting until server is ready for connections.
forked process: 8499
child process started successfully, parent exiting


3) Connect to mongoDB on primary Server for initiat replication set

-bash-3.2$ mongo --port 27001
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27001/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
                               
> rs.initiate()                    -------initiat replication set
{
        "info2" : "no configuration explicitly specified -- making one",
        "me" : "mongodb1.example.com:27001",
        "info" : "Config now saved locally.  Should come online in about a minute.",
        "ok" : 1
}
> rs.status()
{
        "set" : "abc",
        "date" : ISODate("2016-08-28T22:44:30Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "mongodb1.example.com:27001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 326,
                        "optime" : Timestamp(1472424262, 1),
                        "optimeDate" : ISODate("2016-08-28T22:44:22Z"),
                        "electionTime" : Timestamp(1472424262, 2),
                        "electionDate" : ISODate("2016-08-28T22:44:22Z"),
                        "self" : true
                }
        ],
        "ok" : 1
}
abc:PRIMARY>
abc:PRIMARY>

4)  Add secondary servers to replication set.

abc:PRIMARY> rs.add("mongodb2.example.com:27002")
{ "ok" : 1 }
abc:PRIMARY> rs.add("mongodb3.example.com:27003"
... )
{ "ok" : 1 }

abc:PRIMARY> rs.initiate()
{
        "info" : "try querying local.system.replset to see current configuration",
        "ok" : 0,
        "errmsg" : "already initialized"
}
abc:PRIMARY> rs.status()
{
        "set" : "abc",
        "date" : ISODate("2016-08-28T22:47:58Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "mongodb1.example.com:27001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 534,
                        "optime" : Timestamp(1472424443, 1),
                        "optimeDate" : ISODate("2016-08-28T22:47:23Z"),
                        "electionTime" : Timestamp(1472424262, 2),
                        "electionDate" : ISODate("2016-08-28T22:44:22Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "mongodb2.example.com:27002",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 44,
                        "optime" : Timestamp(1472424443, 1),
                        "optimeDate" : ISODate("2016-08-28T22:47:23Z"),
                        "lastHeartbeat" : ISODate("2016-08-28T22:47:57Z"),
                        "lastHeartbeatRecv" : ISODate("2016-08-28T22:47:57Z"),
                        "pingMs" : 14,
                        "syncingTo" : "mongodb1.example.com:27001"
                },
                {
                        "_id" : 2,
                        "name" : "mongodb3.example.com:27003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 35,
                        "optime" : Timestamp(1472424443, 1),
                        "optimeDate" : ISODate("2016-08-28T22:47:23Z"),
                        "lastHeartbeat" : ISODate("2016-08-28T22:47:57Z"),
                        "lastHeartbeatRecv" : ISODate("2016-08-28T22:47:57Z"),
                        "pingMs" : 48,
                        "syncingTo" : "mongodb1.example.com:27001"
                }
        ],
        "ok" : 1
}
abc:PRIMARY>

5)  connect to secondary server

Node2:

-bash-3.2$ mongo --port 27002
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27002/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
abc:SECONDARY>

Node3:

-bash-3.2$ mongo --port 27003
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27003/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
abc:SECONDARY>

use rs.slaveOk() command for apply the replication on secodary servers
example:
abc:SECONDARY>rs.slaveOk()

6) Test replication is working

abc:PRIMARY> show dbs
admin  (empty)
local  0.094GB
abc:PRIMARY> db.products.insert({ "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 })
WriteResult({ "nInserted" : 1 })
abc:PRIMARY> db.products.find()
{ "_id" : ObjectId("57c36b55d9bbb775d4557902"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 }

Node2:

abc:SECONDARY> show dbs
admin  (empty)
local  0.094GB
abc:SECONDARY> db.products.find()
{ "_id" : ObjectId("57c36b55d9bbb775d4557902"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 }
abc:SECONDARY>

Node3:

abc:SECONDARY> show dbs
admin  (empty)
local  0.094GB
abc:SECONDARY> db.products.find()
{ "_id" : ObjectId("57c36b55d9bbb775d4557902"), "emp_name" : "shiv", "emp_id" : 320, "city" : "nashik", "salary" : 4000 }



 Reference :-http://www.tutorialspoint.com

work on autovacuum postgreSQL parameter

 In This blog, we are discussing the auto vacuum parameter on a small scale. we will understand the below parameters and will see how to mod...