Installation and configuration of Postgresql9.6.6 under CentOS 6.6

Posted by batterdmooie on Sat, 04 Apr 2020 10:11:46 +0200

1, Environment introduction

System platform: CentOS release 6.6 (Final)

Postgresql: postgresql-9.6.6

SELINUX=disabled

Iptables off

2, Installation process

1. Install dependency package

yum -y install gcc*
yum -y install readline-devel

2. Source package acquisition

wget http://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz

3. decompression

tar zxf postgresql-9.6.6.tar.gz

4. Create user and set password

adduser postgres
passwd postgres

5. Compile and install

cd postgresql-9.6.6
./configure --prefix=/home/postgres/pgsql
gmake
gmake install

6. Set environment variables

vim /etc/profile

7. Create database directory

mkdir /home/postgres/pgsql/data

Create database operation history file

touch /home/postgres/pgsql/.pgsql_history

Change group

chown -R postgres:postgres /home/postgres/pgsql/*

8. Switch to postgre user and initialize database

su - postgres
/home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql/data
exit

9. Compile start command

Copy linux from postgres extracted folder to / etc/init.d/

cp /root/postgresql-9.6.6/contrib/start-scripts/linux /etc/init.d/postgresql
vim /etc/init.d/postgresql

Modify the following two lines:

prefix=/home/postgres/pgsql
PGDATA="/home/postgres/pgsql/data"

Save exit

Add executable rights

chmod +x /etc/init.d/postgresql

10. Start postgres database

/etc/init.d/postgresql start

11. Test use

[root@MidApp ~]#su - postgres
[postgres@MidApp ~]$ psql
psql (9.6.6)
Type "help" for help.
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | 
 template0 | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)
postgres=# \q

Topics: PostgreSQL Database yum vim