How to install PostgreSQL on OpenSolaris

The installation is not straight forward as a double-click “setup.exe” on Windows. I summarized the steps to get a running PostgreSQL 8.3.x installation on OpenSolaris 2008.11. All done using a terminal session. Commands to execute in green.

  1. Login or open terminal as root user.
  2. pkg install SUNWpostgr-83-server
  3. pkg install SUNWpostgr-83-client
  4. Check the pckages
    root@server:/# pkginfo | grep postg

    system      SUNWpostgr-83-client            PostgreSQL client tools
    system      SUNWpostgr-83-libs              PostgreSQL client libraries
    system      SUNWpostgr-83-server            PostgreSQL database server
    system      SUNWpostgr-83-server-data-root  PostgreSQL database server data directories and root components
    
  5. The user postgres is already created, but we should configure a home directory and shell.
    vi /etc/passwd
    Change the line for postgres user:
    postgres:x:90:90:PostgreSQL Reserved UID:/export/home/postgres:/bin/bash
    Make sure you create the home directory.
  6. Create a .profile for postgres user
    root@server:/etc# cat ~postgres/.profile

    PATH=/usr/postgres/8.3/bin:${PATH}
    MANPATH=/usr/postgres/8.3/man:${MANPATH}
    PGDATA=/var/postgres/data
    export PATH MANPATH PGDATA
    

    (Note for a 64 system you need to point to the 64 folder under /usr/postgres/8.3/bin

  7. Create the directory /var/postgres/data (it is not the default setting of postgres) and chown postgres.postgres data
  8. Login as postgres, su – postgres
  9. Initialize the DB: initdb
    Result similar to

    ...
    Success. You can now start the database server using:
    
    postgres -D /var/postgres/data
    or
    pg_ctl -D /var/postgres/data -l logfile start
    
    start as postgres user: postgres -D /var/postgres/data &
    

The basic installation is now done. Here some further steps to configure further or start/stop the DB (perfomed as postgres user):

  • Start with ‘pg_ctl start’
  • Stop with ‘pg_ctl start’
  • Check for running instance ‘pg_ctl start’
  • Create a user: ‘createuser myname’
  • Start the psql terminal: ‘psql’
  • Change user password in psql: ‘alter user <username> with password <yourpassword>;”
  • Check port (in psql):  ‘show port;’
  • Check configured listen addresses (in psql): ‘show listen_addresses’
  • Show users (in psql): ‘\du’
  • For detailed configuration look at /var/postgres/data/postgresql.conf
  • For security settings at /var/postgres/data/pg_hba.conf
  • You want to allow a remote address to access. Edit the pg_hba.conf and add:
    Sample
    (one specific IP, change vvv… for your ip address): host all all vvv.yyy.zzz.sss/32 trust
    (Please check the syntax for this config file !!!)

Useful Links:

  • PostgreSQL Website (link)
  • You allow remote access to your DB then I recommend pgAdmin (link)
  • You run Apache and php, then you might want to look at phpPgAdmin (link)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s