Download postgresql software
wget http://ftp.postgresql.org/pub/source/v9.2.3/postgresql-9.2.3.tar.bz2
tar -jxvf postgresql-9.2.3.tar.bz2
cd postgresql-9.2.3
./configure --without-readline
make
make install
[root@machine1 postgresql-9.2.3]# useradd postgres
[root@machine1 postgresql-9.2.3]# mkdir /usr/local/
bin/ etc/ games/ include/ lib/ lib64/ libexec/ pgsql/ sbin/ share/ src/
[root@machine1 postgresql-9.2.3]# mkdir /usr/local/pgsql/data
[root@machine1 postgresql-9.2.3]# chown postgres /usr/local/pgsql/data
[root@machine1 postgresql-9.2.3]# /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@machine1 postgresql-9.2.3]# su - postgres
[postgres@machine1 ~]$ /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 ... 32MB
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 collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... 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 option -A, or
--auth-local and --auth-host, 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
[postgres@machine1 ~]$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 26097
[postgres@machine1 ~]$ /usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/createdb: symbol lookup error: /usr/local/pgsql/bin/createdb: undefined symbol: PQconnectdbParams
[postgres@machine1 ~]$ LD_LIBRARY_PATH=/usr/local/pgsql/lib
[postgres@machine1 ~]$ export LD_LIBRARY_PATH=/usr/local/pgsql/lib
[postgres@machine1 ~]$ /usr/local/pgsql/bin/createdb test
[postgres@machine1 ~]$
create database
[postgres@machine1 ~]$ /usr/local/pgsql/bin/psql test
psql (9.2.3)
Type "help" for help.
test=#
test=#
test=#
change postgres password
[postgres@machine1 ~]$ /usr/local/pgsql/bin/psql test
psql (9.2.3)
Type "help" for help.
test=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'postgres';
ALTER ROLE
test=# \q
Edit the postgre configuration file and add the below lines
[root@machine1 postgresql-9.2.3]# vi /usr/local/pgsql/data/pg_hba.conf
#host all all 127.0.0.1/32 trust
to
host all all 127.0.0.1/32 md5
vi /usr/local/pgsql/data/postgresql.conf
# - Connection Settings -
#listen_addresses = 'localhost' # what IP address(es) to listen on;
to
listen_addresses = '*' # what IP address(es) to listen on;
uncomment
password_encryption = on
The first time you run "service postgresql start", it asks you to initialize a database, run:
service postgresql initdb
To start the postgres service while starting the server, follow the below steps
[root@machine1 ~]# cp -rf /usr/local/src/postgresql-9.2.3/contrib/start-scripts/linux /etc/init.d/postgres
[root@machine1 ~]# chmod 755 /etc/init.d/postgres
[root@machine1 ~]# /etc/init.d/postgres start
Starting PostgreSQL: ok
[root@machine1 ~]# /etc/init.d/postgres restart
Restarting PostgreSQL: ok
To have PostgreSQL start automatically when the computer boots add
symbolic links from the correct /etc/rc*.d/ directories to
/etc/init.d/postgres. If the normal runlevel is 3 then you really only
need to add it to rc3.d:
[root@machine1 ~]# ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres
[root@machine1 ~]# ll /etc/rc3.d/S85postgres
lrwxrwxrwx 1 root root 20 Jun 28 16:25 /etc/rc3.d/S85postgres -> /etc/init.d/postgres
We now successfully installed the postgresql, if you would like to change the port number, do the changes in the below configuration file
/usr/local/pgsql/data/postgresql.conf
wget http://ftp.postgresql.org/pub/source/v9.2.3/postgresql-9.2.3.tar.bz2
tar -jxvf postgresql-9.2.3.tar.bz2
cd postgresql-9.2.3
./configure --without-readline
make
make install
[root@machine1 postgresql-9.2.3]# useradd postgres
[root@machine1 postgresql-9.2.3]# mkdir /usr/local/
bin/ etc/ games/ include/ lib/ lib64/ libexec/ pgsql/ sbin/ share/ src/
[root@machine1 postgresql-9.2.3]# mkdir /usr/local/pgsql/data
[root@machine1 postgresql-9.2.3]# chown postgres /usr/local/pgsql/data
[root@machine1 postgresql-9.2.3]# /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@machine1 postgresql-9.2.3]# su - postgres
[postgres@machine1 ~]$ /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 ... 32MB
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 collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... 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 option -A, or
--auth-local and --auth-host, 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
[postgres@machine1 ~]$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 26097
[postgres@machine1 ~]$ /usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/createdb: symbol lookup error: /usr/local/pgsql/bin/createdb: undefined symbol: PQconnectdbParams
[postgres@machine1 ~]$ LD_LIBRARY_PATH=/usr/local/pgsql/lib
[postgres@machine1 ~]$ export LD_LIBRARY_PATH=/usr/local/pgsql/lib
[postgres@machine1 ~]$ /usr/local/pgsql/bin/createdb test
[postgres@machine1 ~]$
create database
[postgres@machine1 ~]$ /usr/local/pgsql/bin/psql test
psql (9.2.3)
Type "help" for help.
test=#
test=#
test=#
change postgres password
[postgres@machine1 ~]$ /usr/local/pgsql/bin/psql test
psql (9.2.3)
Type "help" for help.
test=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'postgres';
ALTER ROLE
test=# \q
Edit the postgre configuration file and add the below lines
[root@machine1 postgresql-9.2.3]# vi /usr/local/pgsql/data/pg_hba.conf
#host all all 127.0.0.1/32 trust
to
host all all 127.0.0.1/32 md5
vi /usr/local/pgsql/data/postgresql.conf
# - Connection Settings -
#listen_addresses = 'localhost' # what IP address(es) to listen on;
to
listen_addresses = '*' # what IP address(es) to listen on;
uncomment
password_encryption = on
The first time you run "service postgresql start", it asks you to initialize a database, run:
service postgresql initdb
To start the postgres service while starting the server, follow the below steps
[root@machine1 ~]# cp -rf /usr/local/src/postgresql-9.2.3/contrib/start-scripts/linux /etc/init.d/postgres
[root@machine1 ~]# chmod 755 /etc/init.d/postgres
[root@machine1 ~]# /etc/init.d/postgres start
Starting PostgreSQL: ok
[root@machine1 ~]# /etc/init.d/postgres restart
Restarting PostgreSQL: ok
To have PostgreSQL start automatically when the computer boots add
symbolic links from the correct /etc/rc*.d/ directories to
/etc/init.d/postgres. If the normal runlevel is 3 then you really only
need to add it to rc3.d:
[root@machine1 ~]# ln -s /etc/init.d/postgres /etc/rc3.d/S85postgres
[root@machine1 ~]# ll /etc/rc3.d/S85postgres
lrwxrwxrwx 1 root root 20 Jun 28 16:25 /etc/rc3.d/S85postgres -> /etc/init.d/postgres
We now successfully installed the postgresql, if you would like to change the port number, do the changes in the below configuration file
/usr/local/pgsql/data/postgresql.conf
No comments:
Post a Comment