quinta-feira, 18 de maio de 2023

[Oracle 23c] How to install an Oracle 23c test environment on Linux 8 running on VirtualBox in five commands.

Hello all!!!

How are you doing?

Today I'll show how you can install Oracle 23c in a Linux 8 using VirtualBox.

If you need help to install Linux on VirtualBox, you can use this link: 

But always remember:
1) This step-by-step worked for me, but it may not work for you.
2) It's a basic and limited environment. The real life will be different, for sure.
3) This post is for study and testing as well, and has no concern for performance and security best practices.

So, let's get started!!!

1) We are run the dnf to install and configure pre-requirements using ROOT user.
dnf install -y oraclelinux-developer-release-el8
dnf install -y oracle-database-preinstall-23c

If you don't know what DNF is, it's a software package manager, the successor to famous YUM. The DNF check and install dependencies and determine some actions required to install this. Feel free to view this link and learn more about it: Using the DNF software package manager




2) I'll download the Oracle 23c software using WGET (or CURL).

wget https://download.oracle.com/otn-pub/otn_software/db-free/oracle-database-free-23c-1.0-1.el8.x86_64.rpm

or

curl -L -o oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/developer/x86_64/getPackage/oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm


3) Now, I'll install the Oracle 23c Software

dnf -y localinstall /root/oracle-database-free-23c-1.0-1.el8.x86_64.rpm


If I try to install using the Oracle user, I'll get this error:


4) It's time to create database in silent mode - using Oracle user

export DB_PASSWORD=SysOracle1106

(echo "${DB_PASSWORD}"; echo "${DB_PASSWORD}";) | /etc/init.d/oracle-free-23c configure



5) And finally, I'll enable the Oracle 23c on SYSTEMCTL

systemctl enable oracle-free-23c


The Oracle Env values are:
export ORACLE_HOME=/opt/oracle/product/23c/dbhomeFree
export PATH=$ORACLE_HOME/bin:$PATH

The credencials to connect will be:
-- CDB
sqlplus sys/SysOracle1106@//localhost:1521/free as sysdba

-- PDB
sqlplus sys/SysOracle1106@//localhost:1521/freepdb1 as sysdba

And finally, to start and stop the service, we can use:
/etc/init.d/oracle-free-23c stop
/etc/init.d/oracle-free-23c start



For this blog post, I used these great blogs:

And as Woody Woodpecker says: "That's all folks!!!"

I hope this helps you!!

Regards
Mario

segunda-feira, 8 de maio de 2023

[Oracle 23c] How to create and run an Oracle 23c test environment faster using Docker in four commands.

Hello all

How are you doing?

Today, I'll show how you can create and run a basic test environment with Oracle 23c using Docker with four commands.

Yes my friend, four commands!!!

But always remember:
1) This step-by-step worked for me, but it may not work for you.
2) It is a basic environment. Real life will be different, for sure.
3) This post is for study and testing only and has no concern for performance and security best practices.

As the UFC guy says, it's showtime!!!

1) Create New Container
docker run -d -p 1521:1522 -e ORACLE_PASSWORD=SysPassword1 -v oracle-volume=/opt/oracle/data gvenzl/oracle-free:latest


Important: If you have run it for the first time, the image download has been executed.  

2) List and rename the new container
docker ps
docker rename c814e75ee041 Oracle23c


3) Access the container Oracle23c
docker exec -it Oracle23c /bin/bash


And thats it!!! As simple as that!!

For this test, I used these fonts:

I hope this tip helps you!

Regards
Mario







terça-feira, 11 de abril de 2023

[MongoDB] How the replication works in MongoDB? And how to create a Test Environment using Docker-Compose!!!

Hello all

How are you doing?

Today, I'm going to talk about replication in MongoDB and how I can create a Test Environment using Docker-Compose.

If you don't know how to install a docker-compose, click here and here.

And always remember:
1) This step-by-setp worked for me, but it might not work for you.
2) It's a basic install. As we go along, we'll get better and better.
3) This post is just for study and test, and it has no concern for Performance and Security Best Practices.

According to the manual, "The Replica Set in MongoDB is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability and are the basis for all production deployments. Replication provides redundancy and increases data availability. With multiple copies of data on different database servers, replication provides a level of fault tolerance against the loss of a single database server."

It's important understand that the secondaries replicas aren't open to write operation. But we can specify a read preference to send read operations to secondaries, if we want. 

If you want active nodes, you can use Sharding which are a method for distributing data across multiple machines, but this is a conversation to other article.

This is a basic schema about replication in MongoDB.



For learn more about replication, click on image above.

If you understood this, let's get started!!!

For my test, I'll create 3 containers running on AWS EC2 instance using Amazon Linux 2. The data will be persistent because I'll use the "Docker-Managed Volume" for this. 

These automation scripts were based on these original scripts here!!!

1) On compose directory, I'll create an archive call "docker-compose-replicaset.yml". 
Important: It's forbidden to use "TAB" for indentation.

version: '3.9'

services:
  mongodb01:
    container_name: mongodb01
    image: mongo:6
    volumes:
      - shared_database:/data/mongodb
      - /root/compose/scripts/rs-init.sh:/scripts/rs-init.sh
    networks:
      MongoCluster:
        ipv4_address: 172.15.0.11
    ports:
      - 27021:27017
    restart: always
    entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "myRS"]
  mongodb02:
    container_name: mongodb02
    image: mongo:6
    volumes:
      - shared_database:/data/mongodb
    networks:
      MongoCluster:
        ipv4_address: 172.15.0.12
    ports:
      - 27022:27017
    restart: always
    entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "myRS"]
  mongodb03:
    container_name: mongodb03
    image: mongo:6
    volumes:
      - shared_database:/data/mongodb
    networks:
      MongoCluster:
        ipv4_address: 172.15.0.13
    ports:
      - 27023:27017
    restart: always
    entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "myRS"]

volumes:
  shared_database:

networks:
  MongoCluster:
    driver: bridge
    ipam:
     config:
       - subnet: 172.15.0.0/16

The main information about this script are:
mongodb01 = Name of service
container_name = Container (machine) name
image = Docker image. I'll use the MongoDB official image 
volumes = Persistent volumes that will be shared in all nodes
networks = Network using to the cluster 
ports = Service ports and port range 
entrypoint = Override the default entrypoint. Setting entrypoint both overrides any default entrypoint set on the service’s image with the ENTRYPOINT Dockerfile instruction.

volumes:
  shared_database = Using a "Docker-Managed Volume" for share a Docker-managed volume between containers.

2) Create directory scripts in compose directory.
     mkdir -p /root/compose/scripts

3) Create script "rs-init.sh" in directory scripts

#!/bin/bash
DELAY=25
mongosh <<EOF
var config = {
    "_id": "myRS",
    "version": 1,
    "members": [
        {
            "_id": 1,
            "host": "mongodb01:27017",
            "priority": 2
        },
        {
            "_id": 2,
            "host": "mongodb02:27017",
            "priority": 1
        },
        {
            "_id": 3,
            "host": "mongodb03:27017",
            "priority": 1
        }
    ]
};
rs.initiate(config, { force: true });
EOF

echo "****** Waiting for ${DELAY} seconds for replicaset configuration to be applied ******"
sleep $DELAY
echo "****** Environment ready to use ******"

4) Create the script "startRS.sh" on compose directory.

#!/bin/bash
DELAY=10

## Cleanup older creations
docker-compose --file docker-compose-replicaset.yml down
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)

## Start Docker-compose using my configs
docker-compose --file docker-compose-replicaset.yml up -d

echo "****** Waiting for ${DELAY} seconds for containers to go up ******"
sleep $DELAY

## Start Replica Set just on the first execution. After that, a warning will be displayed.
docker exec mongodb01 /scripts/rs-init.sh

## Check
docker ps
docker exec -it mongodb01 /bin/hostname -i
docker exec -it mongodb02 /bin/hostname -i
docker exec -it mongodb03 /bin/hostname -i
docker exec -it mongodb01 mongosh --eval "rs.status()"

4) Run chmod to to the scripts executable
chmod +x starRS.sh
chmod +x scripts/rs-init.sh

If you want to download these scripts, click here.

Finally, we just run the startRS.sh








And now, if you want test the replica set, you can use this:

On Primary (mongodb01):
docker exec -it mongo01 mongosh
rs.stepDown()

On Secondary (mongodb02):
docker exec -it mongo02 mongosh


That's all folks!!!

I hope that this blog helps you!!!

Regards
Mario

sexta-feira, 3 de março de 2023

[O-Tips] Creating a new Oracle DEV environment with Appsync.

Hello all

Today, I recorded a new video talking about Appsync and how we can provide a new Oracle database for Dev team. 

Yes, I know I need to improve my English, and I've been working very hard at it. So, if you understood me, my goal has been achieved. 🥶

Dell Appsync is a Copy Data Management Software. The tool helps customers create and manage snapshots.

Furthermore, the Appsync helps the DBA team to provide a new database environment faster and easier than RMAN restore - or duplicate, for example.

On this video, I'll show how I can create and mount a Snapshot using AppSync.

For more information about Appsync, click here.

And, for you watch the video, access the O-Tips Youtube Channel.


I hope this video helps you!!!

Regards
Mario

quinta-feira, 2 de fevereiro de 2023

[Mongo DB] Introduction to the Document Model

Hello all

One more step on Mongo DB University.

Today, I'm learning about MongoDB and the Document Model.


The main points of this module are: 

Overall, we can say that Mongo DB:
    - It's a General-Purpose Document Database.
    - By default, Mongo DB supports a flexible schema model and a polymorphic data. 
    - This allows us to store documents with different structures in the same collection.

The main advantages to use Mongo DB: 
    1) Documents offer a flexible and developer-friendly way to work with data.
    2) Easier and faster to plan how application data will correspond to data store in the database.
    3) Modal data of any shape or structure.
    4) Documents can model everything:
            Key-values pairs
    Text
    Geospatial indexes
    Time series
    Graph data
    and more
    5) Use one format for any application.
    6) Easy connect - Provide drivers in all major programming languages.
Basically, you can use Mongo DB in any application:
    E-commerce
    Content management
    IoT and time series data
    Trading and payments
    Gaming
    Mobile Apps
    Real-time analytics and AI
Your main features are:
    Scalability
    Resilience
    Speed of development
    High levels of data privacy
    Security
And finally, we have 3 Key term:
    Document - The basic unit of data on Mongo DB.
    
    Collection - A group of those documents. Documents in a collection are tipically similar they don't have the exact same structure, because Mongo DB has a flexible schema model.

    Database - A container for our collections. 

The Document model.

We can say many things about The Document Model, but this is the summary:
    - On Mongo DB, data is organized into documents, collections, and databases.
    - Mongo DB stores data in structures known as documents
    - Mongo DB structures data in documents, which are similar to JSON Objects
    - Documents are stored in BSON, which supports a large range of data types, including all JSON data types, dates, numbers, and ObjectIds.
    - Mongo DB displayed the data documents in JSON format, but they're stored in the database in a format called BSON (Binary JSON).
    - BSON is an extension of JSON and providing additional features 
    - BSON add support for additional data types unavailable in Standard JSON 
    - Every document requires an "_id" field, which acts as a primary key. 
    - The "_id" is a required field in every MongoDB document, but it's not a data type. If an inserted document does not include an "_id" field, MongoDB will automatically create the "_id" field and populate it with a value of type ObjectId.
    - Documents can contain different fields and fields may contains different data types.
    - If you want to have more control over the structure and content, we can add optional schema validation rules to set constraints on the structure of documents. 
Some Datatypes that you have on Mongo DB:
    All the JSON datatypes
        String
Object
Array
Boolean
Null
Dates
Numbers
ObjectIDs - It's a special data type used in Mongo DB to create unique identified.
    If you want moder information, click here.


Finally, an example to the syntax for a MongoDB document:

Syntax:
{
"key": value,
"key": value,
"key": value
}
Example:
    db.createCollection("blog") 
    
     "codigo": 2, 
     "trilogy": "Harry Potter", 
     "sequence": "Harry Potter and the Chamber of Secrets", 
     "year": "2002",
     "points": ["The first movie of trilogy", "I watched the movie at the cinema"]
    }

So that's it for today, folks.

I hope this helps you!

Regards
Mario

segunda-feira, 16 de janeiro de 2023

[Mongo DB] - Basic update and delete operations (or "U" & "D" from CRUD)

Hello all

In the last post (here), I have talked about read and list operations, or the "R" from CRUD.

Today, I'm going to talk about update and delete operations in Mongo DB, the "U" and the "D" in CRUD. 

But remember, I'm talking about basic operations. As we know, the Mongo DB world is much bigger than this post.  

Let's get started!!!

The references are here and here.

We started with update operation.

We often use the operator "set" to execute the update.

-- Update a single data where codigo=14
db.movies.updateOne({ codigo: 14 },{ $set: { year: "2020" } })



-- Update using operator - We are updating the year on documents where codigo >= 97
db.movies.updateMany( { codigo: { $gte: 97 } } ,{ $set: { year: 2025 } })


-- Update the document where codigo=97, using the exclusive operator to increment the original value
db.movies.updateOne( { codigo: 97 } , { $inc: { codigo: -10 } } )


-- We can create a new "column" call "watched" and update all documents on collection with true, as well. The famous "Update without where" 🥶. 
db.movies.updateMany({ }, { $set: { watched: true } })

Ok, the basic update operations are easy!!!

And, what about the delete operations? 

They're very easy too!!!

-- Delete one document where codigo=98
db.movies.deleteOne ( { codigo: 98 } )

-- Delete many documents where trilogy = "Procurando Nemo"
db.movies.deleteMany({  trilogy: 'Procurando Nemo' })



Owwwwwww yes, it's easier than update, right...

With this post, I'm finished the posts with CRUD operations on Mongo DB.

I hope that it helps you to start on with Mongo DB.

The next post will talk about Index. 

See you!!!

Regards
Mario 

 







quarta-feira, 30 de novembro de 2022

[Mongo DB] - Basic sort and read operations (or "R" from CRUD)

Hello all

In the last post (here), I have talked about create operations and running inserts, or the "C" from CRUD.

Today, I'm going to talk about executing read operations in Mongo DB, the "R" in CRUD. I'll talk about sort, as well.

But remember, I'm talking about basic operations. As we know, the Mongo DB world is much bigger than this post.  

Let's get started!!!

The references are here and here.

-- List all
db.movies.find()


-- Find the first row matching the object
db.movies.findOne({trilogy: "Transformers"})


-- Limit the number of rows
db.movies.find().limit(3)


-- Count the number of rows
db.movies.find().count()


-- Where trilogy="Transformers"
db.movies.find( {trilogy: "Harry Potter"} )


-- List fields _id, codigo, sequence, year
db.movies.find( {trilogy: "Transformers"}, { codigo: 1, sequence: 1, year: 1 })


-- List fields withouth id
db.movies.find( {trilogy: "Transformers"}, { _id: 0, codigo: 1, sequence: 1, year: 1 })


-- Concat Trilogy - Sequence
db.movies.find({trilogy: "Transformers"},{ _id: 0, codigo: 1, year: 1, name: {$concat: ["$trilogy"," - ","$sequence"]} })


-- List rows with codigo are between 5 and 12
db.movies.find({ codigo: { $gt: 5, $lt: 12 } },{ _id: 0, codigo: 1, year: 1, name: {$concat: ["$trilogy"," - ","$sequence"]} })


-- List rows with codigo are between 5 and 12 and Trilogy="Transformers"
db.movies.find({ codigo: { $gt: 5, $lt: 12 }, trilogy: "Transformers"},{ _id: 0, codigo: 1, year: 1, name: {$concat: ["$trilogy"," - ","$sequence"]} })


-- List rows with codigo are between 5 and 12 and Sort - Year Desc, Name Asc
db.movies.find({ codigo: { $gt: 5, $lt: 12 } },{ _id: 0, codigo: 1, year: 1, name: {$concat: ["$trilogy"," - ","$sequence"]} }).sort({"year": -1, "name": 1 })


That's all folks!!!

Yes, the reading operations are easy!!! 

I hope that it helps you!!!

Regards
Mario 

quinta-feira, 24 de novembro de 2022

[MongoDB] - Logical Structures and basic create operations (or "C" from CRUD)

Hello all

Today, we talk about Logical Structures in MongoDB and how do you insert one or many register into a collection.

But first, we need to understand what a database is, a collection, a document and a field in MongoDB.

For example, one database can have many collections. A collection can have many documents, and documents can have fields. It's easy :) 

As the glossary definitions:

Database
A physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.

Collection
A grouping of MongoDB documents. A collection is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection have a similar or related purpose. 

Document
A record in a MongoDB collection and the basic unit of data in MongoDB. Documents are analogous to JSON objects but exist in the database in a more type-rich format known as BSON.

Documents have the following restrictions on field names:
  • The field name _id is reserved for use as a primary key; its value must be unique in the collection, is immutable, and may be of any type other than an array. If the _id contains subfields, the subfield names cannot begin with a ($) symbol.
  • Field names cannot contain the null character.
  • The server permits storage of field names that contain dots (.) and dollar signs ($). MongoDB 5.0 adds improved support for the use of ($) and (.) in field names. There are some restrictions. 
Field
A name-value pair in a document. A document has zero or more fields. Fields are analogous to columns in relational databases. 

Ok, it's easy. Now, we'll create a new database, a new collection and insert the first documents on the collection. Of course, we'll list the documents.

View all databases
show dbs
show databases





Create new database or switch database 
use thordb

View current Database
db

Show all collections in database
show collections

Create collection call movies
db.createCollection('movies')

As soon as possible, we'll have a post just talking about Create Collections.









Insert a single row
db.movies.insertOne({codigo: 1, trilogy: "Harry Potter", sequence: "The Philosophers Stone", year: "2001"})







Insert many rows
db.movies.insertMany ([
{codigo: 2, trilogy: "Harry Potter", sequence: "Harry Potter and the Chamber of Secrets", year: "2002"},
{codigo: 3, trilogy: "Harry Potter", sequence: "Harry Potter and the Prisoner of Azkaban", year: "2004"},
{codigo: 4, trilogy: "Harry Potter", sequence: "Harry Potter and the Goblet of Fire", year: "2005"},
{codigo: 5, trilogy: "Harry Potter", sequence: "Harry Potter and the Order of the Phoenix", year: "2007"},
{codigo: 6, trilogy: "Transformers", sequence: "Transformers: Dark of the Moon", year: "2011"},
{codigo: 7, trilogy: "Transformers", sequence: "Transformers: Age of Extinction", year: "2014"},
{codigo: 8, trilogy: "Transformers", sequence: "Transformers: The Last Knight", year: "2017"},
{codigo: 9, trilogy: "Harry Potter", sequence: "Harry Potter and the Half-Blood Prince", year: "2009"},
{codigo: 10, trilogy: "Harry Potter", sequence: "Harry Potter and the Deathly Hallows P1", year: "2010"},
{codigo: 11, trilogy: "Transformers", sequence: "Transformers: Revenge of the Fallen", year: "2009"},
{codigo: 12, trilogy: "Harry Potter", sequence: "Harry Potter and the Deathly Hallows P2", year: "2011"},
{codigo: 13, trilogy: "Transformers", sequence: "Transformers", year: "2007"},
{codigo: 14, trilogy: "Transformers", sequence: "Bumblebee", year: "2018"},
{codigo: 15, trilogy: "Harry Potter", sequence: "Fantastic Beasts and Where to Find Them", year: "2016"}
])



















Show all rows in a collection 
db.movies.find()




























Yes baby, today you learned the basic about the "C" or "Create Operations" from CRUD in MongoDB.

That's it. As I said, it was easy. The basic always is easy!!!

On next posts, we'll learn about the "R" or "Read Operations" and we'll learn about array operations. 

I hope that it helps you.

Regards 
Mario

Previous articles:

Postagem em destaque

[ORACLE] Useful scripts for the day-to-day life of a DBA (Part 3) - System metrics

Hello everyone.   Hope you're doing well! As I said here , I've created a repository on GITHUB to share some scripts that I like t...