PostgreSQL 9.5 : Install2017/09/25 |
The version of PostgreSQL in CentOS 6 repository is 8.4 but Install 9.5 with RPM package if you need.
|
|
[1] | It's possible to install from CentOS SCLo Software Collections. It's OK to install it even if 8.4 is already installed because 9.5 is located on another PATH. |
# install from SCLo [root@dlp ~]# yum --enablerepo=centos-sclo-rh -y install rh-postgresql95-postgresql-server
|
[2] | Packages from Software Collections are installed uder the /opt directory. To use it, Load environment variables like follows. |
# load environment variables [root@dlp ~]# scl enable rh-postgresql95 bash
[root@dlp ~]#
[root@dlp ~]# postgres -V postgres (PostgreSQL) 9.5.7 which postgres /opt/rh/rh-postgresql95/root/usr/bin/postgres |
[3] | If you'd like to enable PostgreSQL 9.5 automatically at login time, configure like follows. |
[root@dlp ~]#
vi /etc/profile.d/rh-postgresql95.sh # create new #!/bin/bash source /opt/rh/rh-postgresql95/enable export X_SCLS="`scl enable rh-postgresql95 'echo $X_SCLS'`" |
[4] | Enable PostgreSQL 9.5 and start PostgreSQL Server. |
[root@dlp ~]#
postgresql-setup --initdb --unit rh-postgresql95-postgresql * Initializing database in '/var/opt/rh/rh-postgresql95/lib/pgsql/data' * Initialized, logs are in /var/lib/pgsql/initdb_rh-postgresql95-postgresql.log
[root@dlp ~]#
vi /var/opt/rh/rh-postgresql95/lib/pgsql/data/postgresql.conf # line 59: uncomment and change if allow accesses from remote hosts listen_addresses = ' * '
# line 417: uncomment and change if change log format # the exmaple below is [Date User DB ***] format log_line_prefix = ' %t %u %d '
/etc/rc.d/init.d/rh-postgresql95-postgresql start Starting rh-postgresql95-postgresql service: [ OK ] [root@dlp ~]# chkconfig rh-postgresql95-postgresql on |
[5] | If IPTables is running and also PostgreSQL is used from remote Hosts, allow port like follows. PostgreSQL uses 5432/TCP. |
[root@dlp ~]# iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
|
[6] | Set PostgreSQL admin user's password and add a user and also add a test database. |
# set password [root@dlp ~]# su - postgres -bash-4.1$ psql -c "alter user postgres with password 'password'" ALTER ROLE # add DB user [cent] as an example -bash-4.1$ createuser cent
# create a test database (owner is the user above) -bash-4.1$ createdb testdb -O cent
|
[7] | Login as a user just added above and operate DataBase as test operation. |
# show Databases [cent@dlp ~]$ psql -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileg es -----------+----------+----------+-------------+-------------+------------------ ----- 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 testdb | cent | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows) # connect to test DB [cent@dlp ~]$ psql testdb
psql (9.5.7)
Type "help" for help. # set password testdb=# alter user cent with password 'password'; ALTER ROLE # create a test table testdb=# create table test ( no int,name text ); CREATE TABLE # insert test data testdb=# insert into test (no,name) values (1,'cent'); INSERT 0 1 # show tables testdb=# select * from test;
no | name ----+------- 1 | cent (1 row) # delete test table testdb=# drop table test; DROP TABLE # quit testdb=# \q
# delete test database [cent@dlp ~]$ dropdb testdb
|
Sponsored Link |