Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

During

...

the

...

time

...

of

...

this

...

article,

...

the

...

instructions

...

on

...

the

...

Ubuntu

...

wiki

...

were

...

pretty

...

light

...

and

...

from

...

what

...

I

...

can

...

see

...

not

...

quite

...

complete.

...

These

...

instructions

...

are

...

currently

...

written

...

for

...

PostgreSQL

...

8.x.

...

and 9.x.

Installing PostgreSQL

Ensure UTF-8

...

Encoding

...

is

...

Set

If you did not follow the Bonsai Framework to setup Ubuntu yourself, make sure that your operating system has the right encoding set as explained in the "Select Locale" part of my Ubuntu Linux Base Server article.

Install

The Ubuntu install is simply,

Code Block
languagebash
sudo apt-get install postgresql # installs postgresql{code}

Similar

...

to

...

how

...

Apache

...

is

...

installed,

...

Ubuntu

...

has

...

it's

...

own

...

standard.

...

Here

...

are

...

the

...

keynotes.

...

You

...

will

...

now

...

have

...

a

...

postgresql

...

user

...

on

...

your

...

system.

...

This

...

account

...

is

...

reserved

...

for

...

running

...

Postgresql

...

in

...

a

...

secure

...

manner.

...

This

...

account

...

neither

...

has

...

a

...

password

...

or

...

a

...

home

...

directory.

...

This account also has a role in the database for administration purposes. I will show you how to use this account as we go forward.

The postgresql service is also added to the system to start automatically.

Finally here are some directories to be aware of,

  • /var/lib/postgresql/8.4/main

...

  • -

...

  • location

...

  • of

...

  • the

...

  • main

...

  • database

...

  • that

...

  • can

...

  • only

...

  • be

...

  • viewed

...

  • and

...

  • modified

...

  • by

...

  • the

...

  • user

...

  • postgresql

...

  • .

...

  • /etc/postgresql/8.4/main

...

  • -

...

  • location

...

  • of

...

  • all

...

  • configuration

...

  • files.

...

  • /var/log/postgresql/

...

  • -

...

  • location

...

  • where

...

  • Ubuntu

...

  • keeps

...

  • all

...

  • the

...

  • logs

...

  • and

...

  • automatically

...

  • is

...

  • set

...

  • to

...

  • archive

...

  • and

...

  • roll

...

  • over.

...

That's

...

all

...

there

...

is

...

for

...

the

...

installation.

...

Ubuntu

...

apt-get

...

makes

...

it

...

easy

...

and

...

does

...

all

...

the

...

hard

...

work

...

for

...

you.

Secure Master Account

By default, the master account in the database postgres does not have a password. We want to set this up so that we can provide access to a dba without the dba requiring sudo access to the operating system. Also, leaving at is makes postgres open to any user with sudo privileges.

Change the Default postgres Database User Account

The first step, is to launch the postgresql shell.

Code Block
langhtml
sudo -u postgres psql postgres

The command is confusing so here is a break down,

Code Block
languagebash
sudo -u postgres # Run as the operating system user postgres which also has a role in the database.
psql             # Launch the postgres shell.
postgres         # Name of the database to load (not the user).
Info

Sometimes the last parameter is not used. This is short-hand. If no database name is specified, psql will try to load the database matching the user name.

Here is what it looks like once you are in,

Code Block
langhtml
psql (8.4.1)
Type "help" for help.

postgres=#{code}

All

...

commands

...

are

...

prefixed

...

by

...

the

...

the

...

\.

...

So

...

to

...

change

...

the

...

postgres

...

account

...

password

...

. In the Bonsai Framework, we use the selected password algorithm derived from the server name.

Code Block
languagesql
postgres=# \password postgres{code}

Note

...

that

...

this

...

changes

...

the

...

account

...

inside

...

of

...

postgres,

...

not

...

the

...

operating

...

system

...

account

...

postgres.

...

Finally

...

exit

...

the

...

postgres

...

shell,

...

Code Block
languagesql
postgres=# \quit{code}

With

...

this

...

change

...

you

...

can

...

now

...

use

...

a

...

GUI client

...

software

...

such

...

as

...

pgAdmin

...

III.

...

Note

...

that

...

be

...

by

...

default,

...

postgres

...

is

...

very

...

secure.

...

As

...

such

...

with

...

this

...

change

...

you

...

will

...

be

...

able

...

to

...

use

...

pgAdmin

...

III

...

in

...

only

...

the

...

following

...

2

...

scenarios,

...

  1. Using

...

  1. the

...

  1. pgAdmin

...

  1. III

...

  1. installed

...

  1. on

...

  1. the

...

  1. same

...

  1. system

...

  1. as

...

  1. Postgresql.

...

  1. From

...

  1. another

...

  1. machine

...

  1. using

...

  1. an

...

  1. SSH

...

  1. Tunnel.

...

Further Reading

Page Tree
root@self