Database
 sql >> Database >  >> RDS >> Database

Come installare pgAdmin 4 su Ubuntu 20.04/18.04/16.04

Questo tutorial mostra come installare pgAdmin 4 su Ubuntu 20.04/18.04/16.04. pgAdmin è uno strumento di sviluppo e amministrazione PostgreSQL open source, pgAdmin è fondamentalmente utilizzato per la gestione del server di database PostgreSQL.

È necessario disporre di un server PostgreSQL su un sistema/VM locale o remoto. In caso contrario, fare riferimento al documento seguente e installare PostgreSQL. Per questo tutorial, ho installato il server PostgreSQL e lo strumento pgAdmin sullo stesso sistema Ubuntu.

Come installare PostgreSQL 12 su Ubuntu 20.04/18.04/16.04

Passo per installare pgAdmin4 su Ubuntu

Passaggio 1:aggiungi il repository APT di PostgreSQL

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'

Esempio di output:

root@PostgreSQL:~# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
root@PostgreSQL:~# sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Hit:1 http://us.archive.ubuntu.com/ubuntu groovy InRelease 
Hit:2 http://security.ubuntu.com/ubuntu groovy-security InRelease 
Hit:3 http://us.archive.ubuntu.com/ubuntu groovy-updates InRelease 
Hit:4 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/groovy pgadmin4 InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu groovy-backports InRelease
Reading package lists... Done
Building dependency tree 
Reading state information... Done
206 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@PostgreSQL:~#

Passaggio 2:installa pgAdmin4 su Ubuntu

sudo apt install pgadmin4 

Esempio di output:

root@PostgreSQL:~# sudo apt install pgadmin4
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libapache2-mod-wsgi-py3 pgadmin4-desktop pgadmin4-server pgadmin4-web
The following NEW packages will be installed:
libapache2-mod-wsgi-py3 pgadmin4 pgadmin4-desktop pgadmin4-server
pgadmin4-web
0 upgraded, 5 newly installed, 0 to remove and 206 not upgraded.
Need to get 79.7 MB/161 MB of archives.
After this operation, 300 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/groovy pgadmin4/main amd64 pgadmin4-desktop amd64 5.2 [79.7 MB]
Get:2 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/groovy pgadmin4/main all pgadmin4-web all 5.2 [2,640 B]
Get:3 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/groovy pgadmin4/main all pgadmin4 all 5.2 [840 B]
Fetched 69.0 MB in 59s (1,178 kB/s) 
Selecting previously unselected package libapache2-mod-wsgi-py3.
(Reading database ... 195104 files and directories currently installed.)
Preparing to unpack .../libapache2-mod-wsgi-py3_4.7.1-2_amd64.deb ...
Unpacking libapache2-mod-wsgi-py3 (4.7.1-2) ...
Selecting previously unselected package pgadmin4-server.
Preparing to unpack .../pgadmin4-server_5.2_amd64.deb ...
Unpacking pgadmin4-server (5.2) ...
Selecting previously unselected package pgadmin4-desktop.
Preparing to unpack .../pgadmin4-desktop_5.2_amd64.deb ...
Unpacking pgadmin4-desktop (5.2) ...
Selecting previously unselected package pgadmin4-web.
Preparing to unpack .../pgadmin4-web_5.2_all.deb ...
Unpacking pgadmin4-web (5.2) ...
Selecting previously unselected package pgadmin4.
Preparing to unpack .../archives/pgadmin4_5.2_all.deb ...
Unpacking pgadmin4 (5.2) ...
Setting up pgadmin4-server (5.2) ...
Setting up libapache2-mod-wsgi-py3 (4.7.1-2) ...
apache2_invoke: Enable module wsgi
Setting up pgadmin4-desktop (5.2) ...
Setting up pgadmin4-web (5.2) ...
Setting up pgadmin4 (5.2) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu4) ...
root@PostgreSQL:~#

Passaggio 3:configura le credenziali pgAdmin4 

sudo /usr/pgadmin4/bin/setup-web.sh

Sostituisci l'ID e-mail [email protected] e configura la tua password complessa.

Dopo l'installazione verrà avviato il servizio Apache

$ systemctl status apache2

Esempio di output:

root@PostgreSQL:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor pres>
Active: active (running) since Sun 2021-05-16 12:28:13 EDT; 4min 37s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 25828 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/>
Main PID: 25832 (apache2)
Tasks: 34 (limit: 4648)
Memory: 33.9M
CGroup: /system.slice/apache2.service
├─25832 /usr/sbin/apache2 -k start
├─25833 /usr/sbin/apache2 -k start
├─25834 /usr/sbin/apache2 -k start
├─25835 /usr/sbin/apache2 -k start
├─25836 /usr/sbin/apache2 -k start
├─25837 /usr/sbin/apache2 -k start
└─25838 /usr/sbin/apache2 -k start

May 16 12:28:12 PostgreSQL systemd[1]: Starting The Apache HTTP Server...
May 16 12:28:13 PostgreSQL apachectl[25831]: AH00558: apache2: Could not relia>
May 16 12:28:13 PostgreSQL systemd[1]: Started The Apache HTTP Server.

root@PostgreSQL:~#

Fase 4:configura il firewall su Ubuntu (opzionale)

sudo ufw allow http

sudo ufw allow https

Esempio di output:

root@PostgreSQL:~# sudo ufw allow http
Rules updated
Rules updated (v6)
root@PostgreSQL:~# sudo ufw allow https
Rules updated
Rules updated (v6)
root@PostgreSQL:~#

Fase 5:accedi a pgadmin4 sul browser web

http://[ServerIP_o_dominio]/pgadmin4

Accedi con le credenziali che abbiamo creato nel passaggio 3

Una volta effettuato l'accesso, verrà visualizzata la schermata qui sotto.

Fase 6:aggiungi un server PostgreSQL da amministrare con pgAdmin

Fai clic su "Aggiungi nuovo server" (puoi aggiungere un server PostgreSQL locale o remoto)

Nella sezione "Generale ", Fornisci il nome del server PostgreSQL con la descrizione 

Ora, fai clic su "Connessione tab", fornisce i dettagli del server come IP/host PostgreSQL, utente del database e password

Ora salvalo. Se tutta la configurazione è corretta sarai in grado di vedere il server PostgreSQL sul lato sinistro.

Alla fine dell'articolo, abbiamo visto come installare pgAdmin 4 su Ubuntu 20.04/18.04/16.0 ed esplorare di più sull'interfaccia utente web di pgAdmin.