如何在Fedora 31/30/29上安裝PostgreSQL 12

????????本指南將討論在Fedora 31/30/29上PostgreSQL 12的安裝。PostgreSQL是一種開放源代碼數據庫服務器,其創(chuàng)建目的是可靠,健壯并適用于注重性能的部署。PostgreSQL 12已于2019年10月3日發(fā)布,具有許多新功能以供一般使用。


大象大象你的鼻子怎么那么長!

步驟1:更新系統(tǒng)

確保系統(tǒng)軟件包是最新的:

sudo dnf install -y vim bash-completion wget

sudo dnf update -y

由于您可能具有內核更新,因此建議您在升級后重新引導系統(tǒng)

sudo reboot

步驟2:添加PostgreSQL Yum存儲庫

通過運行以下命令將PostgreSQL Yum存儲庫添加到您的Fedora系統(tǒng):

Fedora 31:

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-31-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 30:

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-30-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 29:

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-29-x86_64/pgdg-fedora-repo-latest.noarch.rpm

當提示您確認安裝時,請按?y?鍵。

Last metadata expiration check: 0:01:25 ago on Sat 12 Oct 2019 06:52:54 AM UTC.

pgdg-fedora-repo-latest.noarch.rpm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 21 kB/s | 9.7 kB? ? 00:00? ?

Dependencies resolved.

===================================================================================================================================================

Package? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Architecture? ? ? ? ? ? ? ? ? Version? ? ? ? ? ? ? ? ? ? ? ? Repository? ? ? ? ? ? ? ? ? ? ? ? ? ? Size

===================================================================================================================================================

Installing:

pgdg-fedora-repo? ? ? ? ? ? ? ? ? ? ? ? noarch? ? ? ? ? ? ? ? ? ? ? ? 42.0-5? ? ? ? ? ? ? ? ? ? ? ? @commandline? ? ? ? ? ? ? ? ? ? ? ? 9.7 k

Transaction Summary

===================================================================================================================================================

Install? 1 Package

Total size: 9.7 k

Installed size: 9.7 k

Is this ok [y/N]: y

Downloading Packages:

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

? Preparing? ? ? ? :? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/1

? Installing? ? ? : pgdg-fedora-repo-42.0-5.noarch? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/1

? Verifying? ? ? ? : pgdg-fedora-repo-42.0-5.noarch? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/1

Installed:

? pgdg-fedora-repo-42.0-5.noarch? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Complete!

步驟3:在Fedora 31/30/29上安裝PostgreSQL 12

將PostgreSQL Repository添加到Fedora系統(tǒng)后,安裝PostgreSQL 12 Server / Client軟件包:

sudo dnf install postgresql12-server postgresql12

同意安裝。

Last metadata expiration check: 0:01:17 ago on Sat 12 Oct 2019 07:00:29 AM UTC.

Dependencies resolved.

===================================================================================================================================================

Package? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Architecture? ? ? ? ? ? ? ? Version? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Repository? ? ? ? ? ? ? ? ? ? Size

===================================================================================================================================================

Installing:

postgresql12-server? ? ? ? ? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? ? ? ? ? 12.0-1PGDG.f30? ? ? ? ? ? ? ? ? ? ? ? ? pgdg12? ? ? ? ? ? ? ? ? ? ? 5.1 M

Installing dependencies:

postgresql12? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? ? ? ? ? 12.0-1PGDG.f30? ? ? ? ? ? ? ? ? ? ? ? ? pgdg12? ? ? ? ? ? ? ? ? ? ? 1.5 M

postgresql12-libs? ? ? ? ? ? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? ? ? ? ? 12.0-1PGDG.f30? ? ? ? ? ? ? ? ? ? ? ? ? pgdg12? ? ? ? ? ? ? ? ? ? ? 393 k

Transaction Summary

===================================================================================================================================================

Install? 3 Packages

Total download size: 7.0 M

Installed size: 32 M

Is this ok [y/N]: y

步驟4:初始化數據庫并啟用自動啟動

現(xiàn)在已經安裝了數據庫軟件包,通過運行以下命令來初始化數據庫

$ sudo / usr / pgsql-12 / bin / postgresql-12-setup initdb

初始化數據庫...確定

然后啟動并啟用服務以在啟動時啟動

sudo systemctl enable --now postgresql-12

確認服務狀態(tài)。

$ systemctl status postgresql-12

● postgresql-12.service - PostgreSQL 12 database server

? Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)

? Active: active (running) since Sat 2019-10-12 07:08:57 UTC; 12s ago

? ? Docs: https://www.postgresql.org/docs/12/static/

? Process: 1506 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)

Main PID: 1511 (postmaster)

? ? Tasks: 8 (limit: 2354)

? Memory: 15.9M

? CGroup: /system.slice/postgresql-12.service

? ? ? ? ? ├─1511 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/

? ? ? ? ? ├─1512 postgres: logger?

? ? ? ? ? ├─1514 postgres: checkpointer?

? ? ? ? ? ├─1515 postgres: background writer?

? ? ? ? ? ├─1516 postgres: walwriter?

? ? ? ? ? ├─1517 postgres: autovacuum launcher?

? ? ? ? ? ├─1518 postgres: stats collector?

? ? ? ? ? └─1519 postgres: logical replication launcher?

Oct 12 07:08:57 fed30.novalocal systemd[1]: Starting PostgreSQL 12 database server...

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.760 UTC [1511] LOG:? starting PostgreSQL 12.0 on x86_64-pc-linux-gnu, compil>

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.762 UTC [1511] LOG:? listening on IPv6 address "::1", port 5432

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.762 UTC [1511] LOG:? listening on IPv4 address "127.0.0.1", port 5432

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.767 UTC [1511] LOG:? listening on Unix socket "/var/run/postgresql/.s.PGSQL.>

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.774 UTC [1511] LOG:? listening on Unix socket "/tmp/.s.PGSQL.5432"

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.782 UTC [1511] LOG:? redirecting log output to logging collector process

Oct 12 07:08:57 fed30.novalocal postmaster[1511]: 2019-10-12 07:08:57.782 UTC [1511] HINT:? Future log output will appear in directory "log".

Oct 12 07:08:57 fed30.novalocal systemd[1]: Started PostgreSQL 12 database server.

如果您有正在運行的防火墻服務,并且遠程客戶端應連接到數據庫服務器,則允許PostgreSQL服務。

sudo firewall-cmd --add-service=postgresql --permanent

sudo firewall-cmd --reload

步驟5:啟用對PostgreSQL的遠程訪問(可選)

如果您有“應用程序”通過網絡連接到數據庫服務器,請編輯該文件/var/lib/pgsql/12/data/postgresql.conf?,并將“偵聽地址”設置為服務器IP地址,或將所有接口設置為“?*?”。

$ sudo vim /var/lib/pgsql/12/data/postgresql.conf

listen_addresses = '*'

還要將PostgreSQL設置為接受來自允許的主機的遠程連接。

$ sudo vim /var/lib/pgsql/11/data/pg_hba.conf

# Accept from anywhere

host all all 0.0.0.0/0 md5

# Accept from trusted subnet

host all all 10.10.10.0/24 md5

進行更改后,重新啟動PostgreSQL 12服務。

sudo systemctl重新啟動postgresql-12

步驟6:設定PostgreSQL管理員使用者的密碼

設置PostgreSQL管理員用戶密碼。

$ sudo su - postgres

$ psql -c "alter user postgres with password 'StrongPassword'"

其中StrongPasswordpostgres用戶的新密碼。

步驟7:安裝pgAdmin 4 Web管理

如果您需要一種簡單的方法來管理PostgreSQL數據庫服務器(類似于MySQL的phpMyAdmin),請考慮安裝pgAdmin4。


原文地址:https://computingforgeeks.com/how-to-install-postgresql-12-on-fedora/

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容