Databasecommandinstal
Databasecommandinstal
Once you are logged in to your server, run the following command to update your base system with
the latest available packages.
apt-get update -y
Next, download and add the PostgreSQL GPG key using the following command:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
Next, update the repository cache and install PostgreSQL 14 using the following command:
apt-get update -y
apt-get install postgresql-14 -y
Please be aware that the configured PostgreSQL repository mentioned above is capable of
downloading the most recent version of PostgreSQL. As of this update, PostgreSQL is operating on
version 15, with the release of version 16 imminent. To ensure the installation of the latest version
at any time, modify the command above as follows:
apt-get -y install postgresql
After installing PostgreSQL, check the status of the PostgreSQL with the following command:
systemctl status postgresql
You can also verify the PostgreSQL version using the command below:
sudo -u postgres psql -c "SELECT version();"
postgres=#
Save and close the file, then restart the PostgreSQL service to apply the changes:
systemctl restart postgresql
You can now check the PostgreSQL listening port using the following command:
ss -antpl | grep 5432
You will get the following output:
LISTEN 0 244 0.0.0.0:5432 0.0.0.0:*
users:(("postgres",pid=19030,fd=5))
LISTEN 0 244 [::]:5432 [::]:*
users:(("postgres",pid=19030,fd=6))
Now, go to the remote system and connect to the PostgreSQL instance using the following
command:
psql 'postgres://root:securepassword@104.245.34.223:5432/postgres?sslmode=disable'
postgres=#
3. Install pgAdmin 4
Install all required dependencies for pgAdmin 4 installation.
$ sudo apt-get install curl gnupg2 -y
Configure the web mode. You'll be required to enter an email address and a password for later login.
$ sudo /usr/pgadmin4/bin/setup-web.sh
For UFW firewall configured, allow http or https traffic depending on what you are using.
$ sudo ufw allow http
$ sudo ufw allow https
Enter the preferred name of the server in the Name input section.
On the pop up dialogue box, switch to the Connection tab and enter the required fields with the
appropriate data.
1. Enter your IP address under the Host name/address.
2. Leave Port value as 5432.
3. Enter testdb under Maintenance database.
4. Enter pgadmin under Username.
5. Enter secure_password as password. Modify the secure_password value with the actual
value used in Step 1.
6. Click Save to login to the server.
After the connection is successful, go to the upper left corner of the dashboard, and you will see
your server. browse through by expanding the arrows to access your database testdb.
Conclusion
You have now successfully browsed to the database. You'll be able to see the database server
metrics on the main dashboard on graphs. You can then begin to fully manage the server and add
more databases.