Installing Postgres SQL Database

Here’re the steps to install a Postgres SQL database on RedHat 9.0.

1. login as root
2. su postgres
3. mkdir /home/db
4. chown postgres /home/db and chgrp postgres /home/db
5. export PGDATA=/home/db
6. 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.
This locale setting will prevent the use of indexes for pattern matching
operations. If that is a concern, rerun initdb with the collation order
set to “C”. For more information see the Administrator’s Guide.

Fixing permissions on existing directory /home/db… ok
creating directory /home/db/base… ok
creating directory /home/db/global… ok
creating directory /home/db/pg_xlog… ok
creating directory /home/db/pg_clog… ok
creating template1 database in /home/db/base/1… ok
creating configuration files… ok
initializing pg_shadow… ok
enabling unlimited row size for system tables… ok
initializing pg_depend… ok
creating system views… ok
loading pg_description… ok
creating conversions… ok
setting privileges on built-in objects… ok
vacuuming database template1… ok
copying template1 to template0… ok

Success. You can now start the database server using:

/usr/bin/postmaster -D /home/db
or
/usr/bin/pg_ctl -D /home/db -l logfile start

7. /usr/bin/pg_ctl -D /home/db -l logfile start

bash-2.05b$ /usr/bin/pg_ctl -D /home/db -l logfile start
postmaster successfully started

bash-2.05b$ createdb test
CREATE DATABASE

bash-2.05b$ psql test
Welcome to psql 7.3.2, the PostgreSQL interactive terminal.

Type: copyright for distribution terms
h for help with SQL commands
? for help on internal slash commands
g or terminate with semicolon to execute query
q to quit

test=#

test=# CREATE TABLE films (
test(# code char(5) CONSTRAINT firstkey PRIMARY KEY,
test(# title varchar(40) NOT NULL,
test(# did integer NOT NULL,
test(# date_prod date,
test(# kind varchar(10),
test(# len interval hour to minute
test(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index ‘firstkey’ for table ‘films’
CREATE TABLE

test=# INSERT INTO films (code, title, did, date_prod, kind)
test-# VALUES (‘T_601’, ‘Yojimbo’, 106, DEFAULT, ‘Drama’);
INSERT 16981 1

test=# select * from films;
code | title | did | date_prod | kind | len
——-+———+—–+———–+——-+—–
T_601 | Yojimbo | 106 | | Drama |
(1 row)

bash-2.05b$ pg_ctl -D /home/db stop
waiting for postmaster to shut down……done
postmaster successfully shut down

starting it with networking

bash-2.05b$ pg_ctl -D /home/db -l logfile -o -i start
postmaster successfully started

bash-2.05b$ psql test
Welcome to psql 7.3.2, the PostgreSQL interactive terminal.

Type: copyright for distribution terms
h for help with SQL commands
? for help on internal slash commands
g or terminate with semicolon to execute query
q to quit

test=# create user tester with password ‘tester’;
CREATE USER

create table for mono test

test=# CREATE TABLE “test” (
test(# “person” character varying(256) NOT NULL,
test(# “email” character varying(256) NOT NULL
test(# );
CREATE TABLE
test=# insert into test (person, email) values(‘user1′,’users@nomail.com’);
INSERT 16984 1
test=# insert into test (person, email) values(‘user2′,’user2@nomail.com’);
INSERT 16985 1
test=# select * from test;
person | email
——–+——————
user1 | users@nomail.com
user2 | user2@nomail.com
(2 rows)

I got this error

Npgsql.NpgsqlException:
No pg_hba.conf entry for host 127.0.0.1, user tester, database tester
Severity: FATAL
in <0x00061> Npgsql.NpgsqlConnection:CheckErrors ()
in <0x0004f> (wrapper remoting-invoke-with-check) Npgsql.NpgsqlConnection:CheckErrors ()
in <0x00447> Npgsql.NpgsqlConnection:Open ()

Well, the database name should be test, but it reported “tester”. I don’t know why. I’m testing dbpage1.aspx.

OK, I added a record in pg_hba.conf to allow host from 127.0.0.1 to connect to the database, but got this error instead

Npgsql.NpgsqlException:
Database “tester” does not exist in the system catalog.
Severity: FATAL

It still thinks the database is “tester”. I need to check the connect string one more time and will shutdown Apache to see if it changes anything.

While waiting for reboot, I downloaded pgadmin, a GUI program for managing Postgres database. Nice!

Finally, I got it running on dbpage1.aspx and dbpage2.aspx. It turned out that the connect string was wrong. The original connect string was “sever=127.0.0.1;user id=tester;password=tester;dbname=test”. The correct string should be using “database=test”!

Don’t forget granting permission to the tester on the database test!

Here’s the dbpage1.aspx sample.

Installing Postgres SQL Database

Here’re the steps to install a Postgres SQL database on RedHat 9.0.

1. login as root
2. su postgres
3. mkdir /home/db
4. chown postgres /home/db and chgrp postgres /home/db
5. export PGDATA=/home/db
6. 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.
This locale setting will prevent the use of indexes for pattern matching
operations. If that is a concern, rerun initdb with the collation order
set to “C”. For more information see the Administrator’s Guide.

Fixing permissions on existing directory /home/db… ok
creating directory /home/db/base… ok
creating directory /home/db/global… ok
creating directory /home/db/pg_xlog… ok
creating directory /home/db/pg_clog… ok
creating template1 database in /home/db/base/1… ok
creating configuration files… ok
initializing pg_shadow… ok
enabling unlimited row size for system tables… ok
initializing pg_depend… ok
creating system views… ok
loading pg_description… ok
creating conversions… ok
setting privileges on built-in objects… ok
vacuuming database template1… ok
copying template1 to template0… ok

Success. You can now start the database server using:

/usr/bin/postmaster -D /home/db
or
/usr/bin/pg_ctl -D /home/db -l logfile start

7. /usr/bin/pg_ctl -D /home/db -l logfile start

bash-2.05b$ /usr/bin/pg_ctl -D /home/db -l logfile start
postmaster successfully started

bash-2.05b$ createdb test
CREATE DATABASE

bash-2.05b$ psql test
Welcome to psql 7.3.2, the PostgreSQL interactive terminal.

Type: copyright for distribution terms
h for help with SQL commands
? for help on internal slash commands
g or terminate with semicolon to execute query
q to quit

test=#

test=# CREATE TABLE films (
test(# code char(5) CONSTRAINT firstkey PRIMARY KEY,
test(# title varchar(40) NOT NULL,
test(# did integer NOT NULL,
test(# date_prod date,
test(# kind varchar(10),
test(# len interval hour to minute
test(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index ‘firstkey’ for table ‘films’
CREATE TABLE

test=# INSERT INTO films (code, title, did, date_prod, kind)
test-# VALUES (‘T_601’, ‘Yojimbo’, 106, DEFAULT, ‘Drama’);
INSERT 16981 1

test=# select * from films;
code | title | did | date_prod | kind | len
——-+———+—–+———–+——-+—–
T_601 | Yojimbo | 106 | | Drama |
(1 row)

bash-2.05b$ pg_ctl -D /home/db stop
waiting for postmaster to shut down……done
postmaster successfully shut down

starting it with networking

bash-2.05b$ pg_ctl -D /home/db -l logfile -o -i start
postmaster successfully started

bash-2.05b$ psql test
Welcome to psql 7.3.2, the PostgreSQL interactive terminal.

Type: copyright for distribution terms
h for help with SQL commands
? for help on internal slash commands
g or terminate with semicolon to execute query
q to quit

test=# create user tester with password ‘tester’;
CREATE USER

create table for mono test

test=# CREATE TABLE “test” (
test(# “person” character varying(256) NOT NULL,
test(# “email” character varying(256) NOT NULL
test(# );
CREATE TABLE
test=# insert into test (person, email) values(‘user1′,’users@nomail.com’);
INSERT 16984 1
test=# insert into test (person, email) values(‘user2′,’user2@nomail.com’);
INSERT 16985 1
test=# select * from test;
person | email
——–+——————
user1 | users@nomail.com
user2 | user2@nomail.com
(2 rows)

I got this error

Npgsql.NpgsqlException:
No pg_hba.conf entry for host 127.0.0.1, user tester, database tester
Severity: FATAL
in <0x00061> Npgsql.NpgsqlConnection:CheckErrors ()
in <0x0004f> (wrapper remoting-invoke-with-check) Npgsql.NpgsqlConnection:CheckErrors ()
in <0x00447> Npgsql.NpgsqlConnection:Open ()

Well, the database name should be test, but it reported “tester”. I don’t know why. I’m testing dbpage1.aspx.

OK, I added a record in pg_hba.conf to allow host from 127.0.0.1 to connect to the database, but got this error instead

Npgsql.NpgsqlException:
Database “tester” does not exist in the system catalog.
Severity: FATAL

It still thinks the database is “tester”. I need to check the connect string one more time and will shutdown Apache to see if it changes anything.

While waiting for reboot, I downloaded pgadmin, a GUI program for managing Postgres database. Nice!

Finally, I got it running on dbpage1.aspx and dbpage2.aspx. It turned out that the connect string was wrong. The original connect string was “sever=127.0.0.1;user id=tester;password=tester;dbname=test”. The correct string should be using “database=test”!

Don’t forget granting permission to the tester on the database test!

Here’s the dbpage1.aspx sample.

Roll your own Web Part

Web Part was introduced in SharePoint Portal and will be adopted in ASP.NET 2.0. The whole Web Part infrastructure involves with the aspects in catalog, configuration, persistence and connection. I’m particularly interested in the connection feature.

To make a Web Part connectable to other Web Parts, it has to implement a set of interfaces. They are ICellProvider/ICellConsumer, IRowProvider/IRowConsumer, IListProvider/IListConsumer and IFilterProvider/IFilterConsumer. To coordinate the communication among the parts, each part also needs to override a few methods such as CommunicationConnect, CommunicationInit and CommunicationMain.

In the implementation, there are two base classes desgined to set up the framework. The BaseControl class is listed here.

	public class BaseControl : UserControl, IMessage	{
		public BaseControl() : base() {
		}
		public event ErrorMessageEventHandler ErrorMessage;
		public event MessageEventHandler Message;
		protected void OnMessage(object sender, MessageEventArgs e) {
			if (this.Message != null)
				this.Message(sender, e);
		}

		protected void OnErrorMessage(object sender, MessageEventArgs e) {
			if (this.ErrorMessage != null)
				this.ErrorMessage(sender, e);
		}

		protected override void Render(HtmlTextWriter writer) {
			base.Render(writer);
		}

		public virtual void CommunicationConnect() {}
		public virtual void CommunicationInit() {}
		public virtual void CommunicationMain() {}
	}

	public interface IRowProvider {
		event RowProviderInitEventHandler RowProviderInit;
		event RowReadyEventHandler RowReady;
	}
	public interface IRowConsumer
	{
		void RowProviderInit(object sender, RowProviderInitEventArgs e);
		void RowReady(object sender, RowReadyEventArgs e);
	}

The BasePage class defines the overall page layout and style, it also fires the CommunicationConnect/Init/Main methods on each connectable controls, plus other basic features that each page needs to share in common.

One needs to refactor and refactor the GUI design to get the best out of this architecture since suddenly many basic features of modern web user interface becomes reusable components that can be connected or composed into elaborate user interface to accompish rather sophisticated work.

New Order Entry GUI Design

Here’s a new GUI design I have come up for order entry management. In addition to a DOM price grid where one can click to generate a buy or sell bracket order with target and stop loss, a canvas is provided to manage orders.

The generated backet orders are represented in a canvas where all price levels are drawn in horizontal grids much like the ones in a chart. Each order such as entry, target and stop loss is reprresented by a circle or rectangle. These three or more circles or rectangles are linked with either dotted or solid lines to form a trade group. One can drag and drop or move the circles or rectangles around and they can anchor at any price grid lines. If one likes to scale in, more target circles or rectangles will be formed in the trade group. If an order is filled, it will be fixed at the filled price grid line vertically, but one can still move it horizontally.

As illustrated in the diagram, if ES is traded, the first trade has a Buy 1 ES (B1) with a target Sell 1 ES (T1) and stop loss Sell 1 ES (X1). The second trade has a Buy 2 ES (B2) and two targets Sell 1 (T1 and T1) and stop loss Sell 2 (X2). One can form multiple trade groups, each with different set of strategy that manages the targets and stop loss. The canvas provides a nearly free-form order entry management interface to any trading platform. In a way, it looks like a chess board!

New Order Entry Program

A new order entry program is being developed. It uses the popular DOM (Depth of Market) grids as the main GUI to visualize the whole order entry and management process, speed the process up and reduce occurence of entry errors. Most of operations will be done with a single mouse click. The first release will support bracket orders. More sophisticated position management techniques such as scale in/out, time stop, changing stop to trail stop once reaching certain target, market chasing, etc., will be added later.