Thursday, September 19, 2013

Tuesday, September 10, 2013

Postgresql 9.3 and NoSQL Awesomeness on Fedora 19

Postgresql 9.3 was released yesterday. This document explains how to install postgresql 9.3 on Fedora 19 system and play with the built-in JSON support for the columns. (i.e the NOSQL Feature within a RDBMS database!)

1. Install Fedora 19 as you usually do

2. Setup PGDG Repository

[root@fallenangel ~]# yum install -y
oaded plugins: fastestmirror, langpacks, refresh-packagekit
pgdg-fedora93-9.3-1.noarch.rpm  | 5.1 kB  00:00:00     
Examining /var/tmp/yum-root-cjnqf8/pgdg-fedora93-9.3-1.noarch.rpm: pgdg-fedora93-9.3-1.noarch
Marking /var/tmp/yum-root-cjnqf8/pgdg-fedora93-9.3-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-fedora93.noarch 0:9.3-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
Total size: 2.1 k
Installed size: 2.1 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-fedora93-9.3-1.noarch         1/1 
  Verifying  : pgdg-fedora93-9.3-1.noarch                         1/1 

  pgdg-fedora93.noarch 0:9.3-1

3. Install postgresql-9.3
[root@fallenangel ~]# yum install postgresql93-server -y

4. Initialize the Postgresql database

[root@fallenangel ~]#  su - postgres
-bash-4.2$ env PGDATA=/var/lib/pgsql/9.3/data /usr/pgsql-9.3/bin/initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/pgsql/9.3/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/pgsql/9.3/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/9.3/data
    /usr/pgsql-9.3/bin/pg_ctl -D /var/lib/pgsql/9.3/data -l logfile start


5. Start the postgresql server

[root@fallenangel ~]# service postgresql-9.3 start
Redirecting to /bin/systemctl start  postgresql-9.3.service
[root@fallenangel ~]# 

6. Connect to the Server and create a test database

[root@fallenangel ~]# su - postgres
-bash-4.2$ createdb json

-bash-4.2$ psql json
psql (9.3.0)
Type "help" for help.

json=# create user json_user with password 'json_password';
json=# grant all privileges on database json to json_user;
json=# \q

7. Connect to the Server with newly created Username

[root@fallenangel ~]# psql -U json_user -d json
psql (9.3.0)
Type "help" for help.

8. Create a new table with JSON datatype in one of the columns

json=> create table "User" (
json(> id integer,
json(> details json
json(> );

json=> insert into "User" (id, details) values (1, '{"uuid":1234, "name":"John Doe", "email": "", "status":"active"}');

json=> insert into "User" (id, details) values (1, '{"uuid":1235, "name":"Tomcat", "email": "", "status":"active", "phones":["+1 800 700 500", "+1 400 300 200"]}');
9. Now the SQL Queries using NoSQL dataset

1. Get the list of all UUIDs (embedded inside `details` column)

json=> select details->'uuid' as "uuid" from "User";
(2 rows)

2. Get the list of all Emails from "User" table

json=> select details->'email' as "email" from "User";
(2 rows)

3. Get the First Phone number (from the array of phones) from "User" table

json=> select details->'name' as "name", details->'phones'->0 as "uuid" from "User";
  name  |       uuid       
 "John Doe" | 
 "Tomcat"   | "+1 800 700 500"
(2 rows)

Please be aware that JSON Implies UTF-8 Charset. There is no need to explicitly mention this.

More JSON functions in postgres-9.3 are available in this document.

LIMITATIONS: Currently, to update the column, we need to pass the entire json data instead of updating a single KEY inside JSON content.

For example, you might expect the following works, But it doesn't.

Update the 'name' key inside the json dataset.

json=> update "User" set details->'name' = 'John Doe II' where details->'name' = 'John Doe';

ERROR:  syntax error at or near "->"
LINE 1: update "User" set details->'name' = 'John Doe II' where deta..

It would be awesome if postgresql developers add such feature.

Friday, September 06, 2013

Installing Facebook's Hiphop "Kimchi" Release on Centos 6.x , RHEL 6.x

Facebook's hiphop changelog is updated for "Kimchi" release in github with the following list.

"Kimchi" 2-Sep-2013
  - Fix order of custom attributes and visibility in ctor arg promotion
  - Implement CachingIterator
  - Implement RecursiveCachingIterator
  - Generalized heuristic for choosing when to inline in the jit
  - Imported calendar extension
  - Use gcc-4.8.1 by default
  - Improve hhvm commandline parsing logic
  - Fix register_shutdown in session_set_save_handler to match PHP 5.4
  - Add "native" functions for use in Systemlib
  - PHP extension source-compatitblility layer
  - Fix ArrayIterator constructor PHP compatibility
  - Enable building against libmemcached 1.0.8
  - Debugger: $_ not cleared but still printed after exception
  - Fix clone of SplPriorityQueue
  - Debugger: Fix bugs when multiple threads hit the same breakpoint
  - Fix several namespace bugs
  - Several PHP compatibility fixes for ArrayObject and ArrayIterator
  - Fix list assignment with collection literals
  - support "tuple(...)" in initializer expressions
  - HHVM should compile with libmemcached 1.0.9+
  - Support "(new Vector {..})->method()" style syntax
  - use trigger_error in PHP for Redis user errors
  - multiple simplexml fixes
  - fixed serialize/unserialize for SplObjectStorage
  - Implement ReflectionParameter::IsCallable()

I have pushed a new package to the repository, Grab the package and test it out.

Major change from packaging point of view is the libmemcached version, which is upgraded to 1.0.16

Follow these steps to upgrade

1. Enable repository as mentioned before

2. Do a yum upgrade (or yum install)

yum install hiphop-php- -y
Resolving Dependencies
--> Running transaction check
---> Package hiphop-php.x86_64 0:2.1.210-4.el6 will be updated
---> Package hiphop-php.x86_64 0: will be an update
--> Processing Dependency: libmemcached >= 1.0.9 for package: hiphop-php-
--> Processing Dependency: for package: hiphop-php-
--> Running transaction check
---> Package libmemcached.x86_64 0:0.49-1.el6 will be updated
---> Package libmemcached.x86_64 0:1.0.16-1.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

 Package              Arch           Version                 Repository    Size
 hiphop-php           x86_64         hop5          19 M
Updating for dependencies:
 libmemcached         x86_64         1.0.16-1.el6            hop5         208 k

Transaction Summary
Upgrade       2 Package(s)

Total download size: 19 M
Downloading Packages:
Total                                           777 kB/s |  19 MB     00:24     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : libmemcached-1.0.16-1.el6.x86_64                             1/4 
  Updating   : hiphop-php-                            2/4 
  Cleanup    : hiphop-php-2.1.210-4.el6.x86_64                              3/4 
  Cleanup    : libmemcached-0.49-1.el6.x86_64                               4/4 
  Verifying  : hiphop-php-                            1/4 
  Verifying  : libmemcached-1.0.16-1.el6.x86_64                             2/4 
  Verifying  : hiphop-php-2.1.210-4.el6.x86_64                              3/4 
  Verifying  : libmemcached-0.49-1.el6.x86_64                               4/4 

  hiphop-php.x86_64 0:                                           

Dependency Updated:
  libmemcached.x86_64 0:1.0.16-1.el6                                            

3. See that new package is installed

bash-4.1# rpm -qa | grep hiphop-php
4. Check the hhvm version details

bash-4.1# /usr/bin/hhvm --version
HipHop VM v2.1.0-dev (rel)
Compiler: heads/master-0-g13ddbb4ec17cffeeaaa83940016e6811cd71b387
Repo schema: a40e2fdb7f3c4700ef306f956630f09cd1ba53e0
bash-4.1# cd /var/www && /usr/bin/hhvm index.php 
Hello world.
5. Have fun!

NOTE: Please be aware that, from facebook's point of view this is just a internal release in the 2.1.0-dev series.

Monday, September 02, 2013

Getting ready for the faster HHVM (hiphop php) version

UPDATE: Now you can install "Kimchi" release as of 6-Sep-2013 

HHVM (hiphop php) is getting ready for a faster version with the following changes

I have built a preview version as of Sep-1-2013, which can be easily installed on your system.

Steps to Upgrade from 2.1.0 on CentOS-6.x / RHEL-6.x

1. Make sure you have enabled repository as mentioned in this blog post.

2. Update hiphop-php

[nareshv@fallenangel ~]$ sudo yum install hiphop-php-
Total download size: 19 M
Is this ok [y/N]: y
Downloading Packages:
hiphop-php-                                                                                                                                          |  19 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : hiphop-php-   1/2 
  Cleanup    : hiphop-php-2.1.210-4.el6.x86_64     2/2 
  Verifying  : hiphop-php-   1/2 
  Verifying  : hiphop-php-2.1.210-4.el6.x86_64     2/2 

  hiphop-php.x86_64 0:                                                                                                                                                                 


3. Check the version of new Hiphop

[nareshv@fallenangel ~]$ /usr/bin/hhvm --version
HipHop VM v2.1.0-dev (rel)
Compiler: heads/master-0-ged8774975e0c017b8baf09d1547d769b26c5f278
Repo schema: d74c9a7e6b05d0018945a73ae5567bafa294f29d

NOTES:Be sure to test this preview release on your testing environment before using it on production.

Sunday, September 01, 2013

Installing version 0.6.1 on Centos / Fedora has released 0.6.1 version with the following changelog

If you have already installed on your centos/rhel system. Just do the upgrade with the following steps

Upgrading from 0.5.3 to 0.6.1

1. Make sure you have enabled repository as mentioned in previous post

2. Do a yum upgrade

yum update docker-io