Development notes

Thoughts, notes and ideas about development

Partitioning in Relational databases

Introduction Partitioning is a process of dividing a table into multiple smaller pieces, where each piece of such a database object is called a partition. This tutorial describes what is Partitioning and provided an example of Range partitioning in PostgreSQL database. Benefits of partitioning Query performance could be increased when: most of the heavily accessed rows of the table are in a single partition or a small number of partitions. Continue reading

Indexes into Relational Databases

A database index is a data structure that improves the speed of data retrieval operations on a database table (increase database performance). But such performance has a cost of additional writes to hard drive and storage space to maintain the index data structure. In nutshell, index is a quick path to a single row into database. Indexes allow us to go directly to he required column without scanning the entire database table. Continue reading

SQL Transactions and ACID

Transaction is a sequence of one or more SQL operations treated as a logical unit. Transaction could be completed either entirely successfully or not executed at all. Transactions and locking are important aspects of database for supporting multiple users. Into this tutorial we’ll take a look atTransaction, ACID, Isolation Levels. ACID Transaction must have the following properties called ACID, which means the following: Atomicity: means that transaction must happen as a single unit and exactly once. Continue reading

PostgreSQL functions

PostgreSQL has a lot of built-in functions, such as Trigonometric Functions, String Functions, IP address functions, etc. But we’re not limited by built-in functions. PostgreSQL (as well as other RDBMS) allows to create custom functions. In this tutorial we will take a look at user-defined functions. PostgreSQL supports the following programming languages for writing functions: SQL PL/pgSQL C PL/Python PL/Tcl some other languages Create functions with PL/pgSQL Functions written in PL/pgSQL can contain a variable declaration, conditional and looping constructions, exception handling and so on. Continue reading

PostgreSQL data types cheat sheet

In this tutorial I will show main PostgreSQL data types such as Boolean, Character, Number, Temporal. Also I will describe when and how we can use them. By the way, Postgres is not limited by the mentioned data types. It also supports such types like JSON, Monetary, Geometric, Network Addresses, etc. The full list of supported data types could be found here: Data Types Boolean Data Type The boolean type (could be shortened to bool) can store only 2 possible values true or false and NULLin case when value is unknown. Continue reading

SQL Data Definition Language for Database in PostgreSQL

As was described into my previous post SQL Commands Types cheat sheet Data Definition Language, or just DDL, is a set of commands for creating, deleting, renaming databases and tables. In this tutorial I will describe how to use DDL with databases(schemes). PostgreSQL will be used for demonstration. How to setup PostgreSQL (and PgAdmin3) on Ubuntu please refer to this tutorial: How to install PostgreSQL on Ubuntu 16.04 CREATE database CREATE DATABASE blog; PostgreSQL will create a database named blog with default parameters. Continue reading

SQL Commands Types cheat sheet

SQL language includes four types of command. In this tutorial I will describe them shortly. Data Definition Language (DDL) DDL is a set of commands for creating, deleting, renaming databases and tables. CREATE Creates a new database or a table. ALTER Modifies the structure of a database or a table. DROP Deletes a database or a table. TRUNCATE Removes all table records, including allocated table spaces. Data Manipulation Language (DML) DML is a set of commands for inserting, deleting, updating and selecting data from the database. Continue reading
Older posts