0% found this document useful (0 votes)
15 views2 pages

Install PostgreSQL 9.5 on Linux

This document provides a step-by-step guide for installing PostgreSQL from source on a Ubuntu system. It includes instructions for downloading the source code, installing necessary libraries, creating a PostgreSQL user, setting up environment variables, initializing the data directory, and starting the PostgreSQL service. Additionally, it concludes with a command to check the database connection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Install PostgreSQL 9.5 on Linux

This document provides a step-by-step guide for installing PostgreSQL from source on a Ubuntu system. It includes instructions for downloading the source code, installing necessary libraries, creating a PostgreSQL user, setting up environment variables, initializing the data directory, and starting the PostgreSQL service. Additionally, it concludes with a command to check the database connection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1)Download Postgresql source code and unzip the tar file

#Login to the sudo user

sudo su -

#Download source code

wget [Link]

tar -xvzf [Link]

2)Install needed libraries

sudo apt update

sudo apt-get install gcc

sudo apt install libreadline-dev

sudo apt install zlib1g-dev

sudo apt intall make

3)Start installation from source Code

#Run below commands for installation

cd postgresql-9.5.15

./Configure && make && make install

4)Create postgres user and data directory

#Create postgres user

adduser postgres

#change from default from shell to bash

sudo usermod -s /bin/bash postgres

#Create postgres folder

mkdir /home/postgres

#To create the default settings in a new user's home directory

sudo cp -a /etc/skel/. /home/postgres

#Setting ownershi & permissions

sudo chown -R postgres:postgres /home/postgres/

sudo chmod -R 755 /home/postgres

5)Create Data directory and assign postgres ownership

mkdir -p /cluster/data

chown -R postgres:postgres /cluster/data


6)Setup basic environment variables

su - postgres

vi ~/.profile

#Add end of the line

export PATH=/usr/local/pgsql/bin:$PATH

export PGDATA=/cluster/data

export PGUSER=postgres

export PGPORT=5432

export PGDATABASE=postgres

#Execute below command

source ~/.profile

7)Initialize the data directory and start the PostgreSQL service:

initdb -D /cluster/data

pg_ctl -D /cluster/data -l logfile start

8)Check database connection

psql -p 5432

Ref: [Link]

Common questions

Powered by AI

Proper permissions and ownership settings for PostgreSQL data directories require creating the directory and assigning correct ownership to the 'postgres' user. This is done using 'chown -R postgres:postgres /cluster/data', which recursively changes the owner and group of the directory to postgres. Ensuring permissions are, at minimum, set to 755 for read, write, and execute access by the owner while limiting access for others is critical for security and functionality, preventing unauthorized access and maintaining the integrity of the database files .

Installing PostgreSQL from source may be preferable in scenarios where specific customization or optimizations are required that are not available in pre-compiled packages. Benefits include the ability to customize the build process, control over the installation directory, and the opportunity to apply patches or modifications directly to the source code. It also allows using the latest code directly from the developers if newer features are desired before official package updates are available. This flexibility is beneficial in environments needing tailored configurations or security hardening beyond default setups .

The command sequence used for compiling and installing PostgreSQL from its source code begins with navigating to the extracted source code directory using 'cd postgresql-9.5.15'. Then, the './Configure && make && make install' commands are executed in series. Here, './Configure' prepares the build system, 'make' compiles the source code, and 'make install' places the compiled components in the designated directories on the system. This sequence is crucial for transforming raw source code into an executable software package ready for operational deployment .

Initializing the data directory is a crucial step that prepares the storage location where PostgreSQL will keep all its database files. This initialization process sets up the required directory structure, system catalogs, and configuration files necessary for data storage and access. This ensures that when the PostgreSQL service starts, it can access and manage the stored data correctly. Without initialization, the database system would not have a valid structure to store or retrieve information, leading to errors or failed operations .

The steps involved in preparing a system for installing PostgreSQL from source on Ubuntu include downloading and unzipping the PostgreSQL source code, installing the necessary libraries such as gcc, libreadline-dev, and zlib1g-dev, and preparing the environment with user and directory setup. Specifically, PostgreSQL source code is downloaded using wget and unzipped with the tar command. Then, libraries are installed using 'sudo apt-get install'. Following that, a postgres user and data directory must be created, and environment variables set appropriately .

System preparation with dependencies before a PostgreSQL installation involves updating package lists using 'sudo apt update' and installing essential libraries such as gcc, libreadline-dev, zlib1g-dev, and make. Each step ensures that necessary compiling tools and libraries are available for building PostgreSQL from source. 'gcc' is crucial for compiling the source code, 'libreadline-dev' provides an interface for input buffering, and 'zlib1g-dev' assists with compressed data handling. Installing 'make' is essential for directing the build process. These dependencies ensure that the installation can proceed smoothly and that PostgreSQL will function correctly once installed .

The PostgreSQL service after installation is started using the command 'pg_ctl -D /cluster/data -l logfile start'. This command is significant because it involves the PostgreSQL server running, pointing specifically at the initialized data directory and logging operations to a specified file. This way, the server is configured to handle incoming database connections and transactions. Running the server correctly is essential for maintaining communication between the database and applications that rely on it for data processing .

Setting environment variables before initializing a PostgreSQL data directory is necessary to ensure that the PostgreSQL system knows where to find its data, which user to operate under, and which port and database settings to apply. This configuration allows PostgreSQL to initialize properly and run with the correct settings without additional manual input each time. Variables such as PATH, PGDATA, PGUSER, PGPORT, and PGDATABASE dictate fundamental operational parameters. Proper configuration in the user's profile ensures these settings are automatically loaded during initialization processes .

A verification step that ensures a successfully completed PostgreSQL installation from source on Ubuntu is checking the database connection using 'psql -p 5432'. This command confirms the PostgreSQL server is running and accessible on the specified port. Successfully connecting indicates that the server is correctly configured and operational. This step is essential because it provides immediate validation of the installation process's success, allowing further configuration or usage of the PostgreSQL database system .

The 'postgres' user plays a crucial role in operating the PostgreSQL database system as it acts as the default administrative account used to manage databases and PostgreSQL processes. During the setup process, the 'postgres' user is created to ensure dedicated and secure database management. The process involves creating the user, assigning necessary permissions, and setting up a dedicated home directory. This user is also configured to own database directories and execute PostgreSQL services, ensuring proper security isolation and management .

You might also like