Wednesday, November 07, 2012

Debian and raspberry pi = love , a small ARM Firebird super server

I have installed debian on my raspberry
here is the login and cpu info

ssh pi@192.168.1.104
pi@192.168.1.104's password: 
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

pi@raspberrypi ~ $ cat /proc/cpuinfo 
Processor : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : swp half thumb fastmult vfp edsp java tls 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7

Hardware : BCM2708
Revision : 000f
Serial  : 000000008c86c7c9

First thing i search in a debian is the firebird packages
 apt-cache search firebird
falconpl-dbi-firebird - Firebird SQL database abstraction layer for Falcon P.L
firebird-dev - Development files for Firebird - an RDBMS based on InterBase 6.0 code
firebird2.5-classic - Firebird Classic Server - an RDBMS based on InterBase 6.0 code
firebird2.5-classic-common - common files for firebird 2.5 "classic" and "superclassic"
firebird2.5-classic-dbg - collected debug symbols for firebird2.5-classic and -superclassic
firebird2.5-common - common files for firebird 2.5 servers and clients
firebird2.5-common-doc - copyright, licnesing and changelogs of firebird2.5
firebird2.5-doc - Documentation files for firebird database version 2.5
firebird2.5-examples - Examples for Firebird - an RDBMS based on InterBase 6.0 code
firebird2.5-server-common - common files for firebird 2.5 servers
firebird2.5-super - Firebird Super Server - an RDBMS based on InterBase 6.0 code
firebird2.5-super-dbg - collected debug symbols for firebird2.5-super
firebird2.5-superclassic - Firebird SuperClassic Server - an RDBMS based on InterBase 6.0 code
flamerobin - graphical database administration tool for Firebird DBMS
libdbd-firebird-perl - Perl DBI driver for Firebird RDBMS server
libdbi-perl - Perl Database Interface (DBI)
libfbclient2 - Firebird client library
libfbembed2.5 - Firebird embedded client/server library
libib-util - Firebird UDF support library
libwtdbofirebird-dev - Firebird backend for Wt::Dbo [development]
libwtdbofirebird32 - Firebird backend for Wt::Dbo [runtime]
php5-interbase - interbase/firebird module for php5

What is next ? installing firebird 2.5 super server of course
sudo apt-get install firebird2.5-super
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  firebird2.5-common firebird2.5-common-doc firebird2.5-server-common libfbclient2 libib-util
Suggested packages:
  firebird2.5-doc
The following NEW packages will be installed:
  firebird2.5-common firebird2.5-common-doc firebird2.5-server-common firebird2.5-super libfbclient2 libib-util
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,300 kB of archives.
After this operation, 12.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main firebird2.5-common-doc all 2.5.2~svn+54698.ds4-1 [636 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main firebird2.5-common all 2.5.2~svn+54698.ds4-1 [95.7 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libfbclient2 armhf 2.5.2~svn+54698.ds4-1 [223 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libib-util armhf 2.5.2~svn+54698.ds4-1 [3,814 B]
Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main firebird2.5-server-common armhf 2.5.2~svn+54698.ds4-1 [488 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main firebird2.5-super armhf 2.5.2~svn+54698.ds4-1 [1,853 kB]                             
Fetched 3,300 kB in 13s (238 kB/s)                                                                                                                  
Preconfiguring packages ...
Selecting previously unselected package firebird2.5-common-doc.
(Reading database ... 57783 files and directories currently installed.)
Unpacking firebird2.5-common-doc (from .../firebird2.5-common-doc_2.5.2~svn+54698.ds4-1_all.deb) ...
Selecting previously unselected package firebird2.5-common.
Unpacking firebird2.5-common (from .../firebird2.5-common_2.5.2~svn+54698.ds4-1_all.deb) ...
Selecting previously unselected package libfbclient2:armhf.
Unpacking libfbclient2:armhf (from .../libfbclient2_2.5.2~svn+54698.ds4-1_armhf.deb) ...
Selecting previously unselected package libib-util:armhf.
Unpacking libib-util:armhf (from .../libib-util_2.5.2~svn+54698.ds4-1_armhf.deb) ...
Selecting previously unselected package firebird2.5-server-common.
Unpacking firebird2.5-server-common (from .../firebird2.5-server-common_2.5.2~svn+54698.ds4-1_armhf.deb) ...
Selecting previously unselected package firebird2.5-super.
Unpacking firebird2.5-super (from .../firebird2.5-super_2.5.2~svn+54698.ds4-1_armhf.deb) ...
Processing triggers for man-db ...
Setting up firebird2.5-common-doc (2.5.2~svn+54698.ds4-1) ...
Setting up firebird2.5-common (2.5.2~svn+54698.ds4-1) ...
Setting up libfbclient2:armhf (2.5.2~svn+54698.ds4-1) ...
Setting up libib-util:armhf (2.5.2~svn+54698.ds4-1) ...
Setting up firebird2.5-server-common (2.5.2~svn+54698.ds4-1) ...
adduser: Warning: The home directory `/var/lib/firebird' does not belong to the user you are currently creating.
Setting up firebird2.5-super (2.5.2~svn+54698.ds4-1) ...
Created default security2.fdb
[ ok ] Firebird 2.5 super server not running.
[warn] Not starting Firebird 2.5 super server ... (warning).
[warn] Use `dpkg-reconfigure firebird2.5-super' to enable ... (warning).
So let's enable Firebird super server
pi@raspberrypi ~ $ sudo dpkg-reconfigure firebird2.5-super
[ ok ] Firebird 2.5 super server not running.
[ ok ] Starting Firebird 2.5 super server...done.
[ ok ] Firebird 2.5 super server already running.
Yes it's on
ps axu | grep firebird
firebird  2830  0.0  0.1   4528   796 ?        S    19:18   0:00 /usr/sbin/fbguard -daemon -forever -pidfile /var/run/firebird/2.5/fbserver.pid
firebird  2832  0.2  1.0  62444  4540 ?        Sl   19:18   0:00 /usr/sbin/fbserver

Still got 256m of free memory for nginx , php , or something better a node.js experiment Let's create/use a database and see simple firebird at work
sudo apt-get install firebird2.5-examples firebird-dev
cp /usr/share/doc/firebird2.5-common-doc/examples/empbuild/employee.fdb.gz
gunzip employee.fdb.gz
sudo chown firebird.firebird employee.fdb
mv employee.fdb /var/lib/firebird/2.5/data

isql-fb
Use CONNECT or CREATE DATABASE to specify a database
SQL> connect "/var/lib/firebird/2.5/data/employee.fdb " user 'SYSDBA' password 'masterkey'
CON> ;
Database:  "/var/lib/firebird/2.5/data/employee.fdb ", User: SYSDBA
SQL> 
show tables;
       COUNTRY                                CUSTOMER                       
       DEPARTMENT                             EMPLOYEE                       
       EMPLOYEE_PROJECT                       JOB                            
       PROJECT                                PROJ_DEPT_BUDGET               
       SALARY_HISTORY                         SALES                          


SQL> show version;
ISQL Version: LI-V2.5.2.26508 Firebird 2.5
Server version:
Firebird/linux ARM (access method), version "LI-V2.5.2.26508 Firebird 2.5"
Firebird/linux ARM (remote server), version "LI-V2.5.2.26508 Firebird 2.5/tcp (raspberrypi)/P12"
Firebird/linux ARM (remote interface), version "LI-V2.5.2.26508 Firebird 2.5/tcp (raspberrypi)/P12"
on disk structure version 11.2
SQL> 
SQL> create database "/var/lib/firebird/2.5/data/first_database.fdb" user 'SYSDBA' password 'masterkey'
CON> ;
Commit current transaction (y/n)?y
Committing.
SQL> connect "/var/lib/firebird/2.5/data/first_database.fdb" user 'SYSDBA' password 'masterkey';
Commit current transaction (y/n)?y
Committing.
Database:  "/var/lib/firebird/2.5/data/first_database.fdb", User: SYSDBA
SQL> CREATE TABLE TEST (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(20));
SQL> show tables
CON> ;
       TEST                            
SQL> INSERT INTO TEST VALUES (1, 'John');
SQL> INSERT INTO TEST VALUES (2, 'Joe');
SQL> select * from test;

          ID NAME                 
============ ==================== 
           1 John                 
           2 Joe                  

SQL> 


Later i will try firebird c api examples
cd /usr/share/doc/firebird2.5-common-doc/examples/api 
cp *.gz ~/
chown pi.pi *.gz
cd ~
gunzip *.gz
gcc -L/usr/lib -lfbclient -I/usr/share/doc/firebird2.5-common-doc/examples/include/ api1.c
ISC_USER=SYSDBA ISC_PASSWORD=masterkey ./a.out /tmp/new.fdb
Created database '/tmp/new.fdb'.

Successfully accessed the newly created database.
So all it works as it should without errors and at the speed of pentium 2 like system or even faster I love the small server and i can leave it on 24x7 without the need to think too much for the energy costs
Next i have tested the firebird python driver fdb
sudo apt-get install python-pip
 

pip install fdb
cat test.py
con = fdb.connect(dsn='/var/lib/firebird/2.5/data/employee.fdb', user='sysdba', password='masterkey')

cur = con.cursor()
SELECT = "select * from employee"



# 2. Equivalently using fetchall():
# This is potentially dangerous if result set is huge, as the whole result set is first materialized
# as list and then used for iteration.
cur.execute(SELECT)
for row in cur.fetchall():
    print 'ID:%d Name %s.' % (row[0], row[1])


python test.py
....
ID:141 Name Pierre.
ID:144 Name John.
ID:145 Name Mark.

Next on my testing list is compiling the node.js (doing it rightnow) and the pure JavaScript Firebird driver with an express demo Update : compiling node is done here are my results
wget https://nodejs.org/dist/v4.2.2/node-v4.2.2.tar.gz
tar zxvf node-v4.2.*.tar.gz
cd node-v4.2.*/
./configure
make install
# https://github.com/hgourvest/node-firebird
$ npm install node-firebird
node-firebird@0.7.0 node_modules/node-firebird
$ npm install express
npm install express
express@4.13.3 node_modules/express
├── content-type@1.0.1
├── methods@1.1.1
├── vary@1.0.1
├── etag@1.7.0
├── serve-static@1.10.0
├── path-to-regexp@0.1.7
├── escape-html@1.0.2
├── merge-descriptors@1.0.0
├── array-flatten@1.1.1
├── cookie@0.1.3
├── utils-merge@1.0.0
├── range-parser@1.0.3
├── parseurl@1.3.0
├── cookie-signature@1.0.6
├── content-disposition@0.5.0
├── fresh@0.3.0
├── depd@1.0.1
├── qs@4.0.0
├── finalhandler@0.4.0 (unpipe@1.0.0)
├── on-finished@2.3.0 (ee-first@1.1.1)
├── proxy-addr@1.0.8 (ipaddr.js@1.0.1, forwarded@0.1.0)
├── debug@2.2.0 (ms@0.7.1)
├── accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.7)
├── type-is@1.6.9 (media-typer@0.3.0, mime-types@2.1.7)
└── send@0.13.0 (statuses@1.2.1, ms@0.7.1, destroy@1.0.3, mime@1.3.4, http-errors@1.3.1)
npm info node-firebird
npm info node-firebird
{ name: 'node-firebird',
description: 'Pure JavaScript and Asynchronous Firebird client for Node.js.',
'dist-tags': { latest: '0.7.0' },
versions:
[ '0.0.1',
.....
'0.7.0' ],
maintainers:
[ 'hgourvest <hgourvest@gmail.com>',
'mariuz <mapopa@gmail.com>',
'petersirka <petersirka@gmail.com>' ],
time:
{ modified: '2015-10-06T13:51:50.072Z',
created: '2012-05-31T09:34:16.821Z',
'0.0.1': '2012-05-31T09:34:19.483Z',
....
'0.7.0': '2015-10-06T13:51:50.072Z' },
author: 'Henri Gourvest <hgourvest@gmail.com>',
repository:
{ type: 'git',
url: 'git+https://github.com/hgourvest/node-firebird.git' },
users: { mariuz: true, deadcoder: true, petersirka: true },
homepage: 'https://github.com/hgourvest/node-firebird',
keywords: [ 'firebird', 'database', 'rdbms', 'sql' ],
readmeFilename: 'README.md',
bugs: { url: 'https://github.com/hgourvest/node-firebird/issues' },
contributors:
[ 'Popa Marius Adrian <mapopa@gmail.com>',
'Peter Širka <petersirka@gmail.com>' ],
version: '0.7.0',
main: './lib',
licenses:
{ type: 'MPL-2.0',
url: 'https://raw.githubusercontent.com/hgourvest/node-firebird/master/LICENSE' },
gitHead: 'f27cdd250703d941308dc756c13b006ed3e04001',
scripts: {},
dist:
{ shasum: '1a6bc1f9d5a26da674c3a6903c7a62414ed8ba3e',
tarball: 'http://registry.npmjs.org/node-firebird/-/node-firebird-0.7.0.tgz' },
directories: {} }

3 comments:

bart de reu said...

Thanks for this, helped me allot !

Rocky Castaneda said...

Have you tried or do you have a preferred webserver to use with pi and firebirdsql?

Popa Adrian Marius said...

node contains also a web server but if you want to serve static content fast i recommend nginx