How to install and initialize the PostgreSQL instance after installation

How to install and initialize the PostgreSQL instance after installation.


In this post we will discuss how to install postgres server and initialize the service for first time. Also we discuss how to do all activity in RHEL6/7 servers.

You can also follow other topics:
Method 1:- How to install and initialize the PostgreSQL instance after installation

Step1: Install postgres server
# yum install postgres-server

Step2: Check postgres version
# postgres -V
-bash: postgres: command not found

Step3: Check postgres  service name
# systemctl list-units --type service --all
postgres.service   not-found       active   exited  postgres.service

Step4: Find installation directory
# find / -name postgres*
/sys/fs/cgroup/systemd/system.slice/postgres.service
/etc/selinux/targeted/active/modules/100/postgresql
/var/lib/pgsql/11/bin/postgres
/var/lib/pgsql/11/include/internal/postgres_fe.h
/var/lib/pgsql/11/include/server/postgres.h
/var/lib/pgsql/11/include/server/postgres_ext.h
/var/lib/pgsql/11/include/server/postgres_fe.h
/var/lib/pgsql/11/include/postgres_ext.h
/var/lib/pgsql/11/lib/contrib/postgres_fdw
/var/lib/pgsql/11/lib/postgres_fdw.so
/var/lib/pgsql/11/share/extension/postgres_fdw--1.0.sql
/var/lib/pgsql/11/share/extension/postgres_fdw.control
/var/lib/pgsql/11/share/postgres.bki
/var/lib/pgsql/11/share/postgres.description
/var/lib/pgsql/11/share/postgres.shdescription
/var/lib/pgsql/11/share/postgresql.conf.sample
/var/spool/mail/postgres
/usr/lib/firewalld/services/postgresql.xml

# locate bin/postgres
/usr/local/pgsql/bin/postgres

Step5: Check postgres  service status
# systemctl status postgres.service
● postgres.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead) since Mon 2019-09-30 17:11:54 IST; 1 weeks 3 days ago
 
Step6: Check sshd service status
# systemctl status sshd.service
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-09-30 17:11:59 IST; 1 weeks 3 days ago

Step 7: Start postgres service
# systemctl start postgres.service
Failed to start postgres.service: Unit not found.
 
# service postgres start
Redirecting to /bin/systemctl start postgres.service
Failed to start postgres.service: Unit not found.

Step 8: Initialize the PostgreSQL instance
# /var/lib/pgsql/11/bin/postgres initdb
 
PostgreSQL 11 default data directory location is /var/lib/pgsql/11/data

Step9: Start postgres service and configure service for auto start in system bootup

RHEL -7
# systemctl start postgres.service
# systemctl enable postgres.service

RHEL -6
# service postgres start
# chkconfig postgres on

Step10: Check postgres server version
# su - postgres -c "psql"
psql (11.1)
Type "help" for help.

Method 2:- How to install and initialize the PostgreSQL instance after installation

Step1: Make database directory in postgres installed location.
# mkdir /var/lib/pgsql/11/data
 
Step2: Change ownership to postgres
# chown -R postgres:postgres /var/lib/pgsql/11/data

Step3: Change to postgres user
# sudo -i -u postgres

Step4: Initialize the PostgreSQL instance 
$ initdb -D /var/lib/pgsql/11/data

Step5: Start postgres server
# systemctl start postgres.service

Step6: Check postgres server version 
# postgres -V
postgres (PostgreSQL) 11.1 

Step7: Check postgres service status
# systemctl list-units --type service --all
postgres.service    loaded    active   exited  LSB: Bring up/down networking 

Step8: Configure service for auto start in system bootup
# systemctl enable postgres.service 
postgres.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig postgres on 

Step9: Check postgres server version  
# su - postgres -c "psql" 
psql (11.1)
Type "help" for help. 
 
 
 

Comments

Popular posts from this blog

How to install glibc 2.14 on RHEL 6/ RHEL 7/ CentOS 7

Export and Import users/groups and OU in AD Server 2008 using LDIFDE command.

How to Set Up and Configure latest yum repository on CentOS