8

Install pgAdmin 4 for PostgreSQL on FreeBSD 12.2

 2 years ago
source link: https://www.vultr.com/docs/install-pgadmin-4-for-postgresql-on-freebsd-12-2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
<?xml encoding="utf-8" ??>

Introduction

pgAdmin is an open-source software project for administrating and managing PostgreSQL database server that includes a graphical administration interface, an SQL query tool, and a procedural code debugger. This guide explains how to install pgAdmin 4 on FreeBSD 12.2.

Prerequisites

1. Configure PostgreSQL

  1. Access the PostgreSQL instance.

    $ sudo su - postgres
    
  2. Modify the default user postgres password.

    psql -c "alter user postgres with password 'yourPassword'"
    
  3. Create user pgadmin.

    createuser pgadmin
    
  4. Create a testdb database owned by user pgadmin.

    createdb testdb -O pgadmin
    
  5. Exit the PostgreSQL instance

    exit
    

2. Install pgAdmin 4

  1. Create a symbolic link of Python3.8 binary to /usr/local/bin/python.

    $ sudo ln -s /usr/local/bin/python3.8 /usr/local/bin/python
    
  2. Install and upgrade pip, which is a package manager for Python.

    $ sudo pkg install py38-pip
    $ sudo pip install --upgrade pip
    
  3. Install the virtualenv package, which is used to create isolated Python environments.

    $ sudo pkg install py38-virtualenv
    
  4. Create a virtual environment for pgAdmin.

    $ virtualenv pgadmin4
    
  5. Activate the Virtual environment.

    $ . pgadmin4/bin/activate
    
  6. Install Python dependencies.

    $ sudo pip install cryptography==3.1.1 pyopenssl ndg-httpsclient pyasn1 simple-websocket
    
  7. Install Python SQLite3 package.

    $ sudo pkg install py38-sqlite3
    
  8. Download and install Python wheel package for pgAdmin. To get the latest version, go to pgAdmin wheel packages.

    $ sudo pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v5.4/pip/pgadmin4-5.4-py3-none-any.whl
    
  9. Create the data directories and give write permissions.

    $ sudo mkdir -pv /var/lib/pgadmin
    $ sudo chmod 770 /var/lib/pgadmin
    $ sudo mkdir -pv /var/log/pgadmin
    $ sudo chmod 770 /var/log/pgadmin
    
  10. Install the nano editor.

    $ sudo pkg install nano
    
  11. Copy the pgAdmin configuration file.

    $ sudo cp ./pgadmin4/lib/python3.8/site-packages/pgadmin4/config.py ./pgadmin4/lib/python3.8/site-packages/pgadmin4/config_local.py
    
  12. Edit the configuration file.

    $ sudo nano ./pgadmin4/lib/python3.8/site-packages/pgadmin4/config_local.py
    
  13. Find the line DEFAULT_SERVER = '127.0.0.1' and change it to match the line below.

    DEFAULT_SERVER = '0.0.0.0'
    
  14. Save and exit the file.

  15. Run pgAdmin 4.

    $ sudo python pgadmin4/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py
    
  16. Enter your email address and password to create your pgAdmin administrator account.

  17. Open your browser and navigate to your server's IP address at port 5050 to access the pgAdmin 4 user interface. Use the email address and password that you set in the previous step. For example:

    http://192.0.2.11:5050
    

3. Connect to the Database Server with pgAdmin 4

  1. Go to the pgAdmin 4 web portal and click Add New Server.

    Add new server

  2. You'll be prompted with a dialog box. Enter your preferred server name in the Name field.

    Server Name

  3. Switch to the Connection tab and enter the required fields with the appropriate data.

    • Enter localhost under the Host name/address.
    • Leave Port value as 5432.
    • Enter testdb under Maintenance database.
    • Enter pgadmin under Username.
    • Enter the database password you chose in section 1.
    • Click Save to login to the server.

    Third step

  4. After a successful connection, choose your server in the upper left corner, then expand the arrows to access the testdb database.

    Fourth step

Conclusion

You have installed pgAdmin 4 for PostgreSQL Server. You can now manage your database server via the dashboard.

Want to contribute?

You could earn up to $600 by adding new articles


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK