Skip to main content

Installing,Starting,Stopping PostgreSQL Server on Linux OS

In this post, we will see how to Install and Run PostgreSQL on Linux machines.



There are three ways to installation procedures to download the software.

1. Binary Installation
2. Yum Installation
3. RPM Installation

In this post, will see how to install PostgreSQL using Binary installation.

1. Download the binaries from the official website.
$ wget https://get.enterprisedb.com/postgresql/postgresql-9.6.2-4-linux-x64-binaries.tar.gz
2. Untar the downloaded binaries.
$ tar -xvzf postgresql-9.6.2-4-linux-x64-binaries.tar.gz
3. Create appropriate data directories and permissions with root user to run PostgreSQL Server.
# mkdir -p  /var/lib/pgsql/data
# chown -R psql /var/lib/pgsql/data
# su psql
4. Now change the directory path to the downloaded software path
$ cd /home/psql/softwares/pgsql
5. Initialize the data directories required for PostgreSQL to run, there are two ways to initialize the directories.
$ initdb -D /usr/local/pgsql/data
Alternatively, we can also initialize using pg_ctl
pg_ctl - pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server
$ pg_ctl -D /usr/local/pgsql/data initdb
6. After successfully initializing the data directory, we need to start the server using the below command.
$ /home/psql/softwares/pgsql/bin/pg_ctl -D /var/lib/pgsql/data -l logfile start
7. Before login into the shell, create a test database to login

Note: When logging to the server for the first time you won't have any access enabled. To enable the access do below steps:
$ cd /home/psql/softwares/pgsql/bin/
$ ./psql template1
psql.bin (9.6.2)
Type "help" for help.

template1=# CREATE DATABASE mydb;
CREATE DATABASE

8. Once the database is created you can login using the database which you have created like below.
$psql mydb
psql.bin (9.6.2)
Type "help" for help.

mydb=# 

mydb=# select version();
                                                 version
----------------------------------------------------------------------------------------------------------
 PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit
(1 row)

mydb=# select current_date;
    date
------------
 2017-05-04
(1 row)

mydb=# select 5 + 5;
 ?column?
----------
       10
(1 row)

mydb=# \q
9. And, finally to shutdown database use below commands.
$ /home/psql/softwares/pgsql/bin/pg_ctl -D /var/lib/pgsql/data -l logfile stop
waiting for server to shut down.... done
server stopped
So, that's it for this post, will have a look at other two installations in the coming posts.

Comments

  1. How do you make it to auto start on os boot

    ReplyDelete
  2. And thank you for the good article

    ReplyDelete
  3. SEGA TINOHORE SEGA TINOHORE SEGA TINOHORE
    SEGA TINOHORE SEGA 2019 ford ecosport titanium TINOHORE how much is titanium worth TINOHORE. Designed for the SEGA fans of Genesis, the titanium money clip new iron titanium SEGA T-Mobile app titanium nitride gun coating has you covered!

    ReplyDelete

Post a Comment

Popular posts from this blog

Monitoring MySQL with Percona Monitoring and Management

In this blog post we will see how to monitor MySQL databases using the open source monitoring tool provided by Percona, referred as Percona Monitoring and Management (PMM). About PMM: Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL and MongoDB performance. It is developed by Percona in collaboration with experts in the field of managed database services, support and consulting. PMM is a free and open-source solution that you can run in your own environment for maximum security and reliability. It provides thorough time-based analysis for MySQL and MongoDB servers to ensure that your data works as efficiently as possible. Basic Requirements: 1. Need at least one Linux server to install PMM Client and PMM Server. 2. Need Operating System - root user credentials 3. Default port's(80) have to be open if using to or more servers. 4. A MySQL user is required to capture the Queries in the Database. 5. A Docker se...

Unable to open the log file (mysqld)

While starting the server you may find the below errors sometimes, it's because of unintentionally deleting the MySQL Binary Log files. When starting mysql if the server unable to find the mysql-bin-log files then below errors will arise. 170418 12:15:19 InnoDB: 5.5.30 started; log sequence number 32347593422 /usr/sbin/mysqld: File './mysql-bin.000023' not found (Errcode: 2) 170418 12:15:19 [ERROR] Failed to open log (file './mysql-bin.000023', errno 2) 170418 12:15:19 [ERROR] Could not open log file 170418 12:15:19 [ERROR] Can't init tc log 170418 12:15:19 [ERROR] Aborting 170418 12:15:19 InnoDB: Starting shutdown... 170418 12:15:20 InnoDB: Shutdown completed; log sequence number 32347593422 170418 12:15:20 [Note] /usr/sbin/mysqld: Shutdown complete Do we have a solution to get rid of this and start MySQL again? Well, we have two types of workarounds to start MySQL again. 1. Deleting the missed files in binlog .index  file 2. Disabling the binlog log...