Neste artigo, você aprenderá como instalar o PostgreSQL 12 no Fedora 33. O PostgreSQL é um dos populares servidores de banco de dados de código aberto.
Etapas para instalar o PostgreSQL 12 no Fedora 33.
Passo 1:Atualizar os pacotes do sistema Fedora
sudo dnf update -y
Nota:Reinicie seu sistema após a atualização.
sudo reboot
Etapa 2:Adicione o repositório PostgreSQL Yum no Fedora 33
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Pressione “s ” para confirmar a instalação
Saída de amostra:
[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 ~]#
Etapa 3:Instale o PostgreSQL 12 no Fedora 33
sudo dnf install postgresql12-server postgresql12
Pressione “s ” para confirmar a instalação
Saída de amostra:
[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 ~]#
Etapa 4:inicializar o banco de dados PostgreSQL
$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Saída de amostra:
[root@fedora ~]# sudo /usr/pgsql-12/bin/postgresql-12-setup initdb Initializing database ... OK [root@fedora ~]#
Etapa 5:Iniciar automaticamente o serviço PostgreSQL na inicialização
sudo systemctl enable --now postgresql-12
Saída de Amostra
[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 ~]#
Etapa 6:verifique o status do serviço PostgreSQL
systemctl status postgresql-12
Saída de Amostra
[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 ~]#
Etapa 7:configurar o firewall
(Opcional Se você estiver usando firewall, siga as etapas abaixo)
– Isso permitirá que clientes remotos se conectem ao servidor de banco de dados PostgreSQL
sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
Saída de amostra
[root@fedora ~]# sudo firewall-cmd --add-service=postgresql --permanent success [root@fedora ~]# sudo firewall-cmd --reload success [root@fedora ~]#
Etapa 8:permitir acesso remoto ao PostgreSQL
isso é opcional, você pode pular se não quiser permitir acesso remoto ao seu servidor de banco de dados PostgreSQL
Editar arquivo –> ” /var/lib/pgsql/12/data/postgresql.conf ”
$ sudo vim /var/lib/pgsql/12/data/postgresql.conf listen_addresses = '*'
Defina Listen to address para o endereço IP do seu servidor ou você pode mencionar “*” para todas as interfaces.
Você precisa definir conexões remotas de hosts permitidos.
$ 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
você precisa reiniciar o serviço PostgreSQL após as alterações feitas no arquivo de configuração.
sudo systemctl restart postgresql-12
Etapa 9:definir a senha do usuário administrador do PostgreSQL
$ sudo su - postgres $ psql -c "alter user postgres with password 'YourPassword'"
No comando acima, atualize ‘YourPassword’ para uma senha forte para o usuário do Postgres.
Saída de amostra:
[root@fedora ~]# sudo su - postgres [postgres@fedora ~]$ psql -c "alter user postgres with password 'YourPassword'" ALTER ROLE [postgres@fedora ~]$
No final do tutorial, você aprendeu como instalar o PostgreSQL 12 no Fedora 33.