Author: alien

  • Khóa học miễn phí Apache Derby – Create Table nhận dự án làm có lương

    Apache Derby – Create Table



    The CREATE TABLE statement is used for creating a new table in Derby database.

    Syntax

    Following is the syntax of the CREATE statement.

    CREATE TABLE table_name (
       column_name1 column_data_type1 constraint (optional),
       column_name2 column_data_type2 constraint (optional),
       column_name3 column_data_type3 constraint (optional)
    );
    

    Another way to create a table in Apache Derby is that you can specify the column names and data types using a query. The syntax for this is given below −

    CREATE TABLE table_name AS SELECT * FROM desired_table WITH NO DATA;
    

    Example

    The following SQL statement creates a table named Student with four columns, where id is the primary key and it is auto generated.

    ij> CREATE TABLE Student (
       Id INT NOT NULL GENERATED ALWAYS AS IDENTITY,
       Age INT NOT NULL,
       First_Name VARCHAR(255),
       last_name VARCHAR(255),
       PRIMARY KEY (Id)
    );
    > > > > > > > 0 rows inserted/updated/deleted
    

    The DESCRIBE command describes specified table by listing the columns and their details, if the table exists. You can use this command to verify if the table is created.

    ij> DESCRIBE Student;
    COLUMN_NAME |TYPE_NAME |DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
    ------------------------------------------------------------------------------
    ID |INTEGER |0 |10 |10 |AUTOINCRE&|NULL |NO
    AGE |INTEGER |0 |10 |10 |NULL |NULL |NO
    FIRST_NAME |VARCHAR |NULL|NULL|255 |NULL |510 |YES
    LAST_NAME |VARCHAR |NULL|NULL|255 |NULL |510 |YES
    4 rows selected
    

    Create a Table using JDBC Program

    This section teaches you how to create a table in Apache Derby database using JDBC application.

    If you want to request the Derby network server using network client, make sure that the server is up and running. The class name for the Network client driver is org.apache.derby.jdbc.ClientDriver and the URL is jdbc:derby://localhost:1527/DATABASE_NAME;create=true;user=USER_NAME;passw ord=PASSWORD”.

    Follow the steps given below to create a table in Apache Derby −

    Step 1: Register the driver

    To communicate with the database, first of all, you need to register the driver. The forName() method of the class, Class accepts a String value representing a class name loads it in to the memory, which automatically registers it. Register the driver using this method.

    Step 2: Get the connection

    In general, the first step we do to communicate to the database is to connect with it. The Connection class represents the physical connection with a database server. You can create a connection object by invoking the getConnection() method of the DriverManager class. Create a connection using this method.

    Step 3: Create a statement object

    You need to create a Statement or PreparedStatement or, CallableStatement objects to send SQL statements to the database. You can create these using the methods createStatement(), prepareStatement() and, prepareCall() respectively. Create either of these objects using the appropriate method.

    Step 4: Execute the query

    After creating a statement, you need to execute it. The Statement class provides various methods to execute a query like the execute() method to execute a statement that returns more than one result set. The executeUpdate() method executes queries like INSERT, UPDATE, DELETE. The executeQuery() method to results that returns data etc. Use either of these methods and execute the statement created previously.

    Example

    Following JDBC example demonstrates how to create a table in Apache Derby using JDBC program. Here, we are connecting to a database named sampleDB (will create if it does not exist) using the embedded driver.

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class CreateTable {
       public static void main(String args[]) throws Exception {
          //Registering the driver
          Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
          //Getting the Connection object
          String URL = "jdbc:derby:sampleDB;create=true";
          Connection conn = DriverManager.getConnection(URL);
    
          //Creating the Statement object
          Statement stmt = conn.createStatement();
    
          //Executing the query
          String query = "CREATE TABLE Employees( "
             + "Id INT NOT NULL GENERATED ALWAYS AS IDENTITY, "
             + "Name VARCHAR(255), "
             + "Salary INT NOT NULL, "
             + "Location VARCHAR(255), "
             + "PRIMARY KEY (Id))";
             stmt.execute(query);
             System.out.println("Table created");
       }
    }
    

    Output

    On executing the above program, you will get the following output

    Table created
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Apache Derby – Tools nhận dự án làm có lương

    Apache Derby – Tools



    Apache Derby provides you tools such as sysinfo, ij and, dblook.

    sysinfo tool

    Using this tool, you can get information about Java and Derby environment.

    Browse through the bin folder of Derby installation directory and execute the sysinfo command as shown below −

    C:UsersMY_USER>cd %DERBY_HOME%/bin
    C:Derbybin>sysinfo
    

    On executing, it gives you system information about java and derby as given below −

    ------------------ Java Information ------------------
    Java Version: 1.8.0_101
    Java Vendor: Oracle Corporation
    Java home: C:Program FilesJavajdk1.8.0_101jre
    Java classpath: C:UsersTutorialspointGoogle
    DriveOfficeDerbyderby_zipNew folderdb-derby-10.12.1.1-
    binlib;C:EXAMPLES_Taskjars*;C:EXAMPLESjarsmysql-connector-java-5.1.40-
    bin.jar;C:UsersTutorialspointGoogle DriveOffice37.Junit
    Updatejars;C:Program FilesApache Software FoundationTomcat
    8.5lib*;C:Derbylibderby.jar;C:Derbylibderbyclient.jar;C:Derbylibderb
    yLocale_cs.jar;C:DerbylibderbyLocale_de_DE.jar;C:DerbylibderbyLocale_es.j
    ar;C:DerbylibderbyLocale_fr.jar;C:DerbylibderbyLocale_hu.jar;C:Derbylib
    derbyLocale_it.jar;C:DerbylibderbyLocale_ja_JP.jar;C:DerbylibderbyLocale
    _ko_KR.jar;C:DerbylibderbyLocale_pl.jar;C:DerbylibderbyLocale_pt_BR.jar;C
    :DerbylibderbyLocale_ru.jar;C:DerbylibderbyLocale_zh_CN.jar;C:Derbylib
    derbyLocale_zh_TW.jar;C:Derbylibderbynet.jar;C:Derbylibderbyoptionaltools
    .jar;C:Derbylibderbyrun.jar;C:Derbylibderbytools.jar;;C:Derby/lib/derby.
    jar;C:Derby/lib/derbynet.jar;C:Derby/lib/derbyclient.jar;C:Derby/lib/derbyto
    ols.jar;C:Derby/lib/derbyoptionaltools.jar
    OS name: Windows 10
    OS architecture: amd64
    OS version: 10.0
    Java user name: Tutorialspoint
    Java user home: C:UsersTutorialspoint
    Java user dir: C:Derbybin
    java.specification.name: Java Platform API Specification
    java.specification.version: 1.8
    java.runtime.version: 1.8.0_101-b13
    --------- Derby Information --------
    [C:Derbylibderby.jar] 10.14.2.0 - (1828579)
    [C:Derbylibderbytools.jar] 10.14.2.0 - (1828579)
    [C:Derbylibderbynet.jar] 10.14.2.0 - (1828579)
    [C:Derbylibderbyclient.jar] 10.14.2.0 - (1828579)
    [C:Derbylibderbyoptionaltools.jar] 10.14.2.0 - (1828579)
    ------------------------------------------------------
    ----------------- Locale Information -----------------
    Current Locale : [English/United States [en_US]]
    Found support for locale: [cs]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [de_DE]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [es]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [fr]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [hu]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [it]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [ja_JP]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [ko_KR]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [pl]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [pt_BR]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [ru]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [zh_CN]
     version: 10.14.2.0 - (1828579)
    Found support for locale: [zh_TW]
     version: 10.14.2.0 - (1828579)
    ------------------------------------------------------
    ------------------------------------------------------
    

    ijtool

    Using this tool, you can run scripts and queries of apache Derby.

    Browse through the bin folder of Derby installation directory and execute the ij command as shown below −

    C:UsersMY_USER>cd %DERBY_HOME%/bin
    C:Derbybin>ij
    

    This will give you ij shell where you can execute derby command and scripts, as shown below −

    ij version 10.14
    ij>
    

    Using help command, you can get the list of commands supported by this shell.

    C:Derbybin>cd %DERBY_HOME%/bin
    C:Derbybin>ij
    ij version 10.14
    ij> help;
    Supported commands include:
     PROTOCOL ''JDBC protocol'' [ AS ident ];
     -- sets a default or named protocol
     DRIVER ''class for driver -- loads the named class
     CONNECT ''url for database'' [ PROTOCOL namedProtocol ] [ AS connectionName ];
     -- connects to database URL
     -- and may assign identifier
     SET CONNECTION connectionName; -- switches to the specified connection
     SHOW CONNECTIONS; -- lists all connections
     AUTOCOMMIT [ ON | OFF ]; -- sets autocommit mode for the connection
     DISCONNECT [ CURRENT | connectionName | ALL ];
     -- drop current, named, or all connections;
    -- the default is CURRENT
     SHOW SCHEMAS; -- lists all schemas in the current database
     SHOW [ TABLES | VIEWS | PROCEDURES | FUNCTIONS | SYNONYMS ] { IN schema };
     -- lists tables, views, procedures, functions or
    synonyms
     SHOW INDEXES { IN schema | FROM table };
     -- lists indexes in a schema, or for a table
     SHOW ROLES; -- lists all defined roles in the database,
    sorted
     SHOW ENABLED_ROLES; -- lists the enabled roles for the current
     -- connection (to see current role use
     -- VALUES CURRENT_ROLE), sorted
     SHOW SETTABLE_ROLES; -- lists the roles which can be set for the
     -- current connection, sorted
     DESCRIBE name; -- lists columns in the named table
     COMMIT; -- commits the current transaction
     ROLLBACK; -- rolls back the current transaction
     PREPARE name AS ''SQL-J text -- prepares the SQL-J text
     EXECUTE { name | ''SQL-J text'' } [ USING { name | ''SQL-J text'' } ] ;
     -- executes the statement with parameter
    -- values from the USING result set row
     REMOVE name; -- removes the named previously prepared
    statement
     RUN ''filename -- run commands from the named file
     ELAPSEDTIME [ ON | OFF ]; -- sets elapsed time mode for ij
     MAXIMUMDISPLAYWIDTH integerValue;
     -- sets the maximum display width for
    -- each column to integerValue
     ASYNC name ''SQL-J text -- run the command in another thread
     WAIT FOR name; -- wait for result of ASYNC''d command
     HOLDFORCONNECTION; -- sets holdability for a connection to HOLD
     -- (i.e. ResultSet.HOLD_CURSORS_OVER_COMMIT)
     NOHOLDFORCONNECTION; -- sets holdability for a connection to NO HOLD
     -- (i.e. ResultSet.CLOSE_CURSORS_AT_COMMIT)
     GET [SCROLL INSENSITIVE] [WITH { HOLD | NOHOLD }] CURSOR name AS ''SQL-J
    query
     -- gets a cursor (JDBC result set) on the query
    -- the default is a forward-only cursor with
    holdability
     NEXT name; -- gets the next row from the named cursor
     FIRST name; -- gets the first row from the named scroll
    cursor
     LAST name; -- gets the last row from the named scroll
    cursor
     PREVIOUS name; -- gets the previous row from the named scroll
    cursor
     ABSOLUTE integer name; -- positions the named scroll cursor at the
    absolute row number
     -- (A negative number denotes position from the
    last row.)
     RELATIVE integer name; -- positions the named scroll cursor relative to
    the current row
     -- (integer is number of rows)
     AFTER LAST name; -- positions the named scroll cursor after the
    last row
     BEFORE FIRST name; -- positions the named scroll cursor before the
    first row
     GETCURRENTROWNUMBER name; -- returns the row number for the current
    position of the named scroll cursor
     -- (0 is returned when the cursor is not
    positioned on a row.)
     CLOSE name; -- closes the named cursor
     LOCALIZEDDISPLAY [ ON | OFF ];
     -- controls locale sensitive data representation
     EXIT; -- exits ij
     HELP; -- shows this message
    Any unrecognized commands are treated as potential SQL-J commands and executed
    directly.
    

    dblooktool

    This tool is used to generate Data Definition Language.

    Browse through the bin folder of Derby installation directory and execute the dblook command as shown below −

    C:UsersMY_USER>cd %DERBY_HOME%/bin
    C:Derbybin>dblook -d myURL
    

    Where, myURL is the connection URL of the database for which you need to generate DDL.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Apache Derby – Introduction nhận dự án làm có lương

    Apache Derby – Introduction



    Apache Derby is a Relational Database Management System which is fully based on (written/implemented in) Java programming language. It is an open source database developed by Apache Software Foundation.

    Oracle released the equivalent of Apache Derby with the name JavaDB.

    Features of Apache Derby

    Following are the notable features of Derby database −

    • Platform independent − Derby uses on-disc database format where the databases in it are stored in a file in the disc within the directory with the same name as the database.

    • No modifying data − Because of this, you can move derby databases to other machines without modifying the data.

    • Transactional support − Derby provides complete support for transactions ensuring data integrity.

    • Including databases − You can include pre-build/existing databases into your current derby applications.

    • Less space − Derby database has a small footprint, i.e., it occupies less space and it is easy to use and deploy it.

    • Embed with Java Application − Derby provides an embedded database engine which can be embedded in to Java applications and it will be run in the same JVM as the application. Simply loading the driver starts the database and it stops with the applications.

    Limitations of Apache Derby

    Following are the limitations of Apache Derby −

    • Derby does not support indexes for datatypes such as BLOB and LONGVARCHAR.

    • If Derby does not have enough disc space, it will shut down immediately.

    Data storage

    While storing data, Apache Derby follows a concept known as conglomerate. In this, data of a table will be stored in a separate file. In the same way, each index of a table is also stored in a separate file. Thus, there will be a separate file for every table or index in the database.

    Apache Derby Library/Components

    Apache Derby distribution provides various components. In the lib folder of the apache distribution you have downloaded, you can observe jar files representing various components.

    Jar file Component Description
    derby.jar Database Engine and JDBC driver

    The Database engine of Apache Derby is an embedded relational database engine which supports JDBC and SQL API’s.

    This also acts as embedded Driver, using which you can communicate to Derby using Java applications.

    derbynet.jar derbyrun.jar Network server

    The Network Sever of Apache Derby provides the client server functionality, where the clients can connect to the Derby server through a network.

    derbyclient.jar Network client JDBC driver
    derbytools.jar Command line tools This jar file holds tools such as sysinfo, ij, and dblook.
    derbyoptionaltools.jar Optional command line utilities (tools)

    This jar file provides optional tools: databaseMetaData optional tool, foreignViews optional tool, luceneSupport optional tool, rawDBReader optional tool, simpleJson optional tool, etc

    derbyLocale_XX.jar Jar files to localize messages

    In addition to the above mentioned jar files, you can see several derbyLocale_XX.jar (es, fr, hu, it, ja, etc.). Using these, you can localize the messages of Apache Derby.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – DB Access Control nhận dự án làm có lương

    Amazon RDS – DB Access Control



    To access the Amazon RDS DB instance the user needs specific permissions. This is configured using AWS IAM (Identity and Access management). In this tutorial we will see how this configuration is done.

    The configuration involves two parts.

    • Authentication

    • Access Control

    Authentication

    It involves creating the username, password and generating the access keys for the user. With help of access key, it is possible to make programmatic access to the AWS RDS service. The SDK and CLI tools use the access keys to cryptographically sign in with the request.

    We can aslo use an IAM Role to authenticate a user. But the role is not attached to any specific user, rather any user can assume the role temporarily and complete the required task. After the task is over the role can be revoked and the user loses the authentication ability.

    Access Control

    After a user is authenticated, a policy attached to that user determines the type of tasks the uer can carry on. Below is an example of policy which allows the creation of a RDS DB instance, on a t2.micro instance for the DB Engine MySQL.

    {
        "Version": "2018-09-11",
        "Statement": [
            {
                "Sid": "AllowCreateDBInstanceOnly",
                "Effect": "Allow",
                "Action": [
                    "rds:CreateDBInstance"
                ],
                "Resource": [
                    "arn:aws:rds:*:123456789012:db:test*",
                    "arn:aws:rds:*:123456789012:og:default*",
                    "arn:aws:rds:*:123456789012:pg:default*",
                    "arn:aws:rds:*:123456789012:subgrp:default"
                ],
                "Condition": {
                    "StringEquals": {
                        "rds:DatabaseEngine": "mysql",
                        "rds:DatabaseClass": "db.t2.micro"
                    }
                }
            }
        ]
    }
    

    Action on Any RDS Resource

    In the below example we see a policy that allows any describe action on any RDS resource. The * symbol is used to represent any resource.

    {
       "Version":"2012-10-17",
       "Statement":[
          {
             "Sid":"AllowRDSDescribe",
             "Effect":"Allow",
             "Action":"rds:Describe*",
             "Resource":"*"
          }
       ]
    }
    

    Disallow deleting a DB Instance

    The below policy disallows a user from deleting a specific DB instance.

    {
       "Version":"2012-10-17",
       "Statement":[
          {
             "Sid":"DenyDelete1",
             "Effect":"Deny",
             "Action":"rds:DeleteDBInstance",
             "Resource":"arn:aws:rds:us-west-2:123456789012:db:my-mysql-instance"
          }
       ]
    }
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – Event Notifications nhận dự án làm có lương

    Amazon RDS – Event Notifications



    Throughout the life cycle of amazon RDS DB instances, many DB events occur which are important to be known beforehand. For example – A backup of the DB instance has started, or an error has occurred while restarting MySQL or MariaDB.

    Notification Categories

    Based on the nature of the event, notifications can be classified into following categories.

    Category Example
    Availability DB instance is restarting or undergoing controlled shutdown Backup backup of the DB instance has started, or it is complete Configuration change The DB instance class for this DB instance is being changed or it is being converted to a Single-AZ DB instance. Failover The instance has recovered from a partial failover. Failure The DB instance has failed due to an incompatible configuration Notification Patching of the DB instance has completed Recovery Recovery of the DB instance is complete Restoration The DB instance has been restored from a DB snapshot

    Creating Event Notifications

    Below are the steps to create event subscriptions through which the notifications are sent to the subscriber.

    Step-1

    Choose the Event subscription tab from the RDS dashboard.

    Step-2

    We give a name to the event and choose the subscription source.

    event_subs_1.JPG

    Now choosing the source.

    event_subs_2.JPG

    Step-3

    In the next step we see the details of the source type of a subscription type chosen for the event.

    event_subs_3.JPG

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – Multi-AZ Deployments nhận dự án làm có lương

    Amazon RDS – Multi-AZ Deployments



    In a Multi-AZ deployment, Amazon RDS automatically provisions and maintains a synchronous standby replica in a different Availability Zone. The primary DB instance is synchronously replicated across Availability Zones to a standby replica to provide data redundancy, eliminate I/O freezes, and minimize latency spikes during system backups. Running a DB instance with high availability can enhance availability during planned system maintenance and help protect your databases against DB instance failure and Availability Zone disruption.

     amazon_multi_az.JPG

    Creating Multi-AZ deployment

    You can choose the option of selecting a multi-AZ deployment when creating a DB instance or you can also choose the option of modifying an existing db instance to become a multi-AZ DB instance. The following diagram shows the option where we are modifying an existing option. But the same option is also available during the creation of the DB instance.

     amazon_multi_az2.JPG

    How Multi-AZ works

    In the event of a planned or unplanned outage of your DB instance, Amazon RDS automatically switches to a standby replica in another Availability Zone if you have enabled Multi-AZ. The time it takes for the failover to complete depends on the database activity and other conditions at the time the primary DB instance became unavailable. Failover times are typically 60-120 seconds. However, large transactions or a lengthy recovery process can increase failover time.

    Multi-AZ deployments for Oracle, PostgreSQL, MySQL, and MariaDB DB instances use Amazon”s failover technology. SQL Server DB instances use SQL Server Mirroring.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – DB Snapshots nhận dự án làm có lương

    Amazon RDS – DB Snapshots



    Amazon RDS creates automated backups of your DB instance during the backup window of your DB instance and stores them as volume snapshots.

    Automated Backup

    For Automated backup to work properly, followings are the criteria.
    • Your DB instance must be in the ACTIVE state for automated backups to occur. Automated backups don”t occur while your DB instance is in a state other than ACTIVE, for example STORAGE_FULL.

    • Automated backups and automated snapshots don”t occur while a copy is executing in the same region for the same DB instance.

    The first snapshot of a DB instance contains the data for the full DB instance. Subsequent snapshots of the same DB instance are incremental, which means that only the data that has changed after your most recent snapshot is saved.

    The following diagram shows how we can configure the automated backup window for a DB instance using the AWS console. To disable the automated backup, set the number of days to zero.

     snapshot_1.JPG

    Manual Backup

    We can also take backups manually by using snapshots. To take a snapshot manually we use the instance action option after selecting the instance as shown below.

     snapshot_2.JPG

    We can aslo take manual backup using the CLI with the below command.

    aws rds create-db-snapshot /
        --db-instance-identifier sourcedbinstance /
        --db-snapshot-identifier dbsnapshotinstance
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – DB Monitoring nhận dự án làm có lương

    Amazon RDS – DB Monitoring



    In order to maintain the reliability, availability, and performance of Amazon RDS, we need to collect monitoring data so that we can easily debug a multi-point failure. With Amazon RDS, you can monitor network throughput, I/O for read, write, and/or metadata operations, client connections, and burst credit balances for your DB instances. We should also consider storing historical monitoring data. This stored data will give you a baseline to compare against with current performance data.

    Below are examples of some monitoring data and how they help in maintaining healthy RDS instances.

    • High CPU or RAM consumption – High values for CPU or RAM consumption might be appropriate, provided that they are in keeping with your goals for your application (like throughput or concurrency) and are expected.

    • Disk space consumption – Investigate disk space consumption if space used is consistently at or above 85 percent of the total disk space. See if it is possible to delete data from the instance or archive data to a different system to free up space.

    • Network traffic – For network traffic, talk with your system administrator to understand what expected throughput is for your domain network and Internet connection. Investigate network traffic if throughput is consistently lower than expected.

    • Database connections – Consider constraining database connections if you see high numbers of user connections in conjunction with decreases in instance performance and response time.

    • IOPS metrics – The expected values for IOPS metrics depend on disk specification and server configuration, so use your baseline to know what is typical. Investigate if values are consistently different than your baseline. For best IOPS performance, make sure your typical working set will fit into memory to minimize read and write operations.

    Monitoring with Amazon CloudWatch

    Amazon RDS sends metrics and dimensions to Amazon CloudWatch every minute. We can monitor these metrices from the AWS console as shown in the below diagrams.

     monitoring_matrices.jpg

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – MySQL DBA Tasks nhận dự án làm có lương

    Amazon RDS – MySQL DBA Tasks



    As with every other database, Amazon RDS MYSQL also needs DBA tasks to fine tune the database and do periodic health checks etc. But as the AWS platform does not allow the shell access to the DB, there are a limited number of DBA tasks that can be performed as compared to the on-premise installation of MySQL. Below is a list of common DBA tasks that can be performed in AWS RDS MySQL database and their descriptions.

    Accessing Error Logs

    The MySQL error log ( mysql-error.log) file can be viewed by using the Amazon RDS console or by retrieving the log using the Amazon RDS CLI. mysql-error.log is flushed every 5 minutes, and its contents are appended to mysql-error-running.log. The mysql-error-running.log file is then rotated every hour and the hourly files generated during the last 24 hours are retained.

    Using RDS Console

    Below there are links to two log files described above.

     mysql_rds_log1.JPG

    Using CLI

    Using CLI the log files are published to CloudWatch Logs as a JSON Object.

    aws rds modify-db-instance
        --db-instance-identifier mydbinstance
        --cloudwatch-logs-export-configuration ''{"EnableLogTypes":["audit","error","general","slowquery"]}''
        --apply-immediately
    
    

    Killing a Long Running Session or Query

    Sometimes the DBA needs to kill a long running session or query which is not giving the result quick enough. This DBA task is done by first finding the process ID of the query and then using a RDS function to kill the query. The below commands are the examples.

    # get the ID
    Select * from INFORMATION_SCHEMA.PROCESSLIST
    #Apply the Kill Function
    CALL mysql.rds_kill(processID);
    

    Improve Crash recovery Time

    We can improve the recovery time from a crash by setting a DB parameter called innodb_file_per_table. We can find this parameter in the RDS console as shown below.

     mysql_DBA_parameters.JPG

    Next we can Search for the parameter name as shown below.

    mysql_innodb_file_param.JPG

    Amazon RDS sets the default value for innodb_file_per_table parameter to 1, which allows you to drop individual InnoDB tables and reclaim storage used by those tables for the DB instance. This speeds up the recovery time from the crash.

    Stop and Reboot DB

    Stopping a DB, Rebooting it or creating snapshots etc can be done easily through RDS console as shown in the below diagram.

    mysql_db_stop_reboot.JPG

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Amazon RDS – MySQL Features nhận dự án làm có lương

    Amazon RDS – MySQL Features



    MySQL is a popular Relational DB which is available in the amazon RDS services with its community edition features. Almost every feature of MYSQL can be leveraged in the RDS platform with only some restrictions based on regions and availability zones. Below is a brief description on MYSQLs major features in the RDS platform.Supported Versions

    The versions 5.5, 5.6 and 5.7 are the major versions supported in the RDS platform. Except for 5.6.27 all versions are supported in all AWS regions. If no version is mentioned during the DB creation, it defaults to the most recent version at that point in time. Below is an example of how to get all supported DB Engine versions using AWS API in a python SDK program.

    import boto3
    
    client = boto3.client(''rds'')
    
    response = client.describe_db_engine_versions(
        DBParameterGroupFamily=''mysql5.6'',
        DefaultOnly=True,
        Engine=''mysql'',
        EngineVersion=''5.6'',
        ListSupportedCharacterSets=True,
    )
    
    print(response)
    
    

    When the above code is run we get an output as below −

    {
       "ResponseMetadata": {},
       "DBEngineVersions''": [
          {
             "Engine''": "mysql",
             "DBParameterGroupFamily''": "mysql5.6",
             "SupportsLogExportsToCloudwatchLogs''": true,
             "SupportedCharacterSets''": [],
             "SupportsReadReplica''": true,
             "DBEngineDescription''": "MySQL Community Edition",
             "EngineVersion''": "5.6.40",
             "DBEngineVersionDescription''": "MySQL 5.6.40",
             "ExportableLogTypes''": [
                "audit",
                "error",
                "general",
                "slowquery"
             ],
             "ValidUpgradeTarget''": [
                {
                   "Engine''": "mysql",
                   "IsMajorVersionUpgrade''": true,
                   "AutoUpgrade''": false,
                   "Description''": "MySQL 5.7.22",
                   "EngineVersion''": "5.7.22"
                }
             ]
          }
       ]
    }
    

    Version Upgrade

    There MySQL version number is maintained as MYSQL A.B.C. In this notation, A.B indicates the major version and C indicates the minor version. The upgrade approach is different between minor and major version upgrades.

    Minor Version Upgrade

    The DB instances are automatically upgraded to new minor versions when ever they are supported by Amazon RDS. This patching occurs during a schedules maintenance window which you can control. You can also manually upgrade to new versions if you prefer to turn off the automatic update.

    Major Version upgrade

    Major version upgrades are not available as automatic upgrade. It must be done by the account user manually by modifying the DB instance. Below flowchart indicated the steps in achieving the major version upgrade. This approach ensures that the upgrade process is thoroughly tested before it is applied on the live production database.

     mysqldbupgrade.JPG

    Database Security

    The security for RDS MYSQL DB is managed at three layers.

    Using IAM

    In this approach the IAM user should have appropriate policies and permissions. Granting of such permissions is decided by the account holder or the super user who grants these permissions.

    Using VPC

    You either use a VPC security group or DB security group to decide which EC2 instances can open connections to the endpoint and port of a DB instance. These connections can also be made using SSL.

    Using IAM Database Authentication

    In this approach you use a IAM role and an authentication token. The authentication token generates a unique value which is relevant to the IAM role that is used in the access process. Here the same set of credentials are used for database as well as other aws resources, like EC2 and S3 etc.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc