PostgreSQL
 sql >> डेटाबेस >  >> RDS >> PostgreSQL

Ubuntu 20.04/18.04/16.04 पर PostgreSQL 12 कैसे स्थापित करें?

इस लेख में, हम आपको दिखाएंगे कि कैसे  Ubuntu 20.04/18.04/16.04 पर PostgreSQL 12 स्थापित करें। PostgreSQL एक ओपन-सोर्स डेटाबेस सिस्टम है और यह अन्य रिलेशनल डेटाबेस सिस्टम की तरह शक्तिशाली है।

आप postgreSQL 12 का रिलीज़ पेज देख सकते हैं। 

उबंटू पर PostgreSQL 12 स्थापित करने के चरण

चरण 1:Ubuntu सिस्टम अपडेट करें

PostgreSQL को स्थापित करने से पहले सिस्टम को अपडेट करने की हमेशा अनुशंसा की जाती है।

sudo apt update

चरण 2:आवश्यक पैकेज इंस्टॉल करें 

sudo apt -y install vim bash-completion wget

यदि पैकेज पहले से स्थापित है तो आपको नीचे आउटपुट मिलेगा, आप इसे अनदेखा कर सकते हैं।

नमूना आउटपुट:

root@PostgreSQL:~# sudo apt -y install vim bash-completion wget
Reading package lists... Done
Building dependency tree 
Reading state information... Done
bash-completion is already the newest version (1:2.11-2ubuntu1).
vim is already the newest version (2:8.2.0716-3ubuntu2).
wget is already the newest version (1.20.3-1ubuntu1).
wget set to manually installed.
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 212 not upgraded.
root@PostgreSQL:~# 

चरण 3:PostgreSQL 12 रिपॉजिटरी जोड़ें

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

चरण 4:Ubuntu पर PostgreSQL 12 इंस्टॉल करें

sudo apt update

sudo apt -y install postgresql-12 postgresql-client-12

नमूना आउटपुट:

root@PostgreSQL:~# sudo apt -y install postgresql-12 postgresql-client-12
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libpq5
libtypes-serialiser-perl pgdg-keyring postgresql-client-common
postgresql-common sysstat
Suggested packages:
postgresql-doc-12 isag
The following NEW packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libpq5
libtypes-serialiser-perl pgdg-keyring postgresql-12 postgresql-client-12
postgresql-client-common postgresql-common sysstat
0 upgraded, 11 newly installed, 0 to remove and 212 not upgraded.
Need to get 17.5 MB of archives.
After this operation, 59.4 MB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 libpq5 amd64 13.3-1.pgdg20.10+1 [177 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 libcommon-sense-perl amd64 3.75-1build2 [20.5 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 libjson-perl all 4.02000-2 [80.9 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 pgdg-keyring all 2018.2 [10.7 kB]
Get:5 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 postgresql-client-common all 226.pgdg20.10+1 [90.6 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 libtypes-serialiser-perl all 1.0-1 [12.1 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 libjson-xs-perl amd64 4.020-1build1 [83.7 kB]
Get:8 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 postgresql-client-12 amd64 12.7-1.pgdg20.10+1 [1,429 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 sysstat amd64 12.4.0-1 [471 kB]
Get:10 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 postgresql-common all 226.pgdg20.10+1 [246 kB]
Get:11 http://apt.postgresql.org/pub/repos/apt groovy-pgdg/main amd64 postgresql-12 amd64 12.7-1.pgdg20.10+1 [14.9 MB]
Fetched 17.5 MB in 15s (1,141 kB/s) 
Preconfiguring packages ...
Selecting previously unselected package libcommon-sense-perl.
(Reading database ... 192977 files and directories currently installed.)
Preparing to unpack .../00-libcommon-sense-perl_3.75-1build2_amd64.deb ...
Unpacking libcommon-sense-perl (3.75-1build2) ...
Selecting previously unselected package libjson-perl.
Preparing to unpack .../01-libjson-perl_4.02000-2_all.deb ...
Unpacking libjson-perl (4.02000-2) ...
Selecting previously unselected package libtypes-serialiser-perl.
Preparing to unpack .../02-libtypes-serialiser-perl_1.0-1_all.deb ...
Unpacking libtypes-serialiser-perl (1.0-1) ...
Selecting previously unselected package libjson-xs-perl.
Preparing to unpack .../03-libjson-xs-perl_4.020-1build1_amd64.deb ...
Unpacking libjson-xs-perl (4.020-1build1) ...
Selecting previously unselected package libpq5:amd64.
Preparing to unpack .../04-libpq5_13.3-1.pgdg20.10+1_amd64.deb ...
Unpacking libpq5:amd64 (13.3-1.pgdg20.10+1) ...
Selecting previously unselected package pgdg-keyring.
Preparing to unpack .../05-pgdg-keyring_2018.2_all.deb ...
Unpacking pgdg-keyring (2018.2) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack .../06-postgresql-client-common_226.pgdg20.10+1_all.deb ...
Unpacking postgresql-client-common (226.pgdg20.10+1) ...
Selecting previously unselected package postgresql-client-12.
Preparing to unpack .../07-postgresql-client-12_12.7-1.pgdg20.10+1_amd64.deb ..
.
Unpacking postgresql-client-12 (12.7-1.pgdg20.10+1) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../08-postgresql-common_226.pgdg20.10+1_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by post
gresql-common'
Unpacking postgresql-common (226.pgdg20.10+1) ...
Selecting previously unselected package postgresql-12.
Preparing to unpack .../09-postgresql-12_12.7-1.pgdg20.10+1_amd64.deb ...
Unpacking postgresql-12 (12.7-1.pgdg20.10+1) ...
Selecting previously unselected package sysstat.
Preparing to unpack .../10-sysstat_12.4.0-1_amd64.deb ...
Unpacking sysstat (12.4.0-1) ...
Setting up pgdg-keyring (2018.2) ...
Removing apt.postgresql.org key from trusted.gpg: OK
Setting up libpq5:amd64 (13.3-1.pgdg20.10+1) ...
Setting up libcommon-sense-perl (3.75-1build2) ...
Setting up libtypes-serialiser-perl (1.0-1) ...
Setting up libjson-perl (4.02000-2) ...
Setting up sysstat (12.4.0-1) ...

Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) i
n auto mode
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer
→ /lib/systemd/system/sysstat-collect.timer.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer
→ /lib/systemd/system/sysstat-summary.timer.
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /
lib/systemd/system/sysstat.service.
Setting up postgresql-client-common (226.pgdg20.10+1) ...
Setting up libjson-xs-perl (4.020-1build1) ...
Setting up postgresql-client-12 (12.7-1.pgdg20.10+1) ...
update-alternatives: using /usr/share/postgresql/12/man/man1/psql.1.gz to provi
de /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-common (226.pgdg20.10+1) ...
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
en_us
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service 
→ /lib/systemd/system/postgresql.service.
Setting up postgresql-12 (12.7-1.pgdg20.10+1) ...
Creating new PostgreSQL cluster 12/main ...
/usr/lib/postgresql/12/bin/initdb -D /var/lib/postgresql/12/main --auth-local p
eer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/12/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/New_York
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

pg_ctlcluster 12 main start

Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresq
l/postgresql-12-main.log
update-alternatives: using /usr/share/postgresql/12/man/man1/postmaster.1.gz to
provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Processing triggers for systemd (246.6-1ubuntu1) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for libc-bin (2.32-0ubuntu3) ...
root@PostgreSQL:~# 

के लिए ट्रिगर्स को प्रोसेस करना

चरण 5:PostgreSQL सेवा की स्थिति जांचें

systemctl status postgresql.service 

नमूना आउटपुट:

root@PostgreSQL:~# systemctl status postgresql.service 
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor p>
Active: active (exited) since Sun 2021-05-16 09:17:56 EDT; 1min 56s ago
Main PID: 10932 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4648)
Memory: 0B
CGroup: /system.slice/postgresql.service

May 16 09:17:56 PostgreSQL systemd[1]: Starting PostgreSQL RDBMS...
May 16 09:17:56 PostgreSQL systemd[1]: Finished PostgreSQL RDBMS.

root@PostgreSQL:~#

चरण 6:PostgreSQL कनेक्ट करें 

sudo su - postgres

चरण 7:PostgreSQL पासवर्ड रीसेट करें

पासवर्ड को मजबूत पासवर्ड पर रीसेट करने की अनुशंसा की जाती है

psql -c "alter user postgres with password 'StrongAdminP@ssw0rd'"

नमूना आउटपुट:

root@PostgreSQL:~# sudo su - postgres
postgres@PostgreSQL:~$ 
postgres@PostgreSQL:~$ psql -c "alter user postgres with password 'StrongAdminP@ssw0rd'"
ALTER ROLE
postgres@PostgreSQL:~$

चरण 8:PostgreSQL डेटाबेस बनाएं 

$ psql

$ CREATE DATABASE firsttestdb;

$ CREATE USER testuser1 WITH ENCRYPTED PASSWORD 'MyDBP@ss0rd';

$ GRANT ALL PRIVILEGES ON DATABASE firsttestdb to testuser1;

PostgreSQL डेटाबेस की सूची बनाएं:

$\l

PostgreSQL डेटाबेस से कैसे कनेक्ट करें:

 \c firsttestdb

नमूना आउटपुट:

postgres=# \c firsttestdb
You are now connected to database "firsttestdb" as user "postgres".
firsttestdb=#

अब, हम देखेंगे कि PostgreSQL DB को दूरस्थ कनेक्शन की अनुमति कैसे दी जाती है।

चरण 9:PostgreSQL डेटाबेस से दूरस्थ कनेक्शन की अनुमति दें

sudo nano /etc/postgresql/12/main/postgresql.conf 

टिप्पणी पंक्ति "सुनें_पते ='*' "

फ़ाइल सहेजें और PostgreSQL सेवा को पुनरारंभ करें

sudo systemctl restart postgresql 

चरण 10:सुनने का पता जांचें

 netstat  -tunelp | grep 5432

नमूना आउटपुट:

root@PostgreSQL:~# netstat -antple | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 135 253939 13850/postgres 
tcp6 0 0 :::5432 :::* LISTEN 135 253940 13850/postgres 
root@PostgreSQL:~#

लेख के अंत में, हमने देखा कि Ubuntu 20.04/18.04/16.04 पर PostgreSQL 12 कैसे स्थापित करें।


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. सी # विंडोज मोबाइल 6.5 ऐप को पोस्टग्रेस डेटाबेस से कैसे कनेक्ट करें?

  2. postgreSQL - बनाम कोई भी

  3. PostgreSQL प्रतिकृति 101 के लिए विफलता

  4. Psql का उपयोग करके मैं डेटाबेस में स्थापित एक्सटेंशन को कैसे सूचीबद्ध करूं?

  5. कैसे Cosd () PostgreSQL में काम करता है