In questo articolo imparerai come installare PostgreSQL 12 su Fedora 33. PostgreSQL è uno dei popolari server di database open source.
Passaggi per installare PostgreSQL 12 su Fedora 33.
Fase 1:Aggiorna i pacchetti di sistema Fedora
sudo dnf update -y
Nota:riavvia il sistema dopo l'aggiornamento.
sudo reboot
Fase 2:aggiungi il repository Yum PostgreSQL su Fedora 33
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Premi "y ” per confermare l'installazione
Esempio di output:
[root@fedora ~]# sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm Last metadata expiration check: 0:28:12 ago on Sun 31 Jan 2021 07:39:13 AM EST. pgdg-fedora-repo-latest.noarch.rpm 6.6 kB/s | 10 kB 00:01 Dependencies resolved. ============================================================================================= Package Architecture Version Repository Size ============================================================================================= Installing: pgdg-fedora-repo noarch 42.0-13 @commandline 10 k Transaction Summary ============================================================================================= Install 1 Package Total size: 10 k Installed size: 11 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-13.noarch 1/1 Verifying : pgdg-fedora-repo-42.0-13.noarch 1/1 Installed: pgdg-fedora-repo-42.0-13.noarch Complete! [root@fedora ~]#
Fase 3:Installa PostgreSQL 12 su Fedora 33
sudo dnf install postgresql12-server postgresql12
Premi "y ” per confermare l'installazione
Esempio di output:
[root@fedora ~]# sudo dnf install postgresql12-server postgresql12 PostgreSQL common RPMs for Fedora 33 - x86_64 89 kB/s | 282 kB 00:03 PostgreSQL 13 for Fedora 33 - x86_64 61 kB/s | 194 kB 00:03 PostgreSQL 12 for Fedora 33 - x86_64 62 kB/s | 192 kB 00:03 PostgreSQL 11 for Fedora 33 - x86_64 66 kB/s | 193 kB 00:02 PostgreSQL 10 for Fedora 33 - x86_64 42 kB/s | 137 kB 00:03 PostgreSQL 9.6 for Fedora 33 - x86_64 43 kB/s | 117 kB 00:02 PostgreSQL 9.5 for Fedora 33 - x86_64 242 B/s | 506 B 00:02 Dependencies resolved. =========================================================================================================== Package Architecture Version Repository Size =========================================================================================================== Installing: postgresql12-server x86_64 12.5-1PGDG.f33 pgdg12 5.5 M Installing dependencies: postgresql12 x86_64 12.5-1PGDG.f33 pgdg12 1.6 M postgresql12-libs x86_64 12.5-1PGDG.f33 pgdg12 749 k Transaction Summary =========================================================================================================== Install 3 Packages Total download size: 7.8 M Installed size: 32 M Is this ok [y/N]: y Downloading Packages: (1/3): postgresql12-libs-12.5-1PGDG.f33.x86_64.rpm 299 kB/s | 749 kB 00:02 (2/3): postgresql12-12.5-1PGDG.f33.x86_64.rpm 435 kB/s | 1.6 MB 00:03 (3/3): postgresql12-server-12.5-1PGDG.f33.x86_64.rpm 668 kB/s | 5.5 MB 00:08 ---------------------------------------------------------------------------------------------------------------------------------------- Total 949 kB/s | 7.8 MB 00:08 warning: /var/cache/dnf/pgdg12-c8926cd352a04735/packages/postgresql12-12.5-1PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY PostgreSQL 12 for Fedora 33 - x86_64 1.6 MB/s | 1.7 kB 00:00 Importing GPG key 0x442DF0F8: Userid : "PostgreSQL RPM Building Project <[email protected]>" Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : postgresql12-libs-12.5-1PGDG.f33.x86_64 1/3 Running scriptlet: postgresql12-libs-12.5-1PGDG.f33.x86_64 1/3 Installing : postgresql12-12.5-1PGDG.f33.x86_64 2/3 Running scriptlet: postgresql12-12.5-1PGDG.f33.x86_64 2/3 Running scriptlet: postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Installing : postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Running scriptlet: postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Verifying : postgresql12-12.5-1PGDG.f33.x86_64 1/3 Verifying : postgresql12-libs-12.5-1PGDG.f33.x86_64 2/3 Verifying : postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Installed: postgresql12-12.5-1PGDG.f33.x86_64 postgresql12-libs-12.5-1PGDG.f33.x86_64 postgresql12-server-12.5-1PGDG.f33.x86_64 Complete! [root@fedora ~]#
Passaggio 4:inizializza il database PostgreSQL
$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Esempio di output:
[root@fedora ~]# sudo /usr/pgsql-12/bin/postgresql-12-setup initdb Initializing database ... OK [root@fedora ~]#
Passaggio 5:avvio automatico del servizio PostgreSQL all'avvio
sudo systemctl enable --now postgresql-12
Esempio di output
[root@fedora ~]# sudo systemctl enable --now postgresql-12 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-12.service → /usr/lib/systemd/system/postgresql-12.service. [root@fedora ~]#
Fase 6:verifica lo stato del servizio PostgreSQL
systemctl status postgresql-12
Esempio di output
[root@fedora ~]# 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 Sun 2021-01-31 08:21:10 EST; 52s ago Docs: https://www.postgresql.org/docs/12/static/ Process: 5468 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 5473 (postmaster) Tasks: 8 (limit: 3446) Memory: 16.6M CPU: 84ms CGroup: /system.slice/postgresql-12.service ├─5473 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/ ├─5474 postgres: logger ├─5476 postgres: checkpointer ├─5477 postgres: background writer ├─5478 postgres: walwriter ├─5479 postgres: autovacuum launcher ├─5480 postgres: stats collector └─5481 postgres: logical replication launcher Jan 31 08:21:10 fedora systemd[1]: Starting PostgreSQL 12 database server... Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.806 EST [5473] LOG: starting PostgreSQL 12.5 on x86_64-pc-linux-gnu, comp> Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.808 EST [5473] LOG: listening on IPv6 address "::1", port 5432 Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.808 EST [5473] LOG: listening on IPv4 address "127.0.0.1", port 5432 Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.811 EST [5473] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQ> Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.813 EST [5473] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432" Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.832 EST [5473] LOG: redirecting log output to logging collector process Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.832 EST [5473] HINT: Future log output will appear in directory "log". Jan 31 08:21:10 fedora systemd[1]: Started PostgreSQL 12 database server. [root@fedora ~]#
Passaggio 7:configura il firewall
(Facoltativo Se stai utilizzando un firewall, segui i passaggi seguenti)
– Ciò consentirà ai client remoti di connettersi al server di database PostgreSQL
sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
Esempio di output
[root@fedora ~]# sudo firewall-cmd --add-service=postgresql --permanent success [root@fedora ~]# sudo firewall-cmd --reload success [root@fedora ~]#
Passaggio 8:consenti l'accesso remoto a PostgreSQL
questo è facoltativo, puoi saltare se non vuoi consentire l'accesso remoto al tuo server di database PostgreSQL
Modifica file –> ” /var/lib/pgsql/12/data/postgresql.conf ”
$ sudo vim /var/lib/pgsql/12/data/postgresql.conf listen_addresses = '*'
Imposta Ascolta per indirizzare l'indirizzo IP del tuo server oppure puoi menzionare "*" per tutte le interfacce.
Devi impostare connessioni remote da host consentiti.
$ sudo vim /var/lib/pgsql/12/data/pg_hba.conf # Accept from anywhere host all all 0.0.0.0/0 md5 # Accept from trusted subnet host all all 192.168.3.0/24 md5
è necessario riavviare il servizio PostgreSQL dopo le modifiche apportate al file di configurazione.
sudo systemctl restart postgresql-12
Passaggio 9:imposta la password dell'utente amministratore di PostgreSQL
$ sudo su - postgres $ psql -c "alter user postgres with password 'YourPassword'"
Nel comando sopra, aggiorna "YourPassword" con una password complessa per l'utente Postgres.
Esempio di output:
[root@fedora ~]# sudo su - postgres [postgres@fedora ~]$ psql -c "alter user postgres with password 'YourPassword'" ALTER ROLE [postgres@fedora ~]$
Alla fine del tutorial, hai imparato come installare PostgreSQL 12 su Fedora 33.