Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Monday, February 22, 2016

How to recover from disasters with Barman

Disaster recovery for PostgreSQL databases.
  1. Knowledge
    1. Barman is a database recovery tool.
  2. Strategy
    1. Install Barman with yum on the backup server.
    2. Verify the barman user has ssh access to the postgres user on the main server.
    3. Verify the postgres user has ssh access to the barman user on the backup server.
    4. Verify the barman user can connect to the database on the main server.
    5. Configure Barman with default settings, noting the incoming_wals_directory.
    6. Configure Barman to enable continuous WAL archiving.
    7. Restart the server.
    8. Test new backup and restore functionality.
  3. Execution

Friday, December 18, 2015

How to base data with PostgreSQL

The world's most advanced open source database.
  1. Knowledge
    1. PostgreSQL is an open-source database.
  2. Strategy
    1. Install on AWS EC2 Ubuntu.
    2. Configure the database.
    3. A example Python script is provided.
  3. Execution

Saturday, June 20, 2015

How to migrate from the MySQL Extension to PDO

My team's start-up has a web application that is currently using MySQLi Extensions.

Switching to PDO has many advantages:
  • offers a consistent API to work with a variety of databases
  • exposes high-level objects for the programmer to work with database connections
  • low-level drivers perform communication and resource handling with the database server

Basic Workflow

The basic workflow for working with a database can be thought of as a 5-step process:
  1. Establish a connection to the database server and select the database you’ll be working with
  2. Construct a query to send the server
  3. Send the query
  4. Iterate over the returned result rows
  5. Free the resources used by the result and possibly the database connection
With PDO, the same process can be followed and looks like this:

















<?php
// Step 1: Establish a connection
$db = new PDO("mysql:host=localhost;dbname=testdb", "testusr", "secretpass");
// Step 2: Construct a query
$query = "SELECT * FROM foo WHERE bar = " . $db->quote($zip);
// Step 3: Send the query
$result = $db->query($query);
// Step 4: Iterate over the results
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
    print_r($row);
}
// Step 5: Free used resources
$result->closeCursor();
$db = null;