The code is tested on Postgres 7.4.7 and 8.3.3

1) create postgres database 
for example to create a database named fbirn_test2
$ createdb fbirn_test2
$ createlang -d fbirn_test2 plpgsql

2) edit static_data_project.sql for your specific project

3) start psql (e.g. psql -U postgres fbirn_test2) 
and run edited main.sql in psql using for example
 
fbirn_test2=# \i main.sql

and follow instructions


Below is an example schema generation and population session for a database named clinical2
For brevity most of the repeating output is removed (indicated by .....)

-------------------------------------------------------------------------------------------
[bozyurt3@csf db_objects]$ psql -U postgres clinical2
Welcome to psql 8.3.3, the PostgreSQL interactive terminal.

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

clinical2=# \i main.sql
psql:Tables/bk_tupleAccess.sql:1: ERROR:  table "bk_tupleaccess" does not exist
psql:Tables/bk_tupleAccess.sql:16: NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "bk_tupleaccess_pk" for table "bk_tupleaccess"
psql:Tables/bk_tupleAccess.sql:16: NOTICE:  CREATE TABLE / UNIQUE will create implicit index "bk_tupleaccess_sk" for table "bk_tupleaccess"
CREATE TABLE
psql:Tables/nc_animalSpecies.sql:1: ERROR:  table "nc_animalspecies" does not exist
psql:Tables/nc_animalSpecies.sql:14: NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "nc_animalspecies_pk" for table "nc_animalspecies"
psql:Tables/nc_animalSpecies.sql:14: NOTICE:  CREATE TABLE / UNIQUE will create implicit index "nc_animalspecies_sk" for table "nc_animalspecies"
CREATE TABLE
.....

CREATE FUNCTION
CREATE TRIGGER
CREATE FUNCTION
.....


CREATE FUNCTION
psql:main.sql:8: ERROR:  sequence "uid_seq" does not exist
CREATE SEQUENCE
CREATE FUNCTION
CREATE FUNCTION
**************************************************
Some configuration parameters need to be entered before
database schema is prepared for usage.

Please enter the database username (e.g. postgres)
postgres
Entered dbuser:  'postgres'
Please enter the contact person last name (e.g. Ozyurt)
Ozyurt
Entered lastname:  'Ozyurt'
Please enter the contact person first name (e.g. Burak)
Burak
Entered lastname:  'Burak'
Please enter the contact person email address (e.g. iozyurt@ucsd.edu)
iozyurt@ucsd.edu
Entered email:  'iozyurt@ucsd.edu'
**** Preparing database ****
psql:main.sql:108: NOTICE:  db_user_id:108
CONTEXT:  PL/pgSQL function "create_static_data" line 54 at assignment
PL/pgSQL function "prepare_db" line 13 at assignment
psql:main.sql:108: NOTICE:  person_id:-1
CONTEXT:  PL/pgSQL function "create_static_data" line 54 at assignment
PL/pgSQL function "prepare_db" line 13 at assignment
psql:main.sql:108: NOTICE:  new person_id:109
CONTEXT:  PL/pgSQL function "create_static_data" line 54 at assignment
PL/pgSQL function "prepare_db" line 13 at assignment
psql:main.sql:108: NOTICE:  new group_id :110
CONTEXT:  PL/pgSQL function "create_static_data" line 54 at assignment
PL/pgSQL function "prepare_db" line 13 at assignment
 prepare_db 
------------
          0
(1 row)

 add_admin 
-----------
         0
(1 row)

ALTER TABLE
ALTER TABLE
.....

CREATE FUNCTION
IMPORTANT: the data entered by prepare_static_data_project function
is process specific and needs to be customized BEFORE usage
the site_name  must be the name of the site that is setting up
the postgres database
The FBIRN site names are
 Duke
 BWH
 MGH
 UCLA
 UCI
 UNM
 Iowa
 UMN
 Yale
 UCSD
Please enter the site name (e.g. UCSD)
UCSD
Entered sitename:  'UCSD'
*** prepararing project specific static data ...
 prepare_static_data_project 
-----------------------------
                           0
(1 row)

Done!
clinical2-# \q
[bozyurt3@csf db_objects]$ 
-------------------------------------------------------------------------------------------



*** To upgrade BIRN specific project data, after getting the latest updates from NITRC HID svn
==============================================================================================

hidprdp=# \i  static_data_project.sql
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION

-- select prepare_static_data_project(<database-username>,<site-id>)
-- for example
hidprdp=# select prepare_static_data_project('postgres', 'UCSD');



