PostgreSQL 14 : स्थापित करना2023/09/14 |
|
डेटाबेस सर्वर को कॉन्फ़िगर करने के लिए PostgreSQL इंस्टॉल करें।
|
|
| [1] | PostgreSQL स्थापित करें और प्रारंभ करें। |
|
root@www:~# apt -y install postgresql-14
|
| [2] | डिफ़ॉल्ट सेटिंग के अनुसार, केवल [peer] प्रमाणीकरण के साथ लोकलहोस्ट से PostgreSQL सर्वर से कनेक्ट करना संभव है। प्रमाणीकरण विधियों के विवरण के लिए नीचे दी गई आधिकारिक साइट देखें। ⇒ https://www.postgresql.jp/document/10/html/auth-pg-hba-conf.html |
|
# डिफ़ॉल्ट रूप से केवल लोकलहोस्ट सुनें root@www:~# grep listen_addresses /etc/postgresql/14/main/postgresql.conf #listen_addresses = 'localhost' # what IP address(es) to listen on; # डिफ़ॉल्ट रूप से प्रमाणीकरण विधियाँ root@www:~# grep -v -E "^#|^$" /etc/postgresql/14/main/pg_hba.conf local all postgres peer local all all peer host all all 127.0.0.1/32 scram-sha-256 host all all ::1/128 scram-sha-256 local replication all peer host replication all 127.0.0.1/32 scram-sha-256 host replication all ::1/128 scram-sha-256 |
| [3] | [peer] प्रमाणीकरण पर, इसे PostgreSQL सर्वर से कनेक्ट करने के लिए OS उपयोगकर्ता और PostgreSQL उपयोगकर्ता की आवश्यकता होती है जिनका नाम समान है। |
|
# PostgreSQL व्यवस्थापक उपयोगकर्ता के साथ एक PostgreSQL उपयोगकर्ता और उसका डेटाबेस जोड़ें root@www:~# su - postgres postgres@www:~$ createuser ubuntu postgres@www:~$ createdb testdb -O ubuntu
# उपयोगकर्ता और डेटाबेस दिखाएं postgres@www:~$ psql -c "select usename from pg_user;"
usename ---------- postgres ubuntu (2 rows)postgres@www:~$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+---------+-----------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | ubuntu | UTF8 | C.UTF-8 | C.UTF-8 |
(4 rows)
|
| [4] | ऊपर जोड़े गए उपयोगकर्ता के साथ PostgreSQL डेटाबेस से जुड़ने का प्रयास करें। |
|
# testdb से कनेक्ट करें ubuntu@www:~$ psql testdb psql (14.2 (Ubuntu 14.2-1ubuntu1)) Type "help" for help. # उपयोगकर्ता भूमिकाएँ दिखाएँ testdb=> \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} ubuntu | | {} # डेटाबेस दिखाएँ testdb=> \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+---------+----------------------- postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 | template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres testdb | ubuntu | UTF8 | C.UTF-8 | C.UTF-8 | (4 rows) # एक परीक्षण तालिका बनाएं testdb=> create table test_table (no int, name text); CREATE TABLE # तालिकाएँ दिखाएँ testdb=> \dt List of relations Schema | Name | Type | Owner --------+------------+-------+-------- public | test_table | table | ubuntu (1 row) # परीक्षण तालिका में डेटा डालें testdb=> insert into test_table (no,name) values (01,'Ubuntu'); INSERT 0 1 # पुष्टि करना testdb=> select * from test_table; no | name ----+-------- 1 | Ubuntu (1 row) # परीक्षण तालिका हटाएँ testdb=> drop table test_table; DROP TABLE testdb=> \dt Did not find any relations. # बाहर निकलना testdb=> \q # testdb हटाएँ ubuntu@www:~$ dropdb testdb ubuntu@www:~$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+---------+-----------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
|
| Sponsored Link |
|
|