<\/span><\/h2>\r\n\r\n\r\n\r\nFirst, log in to your Debian 10 server via SSH as the root user:<\/p>\r\n\r\n\r\n\r\n
ssh root@IP_Address -p Port_number<\/pre>\r\n\r\n\r\n\r\nOnce logged in, update your system packages with the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get update -y<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 2: Install PostgreSQL<\/span><\/h2>\r\n\r\n\r\n\r\nBefore installing pgAdmin4, the PostgreSQL server must be installed on your server. If not installed you can install it using the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get install postgresql -y<\/pre>\r\n\r\n\r\n\r\nAfter installing PostgreSQL, start the PostgreSQL service and enable it to start at system reboot:<\/p>\r\n\r\n\r\n\r\n
systemctl start postgresql\r\nsystemctl enable postgresql<\/pre>\r\n\r\n\r\n\r\nNext, check the status of the PostgreSQL service using the command below:<\/p>\r\n\r\n\r\n\r\n
systemctl status postgresql<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
\u25cf postgresql.service - PostgreSQL RDBMS\r\n Loaded: loaded (\/lib\/systemd\/system\/postgresql.service; enabled; vendor preset: enabled)\r\n Active: active (exited) since Sat 2021-04-17 05:44:16 UTC; 18s ago\r\n Main PID: 2174 (code=exited, status=0\/SUCCESS)\r\n Tasks: 0 (limit: 2359)\r\n Memory: 0B\r\n CGroup: \/system.slice\/postgresql.service\r\n\r\nApr 17 05:44:16 debian10 systemd[1]: Starting PostgreSQL RDBMS...\r\nApr 17 05:44:16 debian10 systemd[1]: Started PostgreSQL RDBMS.\r\n<\/pre>\r\n\r\n\r\n\r\nBy default, PostgreSQL listens on port 5432. You can check it using the following command:<\/p>\r\n\r\n\r\n\r\n
ss -antpl | grep 5432<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* users:((\"postgres\",pid=2505,fd=5)) \r\nLISTEN 0 128 [::1]:5432 [::]:* users:((\"postgres\",pid=2505,fd=3)) \r\n<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 3: Create a PostgreSQL Database and User<\/span><\/h2>\r\n\r\n\r\n\r\nNext, connect to the PostgreSQL shell and create a database and user:<\/p>\r\n\r\n\r\n\r\n
su - postgres\r\npsql<\/pre>\r\n\r\n\r\n\r\nOnce you are connected, create a user and database with the following command:<\/p>\r\n\r\n\r\n\r\n
postgres= CREATE USER pguser WITH PASSWORD 'password';\r\npostgres= CREATE DATABASE pgdb;<\/pre>\r\n\r\n\r\n\r\nNext, grant all the privileges to PostgreSQL database with the following command:<\/p>\r\n\r\n\r\n\r\n
postgres= GRANT ALL PRIVILEGES ON DATABASE pgdb to pguser;<\/pre>\r\n\r\n\r\n\r\nNext, exit from the PostgreSQL shell with the following command:<\/p>\r\n\r\n\r\n\r\n
postgres= \\q\r\nexit<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 4: Configure PostgreSQL Client Authentication<\/span><\/h2>\r\n\r\n\r\n\r\nBy default, PostgreSQL uses client authentication to control the database connections. You can change it by editing the file \/etc\/postgresql\/11\/main\/pg_hba.conf.<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/postgresql\/11\/main\/pg_hba.conf<\/pre>\r\n\r\n\r\n\r\nChange the following lines:<\/p>\r\n\r\n\r\n\r\n
host all all 127.0.0.1\/32 md5\r\nhost all all ::1\/128 md5\r\n<\/pre>\r\n\r\n\r\n\r\nSave and close the file then restart the PostgreSQL service to apply the changes:<\/p>\r\n\r\n\r\n\r\n
systemctl restart postgresql<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 5: Install pgAdmin4<\/span><\/h2>\r\n\r\n\r\n\r\nBy default, pgAdmin4 is not included in the Debian 10 default repository. So you will need to add the pgAdmin4 repository to the APT.<\/p>\r\n\r\n\r\n\r\n
First, install all the required dependencies using the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get install curl gnupg2 -y<\/pre>\r\n\r\n\r\n\r\nOnce all the dependencies are installed, download and add the GPG key with the following command:<\/p>\r\n\r\n\r\n\r\n
curl https:\/\/www.pgadmin.org\/static\/packages_pgadmin_org.pub | apt-key add<\/pre>\r\n\r\n\r\n\r\nNext, add the pgAdmin4 repository using the following command:<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/apt\/sources.list.d\/pgdg.list<\/pre>\r\n\r\n\r\n\r\nAdd the following line:<\/p>\r\n\r\n\r\n\r\n
deb https:\/\/ftp.postgresql.org\/pub\/pgadmin\/pgadmin4\/apt\/buster pgadmin4 main\r\n<\/pre>\r\n\r\n\r\n\r\nNext, update the repository cache and install the latest version of pgAdmin4 with the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get update\r\napt-get install pgadmin4<\/pre>\r\n\r\n\r\n\r\nNext, you will need to run a web setup script to configure the system to run in web mode. You can run it using the following command;<\/p>\r\n\r\n\r\n\r\n
\/usr\/pgadmin4\/bin\/setup-web.sh<\/pre>\r\n\r\n\r\n\r\nYou will be asked to provide your Email and password to finish the configuration as shown below:<\/p>\r\n\r\n\r\n\r\n
Setting up pgAdmin 4 in web mode on a Debian based platform...\r\nCreating configuration database...\r\nNOTE: Configuring authentication for SERVER mode.\r\n\r\nEnter the email address and password to use for the initial pgAdmin user account:\r\n\r\nEmail address: admin@your-domain.com\r\nPassword: \r\nRetype password:\r\npgAdmin 4 - Application Initialisation\r\n======================================\r\n\r\nCreating storage and log directories...\r\nWe can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at \/pgadmin4. Do you wish to continue (y\/n)? y\r\nThe Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y\/n)? y\r\nApache successfully restarted. You can now start using pgAdmin 4 in web mode at http:\/\/127.0.0.1\/pgadmin4\r\n<\/pre>\r\n\r\n\r\n\r\n