Lecture 8 Database Implementation Jeffery S. Horsburgh Hydroinformatics Fall 2012 This work was funded by National Science Foundation Grant EPS 1135482
Objectives Examine the features of a Relational Database Management System (RDBMS) Create a physical implementation of an Observations Data Model (ODM) database within a RDBMS Load observational data into an ODM database
What We have Talked About Data management and the data life cycle Metadata Information needed to describe observational data Data models and data model design How do you structure the data and metadata for storage and retrieval Google Fusion Tables and Excel Tools
Where We are Going Database implementation – TODAY!! How do you physically implement a data model and load data Using Structured Query Language (SQL) Using code to slice and dice your data Accessing databases from client software Getting data from a database into R
Relational Database Management Systems Robust software for managing data Data stored in tables that may be related Based on Structured Query Language (SQL) Adopted by the American National Standards Institute (ANSI) and the International Standards Organization (ISO) as the standard data access language
File Versus Server-Based RDBMS File-based Everything contained within a single file Generally good for single user, desktop applications Examples: SQLite, Microsoft Access Server-based A database “server” manages databases and all transactions Good for multiple, simultaneous connections and transactions Examples: Oracle, Microsoft SQL Server, MySQL, PostgreSQL
The Beauty of Server-Based RDBMS Yay! Database Server With RDBMS Authentication and Access Control I want some data! Do I recognize your IP address? Do I know you? Are you authorized? Database Data Firewall Simultaneous Data Users
Server-Based RDBMS – “Granules” Database Server Databases Tables Records DB1 DB2 DB3 DBn . . . Site Variable Date Value 1 Temperature 8/2/2007 14:00 12.4 8/2/2007 14:30 12.7 8/2/2007 15:00 13.1 1 Temperature 8/2/2007 14:00 12.4
Physical Implementation of a Data Model within a RDBMS Create a new database Create tables for entities Define attributes and data types Create relationships and define their properties Define constraints All of this can be scripted/automated using SQL
DEMO: Microsoft SQL Server and SQL Server Management Studio
CUAHSI HIS – Sharing Hydrologic Data The CUAHSI Hydrologic Information System (HIS) is an internet based system to support the sharing of hydrologic data. It is comprised of hydrologic databases and servers connected through web services as well as software for data publication, discovery and access. Data Discovery and Integration platform Data Publication platform Data Synthesis and Research platform Data Services Metadata Services Metadata Search HIS Central HydroDesktop HydroServer Service registration Catalog harvesting Service and data theme metadata Data carts Water Data Services Spatial Data Services Like search portals Google, Yahoo, Bing Like browsers Like web servers Like HTML
HydroServer Software Stack Observations Data Model (ODM) Relational database schema for hydrologic observations (store data) ODM Software Utilities ODM Data Loader (load table-based data) ODM Streaming Data Loader (load streaming data) ODM Tools (visualize and manage data) WaterOneFlow web services (publish data)
ILO-4 Database Implementation and Loading Data GOAL: Organize and load observational data for a continuous water quality monitoring site in the Little Bear River to an ODM database on the class server.
The Data You Will be Using 7 water quality and streamflow monitoring sites Temperature Dissolved Oxygen pH Specific Conductance Turbidity Water level/discharge 4 weather stations Relative Humidity Solar radiation Precipitation Barometric Pressure Wind speed and direction Soil moisture Spread spectrum radio telemetry network
Authentication and Access Control The Class HydroServer hydroserver.uwrl.usu.edu Authentication and Access Control Firewall ODM
DEMO: Create a blank ODM database in Microsoft SQL Server Download the ODM blank SQL Server schema Extract the SQL Server blank schema database to the SQL Server data directory Attach database to the SQL Server database engine
Authentication in SQL Server Windows Authentication Uses a Windows account to authenticate a user Users must have an account on the server SQL Server Authentication Specific to SQL Server Enables you to create accounts for SQL Server without giving access to the rest of the server
Authorization in SQL Server Assigning specific permissions to specific users for specific database objects
DEMO: Creating Database Users and Assigning Database Permissions in SQL Server
Load Data into the Database Load metadata using the ODM Data Loader Load observations using the ODM Streaming Data Loader Advantages of using the ODM Data Loaders Designed specifically for ODM Validate data against the business logic of ODM Protect the consistency of data and avoid errors
ODM Data Loading Strategy
ODM Data Loader Loading data to any table in ODM – e.g., Sites, Variables, Methods, etc. Loading Data Values in serial format Multiple sites and variables in one file All data values in a single column Site Variable Date Value 1 Temperature 8/2/2007 14:00 12.4 8/2/2007 14:30 12.7 8/2/2007 15:00 13.1 … Dissolved Oxygen 9.78 9.70 9.56 2 Specific Conductance 351.7 350 351.2
ODM Streaming Data Loader Focused on loading data values Crosstab data Single site, multiple variables Date in one column, each variable in one column Datalogger files from field sensors Date Variable_1 Variable_2 … Variable_n 8/2/2007 14:00 13.01298 1.155137 9.391667 8/2/2007 14:30 13.222 1.15333 9.586666 8/2/2007 15:00 13.19934 1.153291 9.75 8/2/2007 15:30 13.19094 1.153561 9.78 8/2/2007 16:00 13.17751 1.16075 9.703334
Visualize Data Using ODM Tools Connect to the database using a client software application Visualize and manage data using the software tools
DEMO: ODM Tools
What You Will Do for the ILO In your personal ODM database on the server Load Site, Variable, Method, and Source metadata using the ODM Data Loader Load sensor observations using the ODM Streaming Data Loader Visualize and explore the data using ODM Tools Evaluate ODM as a data management tool for sensor data from the Little Bear River experimental watershed