Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Instalar PGADMIN4 en Centos 7

https://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-install-pgadmin-4-on-centos-
7-rhel-7-fedora-29-fedora-28.html

pgAdmin is a free and open source management tool for PostgreSQL and derivative relation
databases such as EDB Advanced Server. It can be installed on multiple OS platforms such as
Linux, Unix, Mac OS X, and Windows to manager PostgreSQL 9.2 and above.

Deployment Mode

pgAdmin can be run as a web or desktop application.

Server Deployment

In server deployment (web application), it is deployed as a web application behind a


web server running as a reverse proxy or using the WSGI interface.

Desktop Deployment

In desktop deployment (desktop application), it is deployed to run in desktop mode by


utilizing the desktop runtime to host the application. When the runtime is launched from
system-tray, it runs the pgAdmin server and launches a web browser to render the user
interface.

In this guide, we will install pgAdmin 4 on CentOS 7 / RHEL 7 & Fedora 29 / Fedora
28 as a web application (server deployment).

Prerequisites
Install PostgreSQL Server

This post assumes that you already have PostgreSQL 9.2 and above installed on your
system. Otherwise, follow the post: How To Install PostgreSQL 11 / 10 on CentOS 7 /
RHEL 7.

Set up EPEL Repository

We would need to enable the EPEL repository to download dependent packages for
pgAdmin.

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-


7.noarch.rpm
Set up PostgreSQL Repository

pgAdmin 4 is available in PostgreSQL repository and your system should have the
PostgreSQL repository by now if you have already completed the installation of
PostgreSQL. If not, add the PostgreSQL repository using the below command.

### PostgreSQL 11 ###


# RHEL 7 #
yum install
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-
x86_64/pgdg-redhat11-11-2.noarch.rpm

# CentoS 7 #
yum install
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-
x86_64/pgdg-centos11-11-2.noarch.rpm

# Fedora 29 #
dnf install
https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-29-
x86_64/pgdg-fedora11-11-2.noarch.rpm

# Fedora 28 #
dnf install
https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-28-
x86_64/pgdg-fedora11-11-2.noarch.rpm

### PostgreSQL 10 ##

# RHEL 7 #
yum install
https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-
x86_64/pgdg-redhat10-10-2.noarch.rpm

# CentoS 7 #
yum install
https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-
x86_64/pgdg-centos10-10-2.noarch.rpm

# Fedora 29 #
dnf install
https://download.postgresql.org/pub/repos/yum/10/fedora/fedora-29-
x86_64/pgdg-fedora10-10-4.noarch.rpm

# Fedora 28 #
dnf install
https://download.postgresql.org/pub/repos/yum/10/fedora/fedora-28-
x86_64/pgdg-fedora10-10-4.noarch.rpm
Install pgAdmin 4

Once you have PostgreSQL repository configured on your system, run the following
command to install pgAdmin 4.

### RHEL / CentOS ###

yum -y install pgadmin4

### Fedora ###

dnf -y install pgadmin4

Start and enable httpd service.

systemctl start httpd


systemctl enable httpd
Configure pgAdmin 4

We would need to do a few configuration changes prior to accessing the pgAdmin 4.

Copy the pgAdmin 4 sample configuration.

cp /etc/httpd/conf.d/pgadmin4.conf.sample
/etc/httpd/conf.d/pgadmin4.conf

Create a pgAdmin log and data directories.

mkdir /var/log/pgadmin4/
mkdir /var/lib/pgadmin4/

Create/Edit config_local.py file.

vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_local.py

Add the following settings.

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

Change permissions of directories so that Apache can write data into it.

chown -R apache:apache /var/lib/pgadmin4/*


chown -R apache:apache /var/log/pgadmin4/*
Run the following command to create a user account for the pgAdmin 4 web interface.
python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py

Output:

NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin
user account:

Email address: [email protected]


Password: xxxxxxxxx
Retype password: xxxxxxxxx
pgAdmin 4 - Application Initialisation
======================================

Restart the Apache web service.

systemctl restart httpd


Firewall

Set up the firewall so that we can access pgAdmin 4 from external machines.

firewall-cmd --permanent --add-service=http


firewall-cmd --reload
SELinux

Consider disabling SELinux permanently for pgAdmin 4 to work properly.

Access pgAdmin 4

Open a web browser and go to the following URL to access the pgAdmin 4 interface.

http://ip.add.re.ss/pgadmin4

Log in to pgAdmin 4 web interface using the email address and password you have
created earlier.

Install pgAdmin 4 on CentOS 7 – pgAdmin Login Screen

Upon successful login, you should see the pgAdmin 4 interface.


Install pgAdmin 4 on CentOS 7 – pgAdmin Home Page

To manage a PostgreSQL server, you will need to add a new server. Click on Add New
Server.

General Tab:

Name:- Name your PostgreSQL Server

Install pgAdmin 4 on CentOS 7 – Add New PostgreSQL Instance

Connection Tab:

Hostname/address:- Hostname or IP Address of PostgreSQL server


Port:- 5432 (Leave default) – Change it if required
Username:- Username by which you are connecting. In my case, it is postgres.
Password:- Password for the user
Install pgAdmin 4 on CentOS 7 – PostgreSQL Instance Details

Click Save to save the changes.

If the connection to PostgreSQL server is successful, you should see the following page.

Install pgAdmin 4 on CentOS 7 – Database Statistics

Troubleshooting

You may get a Fatal: Ident authentication failed for user error.
Install pgAdmin 4 on CentOS 7 – PostgreSQL Error

To fix the issue, edit pg_hba.conf file.

### PostgreSQL 11 ###

vi /var/lib/pgsql/11/data/pg_hba.conf

### PostgreSQL 10 ###

vi /var/lib/pgsql/11/data/pg_hba.conf

Update the below line shown like below.

# TYPE DATABASE USER ADDRESS METHOD

host all all all md5

Restart the PostgreSQL service.

### PostgreSQL 11 ###

systemctl restart postgresql-11

### PostgreSQL 10 ###

systemctl restart postgresql-10


Conclusion

You have successfully installed pgAdmin 4 on CentOS 7 / RHEL 7 & Fedora 29 /


Fedora 28 and added one of your PostgreSQL instances to it to manage the database.
pgAdmin 4 is similar to phpPgAdmin in terms of managing PostgreSQL databases. You
can visit pgAdmin 4 documentation for more information.

How to Install pgAdmin4 in CentOS 7


https://www.tecmint.com/install-pgadmin4-in-centos-7/
by Marin Todorov | Published: December 20, 2018 | Last Updated: May 2, 2019

PgAdmin4 is a easy to use web interface for managing PostgreSQL databases. It can be
used on multiple platforms such as Linux, Windows and Mac OS X. In pgAdmin 4
there is migration from bootstrap 3 to bootstrap 4.

In this tutorial we are going to install pgAdmin 4 on a CentOS 7 system.

Note: This tutorial assumes that you already have PostgreSQL 9.2 or above installed on
your CentOS 7. For instructions how to install it, you can follow our guide: How to
install PostgreSQL 10 on CentOS and Fedora.

How to Install pgAdmin 4 in CentOS 7

This step should have been completed upon the installation of PostgreSQL, but if you
haven’t, you can complete it with:

# yum -y install
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-
x86_64/pgdg-centos11-11-2.noarch.rpm

Now you are ready to install pgAdmin with:

# yum -y install pgadmin4

During the installation, due to dependencies, the following two will be installed as well
– pgadmin4-web and httpd web server.

How to Configure pgAdmin 4 in CentOS 7

There are few minor configuration changes that need to be done to have pgAdmin4
running. First we will rename the sample conf file from pgadmin4.conf.sample to
pgadmin4.conf:

# mv /etc/httpd/conf.d/pgadmin4.conf.sample
/etc/httpd/conf.d/pgadmin4.conf

Adjust the file so it looks like this:

<VirtualHost *:80>
LoadModule wsgi_module modules/mod_wsgi.so
WSGIDaemonProcess pgadmin processes=1 threads=25
WSGIScriptAlias /pgadmin4 /usr/lib/python2.7/site-packages/pgadmin4-
web/pgAdmin4.wsgi

<Directory /usr/lib/python2.7/site-packages/pgadmin4-web/>
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
</VirtualHost>

Next we will create logs and lib directories for pgAdmin4 and set their ownership:

# mkdir -p /var/lib/pgadmin4/
# mkdir -p /var/log/pgadmin4/
# chown -R apache:apache /var/lib/pgadmin4
# chown -R apache:apache /var/log/pgadmin4

And then we can extend the contents of our config_distro.py.

# vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_distro.py

And add the following lines:

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

Finally we will create our user account, with which we will authenticate in the web
interface. To do this, run:

# python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py

Create PgAdmin4 User

Now you can access your server’s http://ip-address/pgadmin4 or


http://localhost/pgadmin4 to reach the pgAdmin4 interface:

PgAdmin4 Login
If you receive 403 error while accessing PgAdmin4 interface, you need to set the
correct SELinux context on the following files.

# chcon -t httpd_sys_rw_content_t /var/log/pgadmin4 -R


# chcon -t httpd_sys_rw_content_t /var/lib/pgadmin4 -R

To authenticate, use the email address and password that you have used earlier. Once
authenticate, you should see the pgAdmin4 interface:

PgAdmin4 Dashboard

At your first login, you will need to add a new server to manage. Click on “Add New
Server”. You will need to configure the PostgresQL connection. In the first tab
“General”, enter the following settings:

 Name – give name of the server you are configuring.


 Comment – leave a comment to give description of the instance.

Add New Server to PgAdmin4

The second tab “Connection” is more important one, as you will have to enter:

 Host – host/IP address of the PostgreSQL instance.


 Port – default port is 5432.
 Maintenance database – this should be postgres.
 Username – the username which will be connecting. You can use postgres user.
 Password – password for the above user.

PgAdmin4 Server Connection Settings

When you have filled everything, Save the changes. If the connection was successful,
you should see the following page:

PgAdmin4 Database Summary


This was it. Your pgAdmin4 installation is complete and you can start managing your
PostgreSQL database.

You might also like