• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

Install Postgres 8.1.14

Started by jep, 2008.04.02, 13:45:09

Previous topic - Next topic

jep

Marked as: Normal
Hello,

Get a copy of Postgres 8.1.14 from Paul Smedley's site ( http://www.smedley.info/os2ports/index.php?page=postgresql ) and unzip it to a folder on you computer.

Save the code below to a file called Install_Postgres.cmd and type the following in the command prompt ( adjust to your liking ):

Install_Postgres UTF8 John TestDB D:\db

where
UTF8 = Use the UTF 8 encoding inside the batabase
John = The adminitrator user over the database
TestDB = Name of the database
D:\db = drive and path where to place the database files

The default password is postgres if I remember correctly

/* Installation of PostGres Database 8.1.14 */

if arg() = 0 then Return Usage()

parse source . . path
pg_path = ''
path = filespec( 'D', path )||filespec( 'P', path )

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

drives = SysDriveMap()
retval = ''
i = 1
do while length( retval ) = 0 & i <= words( drives )
  say 'Searching drive '||subword( drives, i, 1 )||' for Postgres...one moment please.'
  if SysFileTree( subword( drives, i, 1 )||'\*initdb.exe', 'pg_path', 'SFO' ) <> 0 then Return -1
  do j = 1 to pg_path.0
    if stream( filespec( 'D', pg_path.j )||filespec( 'P', pg_path.j )||'pg_ctl.exe' ) <> '' then do
      pg_path = filespec( 'D', pg_path.j )||filespec( 'P', pg_path.j )
      i = words( drives )
    end
  end
  i = i + 1
end
if pg_path = '' then Return -2
pg_lib_path = filespec( 'D', pg_path )||filespec( 'P', strip( pg_path, 'T', '\' ) )||'bin'
say 'Initializing database...one moment please.'
call value 'PATH', pg_lib_path||';.;'||value( 'PATH',, 'OS2ENVIRONMENT' ), 'OS2ENVIRONMENT'
parse value ARG(1) with encoding userName dbName path_to_create
db = strip( translate( path_to_create, '/', '\' ), 'T', '/' )||'/'||dbName
if Directory( path_to_create||'\'||dbName ) = '' then
  if SysMkDir( path_to_create||'\'||dbName ) = 3 then
    if SysMkDir( path_to_create ) = 0 then
      call SysMkDir path_to_create||'\'||dbName
    else do
      say "Couldn't create database in "||path_to_create||'\'||dbName
      Return -3
    end
call directory strip( pg_path, 'T', '\' )
'@'||pg_path||'initdb --encoding='||encoding||' -D '||db
if rc = 0 then do
   '@'||pg_path||'pg_ctl -D '||db||' -l logfile start'
   if rc = 0 then do
      Call SysSleep 5
      say 'Adding the user '||userName||'...'
      '@'||pg_path||'createuser -q -U postgres -s -r -l '||userName
      if rc = 0 then do
         say 'Creating the database '||dbName||'...'
         '@'||pg_path||'createdb -q -O '||userName||' -U '||userName||' '||dbName
         if rc = 0 then do
            say 'Creating Postgres Icons...'
            If  SysCreateObject( 'WPFolder', 'PostGres 8.x', '<WP_DESKTOP>', 'OBJECTID=<PGSQL8>', 'u' ) Then
               If SysCreateObject( 'WPProgram', 'Start Postgres ('||dbName||')', '<PGSQL8>', 'EXENAME='||pg_path||'PG_CTL.EXE;PARAMETERS=-D '||path_to_create||' start;', 'u' ) Then
                            If SysCreateObject( 'WPProgram', 'Stop Postgres ('||dbName||')', '<PGSQL8>', 'EXENAME='||pg_path||'PG_CTL.EXE;PARAMETERS=-D '||path_to_create||' stop;', 'u' ) Then
                  say 'Installation done!'
         end
         else say 'Unable to create database in the directory '||path_to_create||'\'||dbName
      end
      else say 'Unable to grant '||userName||' rights.'
   end
   else say 'The server failed to start...'
end
else say "Couldn't initialize database"
Return 0

Usage:
say 'Usage: Install_Postgres encoding userName dbName drive:\path_to_create'
say ''
say 'where encoding can be e.g. BIG5, EUC_CN, EUC_JP, EUC_KR, EUC_TW, GB18030, GBK,'
say '                           ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8,'
say '                           JOHAB, KOI8, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5,'
say '                           LATIN6, LATIN7, LATIN8, LATIN9, LATIN10, SJIS,'
say '                           SQL_ASCII, UHC, UTF8, WIN866, WIN874, WIN1250,'
say '                           WIN1251, WIN1252, WIN1256 or WIN1258'
say ''
say 'where userName should be your name that you want to use'
say ''
say 'where dbName should be the name to give the DataBase'
say ''
say 'where the last parameter point to the physical drive and directory to place the database.'
say ''
say 'Example: Install_Postgres UTF8 John MyTestDB D:\db'
Return 0