db
MariaDB Create Database
Eine Datenbank anlegen geht ganz einfach
MariaDB [(none)]> create database db1; Query OK, 1 row affected (0.001 sec)
Außer es soll ein Bindestrich im Datenbanknamen vorkommen
MariaDB [(none)]> create database db-1; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-1' at line 1
Vielleicht helfen Anführungszeichen
MariaDB [(none)]> create database "db-1"; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"db-1"' at line 1
Oder einfache Hochkommata
MariaDB [(none)]> create database 'db-1'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''db-1' at line 1
Oder mit einem Schrägstrich quotieren
MariaDB [(none)]> create database 'db\-1'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''db\-'' at line 1
Oder so was
MariaDB [(none)]> create database ´db-1´; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-1´' t line 1
Nein, es müssen Backticks sein
MariaDB [(none)]> create database `db-1`; Query OK, 1 row affected (0.001 sec)
Ist doch logisch!?
Datenbanksysteme
Wenn Du glaubst, Du hast all den Irrsinn rund um verschiedene Datenbank-Systeme wie MySQL, Postgres, CouchDB, MongoDB oder ElasticSearch schon gesehn, dann trifft Dich Oracle…
Zitat des Tages
A lot of your work is done behind the scenes. In fact, people will often wonder what it is you do all day, since much of your work is never actually seen by the end users.
Zitat des Tages
Und nochmal über Entwickler und Administratoren:
Unfortunately these two groups rarely interface unless there is a problem (or an opportunity to point fingers at each other).
Zitat des Tages
Developers know code, and they know various facets of the business; and because they focus on those items daily, they are not spending time racking servers, installing routers, replacing hard disks, allocating space on the SAN, and so forth. Server administrators do those things, but they do not know how to code or build applications that will drive the business forward at the same speed as a developer.
Zitat des Tages
Gilt auch für andere Fachbereiche 🙂
If you come across a developer that believes they know more than anyone else in the room, you can sit back and chuckle because you already know that the DBAs are the smartest, otherwise you wouldn’t always be called to fix their problems all day long.
Zitat des Tages
Some might see it as “dumb luck,” but I prefer the term “smart luck.”
Zitat des Tages
With that responsibility, you will also find that you start getting more blame than credit for your work. I promise you this: no one will ever stop by your desk in the morning and thank you for the fact that everything ran smoothly last night.
Mongodb – Pre-splitting data
Ein weiterer Teil von Notizen zu M202: MongoDB Advanced Deployment and Operations
Start a config server (would be 3 in production):
mongod --port 27019 --dbpath /data/config --smallfiles --oplogSize 128 --fork --syslog --configsvr
Start the replica sets (okay, these are stand alone servers for testing)
mongod --port 30000 --dbpath /data/shard0 --smallfiles --oplogSize 128 --fork --syslog --shardsvr mongod --port 30001 --dbpath /data/shard1 --smallfiles --oplogSize 128 --fork --syslog --shardsvr mongod --port 30002 --dbpath /data/shard2 --smallfiles --oplogSize 128 --fork --syslog --shardsvr
Start a mongo router:
mongos --configdb localhost:27019 --fork --syslog (default uses port 27017)
connect to the mongos with the mongo command and add the single servers to the shard:
mongos> use admin db.runCommand( { addShard: "localhost:30000", maxSize: 0, name: "shard0" } ) db.runCommand( { addShard: "localhost:30001", maxSize: 0, name: "shard1" } ) db.runCommand( { addShard: "localhost:30002", maxSize: 0, name: "shard2" } ) mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "version" : 4, "minCompatibleVersion" : 4, "currentVersion" : 5, "clusterId" : ObjectId("53ebd0db6f0a219ba53abb9e") } shards: { "_id" : "shard0", "host" : "localhost:30000" } { "_id" : "shard1", "host" : "localhost:30001" } { "_id" : "shard2", "host" : "localhost:30002" } databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" }
Create the Database:
use m202 mongos> db.createCollection("presplit") { "ok" : 1 }
Enable sharding for database – and for the collection:
db.runCommand({"enablesharding" : "m202"}) { "ok" : 1 } db.runCommand ({ shardCollection: "m202.presplit", key: { a: 1 }, numInitialChunks: 50 })
sh.enableSharding("users") sh.stopBalancer() sh.shardCollection("m202.presplit", { _id : 1 }) db.adminCommand( { split : "m202.presplit" , middle : { _id : prefix } } ); db.adminCommand( { split : "m202.presplit" , middle : { a : 1 } } );
merge chunks togehter, to build up the required ranges
db.runCommand( { mergeChunks: "m202.presplit", bounds: [ { "a": 15 }, { "a": 20 } ] } )
you need to do that multiple times – you can only merge two chunks at a time
just move your chunks around the shards
db.adminCommand({moveChunk : "m202.presplit", find : {a : 23}, to : "shard2"})
It’s sufficient to use find with the starting of the chunk!
Search the changelog for chunk migrations
db.changelog.find().sort({time : -1 }).pretty()
Adding Tags
sh.addShardTag("test-rs01", "USWEST") sh.addShardTag("test-rs02", "USEAST")
In case something goes wrong, drop the database and start from the beginning:
use <dbname> db.dropDatabase();
Widersprüche der Datenbankarchitektur?
Von Neumann Architektur: Programm und Daten teilen sich einen gemeinsamen Speicherbereich.
DB Prinzip: Logische Trennung von Programm und Daten einführen.