偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

如何在Fedora 34上安裝和配置Postgres 14?

譯文
數(shù)據(jù)庫 其他數(shù)據(jù)庫
Postgresql是一種開源對(duì)象關(guān)系數(shù)據(jù)庫系統(tǒng),經(jīng)過30多年的積極開發(fā),在可靠性、功能穩(wěn)健性和性能方面已贏得了良好的聲譽(yù)。Postgres這個(gè)免費(fèi)的開源關(guān)系數(shù)據(jù)庫管理系統(tǒng)強(qiáng)調(diào)可擴(kuò)展性和SQL合規(guī)。

[[433409]]

【51CTO.com快譯】Postgresql是一種開源對(duì)象關(guān)系數(shù)據(jù)庫系統(tǒng),經(jīng)過30多年的積極開發(fā),在可靠性、功能穩(wěn)健性和性能方面已贏得了良好的聲譽(yù)。Postgres這個(gè)免費(fèi)的開源關(guān)系數(shù)據(jù)庫管理系統(tǒng)強(qiáng)調(diào)可擴(kuò)展性和SQL合規(guī)。

它最初名為POSTGRES,指其起源是加州大學(xué)伯克利分校開發(fā)的Ingres數(shù)據(jù)庫的后續(xù)版。PostgreSQL用作許多Web、移動(dòng)、地理空間和分析等應(yīng)用的主數(shù)據(jù)存儲(chǔ)或數(shù)據(jù)倉庫。PostgreSQL可以在單單一個(gè)產(chǎn)品中存儲(chǔ)結(jié)構(gòu)化數(shù)據(jù)和非結(jié)構(gòu)化數(shù)據(jù)。

本文介紹在Fedora 34中安裝Postgresql 14。

先決條件

要繼續(xù)進(jìn)行,確保您具備以下條件:

1. 更新后的Fedora 34服務(wù)器

2. 對(duì)服務(wù)器的root訪問權(quán)限或擁有root訪問權(quán)的用戶

3. 從服務(wù)器訪問互聯(lián)網(wǎng)

4. 對(duì)Linux終端有基本了解

1. 確保服務(wù)器是最新的

在繼續(xù)之前,確保我們的服務(wù)器有最新的軟件包。使用該命令:

  1. $ sudo dnf -y update 
  2. Last metadata expiration check: 2:55:24 ago on Tue 26 Oct 2021 12:05:29 PM UTC. 
  3. Dependencies resolved. 
  4. Nothing to do. 
  5. Complete! 

2. 安裝和啟動(dòng)Postgres Server

fedora dnf postgres模塊含有Postgres 14安裝版,但不是默認(rèn)的。不妨使用該命令在Fedora上檢查Postges模塊:

  1. $ sudo dnf module list postgresql 
  2. Last metadata expiration check: 2:56:45 ago on Tue 26 Oct 2021 12:05:29 PM UTC. 
  3. Fedora Modular 34 - x86_64 
  4. Name                                                              Stream                                                        Profiles                                                                 Summary 
  5. postgresql                                                        9.6                                                           client, server [d]                                                       PostgreSQL module 
  6. postgresql                                                        10                                                            client, server [d]                                                       PostgreSQL module 
  7. postgresql                                                        11                                                            client, server [d]                                                       PostgreSQL module 
  8. postgresql                                                        12                                                            client, server                                                           PostgreSQL module 
  9. postgresql                                                        13                                                            client, server                                                           PostgreSQL module 
  10. Fedora Modular 34 - x86_64 - Updates 
  11. Name                                                              Stream                                                        Profiles                                                                 Summary 
  12. postgresql                                                        9.6                                                           client, server [d]                                                       PostgreSQL module 
  13. postgresql                                                        10                                                            client, server [d]                                                       PostgreSQL module 
  14. postgresql                                                        11                                                            client, server [d]                                                       PostgreSQL module 
  15. postgresql                                                        12                                                            client, server                                                           PostgreSQL module 
  16. postgresql                                                        13                                                            client, server                                                           PostgreSQL module 
  17. postgresql                                                        14                                                            client, server                                                           PostgreSQL module 
  18. Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled 

這意味著要使用它,就得啟用它。先重置postgres模塊,那樣我們就沒有默認(rèn)版。

  1. sudo dnf module reset postgresql 

然后用該命令啟用postgres 14:

  1. $ sudo dnf module enable postgresql:14 
  2. Last metadata expiration check: 3:03:33 ago on Tue 26 Oct 2021 12:05:29 PM UTC. 
  3. Dependencies resolved. 
  4. ================================================================================================================================================================================================================================================================================ 
  5.  Package                                                           Architecture                                                     Version                                                             Repository                                                         Size 
  6. ======================================================================================================================================================================================================================================================================== 
  7. Enabling module streams: 
  8.  postgresql                                                                                                                         14 
  9.  
  10. Transaction Summary 
  11. ======================================================================================================================================================================================================================================================================== 
  12.  
  13. Is this ok [y/N]: y 
  14. Complete! 

現(xiàn)在不妨安裝Postgresql 14和Contrib軟件包,后者為PostgreSQL數(shù)據(jù)庫系統(tǒng)提供了幾個(gè)額外的功能:

  1. sudo dnf install -y postgresql-server postgresql-contrib 

一旦安裝完成,用以下命令初始化PostgreSQL數(shù)據(jù)庫:

  1. $ sudo postgresql-setup initdb 
  2. WARNING: using obsoleted argument syntax, try --help 
  3. WARNING: arguments transformed to: postgresql-setup --initdb --unit postgresql 
  4.  * Initializing database in '/var/lib/pgsql/data' 
  5.  * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log 

現(xiàn)在啟動(dòng)服務(wù):

  1. sudo systemctl start postgresql 

然后啟用該服務(wù),以便服務(wù)器重啟后它啟動(dòng):

  1. $ sudo systemctl enable postgresql 
  2. Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service. 

確認(rèn)Postgres 14在運(yùn)行:

  1. $ sudo systemctl status postgresql 
  2. ● postgresql.service - PostgreSQL database server 
  3.      Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) 
  4.      Active: active (running) since Tue 2021-10-26 15:18:53 UTC; 46s ago 
  5.     Process: 17645 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS) 
  6.    Main PID: 17647 (postmaster) 
  7.       Tasks: 8 (limit: 4603) 
  8.      Memory: 15.7M 
  9.         CPU: 47ms 
  10.      CGroup: /system.slice/postgresql.service 
  11.              ├─17647 /usr/bin/postmaster -D /var/lib/pgsql/data 
  12.              ├─17648 postgres: logger 
  13.              ├─17650 postgres: checkpointer 
  14.              ├─17651 postgres: background writer 
  15.              ├─17652 postgres: walwriter 
  16.              ├─17653 postgres: autovacuum launcher 
  17.              ├─17654 postgres: stats collector 
  18.              └─17655 postgres: logical replication launcher 
  19.  
  20. Oct 26 15:18:52 ip-10-2-40-182.us-west-2.compute.internal systemd[1]: Starting PostgreSQL database server... 
  21. Oct 26 15:18:52 ip-10-2-40-182.us-west-2.compute.internal postmaster[17647]: 2021-10-26 15:18:52.998 UTC [17647] LOG:  redirecting log output to logging collector process 
  22. Oct 26 15:18:52 ip-10-2-40-182.us-west-2.compute.internal postmaster[17647]: 2021-10-26 15:18:52.998 UTC [17647] HINT:  Future log output will appear in directory "log"
  23. Oct 26 15:18:53 ip-10-2-40-182.us-west-2.compute.internal systemd[1]: Started PostgreSQL database server. 

Active: active (running)顯示該服務(wù)已啟動(dòng)并運(yùn)行中。

下一步,不妨通過連接至PostgreSQL數(shù)據(jù)庫服務(wù)器、打印輸出版本,確認(rèn)安裝已成功。 sudo -u postgres psql -c "SELECT version();"

輸出:

  1. $ sudo -u postgres psql -c "SELECT version();" 
  2. could not change directory to "/home/fedora": Permission denied 
  3.                                                    version 
  4. -------------------------------------------------------------------------------------------------------------- 
  5.  PostgreSQL 14.0 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1), 64-bit 
  6. (1 row) 

3. PostgreSQL角色和數(shù)據(jù)庫驗(yàn)證方法

PostgreSQL使用名為roles的概念來處理客戶身份驗(yàn)證和授權(quán)。默認(rèn)情況下,Postgres被設(shè)置為使用ident authentication,這意味著它將Postgres角色與匹配的Unix/Linux系統(tǒng)帳戶相關(guān)聯(lián)。如果Postgres中存在角色,有相同名稱的Unix/Linux用戶名就能以該角色登錄。

安裝過程創(chuàng)建了一個(gè)名為postgres的用戶帳戶,該帳戶與默認(rèn)的postgres角色相關(guān)聯(lián)。為了使用PostgreSQL,您可以登錄到該帳戶。

PostgreSQL支持多種驗(yàn)證方法。最常用的方法有:

  • Trust——只要滿足pg_hba.conf中定義的條件,角色可以在沒有密碼的情況下進(jìn)行連接。
  • Password——角色可以通過提供密碼進(jìn)行連接。密碼可以存儲(chǔ)為scram-sha-256、md5和password (clear-text)。
  • Ident——僅在TCP/IP連接上受支持。它通過獲取客戶端的操作系統(tǒng)用戶名來工作,有可選的用戶名映射。
  • Peer——與Ident一樣,但僅在本地連接上受支持。

4.連接到postgres數(shù)據(jù)庫

(1)通過切換到postres用戶

通過在終端中輸入以下內(nèi)容,切換到服務(wù)器上的postgres帳戶:

  1. sudo -i -u postgres 

現(xiàn)在您可以立即訪問Postgres提示符,只需輸入:

  1. $ psql 
  2. psql (14.0) 
  3. Type "help" for help. 
  4.  
  5. postgres=# 

您將因此登錄到PostgreSQL提示符,可以立即與數(shù)據(jù)庫管理系統(tǒng)進(jìn)行交互。

(2)通過以postgres用戶的身份來運(yùn)行命令

使用該方法,以postgres用戶的身份直接運(yùn)行命令,使用sudo:

  1. sudo -u postgres psql 

輸出:

  1. $ sudo -u postgres psql 
  2. psql (14.0) 
  3. Type "help" for help. 
  4.  
  5. postgres=# 

5. 配置postgres 14實(shí)例以便遠(yuǎn)程訪問

為此,我們將改動(dòng)postgres配置文件。我們需要打開文件,并調(diào)整配置。Postgresql 14的主配置文件位于該路徑:/var/lib/pgsql/14/data/pg_hba.conf。

不妨將peer識(shí)別改為trust(信任):

  1. sed -i '/^local/s/peer/trust/' /var/lib/pgsql/data/pg_hba.conf 

將ident識(shí)別改為md5,允許密碼登錄。

  1. sed -i '/^host/s/ident/md5/' /var/lib/pgsql/data/pg_hba.conf 

添加block,允許從所有地方訪問:

將該內(nèi)容添加到文件/var/lib/pgsql/data/pg_hba.conf

  1. host    all             all             0.0.0.0/0                md5 

確保PostgreSQL在監(jiān)聽*

將這一行添加到這里的配置文件/var/lib/pgsql/data/postgresql.conf

  1. listen_addresses='*' 

啟用并重啟postgresql服務(wù)器,重新加載配置:

  1. sudo systemctl restart postgresql 
  2. sudo systemctl enable postgresql 

6. 用戶管理

創(chuàng)建超級(jí)用戶

由于一切已到位,不妨創(chuàng)建超級(jí)用戶。

以postres角色連接到數(shù)據(jù)庫:

  1. $ sudo -u postgres psql 
  2. psql (14.0) 
  3. Type "help" for help. 
  4.  
  5. postgres=# 

創(chuàng)建名稱為root的超級(jí)用戶:

  1. CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'passwordhere'

輸出:

  1. postgres=# CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'passwordhere'
  2. CREATE ROLE 
  3. postgres=# \du 
  4.                                    List of roles 
  5.  Role name |                         Attributes                         | Member of 
  6. -----------+------------------------------------------------------------+----------- 
  7.  postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {} 
  8.  root      | Superuser, Create role, Create DB                          | {} 
  9.  
  10. postgres=# 

管理應(yīng)用程序用戶

以此創(chuàng)建數(shù)據(jù)庫、創(chuàng)建用戶,并向該用戶授予訪問該數(shù)據(jù)庫的所有權(quán)限:

  1. create database app_db_name; 
  2. create user app_user with encrypted password 'dbpassword'
  3. grant all privileges on database app_db_name to app_user; 

在此查看用戶和權(quán)限管理方面的完整指南。

從遠(yuǎn)程主機(jī)連接到實(shí)例

使用該命令從本地機(jī)連接到postgres實(shí)例:

  1. psql 'postgres://<username>:<password>@<host>:<port>/<db>?sslmode=disable' 
  2.  
  3. like 
  4. psql 'postgres://root:passwordhere@192.160.1.20:5432/postgres?sslmode=disable' 

結(jié)語

至此我們已在Fedora 34服務(wù)器上安裝了Postgresql 14,做一些基本的配置,然后做基本的用戶管理。

原文標(biāo)題:How to Install and Configure Postgres 14 on Fedora 34

【51CTO譯稿,合作站點(diǎn)轉(zhuǎn)載請(qǐng)注明原文譯者和出處為51CTO.com】

 

責(zé)任編輯:華軒 來源: 51CTO
相關(guān)推薦

2023-11-26 16:23:16

FedoraVSCodium

2021-08-18 11:19:25

FedoraLinuxJava

2021-11-28 06:33:24

Discord消息收發(fā)應(yīng)用 Linux

2017-04-11 13:20:06

CentOSRHELFedora

2020-12-28 06:44:45

FedoraLinux RPM文件

2020-03-02 18:16:12

FedoraLinuxMongoDB

2015-08-04 13:29:06

Fedoralinux

2020-11-25 09:47:11

FedoraGoogle Chro瀏覽器

2017-04-24 18:10:27

DrupalCentOSFedora

2021-11-29 14:38:45

FedoraLinuxBrave瀏覽器

2019-10-21 13:28:38

UbuntuPostgreSQL命令

2020-03-18 14:40:14

Ubuntu 18.0RedisLinux

2022-12-27 08:51:31

WebDebian 11

2021-07-25 10:34:17

FedoraPodmanLinux

2016-01-06 14:00:20

Ubuntu 14Ubuntu 15Apache Solr

2018-05-14 08:36:06

JavaFedoraOpenJDK

2018-06-11 09:55:09

LinuxFedorazsh

2020-11-24 13:55:20

FedoraVirtualBoxLinux

2020-04-08 12:20:25

UbuntuLinuxOracle Java

2017-04-24 17:00:26

Linux樹莓派Fedora 25
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)