Sunday, June 14, 2020

Install Postgresql 12 on Linux Mint

Overview

Linux mint is a Linux distro based on a popular debian based Linux known as Ubuntu. One reason this Linux is popular, is that it fits on many older computers with lower end hardware specifications, and have support for a wide array of monitors. At the same time, this Linux supports many of the modern hardware drivers.

The current Linux Mint is version 19.3 with the code name "Tricia", is released on 18th December 2019. This is developed from Ubuntu version named Bionic. Among the features that one should know about Tricia includes:

  • It is a long term support (LTS) which means, patches will be maintained till 2023.
  • Installation of Linux Mint have better hardware detection and supports modern BIOS installation to utilise password at BIOS.
  • Include a movie player that utilises hardware optimisation.
  • Its Linux desktop environment called Cinnamon, is light weight enough for many lower spec computer. Computers with lower speed hard disk have always suffered in a windows environment, Cinnamon greatly improves any windows experience.
  • Higher level of security for those who are paranoid about PC security.

Postgresql 12

Among the world's most popular open sourced relational database management system (RDBMS) is Postgresql. Default installation will also create a database called postgres and a user with the same name, postgres. Installation comes with a separate application for the server, and a client. A tool, psql is to manage the server from the command line. There are many other applications that can manage Postgresql with a graphical point and click approach.

Version 12 is released on 3rd October 2019 with the following features:
  • Improved table indexing features. Such as rebuild index table without blocking writes to an index, and this reduces down time.
  • Partitioning of tables to improved queries from a limited set of data.
  • JSON document query support.
  • Just-in-time compilation to process large data (data warehouse) more efficiently.

Installation

Linux Mint 19.x by default installs Postgresql version 10. In order to install version 12, Linux Mint must have the latest packages installed to reduce chances of package dependency errors. These are summary of steps in order to install Postgresql version 12.

  1. Add Postgresql repository
  2. Update existing system
  3. Install Postgresql 12 server. This includes the server (postgresql-12) and client (postgresql-client-12) application.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/postgresql.list'
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt upgrade

sudo apt install postgresql-12


Once installed, it will prompt

pg_ctlcluster 12 main start

Following are among the files and locations at default install.

  • The database will be stored at /var/lib/postgresql/12/main
  • Logging information at /var/log/postgresql/postgresql-12-main.log
Documentation can be display with the command;

man postgresql

Accessing the server

Default installation includes the user postgres. Access the server using this user.

sudo -u postgres psql

Here are a list of psql commands to get you started.

Once in psql, here are several commands to browse the database;

Display server version (the Uppercase is a matter of good practice)
SELECT version();

List database schema
\l

Switch database schema
\c database_name

Describe a table
\d table_name

Get the last command
\g

Show history of commands
\s

Help with a command
\h command_name

Exit Postgresql client
\q

You can refer to previous posting "Create database and user" to further try the database.

* Install PHP 7.4 notes (not related to postgresql)
sudo apt-get install -y php7.4-{bcmath,bz2,intl,gd,mbstring,pgsql,zip}
sudo apt-get install -y php7.4-{curl,common,xml,xsl}

Friday, June 5, 2020

Install Tensorflow and Keras on Centos 7 Linux

Tensorflow (available in github) provides a version that utilise the GPU of a server to perform much more heavier computations. Tensorflow version 1.6 onwards are optimimsed to use AVX instructions that is not available in older CPUs. These versions are installed via pip, uses the AVX instruction set at compile time and require CPU that support the AVX instruction set. This instruction set is supported from the second generation of Intel Core CPUs (codenamed SandyBridge).

Pre-requisite: 
Centos 7 Linux updated
Installed Python (see previous posting)
Created a project directory called tensorflow

Default steps are to install Tensorflow 2.x (see tensorflow), but server environments that does not support AVX, they need to install Tensorflow 1.5 (see article and blog). To determine if AVX support is available, run the following command and look for AVX or AVX2.

more /proc/cpuinfo | grep flags

My output shows no AVX.
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni monitor ssse3 lahf_lm

Optional:
Configure the project directory for python:

python3 -m venv my_env

Step 1: Install Tensorflow (Or tensorflow-gpu)

cd tensorflow
source my_env/bin/activate

Install Tensorflow application, then print its version

pip install --upgrade tensorflow

Or for server that doesn't have AVX support,

pip install tensorflow==1.15

pip show tensorflow

Step 2: Test Tensorflow install

Create a script file hello.py with following contents;

import tensorflow as tf
hello = tf.constant('Hello, World')
session = tf.Session()
print( session.run(hello) )

Run the script

python hello.py

Step 3: Install Keras

pip install --upgrade scikit-learn pillow
pip install --upgrade keras keras-utils

Or for server that doesn't have AVX support,

pip install --upgrade scikit-learn pillow
pip install keras==2.1.6

pip show keras

Configuration file will be at ~/.keras/keras.conf
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}

Test install by editing hello.py

import tensorflow as tf
from tensorflow import keras
hello = tf.constant('Hello, World')
session = tf.Session()
print( session.run(hello) )


The above instructions are meant to provide the platform prior to my learning chatbot at site and colab.

Thursday, June 4, 2020

Install Python on Centos 7 Linux

Python is a programming language that can be used for:
  1. Back-end web application
  2. Desktop application
  3. Processing huge amount of data
  4. Control a computer
Example of a basic Python command:

print("Hello, world!")

Install Python

Pip is a tool to manage packages/libraries within Python. On Centos 7, the default pip is version 9.0.3 and it should be upgraded once python is installed.

Following are notes to install Python 3 on Centos 7 Linux. All these are at the command prompt.

sudo yum install python3  python3-devel

Check the installed version

python3 -V

Create directory for python projects

mkdir projects

cd projects

python3 -m venv my_env

Initiate the python project environment

source my_env/bin/activate

Create your first programme in a file called hello.py and save the following line.

print("Hello, World")

Run the programme.

python hello.py

Upgrade pip package manager.

pip install --upgrade pip

Once done with Python, leave the project environment.

deactivate


Extra pip example 

Install setuptools to install applications from source

pip install --upgrade setuptools wheel

Install Tensorflow application, then print its version

pip install --upgrade tensorflow
pip show tensorflow



Blog Archive