The document outlines 9 steps to install and configure PostgreSQL from source on Linux:
1. Download the PostgreSQL source code
2. Install PostgreSQL by running configure, make, and make install commands
3. The configure command allows specifying various options like installation location, enabling/disabling features
4. After installation, PostgreSQL is configured and ready to use
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
9 steps to install and configure postgre sql from source on linux
1. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
Home
About
Free
eBook
Archives
Best
of
the
Blog
Contact
9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux
by
Ramesh
Natarajan
on
April
9,
2009
1 Like 9 Tweet 6
Similar
to
mySQL,
postgreSQL
is
very
famous
and
feature
packed
free
and
open
source
database.
Earlier
we’ve
discussed
several
installaJons
including
LAMP
stack
installaJon,
Apache2
installaJon
from
source,
PHP5
installaJon
from
source
and
mySQL
installaJon.
In
this
arJcle,
let
us
review
how
to
install
postgreSQL
database
on
Linux
from
source
code.
Step
1:
Download
postgreSQL
source
code
From
the
postgreSQL
download
site,
choose
the
mirror
site
that
is
located
in
your
country.
# wget http://wwwmaster.postgresql.org/redir/198/f/source/v8.3.7/postgresql-8.3.7.tar.gz
Step
2:
Install
postgreSQL
# tar xvfz postgresql-8.3.7.tar.gz
# cd postgresql-8.3.7
# ./configure
checking for sgmlspl... no
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking ./src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
config.status: linking ./src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c
config.status: linking ./src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking ./src/backend/port/dynloader/linux.h to src/include/dynloader.h
config.status: linking ./src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port
# make
1
of
10 18
Apr
12
7:17
pm
2. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
make[3]: Leaving directory `/usr/save/postgresql-8.3.7/contrib/spi'
rm -rf ./testtablespace
mkdir ./testtablespace
make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress'
make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src'
make -C config all
make[1]: Entering directory `/usr/save/postgresql-8.3.7/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config'
All of PostgreSQL successfully made. Ready to install.
# make install
make -C test/regress install
make[2]: Entering directory `/usr/save/postgresql-8.3.7/src/test/regress'
/bin/sh ../../../config/install-sh -c pg_regress '/usr/local/pgsql/lib/pgxs/src/test/regress/pg_regress'
make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress'
make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src'
make -C config install
make[1]: Entering directory `/usr/save/postgresql-8.3.7/config'
mkdir -p -- /usr/local/pgsql/lib/pgxs/config
/bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/usr/local/pgsql/lib/pgxs/config/mkinstalldirs'
make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config'
PostgreSQL installation complete.
PostgreSQL
./configure
opCons
Following
are
various
opJons
that
can
be
passed
to
the
./configure:
–prefix=PREFIX
install
architecture-‐independent
files
in
PREFIX.
Default
installaJon
locaJon
is
/usr/local/pgsql
–enable-‐integer-‐dateJmes
enable
64-‐bit
integer
date/Jme
support
–enable-‐nls[=LANGUAGES]
enable
NaJve
Language
Support
–disable-‐shared
do
not
build
shared
libraries
–disable-‐rpath
do
not
embed
shared
library
search
path
in
executables
–disable-‐spinlocks
do
not
use
spinlocks
–enable-‐debug
build
with
debugging
symbols
(-‐g)
–enable-‐profiling
build
with
profiling
enabled
–enable-‐dtrace
build
with
DTrace
support
–enable-‐depend
turn
on
automaJc
dependency
tracking
–enable-‐cassert
enable
asserJon
checks
(for
debugging)
–enable-‐thread-‐safety
make
client
libraries
thread-‐safe
–enable-‐thread-‐safety-‐force
force
thread-‐safety
despite
thread
test
failure
–disable-‐largefile
omit
support
for
large
files
–with-‐docdir=DIR
install
the
documentaJon
in
DIR
[PREFIX/doc]
–without-‐docdir
do
not
install
the
documentaJon
–with-‐includes=DIRS
look
for
addiJonal
header
files
in
DIRS
–with-‐libraries=DIRS
look
for
addiJonal
libraries
in
DIRS
–with-‐libs=DIRS
alternaJve
spelling
of
–with-‐libraries
–with-‐pgport=PORTNUM
change
default
port
number
[5432]
–with-‐tcl
build
Tcl
modules
(PL/Tcl)
–with-‐tclconfig=DIR
tclConfig.sh
is
in
DIR
–with-‐perl
build
Perl
modules
(PL/Perl)
–with-‐python
build
Python
modules
(PL/Python)
–with-‐gssapi
build
with
GSSAPI
support
–with-‐krb5
build
with
Kerberos
5
support
–with-‐krb-‐srvnam=NAME
default
service
principal
name
in
Kerberos
[postgres]
–with-‐pam
build
with
PAM
support
–with-‐ldap
build
with
LDAP
support
–with-‐bonjour
build
with
Bonjour
support
–with-‐openssl
build
with
OpenSSL
support
–without-‐readline
do
not
use
GNU
Readline
nor
BSD
Libedit
for
ediJng
–with-‐libedit-‐preferred
prefer
BSD
Libedit
over
GNU
Readline
–with-‐ossp-‐uuid
use
OSSP
UUID
library
when
building
contrib/uuid-‐ossp
2
of
10 18
Apr
12
7:17
pm
3. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
–with-‐libxml
build
with
XML
support
–with-‐libxslt
use
XSLT
support
when
building
contrib/xml2
–with-‐system-‐tzdata=DIR
use
system
Jme
zone
data
in
DIR
–without-‐zlib
do
not
use
Zlib
–with-‐gnu-‐ld
assume
the
C
compiler
uses
GNU
ld
[default=no]
PostgreSQL
InstallaCon
Issue1:
You
may
encounter
the
following
error
message
while
performing
./configure
during
postgreSQL
installaJon.
# ./configure
checking for -lreadline... no
checking for -ledit... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.
PostgreSQL
InstallaCon
SoluCon1:
Install
the
readline-‐devel
and
libtermcap-‐devel
to
solve
the
above
issue.
# rpm -ivh libtermcap-devel-2.0.8-46.1.i386.rpm readline-devel-5.1-1.1.i386.rpm
warning: libtermcap-devel-2.0.8-46.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:libtermcap-devel ########################################### [ 50%]
2:readline-devel ########################################### [100%]
Step
3:
Verify
the
postgreSQL
directory
structure
Amer
the
installaJon,
make
sure
bin,
doc,
include,
lib,
man
and
share
directories
are
created
under
the
default
/usr/local/pgsql
directory
as
shown
below.
# ls -l /usr/local/pgsql/
total 24
drwxr-xr-x 2 root root 4096 Apr 8 23:25 bin
drwxr-xr-x 3 root root 4096 Apr 8 23:25 doc
drwxr-xr-x 6 root root 4096 Apr 8 23:25 include
drwxr-xr-x 3 root root 4096 Apr 8 23:25 lib
drwxr-xr-x 4 root root 4096 Apr 8 23:25 man
drwxr-xr-x 5 root root 4096 Apr 8 23:25 share
Step
4:
Create
postgreSQL
user
account
# adduser postgres
# passwd postgres
Changing password for user postgres.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Step
5:
Create
postgreSQL
data
directory
Create
the
postgres
data
directory
and
make
postgres
user
as
the
owner.
# mkdir /usr/local/pgsql/data
# chown postgres:postgres /usr/local/pgsql/data
# ls -ld /usr/local/pgsql/data
drwxr-xr-x 2 postgres postgres 4096 Apr 8 23:26 /usr/local/pgsql/data
Step
6:
IniCalize
postgreSQL
data
directory
3
of
10 18
Apr
12
7:17
pm
4. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
Before
you
can
start
creaJng
any
postgreSQL
database,
the
empty
data
directory
created
in
the
above
step
should
be
iniJalized
using
the
initdb
command
as
shown
below.
# su - postgres
# /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
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.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".
fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Step
7:
Validate
the
postgreSQL
data
directory
Make
sure
all
postgres
DB
configuraJon
files
(For
example,
postgresql.conf)
are
created
under
the
data
directory
as
shown
below.
$ ls -l /usr/local/pgsql/data
total 64
drwx------ 5 postgres postgres 4096 Apr 8 23:29 base
drwx------ 2 postgres postgres 4096 Apr 8 23:29 global
drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_clog
-rw------- 1 postgres postgres 3429 Apr 8 23:29 pg_hba.conf
-rw------- 1 postgres postgres 1460 Apr 8 23:29 pg_ident.conf
drwx------ 4 postgres postgres 4096 Apr 8 23:29 pg_multixact
drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_subtrans
drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_tblspc
drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_twophase
-rw------- 1 postgres postgres 4 Apr 8 23:29 PG_VERSION
drwx------ 3 postgres postgres 4096 Apr 8 23:29 pg_xlog
-rw------- 1 postgres postgres 16592 Apr 8 23:29 postgresql.conf
Step
8:
Start
postgreSQL
database
Use
the
postgres
postmaster
command
to
start
the
postgreSQL
server
in
the
background
as
shown
below.
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 2222
4
of
10 18
Apr
12
7:17
pm
5. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
$ cat logfile
LOG: database system was shut down at 2009-04-08 23:29:50 PDT
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
Step
9:
Create
postgreSQL
DB
and
test
the
installaCon
Create
a
test
database
and
connect
to
it
to
make
sure
the
installaJon
was
successful
as
shown
below.
Once
you
start
using
the
database,
take
backups
frequently
as
menJoned
in
how
to
backup
and
restore
PostgreSQL
arJcle.
$ /usr/local/pgsql/bin/createdb test
$ /usr/local/pgsql/bin/psql test
Welcome to psql 8.3.7, 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
test=#
1 Tweet 6 Like 9
Share
Comment
If
you
enjoyed
this
arCcle,
you
might
also
like..
1. 50
Linux
Sysadmin
Tutorials Awk
IntroducJon
–
7
Awk
Print
Examples
2. 50
Most
Frequently
Used
Linux
Commands
(With
Examples) Advanced
Sed
SubsJtuJon
Examples
3. Top
25
Best
Linux
Performance
Monitoring
and
Debugging
Tools 8
EssenJal
Vim
Editor
NavigaJon
Fundamentals
4. Mommy,
I
found
it!
–
15
PracJcal
Linux
Find
Command
Examples 25
Most
Frequently
Used
Linux
IPTables
Rules
Examples
5. Linux
101
Hacks
2nd
EdiJon
eBook
Turbocharge
PuTTY
with
12
Powerful
Add-‐Ons
Tags:
DB
InstallaJon
and
ConfiguraJon,
Free
Database
InstallaJon,
Linux
PostgreSQL
InstallaJon,
Opensource
Database
InstallaJon,
PostgreSQL
ConfiguraJon,
PostgreSQL
database,
PostgreSQL
DB,
PostgresQL
Initdb
Command,
PostgresQL
Postmaster
Command
{
16
comments…
read
them
below
or
add
one
}
1
Robert
Schultz
June
17,
2009
at
10:25
am
Hello
Thank
you
very
much
for
the
easy
to
follow
build/install/run
instrucJons.
They’ve
served
me
just
great
today
5
of
10 18
Apr
12
7:17
pm
6. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
2
siva
June
18,
2009
at
3:39
am
thanx
s
3
siva
June
18,
2009
at
3:40
am
hai…
Thank
you
very
much
4
raju
June
18,
2009
at
4:08
am
hi
iam
using
fedora8
in
default
postgres
is
8.3
iam
install
the
source
8.3.7
in
place
of
that
i
did
all
the
commands
according
from
INSTALL
and
README
the
commands
are
./configure
gmake
su
gmake
install
adduser
postgres
mkdir
/usr/local/pgsql/data
chown
postgres
/usr/local/pgsql/data
su
–
postgres
/usr/local/pgsql/bin/initdb
-‐D
/usr/local/pgsql/data
/usr/local/pgsql/bin/postmaster
-‐D
/usr/local/pgsql/data
>logfile
2>&1
&
/usr/local/pgsql/bin/createdb
test
/usr/local/pgsql/bin/psql
test
how
to
restart
the
postgresql
service
pls
tel
me
any
one
5
Ramesh
Natarajan
June
20,
2009
at
11:55
pm
@Robert
Schultz,
Siva,
Thanks
for
your
comment.
I’m
glad
you
found
this
guide
helpful.
@Raju,
Refer
to
our
PostgreSQL
DBA
Commands
arJcle
that
explain
how
to
setup
postgreSQL
service
and
restart
it.
6
Mike
Davidson
April
6,
2010
at
8:59
am
This
easy
rundown
served
me
beQer
than
the
official
documentaJon
on
postgresql.org–at
least
for
gexng
a
testbed
up
and
running
quickly.
Thank
you.
7
mahesh
August
4,
2010
at
2:58
am
thanks
a
lot,i
am
new
to
postgres
and
it
helped
me
a
lots,
thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,
8
mahesh
August
6,
2010
at
1:41
am
thanks
a
lot!!!!!
9
readline
lib
was
readline6-‐dev
October
1,
2010
at
6:41
pm
For
Ubuntu
9.04
through
10.10
I
had
to
sudo
apt-‐get
install
readline6-‐dev.
10
ravindra
May
9,
2011
at
12:39
am
hi
how
to
enable
uuid
in
postgres8.4.6
6
of
10 18
Apr
12
7:17
pm
7. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
11
Nirmal
July
28,
2011
at
1:53
am
hi
I
have
installed
postgres
version
“postgresql-‐8.3.7″₺
on
RHLE
5.2.
but
all
the
command
not
working
properly
like
pg_restore
service
postgresql
start|stop|status|restart
so
I
want
to
uninstall
the
the
postgresql,
please
tel
me
the
steps.
12
beparas
August
3,
2011
at
7:06
am
Hi,
Thank
you
very
much
for
this
post.
I
download
“postgresql-‐9.0.4″₺
and
cross-‐compile
for
my
embedded
board.
Every
things
works
fine
Jll
Step
8.
When
I
try
to
start
my
postgreSQL
database
its
gives
me
following
error:
“FATAL:
could
not
write
lock
file
“/tmp/.s.PGSQL.5432.lock”:
No
space
lem
on
device”
The
output
of
df
-‐h
is
$df
-‐h
Filesystem
Size
Used
Available
Use%
Mounted
on
/dev/root
3.6G
650.4M
2.8G
18%
/
tmpfs
424.0M
40.0K
424.0M
0%
/dev
shm
424.0M
0
424.0M
0%
/dev/shm
rwfs
512.0K
512.0K
0
100%
/mnt/rwfs
rwfs
512.0K
512.0K
0
100%
/tmp
rwfs
512.0K
512.0K
0
100%
/var
It
shows
that
‘/tmp’
is
full,
but
‘/’
is
2.8G
free.
I
install
all
the
FS
on
4GB
SD
card.
Please
help
me
to
solve
this
problem.
Thanks
in
advance.
13
Anonymous
August
27,
2011
at
10:41
pm
How
to
remove(
completely
)
postgresql,
if
I
have
installed
and
configured
the
PostgreSQL
server
according
to
your
post
above
?
14
Ravi
jaikry
October
20,
2011
at
11:45
pm
nice
tutorial
15
Anonymous
February
21,
2012
at
6:59
am
Thanks,
very
nice
tutorial.
For
Linux
Mint
12
(so
probably
Ubuntu
11.10
also)
I
also
had
to
sudo
apt-‐get
install
readline6-‐dev
as
menJoned
above
for
older
versions.
16
Anonymous
April
4,
2012
at
12:13
pm
I
have
installed
postgres
9.0.7
on
my
linux
server
and
I
can
run
the
regression
tests
against
the
installed
instance
locally
on
my
server.
Next,
I
want
to
run
this
regression
test
against
a
remote
machine
which
has
my
DB
and
app
installed.
Can
someone
tell
me
how
I
can
run
the
regression
test,
where
I
have
to
make
changes
in
configuraJon
to
run
the
test
suite
against
remote
host?
Leave
a
Comment
Name
E-‐mail
Website
7
of
10 18
Apr
12
7:17
pm
8. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
NoJfy
me
of
followup
comments
via
e-‐mail
Submit
Previous
post:
Compress,
Encrypt,
Split
and
Transport
Big
Files
Safely
Next
post:
Open
&
View
10
Different
File
Types
with
Linux
Less
Command
–
The
UlJmate
Power
of
Less
Sign
up
for
our
free
email
newsleQer
you@address.com
Sign Up
RSS
TwiQer
Facebook
Search
EBOOKS
8
of
10 18
Apr
12
7:17
pm
9. 9
Steps
to
Install
and
Configure
PostgreSQL
from
Source
on
Linux hQp://www.thegeekstuff.com/2009/04/linux-‐postgresql-‐install...
POPULAR
POSTS
12
Amazing
and
EssenJal
Linux
Books
To
Enrich
Your
Brain
and
Library
50
UNIX
/
Linux
Sysadmin
Tutorials
50
Most
Frequently
Used
UNIX
/
Linux
Commands
(With
Examples)
How
To
Be
ProducJve
and
Get
Things
Done
Using
GTD
30
Things
To
Do
When
you
are
Bored
and
have
a
Computer
Linux
Directory
Structure
(File
System
Structure)
Explained
with
Examples
Linux
Crontab:
15
Awesome
Cron
Job
Examples
Get
a
Grip
on
the
Grep!
–
15
PracJcal
Grep
Command
Examples
Unix
LS
Command:
15
PracJcal
Examples
15
Examples
To
Master
Linux
Command
Line
History
Top
10
Open
Source
Bug
Tracking
System
Vi
and
Vim
Macro
Tutorial:
How
To
Record
and
Play
Mommy,
I
found
it!
-‐-‐
15
PracJcal
Linux
Find
Command
Examples
15
Awesome
Gmail
Tips
and
Tricks
15
Awesome
Google
Search
Tips
and
Tricks
RAID
0,
RAID
1,
RAID
5,
RAID
10
Explained
with
Diagrams
Can
You
Top
This?
15
PracJcal
Linux
Top
Command
Examples
Top
5
Best
System
Monitoring
Tools
Top
5
Best
Linux
OS
DistribuJons
How
To
Monitor
Remote
Linux
Host
using
Nagios
3.0
Awk
IntroducJon
Tutorial
–
7
Awk
Print
Examples
How
to
Backup
Linux?
15
rsync
Command
Examples
The
UlJmate
Wget
Download
Guide
With
15
Awesome
Examples
Top
5
Best
Linux
Text
Editors
Packet
Analyzer:
15
TCPDUMP
Command
Examples
The
UlJmate
Bash
Array
Tutorial
with
15
Examples
3
Steps
to
Perform
SSH
Login
Without
Password
Using
ssh-‐keygen
&
ssh-‐copy-‐id
Unix
Sed
Tutorial:
Advanced
Sed
SubsJtuJon
Examples
UNIX
/
Linux:
10
Netstat
Command
Examples
The
UlJmate
Guide
for
CreaJng
Strong
Passwords
6
Steps
to
Secure
Your
Home
Wireless
Network
Turbocharge
PuTTY
with
12
Powerful
Add-‐Ons
About
The
Geek
Stuff
9
of
10 18
Apr
12
7:17
pm