लिनक्स में सोर्स कोड का उपयोग करके PostgreSQL 10 कैसे स्थापित करें


PostgreSQL जिसे Postgres भी कहा जाता है, एक शक्तिशाली और खुला स्रोत ऑब्जेक्ट-रिलेशनल डेटाबेस सिस्टम है। यह एक एंटरप्राइज़ स्तर डेटाबेस है जिसमें दोष सहिष्णुता, अतुल्यकालिक प्रतिकृति, मल्टी-वर्ज़न कंसीलर कंट्रोल (MVCC), ऑनलाइन/हॉट बैकअप, प्वाइंट इन टाइम रिकवरी, क्वेरी प्लानर/ऑप्टिमाइज़र, टेबल्स, नेस्टेड ट्रांजेक्शंस (सेवप्वाइंट्स) के लिए आगे लॉगिंग जैसे फीचर्स होते हैं। ) आदि।

वैश्विक विकास समूह द्वारा पोस्टग्रेट्स का 5 अक्टूबर 2017 को जारी किया गया नवीनतम संस्करण 10 है।

नए संस्करण की विशेषताएं इस प्रकार हैं:

  • Logical Replication: This feature enables replication of individual database objects (be it rows, tables, or selective databases) across standby servers. It provides more control over data replication. Implemented by using publisher-subscriber model.
  • Quorum Commit for Synchronous Replication: In this feature, dba can now specify the number of standby’s that acknowledge that the changes to database has done, so that data can be considered safely written.
  • SCRAM-SHA-256 authentication: Improved security that existing MD5-based password authentication and storage.
  • Improved parallel query execution.
  • Declarative table partitioning.
  • Full text search support for JSON and JSONB.

इस लेख में, हम बताएंगे कि लिनक्स सिस्टम में स्रोत कोड इंस्टॉलेशन का उपयोग करके PostgreSQL 10 कैसे स्थापित किया जाए। जो लोग वितरण पैकेज प्रबंधक से आसान स्थापना की तलाश में हैं, वे इन नीचे दिए गए गाइडों का पालन कर सकते हैं।

  1. How to Install PostgreSQL 10 on CentOS/RHEL and Fedora
  2. How to Install PostgreSQL 10 on Debian and Ubuntu

स्रोत कोड का उपयोग करके PostgreSQL स्थापित करें

जैसा कि पोस्टग्रैज ओपन सोर्स डेटाबेस है, इसे सोर्स कोड से किसी की जरूरतों/आवश्यकताओं के अनुसार बनाया जा सकता है। हम विभिन्न अतिरिक्त सुविधाओं के लिए एक या अधिक कमांड लाइन विकल्पों की आपूर्ति करके निर्माण और स्थापना प्रक्रिया को अनुकूलित कर सकते हैं।

स्रोत कोड इंस्टॉलेशन का उपयोग करने का प्रमुख लाभ यह है कि इसे इंस्टॉलेशन के दौरान अत्यधिक अनुकूलित किया जा सकता है।

1। पहले आवश्यक आवश्यक शर्तें जैसे gcc , readline-devel और zlib-devel दिखाए गए पैकेज के आधार का उपयोग करके ।

# yum install gcc zlib-devel readline-devel     [On RHEL/CentOS]
# apt install gcc zlib1g-dev libreadline6-dev   [On Debian/Ubuntu]

2। सिस्टम पर सीधे निम्नलिखित आदेशों का उपयोग करके आधिकारिक पोस्टग्रेज वेबसाइट से स्रोत कोड टार फ़ाइल डाउनलोड करें।

# wget https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.bz2

3। डाउनलोड की गई टारबॉल फ़ाइल को निकालने के लिए टार कमांड का उपयोग करें। postgresql-10.0 नाम की नई निर्देशिका बनाई जाएगी।

# tar -xvf postgresql-10.0.tar.bz2
# ll
total 19236
-rw-------. 1 root root      933 Mar 18  2015 anaconda-ks.cfg
-rw-r--r--. 1 root root     8823 Mar 18  2015 install.log
-rw-r--r--. 1 root root     3384 Mar 18  2015 install.log.syslog
drwxrwxrwx  6 1107 1107     4096 Oct  3  2017 postgresql-10.0
-rw-r--r--  1 root root 19639147 Oct  3  2017 postgresql-10.0.tar.bz2

4। स्थापना प्रक्रिया का अगला चरण अपनी आवश्यकताओं के अनुसार विकल्पों को चुनकर डाउनलोड किए गए स्रोत कोड को कॉन्फ़िगर करना है।

# cd postgresql-10.0

विभिन्न विकल्पों के बारे में सहायता प्राप्त करने के लिए ./ कॉन्फ़िगर --help का उपयोग करें।

# ./configure --help

Defaults for the options are specified in brackets.
Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/pgsql]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

5। अब एक निर्देशिका बनाएं जहां आप पोस्टग्रेज फ़ाइलों को स्थापित करना चाहते हैं और कॉन्फ़िगर के साथ उपसर्ग विकल्प का उपयोग करें।

# mkdir /opt/PostgreSQL-10/
# ./configure --prefix=/opt/PostgreSQL-10
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc supports -Wdeclaration-after-statement... yes
checking whether gcc supports -Wendif-labels... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Wformat-security... yes
checking whether gcc supports -fno-strict-aliasing... yes
checking whether gcc supports -fwrapv... yes
checking whether gcc supports -fexcess-precision=standard... no
....

6। कॉन्फ़िगर करने के बाद, अगले हम कमांड बनाने का उपयोग करके पोस्टग्रेएसक्यूएल का निर्माण शुरू करेंगे।

# make

निर्माण प्रक्रिया समाप्त होने के बाद, अब निम्नलिखित कमांड का उपयोग करके पोस्टग्रैस्कल स्थापित करें।

# make install

Postgresql 10 /opt/PostgreSQL-10 निर्देशिका में स्थापित किया गया है।

7। अब डेटाबेस क्लस्टर को इनिशियलाइज़ करने के लिए डेटा डायरेक्टरी के रूप में उपयोग किए जाने वाले पोस्टग्रेज उपयोगकर्ता और निर्देशिका बनाएं। इस डेटा निर्देशिका के स्वामी को उपयोगकर्ता को पोस्टग्रेज करना चाहिए और अनुमतियाँ 700 होनी चाहिए और हमारी आसानी के लिए पोस्टग्रेजल बायनेरिज़ के लिए भी मार्ग निर्धारित करना चाहिए।

# useradd postgres
# passwd postgres
# mkdir /pgdatabase/data
# chown -R postgres. /pgdatabase/data
# echo 'export PATH=$PATH:/opt/PostgreSQL-10/bin' > /etc/profile.d/postgres.sh

8। अब किसी भी पोस्टग्रेड कमांड का उपयोग करने से पहले डेटाबेस को पोस्टग्रेज के रूप में निम्न कमांड का उपयोग करके आरंभ करें।

# su postgres
$ initdb -D /pgdatabase/data/ -U postgres -W

जहाँ -D इस डेटाबेस क्लस्टर के लिए स्थान है या हम कह सकते हैं कि यह डेटा डायरेक्टरी है जहाँ हम डेटाबेस क्लस्टर को शुरू करना चाहते हैं, -U डेटाबेस सुपरयुज़र नाम और <कोड> के लिए - W db सुपरयूज़र के लिए पासवर्ड प्रॉम्प्ट के लिए।

अधिक जानकारी और विकल्पों के लिए हम initdb –help का उल्लेख कर सकते हैं।

9। डेटाबेस को शुरू करने के बाद, डेटाबेस क्लस्टर शुरू करें या यदि आपको सर्वर के लिए पोर्ट बदलने या पता सुनने की आवश्यकता है, तो डेटाबेस सर्वर के डेटा निर्देशिका में postgresql.conf फ़ाइल को संपादित करें।

$ pg_ctl -D /pgdatabase/data/ -l /pglog/db_logs/start.log start

10। डेटाबेस शुरू करने के बाद, निम्नलिखित आदेशों का उपयोग करके सर्वर प्रक्रिया को पोस्टग्रेज करने की स्थिति को सत्यापित करें।

$ ps -ef |grep -i postgres
$ netstat -apn |grep -i 51751

हम देख सकते हैं कि डेटाबेस क्लस्टर ठीक चल रहा है, और स्टार्टअप लॉग डेटाबेस कोड शुरू करते समय -l विकल्प के साथ निर्दिष्ट स्थान पर पाया जा सकता है।

11। अब डेटाबेस क्लस्टर से कनेक्ट करें और निम्न आदेशों का उपयोग करके डेटाबेस बनाएं।

$ psql -p 51751
postgres=# create database test;
postgres=# \l to list all databases in cluster
postgres=# \q to quit form postgres console

बस! हमारे आगामी लेखों में, मैं कॉन्फ़िगरेशन, प्रतिकृति सेटअप और pgAdmin टूल की स्थापना को कवर करूंगा, तब तक Tecmint से जुड़े रहूंगा।