美文网首页
【mongoDB】mongoDB 服务器local库各表数据

【mongoDB】mongoDB 服务器local库各表数据

作者: Bogon | 来源:发表于2022-09-10 00:05 被阅读0次
  1. 登录数据库

/path/to/mongo  --host=172.16.218.27 --port=27017 -u username  -p 'XXX'  --authenticationDatabase=admin

  1. 查看 local库表
> use local
> show tables

me
oplog.rs
replset.election
replset.minvalid
startup_log
system.replset

local库下面的me集合保存了服务器名称
local库下面的replset.minvalid集合保存了数据库最新操作的时间戳
local库下面的startup_log集合记录这mongod每一次的启动信息
local库下面的system.indexes集合记录当前库的所有索引信息
local库下面的system.replset记录着复制集的成员配置信息rs.conf()读取这个集合
local库下面的oplog.rs集合记录这所有操作
 
MongoDB就是通过oplog.rs来实现数据同步的。当Primary节点插入一条数据后,oplog.rs集合中就会多一条记录

  1. 查看各表数据
> db.me.find().pretty()
{
        "_id" : ObjectId("606e801ee62e9ecd3cf10e53"),
        "host" : "Bogon-192.168.1.101"
}

> db.replset.election.find().pretty()
{
        "_id" : ObjectId("606e804570e39a46a471ad78"),
        "term" : NumberLong(5),
        "candidateIndex" : NumberLong(1)
}

> db.replset.minvalid.find().pretty()
{
        "_id" : ObjectId("606e802be62e9ecd3cf10e58"),
        "ts" : Timestamp(1656295000, 70),
        "t" : NumberLong(4),
        "oplogDeleteFromPoint" : Timestamp(0, 0)
}

> db.startup_log.find().count()
4

> db.startup_log.find().pretty()
{
        "_id" : "Bogon-192.168.1.101-1617854494977",
        "hostname" : "Bogon-192.168.1.101",
        "startTime" : ISODate("2021-04-08T04:01:34Z"),
        "startTimeLocal" : "Thu Apr  8 12:01:34.977",
        "cmdLine" : {
                "net" : {
                        "maxIncomingConnections" : 16000,
                        "port" : 27017
                },
                "processManagement" : {
                        "fork" : true
                },
                "replication" : {
                        "replSet" : "test"
                },
                "storage" : {
                        "dbPath" : "/path/to/test",
                        "directoryPerDB" : true,
                        "wiredTiger" : {
                                "engineConfig" : {
                                        "cacheSizeGB" : 12
                                }
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "/path/to/logs/test.log"
                }
        },
        "pid" : NumberLong(281313),
        "buildinfo" : {
                "version" : "3.4.19",
                "gitVersion" : "a2d97db8fe449d15eb8e275bbf318491781472bf",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        3,
                        4,
                        19,
                        0
                ],
                "openssl" : {
                        "running" : "OpenSSL 1.0.1e-fips 11 Feb 2013",
                        "compiled" : "OpenSSL 1.0.1e-fips 11 Feb 2013"
                },
                "buildEnvironment" : {
                        "distmod" : "rhel70",
                        "distarch" : "x86_64",
                        "cc" : "/opt/mongodbtoolchain/v2/bin/gcc: gcc (GCC) 5.4.0",
                        "ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp",
                        "cxx" : "/opt/mongodbtoolchain/v2/bin/g++: g++ (GCC) 5.4.0",
                        "cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -std=c++11",
                        "linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro",
                        "target_arch" : "x86_64",
                        "target_os" : "linux"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}
{
        "_id" : "Bogon-192.168.1.101-1617854529663",
        "hostname" : "Bogon-192.168.1.101",
        "startTime" : ISODate("2021-04-08T04:02:09Z"),
        "startTimeLocal" : "Thu Apr  8 12:02:09.663",
        "cmdLine" : {
                "net" : {
                        "maxIncomingConnections" : 16000,
                        "port" : 27017
                },
                "processManagement" : {
                        "fork" : true
                },
                "replication" : {
                        "replSet" : "test"
                },
                "security" : {
                        "authorization" : "enabled",
                        "keyFile" : "/path/to/bin/key_file"
                },
                "storage" : {
                        "dbPath" : "/path/to/test",
                        "directoryPerDB" : true,
                        "wiredTiger" : {
                                "engineConfig" : {
                                        "cacheSizeGB" : 12
                                }
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "/path/to/logs/test.log"
                }
        },
        "pid" : NumberLong(297173),
        "buildinfo" : {
                "version" : "3.4.19",
                "gitVersion" : "a2d97db8fe449d15eb8e275bbf318491781472bf",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        3,
                        4,
                        19,
                        0
                ],
                "openssl" : {
                        "running" : "OpenSSL 1.0.1e-fips 11 Feb 2013",
                        "compiled" : "OpenSSL 1.0.1e-fips 11 Feb 2013"
                },
                "buildEnvironment" : {
                        "distmod" : "rhel70",
                        "distarch" : "x86_64",
                        "cc" : "/opt/mongodbtoolchain/v2/bin/gcc: gcc (GCC) 5.4.0",
                        "ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp",
                        "cxx" : "/opt/mongodbtoolchain/v2/bin/g++: g++ (GCC) 5.4.0",
                        "cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -std=c++11",
                        "linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro",
                        "target_arch" : "x86_64",
                        "target_os" : "linux"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}
{
        "_id" : "Bogon-192.168.1.101-1652369253489",
        "hostname" : "Bogon-192.168.1.101",
        "startTime" : ISODate("2022-05-12T15:27:33Z"),
        "startTimeLocal" : "Thu May 12 23:27:33.489",
        "cmdLine" : {
                "net" : {
                        "maxIncomingConnections" : 16000,
                        "port" : 27017
                },
                "processManagement" : {
                        "fork" : true
                },
                "replication" : {
                        "replSet" : "test"
                },
                "security" : {
                        "authorization" : "enabled",
                        "keyFile" : "/path/to/bin/key_file"
                },
                "storage" : {
                        "dbPath" : "/path/to/test",
                        "directoryPerDB" : true,
                        "wiredTiger" : {
                                "engineConfig" : {
                                        "cacheSizeGB" : 12
                                }
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "/path/to/logs/test.log"
                }
        },
        "pid" : NumberLong(15697),
        "buildinfo" : {
                "version" : "3.4.19",
                "gitVersion" : "a2d97db8fe449d15eb8e275bbf318491781472bf",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        3,
                        4,
                        19,
                        0
                ],
                "openssl" : {
                        "running" : "OpenSSL 1.0.1e-fips 11 Feb 2013",
                        "compiled" : "OpenSSL 1.0.1e-fips 11 Feb 2013"
                },
                "buildEnvironment" : {
                        "distmod" : "rhel70",
                        "distarch" : "x86_64",
                        "cc" : "/opt/mongodbtoolchain/v2/bin/gcc: gcc (GCC) 5.4.0",
                        "ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp",
                        "cxx" : "/opt/mongodbtoolchain/v2/bin/g++: g++ (GCC) 5.4.0",
                        "cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -std=c++11",
                        "linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro",
                        "target_arch" : "x86_64",
                        "target_os" : "linux"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}
{
        "_id" : "Bogon-192.168.1.101-1656313009487",
        "hostname" : "Bogon-192.168.1.101",
        "startTime" : ISODate("2022-06-27T06:56:49Z"),
        "startTimeLocal" : "Mon Jun 27 14:56:49.487",
        "cmdLine" : {
                "net" : {
                        "maxIncomingConnections" : 16000,
                        "port" : 27017
                },
                "processManagement" : {
                        "fork" : true
                },
                "replication" : {
                        "replSet" : "test"
                },
                "security" : {
                        "authorization" : "enabled",
                        "keyFile" : "/path/to/bin/key_file"
                },
                "storage" : {
                        "dbPath" : "/path/to/test",
                        "directoryPerDB" : true,
                        "wiredTiger" : {
                                "engineConfig" : {
                                        "cacheSizeGB" : 12
                                }
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "/path/to/logs/test.log"
                }
        },
        "pid" : NumberLong(335827),
        "buildinfo" : {
                "version" : "3.4.19",
                "gitVersion" : "a2d97db8fe449d15eb8e275bbf318491781472bf",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        3,
                        4,
                        19,
                        0
                ],
                "openssl" : {
                        "running" : "OpenSSL 1.0.1e-fips 11 Feb 2013",
                        "compiled" : "OpenSSL 1.0.1e-fips 11 Feb 2013"
                },
                "buildEnvironment" : {
                        "distmod" : "rhel70",
                        "distarch" : "x86_64",
                        "cc" : "/opt/mongodbtoolchain/v2/bin/gcc: gcc (GCC) 5.4.0",
                        "ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp",
                        "cxx" : "/opt/mongodbtoolchain/v2/bin/g++: g++ (GCC) 5.4.0",
                        "cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -std=c++11",
                        "linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro",
                        "target_arch" : "x86_64",
                        "target_os" : "linux"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}


> db.system.replset.find().pretty()
{
        "_id" : "test",
        "version" : 3,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.1.102:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "192.168.1.101:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "192.168.1.103:37017",
                        "arbiterOnly" : true,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : 60000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("606e8023effd108f780076e5")
        }
}

> db.oplog.rs.count()
192678389


注: 如果local库数量量比该复制集所有其他业务数据量加起来都大,说明该复制集数据变更频繁,但是数据增量少,每次变更,都会被oplog记录。

> db.oplog.rs.find().limit(3)
{ "ts" : Timestamp(1652666509, 47), "t" : NumberLong(4), "h" : NumberLong("4931383382447458090"), "v" : 2, "op" : "u", "ns" : "testDB.testColl", "o2" : { "_id" : "626608bb60b2b9ddf2a3aabd" }, "o" : { "$set" : { "updateTime" : ISODate("2022-05-16T02:01:49.451Z") } } }
{ "ts" : Timestamp(1652666509, 48), "t" : NumberLong(4), "h" : NumberLong("3067309742422051292"), "v" : 2, "op" : "u", "ns" : "testDB.testColl", "o2" : { "_id" : "626608bb60b2b9ddf2a3aae0" }, "o" : { "$set" : { "updateTime" : ISODate("2022-05-16T02:01:49.452Z") } } }
{ "ts" : Timestamp(1652666509, 49), "t" : NumberLong(4), "h" : NumberLong("-6402747828476563492"), "v" : 2, "op" : "u", "ns" : "testDB.testColl", "o2" : { "_id" : "626608bb60b2b9ddf2a3aa88" }, "o" : { "$set" : { "updateTime" : ISODate("2022-05-16T02:01:49.453Z") } } }


> db.oplog.rs.find().limit(3).pretty()
{
        "ts" : Timestamp(1652666509, 47),
        "t" : NumberLong(4),
        "h" : NumberLong("4931383382447458090"),
        "v" : 2,
        "op" : "u",
        "ns" : "testDB.testColl",
        "o2" : {
                "_id" : "626608bb60b2b9ddf2a3aabd"
        },
        "o" : {
                "$set" : {
                        "updateTime" : ISODate("2022-05-16T02:01:49.451Z")
                }
        }
}
{
        "ts" : Timestamp(1652666509, 48),
        "t" : NumberLong(4),
        "h" : NumberLong("3067309742422051292"),
        "v" : 2,
        "op" : "u",
        "ns" : "testDB.testColl",
        "o2" : {
                "_id" : "626608bb60b2b9ddf2a3aae0"
        },
        "o" : {
                "$set" : {
                        "updateTime" : ISODate("2022-05-16T02:01:49.452Z")
                }
        }
}
{
        "ts" : Timestamp(1652666509, 49),
        "t" : NumberLong(4),
        "h" : NumberLong("-6402747828476563492"),
        "v" : 2,
        "op" : "u",
        "ns" : "testDB.testColl",
        "o2" : {
                "_id" : "626608bb60b2b9ddf2a3aa88"
        },
        "o" : {
                "$set" : {
                        "updateTime" : ISODate("2022-05-16T02:01:49.453Z")
                }
        }
}


相关文章

网友评论

      本文标题:【mongoDB】mongoDB 服务器local库各表数据

      本文链接:https://www.haomeiwen.com/subject/tocanrtx.html